Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

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 Space_invaders
{
public partial class Form2 : Form
{
bool goLeft, goRight;
int playerSpeed = 12;
int enemySpeed = 5;
int score = 0;
int enemyBulletTimer = 300;

PictureBox[] InvadersArray;
bool shooting;
bool isGameOver;
public Form2()
{
InitializeComponent();
}

private void Form2_Load(object sender, EventArgs e)


{

private void pictureBox1_Click(object sender, EventArgs e)


{
Form1 form= new Form1();
form.Show();
this.Close();
}

private void mainGameTimerEvent(object sender, EventArgs e)


{

private void keyisdown(object sender, KeyEventArgs e)


{
if(e.KeyCode==Keys.Left)
{ goLeft = true; }
if(e.KeyCode==Keys.Right)
{ goRight = true; }
}

private void keyisup(object sender, KeyEventArgs e)


{
if (e.KeyCode == Keys.Left)
{ goLeft = false; }
if (e.KeyCode == Keys.Right)
{ goRight = false; }
if(e.KeyCode==Keys.Space && shooting==false)
{
shooting = true;
makeBullet();
}
if(e.KeyCode==Keys.Enter&&isGameOver==true)
{
removeAll();
gameSetup();
}
}
private void makeInvaders()
{
InvadersArray = new PictureBox[15];
int left = 0;
for(int i=0;i<InvadersArray.Length;i++)
{
InvadersArray[i] = new PictureBox();
InvadersArray[i].Size = new Size(69, 50);
InvadersArray[i].Image = Properties.Resources.Space_invaders_alien1;
InvadersArray[i].Top = 5;
InvadersArray[i].Tag = "Invaders";
InvadersArray[i].Left=left;
InvadersArray[i].SizeMode = PictureBoxSizeMode.Normal;
this.Controls.Add(InvadersArray[i]);
left = left - 80;
}
}
private void gameSetup()
{
txtScore.Text = "Score:0";
score = 0;
isGameOver= false;
enemyBulletTimer = 300;
enemySpeed = 5;
shooting= false;
makeInvaders();
gameTimer.Start();
}
private void gameOver(string message)
{
isGameOver = true;
gameTimer.Stop();
txtScore.Text = "Score" + score+" "+message;
}
private void removeAll()
{

}
private void makeBullet(string bulletTag)
{
PictureBox bullet=new PictureBox();
bullet
}
}
}

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 Space_invaders
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void pictureBox1_Click(object sender, EventArgs e)


{

Form2 form2= new Form2();


form2.Show();
this.Hide();
}

private void pictureBox3_Click(object sender, EventArgs e)


{
this.Close();
}
}
}

You might also like