/// <summary> /// Show hit animation and play hit sound effect /// </summary> /// <param name="row">Row which was hit</param> /// <param name="column">Column which was hit</param> /// <param name="showAnimation">Weather to show the hit animation</param> private static void PlayHitSequence(int row, int column, bool showAnimation) { if (showAnimation) { UtilityFunctions.AddExplosion(row, column); } if (Extentions.MusicPlaying == true) { Audio.PlaySoundEffect(GameResources.GetSound("Hit")); } else if (Extentions.MusicPlaying == false) { } UtilityFunctions.DrawAnimationSequence(); }
/// <summary> /// The user has clicked somewhere on the screen, check if its is a deployment and deploy /// the current ship if that is the case. /// </summary> /// <remarks> /// If the click is in the grid it deploys to the selected location /// with the indicated direction /// </remarks> private static void DoDeployClick() { Point2D mouse = SwinGame.MousePosition(); // Calculate the row/column clicked int row = Convert.ToInt32(Math.Floor((mouse.Y - UtilityFunctions.FIELD_TOP) / (UtilityFunctions.CELL_HEIGHT + UtilityFunctions.CELL_GAP))); int col = Convert.ToInt32(Math.Floor((mouse.X - UtilityFunctions.FIELD_LEFT) / (UtilityFunctions.CELL_WIDTH + UtilityFunctions.CELL_GAP))); if (row >= 0 & row < GameController.HumanPlayer.PlayerGrid.Height) { if (col >= 0 & col < GameController.HumanPlayer.PlayerGrid.Width) { // If in the area try to deploy try { GameController.HumanPlayer.PlayerGrid.MoveShip(row, col, _selectedShip, _currentDirection); } catch (Exception ex) { Audio.PlaySoundEffect(GameResources.GetSound("Error")); UtilityFunctions.Message = ex.Message; } } } }
/// <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 = _myGame.Player == HumanPlayer; if (isHuman) { UtilityFunctions.Message = "You " + result.ToString(); } else { UtilityFunctions.Message = "The _ai " + result.ToString(); } switch (result.Value) { case ResultOfAttack.Destroyed: { PlayHitSequence(result.Row, result.Column, isHuman); if (Extentions.MusicPlaying == true) { Audio.PlaySoundEffect(GameResources.GetSound("Sink")); } else if (Extentions.MusicPlaying == false) { } break; } case ResultOfAttack.GameOver: { PlayHitSequence(result.Row, result.Column, isHuman); Audio.PlaySoundEffect(GameResources.GetSound("Sink")); while (Audio.SoundEffectPlaying(GameResources.GetSound("Sink"))) { SwinGame.Delay(10); SwinGame.RefreshScreen(); } if (HumanPlayer.IsDestroyed) { if (Extentions.MusicPlaying == true) { Audio.PlaySoundEffect(GameResources.GetSound("Lose")); } } else { if (Extentions.MusicPlaying == true) { Audio.PlaySoundEffect(GameResources.GetSound("Winner")); } } break; } case ResultOfAttack.Hit: { PlayHitSequence(result.Row, result.Column, isHuman); break; } case ResultOfAttack.Miss: { PlayMissSequence(result.Row, result.Column, isHuman); break; } case ResultOfAttack.ShotAlready: { if (Extentions.MusicPlaying == true) { Audio.PlaySoundEffect(GameResources.GetSound("Error")); } break; } } }