void GameResult(string result) { IntersectionsDetecter.Stop(); TimeWatcher.Stop(); EnemiesMover.Stop(); RandomEnemyBullets.Stop(); Form2 f = new Form2(result); f.Show(); }
private void IntersectionsDetecter_Tick(object sender, EventArgs e) { int CEnemies = Enemies.Count(); int CShipBullets = ShipBullets.Count(); int CEnemiesBullets = EnemiesBullets.Count(); for (int i = 0; i < CEnemies; i++) { for (int j = 0; j < CShipBullets; j++) { if (CEnemies == 0 || CShipBullets == 0) { break; } else if (Enemies[i].Bounds.IntersectsWith(ShipBullets[j].Bounds)) { ScoreUpdater(Enemies[i]); Enemies[i].Dispose(); ShipBullets[j].Dispose(); Enemies.Remove(Enemies[i]); ShipBullets.Remove(ShipBullets[j]); SoundPlayer player = new SoundPlayer(MaterialsDoc + @"\Sound\Explosion.wav"); player.Play(); CEnemies--; if (i - 1 >= 0) { i--; } if (j - 1 >= 0) { j--; } CShipBullets--; } } } CEnemiesBullets = EnemiesBullets.Count(); if (Level == 2) { for (int i = 0; i < CEnemiesBullets; i++) { for (int j = 0; j < CShipBullets; j++) { if (EnemiesBullets.Count() == 0 || CShipBullets == 0) { break; } if (EnemiesBullets[i].Bounds.IntersectsWith(ShipBullets[j].Bounds)) { ScoreUpdater(EnemiesBullets[i]); EnemiesBullets[i].Dispose(); ShipBullets[j].Dispose(); EnemiesBullets.Remove(EnemiesBullets[i]); ShipBullets.Remove(ShipBullets[j]); SoundPlayer player = new SoundPlayer(MaterialsDoc + @"\Sound\Explosion.wav"); player.Play(); CEnemiesBullets--; if (i - 1 >= 0) { i--; } if (j - 1 >= 0) { j--; } CShipBullets--; } } } CEnemiesBullets = EnemiesBullets.Count(); for (int i = 0; i < CEnemiesBullets; i++) { if (EnemiesBullets[i].Bounds.IntersectsWith(SpaceShip.Bounds)) { EnemiesMover.Stop(); BulletChecker.Stop(); IntersectionsDetecter.Stop(); RandomEnemyBullets.Stop(); WinOrLose.Stop(); GameResult("Loser"); break; } } } if (Enemies.Count == 0 && Level == 1) { EnemiesPictureBoxesMaker(); EnemiesSpawner(); } }
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(); } } }