Ejemplo n.º 1
0
    /// <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))
        {
            DoAttack();
        }
        if (SwinGame.KeyTyped(KeyCode.vk_b))
        {
            UtilityFunctions.ChangeBackground();
        }
        if (SwinGame.KeyTyped(KeyCode.vk_0))
        {
            SwinGame.StopMusic();
        }
        else
        {
            if (SwinGame.KeyTyped(KeyCode.vk_1))
            {
                SwinGame.PlayMusic(GameResources.GameMusic("Background"));
            }
        }
    }
Ejemplo 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 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_b))
        {
            UtilityFunctions.ChangeBackground();
        }
        if (SwinGame.KeyTyped(KeyCode.vk_s))
        {
            if (GameController.HumanPlayer.Ship(_selectedShip).CurrentShipColour == ShipColour.Blue)
            {
                GameController.HumanPlayer.Ship(_selectedShip).CurrentShipColour = ShipColour.Red;
            }
            else
            {
                GameController.HumanPlayer.Ship(_selectedShip).CurrentShipColour = ShipColour.Blue;
            }
        }

        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(PAINT_BUTTON_LEFT, TOP_BUTTONS_TOP, RANDOM_BUTTON_WIDTH, TOP_BUTTONS_HEIGHT))
            {
                if (GameController.HumanPlayer.Ship(_selectedShip).CurrentShipColour == ShipColour.Blue)
                {
                    GameController.HumanPlayer.Ship(_selectedShip).CurrentShipColour = ShipColour.Red;
                }
                else
                {
                    GameController.HumanPlayer.Ship(_selectedShip).CurrentShipColour = ShipColour.Blue;
                }
            }
        }
    }