private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     labelCountShots.Content = BattleShipDB.SelectCountShots();
     labelCountHits.Content  = BattleShipDB.SelectCountHits();
     labelCountGame.Content  = BattleShipDB.SelectCountGame();
     labelCountWins.Content  = BattleShipDB.SelectCountWins();
     labelCountKill.Content  = BattleShipDB.SelectCountKill();
 }
Ejemplo n.º 2
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;
         }
     }
 }
Ejemplo n.º 3
0
 private void buttonStartGame_Click(object sender, RoutedEventArgs e)
 {
     Group1.IsEnabled              = false;
     groupBox.IsEnabled            = false;
     groupBox1.IsEnabled           = false;
     buttonClear.IsEnabled         = false;
     buttonAutoPlacement.IsEnabled = false;
     buttonNewGame.IsEnabled       = true;
     EnemyField.ClickOnBox        += EnemyField_ClickBox;
     buttonStartGame.IsEnabled     = false;
     EnemyField.AutoPlacementShips(new Ships(beginShips));
     enemy = new EnemyAI(lvlEnemy, MyField);
     BattleShipDB.IncCountGame();
 }