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; } } }
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(); }