Sei sulla pagina 1di 4

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Jet_Fighter
{
public partial class Form1 : Form
{
int moveleft = 0;
int enemymove = 4;
Random rnd = new Random();
int bulletspeed = 8;
bool shooting = false;
int score = 0;

public Form1()
{
InitializeComponent();
enemy1.Top = -500;
enemy2.Top = -900;
bullet1.Top = -100;
bullet1.Left = -100;
bullet2.Top = -50;
bullet2.Left = -50;
player.Left = 517;
}

private void Form1_Load(object sender, EventArgs e)


{

private void label1_Click(object sender, EventArgs e)


{

private void keyisdown(object sender, KeyEventArgs e)


{
if(e.KeyCode==Keys.Left)
{
if (player.Location.X<0)
{
moveleft = 0;
}
else
{
moveleft = -10;
}
}
else if (e.KeyCode==Keys.Right)
{
if (player.Location.X>1035)
{
moveleft = 0;
}
else
{
moveleft = 10;
}
}
else if (e.KeyCode==Keys.Space)
{
if(shooting==false)
{
bulletspeed = 10;
bullet1.Left = player.Left + 50;
bullet1.Top = player.Top;
bullet2.Left = player.Left + 15;
bullet2.Top = player.Top;
shooting = true;
}

}
}

private void keyisup(object sender, KeyEventArgs e)


{
if (e.KeyCode==Keys.Left)
{
moveleft = 0;
}
else if (e.KeyCode==Keys.Right)
{
moveleft = 0;
}

private void timer1_Tick(object sender, EventArgs e)


{
player.Left += moveleft;
bullet1.Top -= bulletspeed;
bullet2.Top -= bulletspeed;
enemy1.Top += enemymove;
enemy2.Top += enemymove;
scoretext.Text = "" + score;
if(enemy1.Top==660 || enemy2.Top==660)
{
gameOver();
}
else if (player.Bounds.IntersectsWith(enemy1.Bounds))
{
gameOver();
}
else if (player.Bounds.IntersectsWith(enemy2.Bounds))
{
gameOver();
}
if (shooting && bullet1.Top<0 ||bullet2.Top<0)
{
shooting = false;
bulletspeed = 0;
bullet1.Top = -100;
bullet1.Left = -100;
}
else if(shooting && bullet2.Top<0)
{
shooting = false;
bulletspeed = 0;
bullet2.Top = -50;
bullet2.Left = -50;
}

enemyHit();
}
private void enemyHit()
{
player.Bounds.IntersectsWith(enemy1.Bounds);
if (bullet1.Bounds.IntersectsWith(enemy1.Bounds))
{
score += 1;
enemy1.Top = -500;
int ranP = rnd.Next(1, 300);
enemy1.Left = ranP;
shooting = false;
bulletspeed = 0;
bullet1.Top = -100;
bullet1.Left = -100;
}
else if (bullet1.Bounds.IntersectsWith(enemy2.Bounds))
{
score += 1;
enemy2.Top = -900;
int ranP = rnd.Next(1, 400);
enemy2.Left = ranP;
shooting = false;
bulletspeed = 0;
bullet1.Top = -100;
bullet1.Left = -100;
}
if (bullet2.Bounds.IntersectsWith(enemy1.Bounds))
{
score += 1;
enemy1.Top = -500;
int ranP = rnd.Next(1, 300);
enemy1.Left = ranP;
shooting = false;
bulletspeed = 0;
bullet2.Top = -50;
bullet2.Left = -50;
}
else if (bullet2.Bounds.IntersectsWith(enemy2.Bounds))
{
score += 1;
enemy2.Top = -900;
int ranP = rnd.Next(1, 400);
enemy2.Left = ranP;
shooting = false;
bulletspeed = 0;
bullet2.Top = -50;
bullet2.Left = -50;
}
}
private void gameOver()
{
timer1.Enabled = false;
MessageBox.Show("Your Score =" + score + "Click OK to Play Again");
score = 0;
scoretext.Text = "0";
enemy1.Top = -500;
enemy2.Top = -900;
bullet1.Top = -100;
bullet1.Left = -100;
bullet2.Top = -50;
bullet2.Left = -50;
timer1.Enabled = true;
player.Left = 517;
}
}
}