/* * 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. * * Remarks: * If the click is in the grid it deploys to the selected location * with the indicated direction */ private static void DoDeployClick() { Point2D mouse = default(Point2D); mouse = SwinGame.MousePosition(); //Calculate the row/col clicked int _row = 0; int _col = 0; _row = Convert.ToInt32(Math.Floor((mouse.Y - UtilityFunctions.FIELD_TOP) / (UtilityFunctions.CELL_HEIGHT + UtilityFunctions.CELL_GAP))); _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) { UtilityFunctions.PlaySFX("Error"); UtilityFunctions.Message = ex.Message; } } } }
/* * Summary: Listens for attacks to be completed. * Sender: the game * Result: the result of the attack * Remarks: Displays a message, plays sound and redraws the screen */ private static void AttackCompleted(object sender, AttackResult result) { bool isHuman = false; isHuman = object.ReferenceEquals(_theGame.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); UtilityFunctions.PlaySFX("Sink"); break; case ResultOfAttack.GameOver: PlayHitSequence(result.Row, result.Column, isHuman); UtilityFunctions.PlaySFX("Sink"); while (Audio.SoundEffectPlaying(GameResources.GameSound("Sink"))) { SwinGame.Delay(10); SwinGame.RefreshScreen(); } if (HumanPlayer.IsDestroyed) { UtilityFunctions.PlaySFX("Lose"); } else { UtilityFunctions.PlaySFX("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: UtilityFunctions.PlaySFX("Error"); break; } }
// Summary: Plays the hit sound effect and potentially draws the animation of a succesful hit private static void PlayHitSequence(int row, int column, bool showAnimation) { if (showAnimation) { UtilityFunctions.AddExplosion(row, column); } UtilityFunctions.PlaySFX("Hit"); UtilityFunctions.DrawAnimationSequence(); }
// Summary: Plays the miss sound effect and potentially draws the animation of a miss private static void PlayMissSequence(int row, int column, bool showAnimation) { if (showAnimation) { UtilityFunctions.AddSplash(row, column); } UtilityFunctions.PlaySFX("Miss"); UtilityFunctions.DrawAnimationSequence(); }