using System;
using System.Windows.Forms;
namespace OdevProje
{
public partial class Form1 : Form
{
int moveLeft = 0;
int enemyMove = 1;
Random rnd = new Random();
int bulletSpeed = 15;
bool shooting = false;
bool basildimi = false;
public Form1()
{
InitializeComponent();
dusman1.Top = -500;
dusman2.Top = -550;
dusman3.Top = -590;
dusman4.Top = -400;
dusman5.Top = -340;
dusman6.Top = -200;
dusman7.Top = -380;
mermer.Top = -100;
mermer.Left = -100;
}
private void tusaBasldgnda(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Right)
{
tabanca.Left += 18;
if (tabanca.Left >= 937)
{
tabanca.Left = 937;
}
}
if (e.KeyData == Keys.Left)
{
tabanca.Left -= 8;
if (tabanca.Left <= 2)
{
tabanca.Left = 2;
}
}
else if (e.KeyCode == Keys.Space)
{
if (shooting == false)
{
bulletSpeed = 15;
mermer.Left = tabanca.Left + 10;
mermer.Top = tabanca.Top;
shooting = true;
}
}
}
private void tusBrakldgnda(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Left)
{
moveLeft = 0;
}
else if (e.KeyCode == Keys.Right)
{
moveLeft = 0;
}
}
private void oyunTimer_Tick(object sender, EventArgs e)
{
tabanca.Left += moveLeft;
mermer.Top -= bulletSpeed;
dusman1.Top += enemyMove;
dusman2.Top += enemyMove;
dusman3.Top += enemyMove;
dusman4.Top += enemyMove;
dusman5.Top += enemyMove;
dusman6.Top += enemyMove;
dusman7.Top += enemyMove;
if (dusman1.Top == 560 || dusman2.Top == 560 || dusman3.Top == 560 || dusman4.Top == 560 || dusman5.Top == 560 || dusman6.Top == 560 || dusman7.Top == 560)
{
gameOver();
}
if (shooting && mermer.Top < 0)
{
shooting = false;
bulletSpeed = 0;
mermer.Top = -100;
mermer.Left = -100;
}
enemyHit();
}
private void enemyHit()
{
if (mermer.Bounds.IntersectsWith(dusman1.Bounds))
{
dusman1.Top = -500;
int ranP = rnd.Next(1, 300);
dusman1.Left = ranP;
shooting = false;
bulletSpeed = 0;
mermer.Top = -100;
mermer.Left = -100;
}
else if (mermer.Bounds.IntersectsWith(dusman2.Bounds))
{
dusman2.Top = -650;
int ranP = rnd.Next(1, 400);
dusman2.Left = ranP;
shooting = false;
bulletSpeed = 0;
mermer.Top = -100;
mermer.Left = -100;
}
else if (mermer.Bounds.IntersectsWith(dusman3.Bounds))
{
dusman3.Top = -660;
int ranP = rnd.Next(1, 600);
dusman3.Left = ranP;
shooting = false;
bulletSpeed = 0;
mermer.Top = -100;
mermer.Left = -100;
}
else if (mermer.Bounds.IntersectsWith(dusman4.Bounds))
{
dusman4.Top = -420;
int ranP = rnd.Next(1, 630);
dusman4.Left = ranP;
shooting = false;
bulletSpeed = 0;
mermer.Top = -100;
mermer.Left = -100;
}
else if (mermer.Bounds.IntersectsWith(dusman5.Bounds))
{
dusman5.Top = -1300;
int ranP = rnd.Next(1, 620);
dusman5.Left = ranP;
shooting = false;
bulletSpeed = 0;
mermer.Top = -100;
mermer.Left = -100;
}
else if (mermer.Bounds.IntersectsWith(dusman6.Bounds))
{
dusman6.Top = -700;
int ranP = rnd.Next(1, 600);
dusman6.Left = ranP;
shooting = false;
bulletSpeed = 0;
mermer.Top = -100;
mermer.Left = -100;
}
else if (mermer.Bounds.IntersectsWith(dusman7.Bounds))
{
dusman7.Top = -680;
int ranP = rnd.Next(1, 600);
dusman7.Left = ranP;
shooting = false;
bulletSpeed = 0;
mermer.Top = -100;
mermer.Left = -100;
}
}
private void gameOver()
{
oyunTimer.Enabled = false;
MessageBox.Show(" Click OK to play Again");
dusman1.Top = -500;
dusman2.Top = -650;
dusman3.Top = -660;
dusman4.Top = -420;
dusman5.Top = -700;
dusman6.Top = -680;
dusman7.Top = 720;
mermer.Top = -100;
mermer.Left = -100;
oyunTimer.Enabled = true;
}
}
}