Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PictureBox bg;
- PictureBox[] bullet;
- PictureBox[][] pix;
- Boolean[][] isLocked;
- PictureBox[][] enemy;
- int bulletCount = 1000;
- int enemyCount = 10;
- private void Form1_Load(object sender, EventArgs e)
- {
- pix = new PictureBox[3][];
- isLocked = new Boolean[3][];
- enemy = new PictureBox[3][];
- bg = new PictureBox();
- this.Controls.Add(bg);
- bg.SizeMode = PictureBoxSizeMode.StretchImage;
- bg.SetBounds(0, 100, this.Width, this.Height - 100);
- bullet = new PictureBox[bulletCount];
- for (int b = 0; b < bulletCount; b++)
- {
- bullet[b] = new PictureBox();
- bullet[b].SetBounds(0, 0, 20, 20);
- bullet[b].Visible = false;
- bullet[b].Image = Properties.Resources.bullet;
- bg.Controls.Add(bullet[b]);
- }
- for (int y = 0; y < 3; y++)
- {
- pix[y] = new PictureBox[3];
- isLocked[y] = new Boolean[3];
- enemy[y] = new PictureBox[enemyCount];
- for (int x = 0; x < 3; x++)
- {
- isLocked[y][x] = false;
- pix[y][x] = new PictureBox();
- pix[y][x].SetBounds(300 + (110 * x), 90 + (180 * y), 100, 100);
- pix[y][x].BackColor = Color.Red;
- pix[y][x].MouseClick += new MouseEventHandler(this.mA);
- pix[y][x].MouseHover += new EventHandler(this.mB);
- pix[y][x].MouseLeave += new EventHandler(this.mC);
- bg.Controls.Add(pix[y][x]);
- }
- for (int z = 0; z < enemyCount; z++)
- {
- enemy[y][z] = new PictureBox();
- enemy[y][z].Image = Properties.Resources.e1;
- bg.Controls.Add(enemy[y][z]);
- enemy[y][z].Visible = false;
- }
- }
- }
- void mA(object sender, MouseEventArgs e)
- {
- for (int y = 0; y < 3; y++)
- {
- for (int x = 0; x < 3; x++)
- {
- if (sender.Equals(pix[y][x]) & !isLocked[y][x])
- {
- pix[y][x].Image = tempImg;
- isLocked[y][x] = true;
- tempImg = null;
- }
- }
- }
- }
- void mB(object sender, EventArgs e)
- {
- for (int y = 0; y < 3; y++)
- {
- for (int x = 0; x < 3; x++)
- {
- if (sender.Equals(pix[y][x]) & !isLocked[y][x])
- {
- pix[y][x].Image = tempImg;
- }
- }
- }
- }
- void mC(object sender, EventArgs e)
- {
- for (int y = 0; y < 3; y++)
- {
- for (int x = 0; x < 3; x++)
- {
- if (sender.Equals(pix[y][x]) & !isLocked[y][x])
- {
- pix[y][x].Image = null;
- }
- }
- }
- }
- Image tempImg;
- private void place1_Click(object sender, EventArgs e)
- {
- tempImg = place1.Image;
- }
- private void place2_Click(object sender, EventArgs e)
- {
- tempImg = place2.Image;
- }
- private void place3_Click(object sender, EventArgs e)
- {
- tempImg = place3.Image;
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- for (int x = 0; x < 3; x++)
- {
- for (int z = 0; z < enemyCount; z++)
- {
- if (enemy[x][z].Visible)
- {
- enemy[x][z].Location = new Point(enemy[x][z].Location.X - 10, enemy[x][z].Location.Y);
- }
- }
- }
- }
- private void bulletMove_Tick(object sender, EventArgs e)
- {
- for (int b = 0; b < bulletCount; b++)
- {
- if (bullet[b].Visible)
- {
- bullet[b].Location = new Point(bullet[b].Location.X + 10, bullet[b].Location.Y);
- for (int y = 0; y < 3; y++)
- {
- for (int z = 0; z < enemyCount; z++)
- {
- if (bullet[b].Bounds.IntersectsWith(enemy[y][z].Bounds))
- {
- bullet[b].Visible = false;
- enemy[y][z].Visible = false;
- }
- }
- }
- }
- }
- }
- Random ran = new Random();
- private void enemyGenerate_Tick(object sender, EventArgs e)
- {
- int y = ran.Next(3);
- for (int z = 0; z < enemyCount; z++)
- {
- if (!enemy[y][z].Visible)
- {
- enemy[y][z].SetBounds(bg.Width, 90 + (180 * y), 100, 100);
- enemy[y][z].Visible = true;
- break;
- }
- }
- }
- Boolean[] isAlive = new Boolean[3];
- int bulletCtr = 0;
- private void rangeCheck_Tick(object sender, EventArgs e)
- {
- for (int y = 0; y < 3; y++)
- {
- isAlive[y] = false;
- for (int z = 0; z < enemyCount; z++)
- {
- if (enemy[y][z].Visible)
- {
- isAlive[y] = true;
- }
- }
- if (isAlive[y])
- {
- for (int x = 0; x < 3; x++)
- {
- if (isLocked[y][x])
- {
- bullet[bulletCtr].Location = new Point(pix[y][x].Location.X + pix[y][x].Width, pix[y][x].Location.Y + 40);
- bullet[bulletCtr].Visible = true;
- if (bulletCtr < bulletCount - 1)
- {
- bulletCtr++;
- }
- else
- {
- bulletCtr = 0;
- }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement