/// <summary> /// Checks the results of the attack and switches to /// Ending the Game if the result was game over. /// </summary> /// <param name="result">the result of the last /// attack</param> /// <remarks>Gets the AI to attack if the result switched /// to the AI player.</remarks> private void CheckAttackResult(AttackResult result) { switch (result.Value) { case ResultOfAttack.Miss: if (object.ReferenceEquals(_theGame.Player, ComputerPlayer)) { _playerTurn = false; AIAttack(); } else { _playerTurn = true; } break; case ResultOfAttack.GameOver: SwitchState(GameState.EndingGame); break; } }
/// <summary> /// The last shot had the following result. Child classes can use this /// to prepare for the next shot. /// </summary> /// <param name="result">The result of the shot</param> /// <param name="row">the row shot</param> /// <param name="col">the column shot</param> protected abstract void ProcessShot(int row, int col, AttackResult result);
/// <summary> /// ''' Listens for attacks to be completed. /// ''' </summary> /// ''' <param name="sender">the game</param> /// ''' <param name="result">the result of the attack</param> /// ''' <remarks> /// ''' Displays a message, plays sound and redraws the screen /// ''' </remarks> private static void AttackCompleted(object sender, AttackResult result) { bool isHuman; isHuman = _theGame.Player == HumanPlayer; if (isHuman) { Message = "You " + result.ToString(); } else { Message = "The AI " + result.ToString(); } switch (result.Value) { case object _ when ResultOfAttack.Destroyed: { PlayHitSequence(result.Row, result.Column, isHuman); Audio.PlaySoundEffect(GameSound("Sink")); break; } case object _ when ResultOfAttack.GameOver: { PlayHitSequence(result.Row, result.Column, isHuman); Audio.PlaySoundEffect(GameSound("Sink")); while (Audio.SoundEffectPlaying(GameSound("Sink"))) { SwinGame.Delay(10); SwinGame.RefreshScreen(); } if (HumanPlayer.IsDestroyed) { Audio.PlaySoundEffect(GameSound("Lose")); } else { Audio.PlaySoundEffect(GameSound("Winner")); } break; } case object _ when ResultOfAttack.Hit: { PlayHitSequence(result.Row, result.Column, isHuman); break; } case object _ when ResultOfAttack.Miss: { PlayMissSequence(result.Row, result.Column, isHuman); break; } case object _ when ResultOfAttack.ShotAlready: { Audio.PlaySoundEffect(GameSound("Error")); break; } } }
/*<summary> * Listens for attacks to be completed. *</summary> *<param name="sender">the game</param> *<param name="result">the result of the attack</param> *<remarks> * Displays a message, plays sound and redraws the screen *</remarks> */ private static void AttackCompleted(object sender, AttackResult result) { bool isHuman = (_theGame.Player == HumanPlayer); if (isHuman) { UtilityFunctions.Message = ("You " + result.ToString()); } else { UtilityFunctions.Message = ("The AI " + result.ToString()); } switch (result.Value) { case ResultOfAttack.Destroyed: GameController.PlayHitSequence(result.Row, result.Column, isHuman); if (!_mute) { Audio.PlaySoundEffect(GameResources.GameSound("Sink")); } break; case ResultOfAttack.GameOver: //potentially remove this as it gets played twice if the player wins GameController.PlayHitSequence(result.Row, result.Column, isHuman); //Audio.PlaySoundEffect(GameResources.GameSound("Sink")); while (Audio.SoundEffectPlaying(GameResources.GameSound("Sink"))) { SwinGame.Delay(10); SwinGame.RefreshScreen(); } if (HumanPlayer.IsDestroyed && !_mute) { Audio.PlaySoundEffect(GameResources.GameSound("Lose")); } else { if (!_mute) { Audio.PlaySoundEffect(GameResources.GameSound("Winner")); } } //come back here to add the letter/number coordinates break; case ResultOfAttack.Hit: GameController.PlayHitSequence(result.Row, result.Column, isHuman); break; case ResultOfAttack.Miss: GameController.PlayMissSequence(result.Row, result.Column, isHuman); break; case ResultOfAttack.ShotAlready: if (!_mute) { Audio.PlaySoundEffect(GameResources.GameSound("Error")); } break; } }
/// <summary> /// ProcessShot will be called uppon when a ship is found. /// It will create a stack with targets it will try to hit. These targets /// will be around the tile that has been hit. /// </summary> /// <param name="row">the row it needs to process</param> /// <param name="col">the column it needs to process</param> /// <param name="result">the result og the last shot (should be hit)</param> protected override void ProcessShot(int row, int col, AttackResult result) { }