コード例 #1
0
 private void MyField_ClickOnBox(object sender, ShipEventArgs e)
 {
     if (ships[TypeShip].CountShip != 0)
     {
         try
         {
             MyField.SupplyShip(e.startBox, TypeShip, orientation);
         }
         catch (IndexOutOfRangeException ex)
         {
             MessageBox.Show("Выход за границы поля!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
             return;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
             return;
         }
         ships[TypeShip].CountShip--;
     }
     else
     {
         MessageBox.Show("Такие корабли закончились!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         return;
     }
     if (ships.GetCountShips() == 0)
     {
         buttonStartGame.IsEnabled = true;
     }
 }
コード例 #2
0
ファイル: Simulation.cs プロジェクト: ArenaDave/CodeFighter
 public void ShipDestroyedHandler(object sender, ShipEventArgs e)
 {
     results.Add(new Animation(AnimationActionType.Kill, new AnimationKillDetails(e.ShipID)));
     results.Add(new Animation(AnimationActionType.Message, null, new List <string>()
     {
         "*** " + Ships.First(x => x.ID == e.ShipID).Name + " Is Destroyed! ***"
     }));
     results.Add(new Animation(AnimationActionType.ShipUpdate, new AnimationShipUpdateDetails(Ships.First(x => x.ID == e.ShipID))));
 }
コード例 #3
0
 private void EnemyField_ClickBox(object sender, ShipEventArgs e)
 {
     if (e.startBox.IsShooting)
     {
         MessageBox.Show("Вы сюда уже стреляли!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         return;
     }
     BattleShipDB.IncCountShots();
     if (e.startBox.IsBusy)
     {
         e.startBox.Hitting();
         BattleShipDB.IncCountHits();
         if (EnemyField.boxes.GetCountLivingShipsByName(e.startBox.NameShip) == 0)
         {
             MessageBox.Show("Убил", "Красавчик", MessageBoxButton.OK, MessageBoxImage.Information);
             BattleShipDB.IncCountKill();
         }
     }
     else
     {
         e.startBox.Miss();
     }
     if (EnemyField.boxes.GetCountLivingShips() == 0)
     {
         BattleShipDB.IncCountGame();
         if (MessageBox.Show("Вы победили!Хотите начать сначала?", "Поздравляю", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
         {
             buttonNewGame_Click(buttonNewGame, null);
             return;
         }
         else
         {
             this.Close();
             return;
         }
     }
     enemy.Shoot();
     if (MyField.boxes.GetCountLivingShips() == 0)
     {
         if (MessageBox.Show("Вы проиграли!Хотите начать сначала?", "Соболезнования", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
         {
             buttonNewGame_Click(buttonNewGame, null);
             return;
         }
         else
         {
             this.Close();
             return;
         }
     }
 }