// '' <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))
            {
                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))
            {
                HumanPlayer.RandomizeDeployment();
            }

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

                if ((HumanPlayer.ReadyToDeploy && IsMouseInRectangle(PLAY_BUTTON_LEFT, TOP_BUTTONS_TOP, PLAY_BUTTON_WIDTH, TOP_BUTTONS_HEIGHT)))
                {
                    EndDeployment();
                }
                else if (IsMouseInRectangle(UP_DOWN_BUTTON_LEFT, TOP_BUTTONS_TOP, DIR_BUTTONS_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    _currentDirection = Direction.LeftRight;
                }
                else if (IsMouseInRectangle(LEFT_RIGHT_BUTTON_LEFT, TOP_BUTTONS_TOP, DIR_BUTTONS_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    _currentDirection = Direction.LeftRight;
                }
                else if (IsMouseInRectangle(RANDOM_BUTTON_LEFT, TOP_BUTTONS_TOP, RANDOM_BUTTON_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    HumanPlayer.RandomizeDeployment();
                }
            }
        }
示例#2
0
        /// <summary>
        /// Draws the current state of the game to the screen.
        /// </summary>
        /// <remarks>
        /// What is drawn depends upon the state of the game.
        /// </remarks>
        public static void DrawScreen()
        {
            UtilityFunctions.DrawBackground();

            switch (CurrentState)
            {
            case GameState.ViewingMainMenu:
            {
                MenuController.DrawMainMenu();
                break;
            }

            case GameState.ViewingGameMenu:
            {
                MenuController.DrawGameMenu();
                break;
            }

            case GameState.AlteringSettings:
            {
                MenuController.DrawSettings();
                break;
            }

            case GameState.Deploying:
            {
                DeploymentController.DrawDeployment();
                break;
            }

            case GameState.Discovering:
            {
                DiscoveryController.DrawDiscovery();
                break;
            }

            case GameState.EndingGame:
            {
                EndingGameController.DrawEndOfGame();
                break;
            }

            case GameState.ViewingHighScores:
            {
                HighScoreController.DrawHighScores();
                break;
            }
            }

            UtilityFunctions.DrawAnimations();

            SwinGame.RefreshScreen();
        }
示例#3
0
        /// <summary>
        /// Handles the user SwinGame.
        /// </summary>
        /// <remarks>
        /// Reads key and mouse input and converts these into
        /// actions for the game to perform. The actions
        /// performed depend upon the state of the game.
        /// </remarks>
        public static void HandleUserInput()
        {
            // Read incoming input events
            SwinGame.ProcessEvents();

            switch (CurrentState)
            {
            case GameState.ViewingMainMenu:
            {
                MenuController.HandleMainMenuInput();
                break;
            }

            case GameState.ViewingGameMenu:
            {
                MenuController.HandleGameMenuInput();
                break;
            }

            case GameState.AlteringSettings:
            {
                MenuController.HandleSetupMenuInput();
                break;
            }

            case GameState.Deploying:
            {
                DeploymentController.HandleDeploymentInput();
                break;
            }

            case GameState.Discovering:
            {
                DiscoveryController.HandleDiscoveryInput();
                break;
            }

            case GameState.EndingGame:
            {
                EndingGameController.HandleEndOfGameInput();
                break;
            }

            case GameState.ViewingHighScores:
            {
                HighScoreController.HandleHighScoreInput();
                break;
            }
            }

            UtilityFunctions.UpdateAnimations();
        }
示例#4
0
        /// <summary>
        /// Draws the current state of the game to the screen.
        /// <remarks>
        /// What is drawn depends upon the state of the game.
        /// </remarks>
        /// </summary>
        public static void DrawScreen()
        {
            UtilityFunctions.DrawBackground();

            switch (CurrentState)
            {
            case GameState.ViewingMainMenu:
            {
                MenuController.DrawMainMenu();
                break;
            }

            case GameState.ViewingGameMenu:
            {
                MenuController.DrawGameMenu();
                break;
            }

            case GameState.AlteringSettings:
            {
                MenuController.DrawSettings();
                break;
            }

            case GameState.Rules:
            {
                MenuController.drawRules();
                break;
            }

            case GameState.Controls:
            {
                MenuController.drawControls();
                break;
            }

            case GameState.AlteringVolume:
            {
                if (_state.Skip(1).First() == GameState.ViewingGameMenu)
                {
                    MenuController.DrawVolumeSettings(1);
                }
                else if (_state.Skip(1).First() == GameState.ViewingMainMenu)
                {
                    MenuController.DrawVolumeSettings(0);
                }
                break;
            }

            case GameState.Deploying:
            {
                DeploymentController.DrawDeployment();
                break;
            }

            case GameState.Discovering:
            {
                DiscoveryController.DrawDiscovery();
                break;
            }

            case GameState.EndingGame:
            {
                EndingGameController.DrawEndOfGame();
                break;
            }

            case GameState.ViewingHighScores:
            {
                HighScoreController.DrawHighScores();
                break;
            }
            }

            UtilityFunctions.DrawAnimations();

            SwinGame.RefreshScreen(60);
        }
示例#5
0
        /// <summary>
        /// Handles the user's input.
        /// <remarks>
        /// Reads key and mouse input and converts these into
        /// actions for the game to perform. The actions
        /// performed depend upon the state of the game.
        /// </remarks>
        /// </summary>
        public static void HandleUserInput()
        {
            // Read incoming input events.
            SwinGame.ProcessEvents();

            if (SwinGame.KeyTyped(KeyCode.EqualsKey) || SwinGame.KeyTyped(KeyCode.PlusKey))
            {
                UtilityFunctions.VolumeLevel += 0.1f;
                Audio.SetMusicVolume(UtilityFunctions.VolumeLevel);
            }
            else if (SwinGame.KeyTyped(KeyCode.UnderscoreKey) || SwinGame.KeyTyped(KeyCode.MinusKey))
            {
                UtilityFunctions.VolumeLevel -= 0.1f;
                Audio.SetMusicVolume(UtilityFunctions.VolumeLevel);
            }

            // Switch through themes
            if (SwinGame.KeyTyped(KeyCode.TKey))
            {
                GameResources.GameTheme++;
                if (!Enum.IsDefined(typeof(Theme), GameResources.GameTheme))
                {
                    GameResources.GameTheme = 0;
                }
            }

            switch (CurrentState)
            {
            case GameState.ViewingMainMenu:
            {
                MenuController.HandleMainMenuInput();
                break;
            }

            case GameState.ViewingGameMenu:
            {
                MenuController.HandleGameMenuInput();
                break;
            }

            case GameState.AlteringSettings:
            {
                MenuController.HandleSetupMenuInput();
                break;
            }

            case GameState.Rules:
            {
                HighScoreController.HandleHighScoreInput();
                break;
            }

            case GameState.Controls:
            {
                MenuController.HandleControlersMenu();
                break;
            }

            case GameState.AlteringVolume:
            {
                if (_state.Skip(1).First() == GameState.ViewingGameMenu)
                {
                    MenuController.HandleVolumeMenuInput(1);
                }
                else if (_state.Skip(1).First() == GameState.ViewingMainMenu)
                {
                    MenuController.HandleVolumeMenuInput(0);
                }
                break;
            }

            case GameState.Deploying:
            {
                DeploymentController.HandleDeploymentInput();
                break;
            }

            case GameState.Discovering:
            {
                DiscoveryController.HandleDiscoveryInput();
                break;
            }

            case GameState.EndingGame:
            {
                EndingGameController.HandleEndOfGameInput();
                break;
            }

            case GameState.ViewingHighScores:
            {
                HighScoreController.HandleHighScoreInput();
                break;
            }
            }

            UtilityFunctions.UpdateAnimations();
        }