/// <summary>
        ///     ''' Checks if the mouse is over one of the buttons in a menu.
        ///     ''' </summary>
        ///     ''' <param name="button">the index of the button to check</param>
        ///     ''' <param name="level">the level of the menu</param>
        ///     ''' <param name="xOffset">the xOffset of the menu</param>
        ///     ''' <returns>true if the mouse is over the button</returns>
        private static bool IsMouseOverMenu(int button, int level, int xOffset)
        {
            int btnTop  = MENU_TOP - (MENU_GAP + BUTTON_HEIGHT) * level;
            int btnLeft = MENU_LEFT + BUTTON_SEP * (button + xOffset);

            return(UtilityFunctions.IsMouseInRectangle(btnLeft, btnTop, BUTTON_WIDTH, BUTTON_HEIGHT));
        }
        /// <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.MouseClicked(MouseButton.LeftButton))
            {
                ShipName selected = default(ShipName);
                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();
                }
                else if (UtilityFunctions.IsMouseInRectangle(MENU_BUTTON_LEFT, MENU_BUTTON_TOP, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT))
                {
                    GameController.EndCurrentState();
                }
            }
        }
Beispiel #3
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.EscapeKey))
            {
                GameController.AddNewState(GameState.ViewingGameMenu);
            }

            if (SwinGame.KeyTyped(KeyCode.UpKey) | SwinGame.KeyTyped(KeyCode.DownKey))
            {
                _currentDirection = Direction.UpDown;
            }
            if (SwinGame.KeyTyped(KeyCode.LeftKey) | SwinGame.KeyTyped(KeyCode.RightKey))
            {
                _currentDirection = Direction.LeftRight;
            }

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

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

                // ** BUG **
                // ** Both buttons do the same thing. **
                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();
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Gets the ship that the mouse is currently over in the selection panel.
        /// </summary>
        /// <returns>The ship selected or none</returns>
        private static ShipName GetShipMouseIsOver()
        {
            foreach (ShipName sn in Enum.GetValues(typeof(ShipName)))
            {
                int i = Convert.ToInt32(Math.Floor(Convert.ToDouble(sn)) - 1);

                if (UtilityFunctions.IsMouseInRectangle(SHIPS_LEFT, SHIPS_TOP + i * SHIPS_HEIGHT, SHIPS_WIDTH, SHIPS_HEIGHT))
                {
                    return(sn);
                }
            }

            return(ShipName.None);
        }
        /// <summary>
        ///     ''' Gets the ship that the mouse is currently over in the selection panel.
        ///     ''' </summary>
        ///     ''' <returns>The ship selected or none</returns>
        private static ShipName GetShipMouseIsOver()
        {
            foreach (ShipName sn in Enum.GetValues(typeof(ShipName)))
            {
                int i;
                i = (int)sn - 1;

                if (UtilityFunctions.IsMouseInRectangle(SHIPS_LEFT, SHIPS_TOP + i * SHIPS_HEIGHT, SHIPS_WIDTH, SHIPS_HEIGHT))
                {
                    return(sn);
                }
            }

            return(ShipName.None);
        }
        /// <summary>
        /// Gets the ship that the mouse is currently over in the selection panel.
        /// </summary>
        /// <returns>The ship selected or none</returns>
        private static ShipName GetShipMouseIsOver()
        {
            foreach (ShipName sn in Enum.GetValues(typeof(ShipName)))
            {
                int i = 0;
                i = System.Convert.ToInt32(System.Convert.ToInt32(sn) - 1);

                if (UtilityFunctions.IsMouseInRectangle(SHIPS_LEFT, SHIPS_TOP + i * SHIPS_HEIGHT, SHIPS_WIDTH, SHIPS_HEIGHT))
                {
                    Ship selectedShip = new Ship(sn);
                    return(sn);
                }
            }

            return(ShipName.None);
        }
        // Selects the ship that the mouse is currently hovered over
        // in the selection panel.

        private static ShipName GetShipMouseIsOver()
        {
            foreach (ShipName sn in GameController.PlayableShips)
            // foreach (ShipName sn in Enum.GetValues(typeof(ShipName)))
            {
                int i;
                i = ((int)(sn) - 1);
                if (UtilityFunctions.IsMouseInRectangle(SHIPS_LEFT, (SHIPS_TOP
                                                                     + (i * SHIPS_HEIGHT)), SHIPS_WIDTH, SHIPS_HEIGHT))
                {
                    return(sn);
                }
            }

            return(ShipName.None);
        }
        /// <summary>
        /// Handles input during the discovery phase of the game.
        /// </summary>
        /// <remarks>
        /// Escape opens the game menu. Clicking the mouse will
        /// attack a location.
        /// </remarks>
        public static void HandleDiscoveryInput()
        {
            if (SwinGame.KeyTyped(KeyCode.vk_ESCAPE))
            {
                GameController.AddNewState(GameState.ViewingGameMenu);
            }

            if (SwinGame.MouseClicked(MouseButton.LeftButton))
            {
                if (UtilityFunctions.IsMouseInRectangle(MENU_BUTTON_LEFT, MENU_BUTTON_TOP, MENU_BUTTON_WIDTH, MENU_BUTTON_WIDTH))
                {
                    GameController.EndCurrentState();
                }
                DoAttack();
            }
        }
        /// <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);
            }

            else if (SwinGame.MouseClicked(MouseButton.LeftButton) & UtilityFunctions.IsMouseInRectangle(MENU_LEFT, MENU_TOP, MENU_WIDTH, MENU_WIDTH))
            {
                GameController.AddNewState(GameState.ViewingGameMenu);
            }

            if (SwinGame.KeyTyped(KeyCode.vk_UP))
            {
                _currentDirection = Direction.Up;
            }
            if (SwinGame.KeyTyped(KeyCode.vk_DOWN))
            {
                _currentDirection = Direction.Down;
            }
            if (SwinGame.KeyTyped(KeyCode.vk_LEFT))
            {
                _currentDirection = Direction.Left;
            }
            if (SwinGame.KeyTyped(KeyCode.vk_RIGHT))
            {
                _currentDirection = Direction.Right;
            }

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

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


                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_BUTTON_LEFT, TOP_BUTTONS_TOP, DIR_BUTTONS_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    _currentDirection = Direction.Up;
                    DoUpClick();
                }
                else if (UtilityFunctions.IsMouseInRectangle(DOWN_BUTTON_LEFT, TOP_BUTTONS_TOP, DIR_BUTTONS_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    _currentDirection = Direction.Down;
                    DoDownClick();
                }
                else if (UtilityFunctions.IsMouseInRectangle(LEFT_BUTTON_LEFT, TOP_BUTTONS_TOP, DIR_BUTTONS_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    _currentDirection = Direction.Left;
                    DoLeftClick();
                }
                else if (UtilityFunctions.IsMouseInRectangle(RIGHT_BUTTON_LEFT, TOP_BUTTONS_TOP, DIR_BUTTONS_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    _currentDirection = Direction.Right;
                    DoRightClick();
                }
                else if (UtilityFunctions.IsMouseInRectangle(RANDOM_BUTTON_LEFT, TOP_BUTTONS_TOP, RANDOM_BUTTON_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    GameController.HumanPlayer.RandomizeDeployment();
                }
                else if (UtilityFunctions.IsMouseInRectangle(MUTE_BUTTON_LEFT, MUTE_BUTTON_TOP, MUTE_BUTTON_WIDTH, MUTW_BUTTON_HEIGHT) && (Sound == true))
                {
                    SwinGame.StopMusic();
                    SwinGame.DrawText("AUDIO ON", Color.Grey, MUTE_BUTTON_LEFT, MUTE_BUTTON_TOP);
                    Sound = false;
                }
                else if (UtilityFunctions.IsMouseInRectangle(MUTE_BUTTON_LEFT, MUTE_BUTTON_TOP, MUTE_BUTTON_WIDTH, MUTW_BUTTON_HEIGHT) && (Sound == false))
                {
                    SwinGame.PlayMusic(GameResources.GameMusic("Background"));
                    SwinGame.DrawText("AUDIO OFF", Color.White, MUTE_BUTTON_LEFT, MUTE_BUTTON_TOP);
                    Sound = true;
                }
                else
                {
                    DoDeployClick();
                }
            }
        }