private void EnemiesSpawner() { if (Level == 1) { Random rnd = new Random(); for (int i = 0; i < 3; i++) { Enemies[i].Location = new Point(x_enemy, y_enemy); this.Controls.Add(Enemies[i]); x_enemy += rnd.Next(150, 400); } if (Enemies[2].Location.X > -200) { int n = Enemies[2].Location.X + 200; foreach (PictureBox box in Enemies) { box.Location = new Point(box.Location.X - n, y_enemy); } } foreach (PictureBox box in Enemies) { this.Controls.Add(box); } EnemiesMover.Start(); } else { int[] x = { 100, 400, 700, 250, 550, 850, 50, 350, 650 }; int y = 20; for (int i = 0; i < Enemies.Count(); i++) { Enemies[i].Location = new Point(x[i], y); if (i == 2 || i == 5) { y += 110; } } foreach (PictureBox box in Enemies) { this.Controls.Add(box); } EnemiesMover.Start(); } }
private void StartStopGame(object sender, EventArgs e) { if (StartStop.Text == "Start") { StartStop.Text = "Pause"; if (Level == 1) { if (start) { EnemiesSpawner(); start = false; } IntersectionsDetecter.Start(); TimeWatcher.Start(); EnemiesMover.Start(); BulletChecker.Start(); ScoreTimePan.Click += new EventHandler(BulletMaker); this.Click += new EventHandler(BulletMaker); this.KeyDown += new KeyEventHandler(Level1_KeyDown); this.ActiveControl = null; } else { if (start) { EnemiesSpawner(); start = false; } IntersectionsDetecter.Start(); EnemiesMover.Start(); BulletChecker.Start(); ScoreTimePan.Click += new EventHandler(BulletMaker); this.Click += new EventHandler(BulletMaker); this.KeyDown += new KeyEventHandler(Level1_KeyDown); this.ActiveControl = null; RandomEnemyBullets.Start(); WinOrLose.Start(); } } else { StartStop.Text = "Start"; if (Level == 1) { IntersectionsDetecter.Stop(); TimeWatcher.Stop(); EnemiesMover.Stop(); BulletChecker.Stop(); ScoreTimePan.Click -= new EventHandler(BulletMaker); this.Click -= new EventHandler(BulletMaker); this.KeyDown -= new KeyEventHandler(Level1_KeyDown); } else { IntersectionsDetecter.Stop(); EnemiesMover.Stop(); BulletChecker.Stop(); ScoreTimePan.Click -= new EventHandler(BulletMaker); this.Click -= new EventHandler(BulletMaker); this.KeyDown -= new KeyEventHandler(Level1_KeyDown); this.ActiveControl = null; RandomEnemyBullets.Stop(); WinOrLose.Stop(); } } }