Пример #1
0
        /// <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;

            mouse = SwinGame.MousePosition();

            // Calculate the row/col clicked
            int row, col;

            row = Convert.ToInt32(Math.Floor((mouse.Y - UtilityFunctions.FIELD_TOP) / (double)(UtilityFunctions.CELL_HEIGHT + UtilityFunctions.CELL_GAP))); // Did this fix it?
            col = Convert.ToInt32(Math.Floor((mouse.X - UtilityFunctions.FIELD_LEFT) / (double)(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); // Bookmark - ship is being placed wrong. When set to updown, should place from bottom of ship
                    }
                    catch (Exception ex) {
                        GameResources.PlaySound("Error");
                        UtilityFunctions.Message = ex.Message;
                    }
                }
            }
        }
Пример #2
0
        private static void PlayMissSequence(int row, int column, bool showAnimation)
        {
            if (showAnimation)
            {
                UtilityFunctions.AddSplash(row, column);
            }

            GameResources.PlaySound("Miss");

            UtilityFunctions.DrawAnimationSequence();
        }
Пример #3
0
        /// <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)
            {
                UtilityFunctions.Message = "You " + result.ToString();
            }
            else
            {
                UtilityFunctions.Message = "The AI " + result.ToString();
            }

            switch (result.Value)
            {
            case ResultOfAttack.Destroyed: {
                PlayHitSequence(result.Row, result.Column, isHuman);
                GameResources.PlaySound("Sink");
                break;
            }

            case ResultOfAttack.GameOver: {
                PlayHitSequence(result.Row, result.Column, isHuman);
                GameResources.PlaySound("Sink");

                if (HumanPlayer.IsDestroyed)
                {
                    GameResources.PlaySound("Lose");
                }
                else
                {
                    GameResources.PlaySound("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: {
                GameResources.PlaySound("Error");
                break;
            }
            }
        }
Пример #4
0
        private static void PlayHitSequence(int row, int column, bool showAnimation)
        {
            if (showAnimation)
            {
                UtilityFunctions.AddExplosion(row, column);
            }

            GameResources.PlaySound("Hit");

            UtilityFunctions.DrawAnimationSequence();
        }