Esempio n. 1
0
    /// <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>
    protected 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(ScreenController.IsMouseInRectangle(btnLeft, btnTop, BUTTON_WIDTH, BUTTON_HEIGHT));
    }
Esempio n. 2
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 virtual void HandleDeploymentInput()
    {
        if (SwinGame.KeyTyped(KeyCode.vk_ESCAPE))
        {
            _controller.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))
        {
            _controller.HumanPlayer.RandomizeDeployment();
        }

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

            if (_controller.HumanPlayer.ReadyToDeploy && ScreenController.IsMouseInRectangle(PLAY_BUTTON_LEFT, TOP_BUTTONS_TOP, PLAY_BUTTON_WIDTH, TOP_BUTTONS_HEIGHT))
            {
                _controller.EndDeployment();
            }
            else if (ScreenController.IsMouseInRectangle(UP_DOWN_BUTTON_LEFT, TOP_BUTTONS_TOP, DIR_BUTTONS_WIDTH, TOP_BUTTONS_HEIGHT))
            {
                _currentDirection = Direction.LeftRight;
            }
            else if (ScreenController.IsMouseInRectangle(LEFT_RIGHT_BUTTON_LEFT, TOP_BUTTONS_TOP, DIR_BUTTONS_WIDTH, TOP_BUTTONS_HEIGHT))
            {
                _currentDirection = Direction.LeftRight;
            }
            else if (ScreenController.IsMouseInRectangle(RANDOM_BUTTON_LEFT, TOP_BUTTONS_TOP, RANDOM_BUTTON_WIDTH, TOP_BUTTONS_HEIGHT))
            {
                _controller.HumanPlayer.RandomizeDeployment();
            }
        }
    }
Esempio n. 3
0
    /// <summary>
    /// Gets the ship that the mouse is currently over in the selection panel.
    /// </summary>
    /// <returns>The ship selected or none</returns>
    protected static ShipName GetShipMouseIsOver()
    {
        foreach (ShipName sn in Enum.GetValues(typeof(ShipName)))
        {
            int i = Convert.ToInt32(Math.Floor(Convert.ToDouble(sn)) - 1);

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

        return(ShipName.None);
    }