/// <summary> /// The shootUpdate method controls randomly the /// shooting of the enemies. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ShootUpdate(object sender, EventArgs e) { //------------------------------- for (int i = 0; i < ships.Length; i++) { if (ships[i].IsDead() == true) { shipsNum.Remove(i); } } for (int i = 0; i < commanders.Length; i++) { if (commanders[i].IsDead() == true) { commandersNum.Remove(i); } } for (int i = 0; i < ufos.Length; i++) { if (ufos[i].IsDead() == true) { ufosNum.Remove(i); } } //-------------------------------- Random rand = new Random(); int num1 = rand.Next(ships.Length); if (shipsNum.Contains(num1)) { shipsNum.Remove(num1); exists1 = true; } if (exists1 == true) { if (ships[num1].IsDead() == true) { shipsNum.Remove(num1); } else { if (ships[num1].isShoot() == false) { ships[num1].Shoot(10); } } exists1 = false; } //------------------------------------ int num2 = rand.Next(commanders.Length); if (commandersNum.Contains(num2)) { exists2 = true; commandersNum.Remove(num2); } if (exists2 == true) { if (commanders[num2].IsDead() == true) { commandersNum.Remove(num2); } else { if (commanders[num2].isShoot() == false) { commanders[num2].Shoot(15); } } exists2 = false; } //------------------------------------ int num3 = rand.Next(ufos.Length); if (ufosNum.Contains(num3)) { exists3 = true; ufosNum.Remove(num3); } if (exists3 == true) { if (ufos[num3].IsDead() == true) { ufosNum.Remove(num3); } else { if (ufos[num3].isShoot() == false) { ufos[num3].Shoot(5); } } exists3 = false; } //---------------------------------------- if (this.enemies.Count == 0) { this.canvas.Children.Remove(lv2Pic); timerRandomShoot.Stop(); if (this.round == 1) { round++; Play(); } else { Level3 lv3 = new Level3(this.window, this.canvas, this.player); lv3.Play(); } } }
private void ShootUpdate(object sender, EventArgs e) { BackToMainWindown(); //------------------------------- for (int i = 0; i < ships.Count; i++) { if (ships[i].IsDead() == true) { arr1.Remove(i); } } for (int i = 0; i < commanders.Count; i++) { if (commanders[i].IsDead() == true) { arr2.Remove(i); } } //-------------------------------- Random rand = new Random(); int num1 = rand.Next(ships.Count);//8 if (arr1.Contains(num1)) { arr1.Remove(num1); exists1 = true; } if (exists1 == true) { if (ships[num1].IsDead() == true) { arr1.Remove(num1); } else { if (ships[num1].isShoot() == false) { ships[num1].Shoot(10); } } exists1 = false; } //------------------------------------ int num2 = rand.Next(4); if (arr2.Contains(num2)) { exists2 = true; arr2.Remove(num2); } if (exists2 == true) { if (commanders[num2].IsDead() == true) { arr2.Remove(num2); } else { if (commanders[num2].isShoot() == false) { commanders[num2].Shoot(20); } } exists2 = false; } //---------------------------------------- if (enemies.Count == 0 && currentLevel == 1) { timerRandomShoot.Stop(); Level2 lv2 = new Level2(this.window, this.canvas, this.player); lv2.setLoad(true); lv2.Play(); } else if (this.enemies.Count == 0 && currentLevel == 2) { if (round < 3) { round++; Level2 lv2 = new Level2(this.window, this.canvas, this.player); lv2.setRound(round); lv2.setLoad(true); lv2.Play(); } else { if (round == 3) { Level3 lv3 = new Level3(this.window, this.canvas, this.player); lv3.Play(); } } } }