예제 #1
0
        private static void PlayMissSequence(int row, int column, bool showAnimation)
        {
            if (showAnimation)
            {
                UtilityFunctions.AddSplash(row, column);
            }

            Audio.PlaySoundEffect(GameResources.GameSound("Miss"));

            UtilityFunctions.DrawAnimationSequence();
        }
예제 #2
0
        private static void PlayHitSequence(int row, int column, bool showAnimation)
        {
            if (showAnimation)
            {
                UtilityFunctions.AddExplosion(row, column);
            }

            Audio.PlaySoundEffect(GameResources.GameSound("Hit"));

            UtilityFunctions.DrawAnimationSequence();
        }
예제 #3
0
        private static void PlayMissSequence(int row, int column, bool showAnimation)
        {
            if (showAnimation)
            {
                UtilityFunctions.AddSplash(row, column);
            }

            if (Variables._isMute == false) //mute extension
            {
                Audio.PlaySoundEffect(GameResources.GameSound("Miss"));
            }
            UtilityFunctions.DrawAnimationSequence();
        }
예제 #4
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();
            }

            var switchExpr = result.Value;

            switch (switchExpr)
            {
            case ResultOfAttack.Destroyed:
            {
                PlayHitSequence(result.Row, result.Column, isHuman);

                if (Variables._isMute == false)     //mute extension
                {
                    Audio.PlaySoundEffect(GameResources.GameSound("Sink"));
                }

                break;
            }

            case ResultOfAttack.GameOver:
            {
                PlayHitSequence(result.Row, result.Column, isHuman);

                if (Variables._isMute == false)     //mute extension
                {
                    Audio.PlaySoundEffect(GameResources.GameSound("Sink"));
                }

                while (Audio.SoundEffectPlaying(GameResources.GameSound("Sink")))
                {
                    SwinGame.Delay(10);
                    SwinGame.RefreshScreen();
                }

                if (HumanPlayer.IsDestroyed)
                {
                    if (Variables._isMute == false)     //mute extension
                    {
                        Audio.PlaySoundEffect(GameResources.GameSound("Lose"));
                    }
                }
                else
                {
                    if (Variables._isMute == false)     //mute extension
                    {
                        Audio.PlaySoundEffect(GameResources.GameSound("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 (Variables._isMute == false)     //mute extension
                {
                    Audio.PlaySoundEffect(GameResources.GameSound("Error"));
                }
                break;
            }
            }
        }
예제 #5
0
        /// <summary>
        /// Handles user input for the Deployment phase of the game.
        /// </summary>
        /// <remarks>
        /// Involves selecting the ships, deloying ships, changing the direction
        /// of the ships to add, randomising deployment, end then ending
        /// deployment
        /// </remarks>
        public static void HandleDeploymentInput()
        {
            if (SwinGame.KeyTyped(KeyCode.vk_ESCAPE))
            {
                GameController.AddNewState(GameState.ViewingGameMenu);
            }

            if (SwinGame.KeyTyped(KeyCode.vk_UP) | SwinGame.KeyTyped(KeyCode.vk_DOWN))
            {
                _currentDirection = Direction.UpDown;
            }

            if (SwinGame.KeyTyped(KeyCode.vk_LEFT) | SwinGame.KeyTyped(KeyCode.vk_RIGHT))
            {
                _currentDirection = Direction.LeftRight;
            }

            if (SwinGame.KeyTyped(KeyCode.vk_r))
            {
                GameController.HumanPlayer.RandomizeDeployment();
            }

            if (SwinGame.KeyTyped(KeyCode.vk_a))
            {
                int  col, row;
                Ship the_ship;
                GameController.HumanPlayer._Ships.TryGetValue(_selectedShip, out the_ship);
                row = the_ship._row;
                col = the_ship._col - 1;
                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.GameSound("Error"));
                        UtilityFunctions.Message = ex.Message;
                    }
                }
            }

            if (SwinGame.KeyTyped(KeyCode.vk_w))
            {
                int  col, row;
                Ship the_ship;
                GameController.HumanPlayer._Ships.TryGetValue(_selectedShip, out the_ship);
                row = the_ship._row - 1;
                col = the_ship._col;
                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.GameSound("Error"));
                        UtilityFunctions.Message = ex.Message;
                    }
                }
            }

            if (SwinGame.KeyTyped(KeyCode.vk_d))
            {
                int  col, row;
                Ship the_ship;
                GameController.HumanPlayer._Ships.TryGetValue(_selectedShip, out the_ship);
                row = the_ship._row;
                col = the_ship._col + 1;
                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.GameSound("Error"));
                        UtilityFunctions.Message = ex.Message;
                    }
                }
            }

            if (SwinGame.KeyTyped(KeyCode.vk_s))
            {
                int  col, row;
                Ship the_ship;
                GameController.HumanPlayer._Ships.TryGetValue(_selectedShip, out the_ship);
                row = the_ship._row + 1;
                col = the_ship._col;
                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.GameSound("Error"));
                        UtilityFunctions.Message = ex.Message;
                    }
                }
            }

            if (SwinGame.MouseClicked(MouseButton.LeftButton))
            {
                ShipName selected;
                selected = GetShipMouseIsOver();
                if (selected != ShipName.None)
                {
                    _selectedShip = selected;
                }
                else
                {
                    DoDeployClick();
                }

                if (GameController.HumanPlayer.ReadyToDeploy & UtilityFunctions.IsMouseInRectangle(PLAY_BUTTON_LEFT, TOP_BUTTONS_TOP, PLAY_BUTTON_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    GameController.EndDeployment();
                }
                else if (UtilityFunctions.IsMouseInRectangle(UP_DOWN_BUTTON_LEFT, TOP_BUTTONS_TOP, DIR_BUTTONS_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    _currentDirection = Direction.UpDown;
                }
                else if (UtilityFunctions.IsMouseInRectangle(LEFT_RIGHT_BUTTON_LEFT, TOP_BUTTONS_TOP, DIR_BUTTONS_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    _currentDirection = Direction.LeftRight;
                }
                else if (UtilityFunctions.IsMouseInRectangle(RANDOM_BUTTON_LEFT, TOP_BUTTONS_TOP, RANDOM_BUTTON_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    GameController.HumanPlayer.RandomizeDeployment();
                }
            }
        }