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);
            }

            //Cheat to end of game
            if (SwinGame.KeyTyped(KeyCode.vk_c))
            {
                GameController.SwitchState(GameState.EndingGame);
            }

            if (SwinGame.MouseClicked(MouseButton.LeftButton))
            {
                DoAttack();
            }

            const int BX      = 693;
            const int BY      = 72;
            const int BWIDTH  = 78;
            const int BHEIGHT = 44;
            Rectangle R       = SwinGame.RectangleFrom(BX, BY, BWIDTH, BHEIGHT);

            if (SwinGame.MouseClicked(MouseButton.LeftButton))
            {
                Point2D mPoint = SwinGame.MousePosition();
                if (SwinGame.PointInRect(mPoint, R))
                {
                    GameController.EndCurrentState();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The main menu was clicked, perform the button's action.
        /// </summary>
        /// <param name="button">the button pressed</param>
        private static void PerformMainMenuAction(int button)
        {
            switch (button)
            {
            case MAIN_MENU_PLAY_BUTTON:
            {
                GameController.StartGame();
                break;
            }

            case MAIN_MENU_SETUP_BUTTON:
            {
                GameController.AddNewState(GameState.AlteringSettings);
                break;
            }

            case MAIN_MENU_TOP_SCORES_BUTTON:
            {
                GameController.AddNewState(GameState.ViewingHighScores);
                break;
            }

            case MAIN_MENU_QUIT_BUTTON:
            {
                GameController.EndCurrentState();
                break;
            }
            }
        }
        /// <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(UtilityFunctions.EscapeKey))
            {
                GameController.AddNewState(GameState.ViewingGameMenu);
            }

            if (SwinGame.KeyTyped(UtilityFunctions.CheatsKey))
            {
                UtilityFunctions.ShowShipsCheat = !UtilityFunctions.ShowShipsCheat;
            }

            if (SwinGame.MouseClicked(MouseButton.LeftButton))
            {
                DoAttack();
            }
            if (SwinGame.KeyTyped(KeyCode.vk_b))
            {
                UtilityFunctions.ChangeBackground();
            }

            if (SwinGame.KeyTyped(KeyCode.vk_s))
            {
                GameController.SaveGame();
            }
        }
Ejemplo n.º 4
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.MouseClicked(MouseButton.LeftButton))
            {
                ShipName selected = default(ShipName);
                selected = GetShipMouseIsOver();
                if (selected != ShipName.None)
                {
                    _selectedShip = selected;
                }
                else
                {
                    DoDeployClick();
                }

                //If player hits Ready to Play, Start the game.
                if (GameController.HumanPlayer.ReadyToDeploy & UtilityFunctions.IsMouseInRectangle(PLAY_BUTTON_LEFT, TOP_BUTTONS_TOP, PLAY_BUTTON_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    GameController.EndDeployment();
                }
                //if the play clicks Up Arrow, change the orientation of the ships deployment
                else if (UtilityFunctions.IsMouseInRectangle(UP_DOWN_BUTTON_LEFT, TOP_BUTTONS_TOP, DIR_BUTTONS_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    _currentDirection = Direction.UpDown;
                }
                //if the player clicks the left/right arrow, chage the orientation ofthe ships deployment
                else if (UtilityFunctions.IsMouseInRectangle(LEFT_RIGHT_BUTTON_LEFT, TOP_BUTTONS_TOP, DIR_BUTTONS_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    _currentDirection = Direction.LeftRight;
                }
                //if randomise is clicked, randomise all the ships deployment
                else if (UtilityFunctions.IsMouseInRectangle(RANDOM_BUTTON_LEFT, TOP_BUTTONS_TOP, RANDOM_BUTTON_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    GameController.HumanPlayer.RandomizeDeployment();
                }
            }
        }
        /// <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
        /// Isuru: Updated Keycodes
        /// </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;
                DeployShips();
            }
            if (SwinGame.KeyTyped(KeyCode.LeftKey) | SwinGame.KeyTyped(KeyCode.RightKey))
            {
                _currentDirection = Direction.LeftRight;
                DeployShips();
            }

            if (SwinGame.KeyTyped(KeyCode.RKey))
            {
                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;
                    DeployShips();
                }
                else if (UtilityFunctions.IsMouseInRectangle(LEFT_RIGHT_BUTTON_LEFT, TOP_BUTTONS_TOP, DIR_BUTTONS_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    _currentDirection = Direction.LeftRight;
                    DeployShips();
                }
                else if (UtilityFunctions.IsMouseInRectangle(RANDOM_BUTTON_LEFT, TOP_BUTTONS_TOP, RANDOM_BUTTON_WIDTH, TOP_BUTTONS_HEIGHT))
                {
                    GameController.HumanPlayer.RandomizeDeployment();
                }
            }
        }
Ejemplo n.º 6
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();
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Handles the  processing of user input when the quit menu is showing
 /// </summary>
 public static void HandleQuitMenuInput()
 {
     if (SwinGame.MouseClicked(MouseButton.LeftButton))
     {
         if (SwinGame.PointInRect(SwinGame.MousePosition(), SwinGame.ScreenWidth() / 2 + 70, 400, 50, 25))
         {
             GameController.AddNewState(GameState.ViewingMainMenu);
         }
         if (SwinGame.PointInRect(SwinGame.MousePosition(), SwinGame.ScreenWidth() / 2 - 70, 400, 50, 25))
         {
             GameController.AddNewState(GameState.Quitting);
         }
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Read the user's name for their highsSwinGame.
        /// </summary>
        /// <param name="value">the player's sSwinGame.</param>
        /// <remarks>
        /// This verifies if the score is a highsSwinGame.
        /// </remarks>
        public static void ReadHighScore(int value)
        {
            const int ENTRY_TOP = 500;

            if (_Scores.Count == 0)
            {
                LoadScores();
            }

            //is it a high score
            if (value > _Scores[_Scores.Count - 1].Value)
            {
                Score s = new Score();
                s.Value = value;

                GameController.AddNewState(GameState.ViewingHighScores);

                int x = 0;
                x = SCORES_LEFT + SwinGame.TextWidth(GameResources.GameFont("Courier"), "Name: ");

                SwinGame.StartReadingText(Color.White, NAME_WIDTH, GameResources.GameFont("Courier"), x, ENTRY_TOP);

                //Read the text from the user
                while (SwinGame.ReadingText())
                {
                    SwinGame.ProcessEvents();

                    UtilityFunctions.DrawBackground();
                    DrawHighScores();
                    SwinGame.DrawText("Name: ", Color.White, GameResources.GameFont("Courier"), SCORES_LEFT, ENTRY_TOP);
                    SwinGame.RefreshScreen();
                }

                s.Name = SwinGame.TextReadAsASCII();

                if (s.Name.Length < 3)
                {
                    s.Name = s.Name + new string(Convert.ToChar(" "), 3 - s.Name.Length);
                }

                _Scores.RemoveAt(_Scores.Count - 1);
                _Scores.Add(s);
                _Scores.Sort();
                SaveScores();

                //GameController.EndCurrentState();
                GameController.AddNewState(GameState.ViewingHighScores);
            }
        }
        /// <summary>
        /// Read the user's name for their highsSwinGame.
        /// </summary>
        /// <param name="value">the player's sSwinGame.</param>
        /// <remarks>
        /// This verifies if the score is a highsSwinGame.
        /// </remarks>
        public static void ReadHighScore(int value)
        {
            const int ENTRY_TOP = 500;

            if (_scores.Count == 0)
            {
                LoadScores();
            }

            // Return if this score is not a highscore
            if (_scores.Count > 0 && value <= _scores[_scores.Count - 1].value)
            {
                return;
            }

            Score s = new Score {
                value = value
            };

            int x = SCORES_LEFT + SwinGame.TextWidth(GameResources.GetFont("Courier"), "Name: ");

            GameController.AddNewState(GameState.ViewingHighScores);
            SwinGame.StartReadingText(Color.White, NAME_WIDTH, GameResources.GetFont("Courier"), x, ENTRY_TOP);

            // Reads the text from the user
            while (SwinGame.ReadingText())
            {
                SwinGame.ProcessEvents();
                UtilityFunctions.DrawBackground();
                DrawHighScores();
                SwinGame.DrawText("Name: ", Color.White, GameResources.GetFont("Courier"), SCORES_LEFT, ENTRY_TOP);
                SwinGame.RefreshScreen();
            }

            s.name = SwinGame.TextReadAsASCII();

            if (s.name.Length < 3)
            {
                s.name += new string(Convert.ToChar(' '), 3 - s.name.Length);
            }

            //scores.RemoveAt(scores.Count - 1);
            _scores.Add(s);
            _scores.Sort();
            GameController.EndCurrentState();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// The game menu was clicked, perform the button's action.
        /// </summary>
        /// <param name="button">the button pressed</param>
        private static void PerformGameMenuAction(int button)
        {
            switch (button)
            {
            case GAME_MENU_RETURN_BUTTON: {
                GameController.EndCurrentState();
                break;
            }

            case GAME_MENU_SURRENDER_BUTTON: {
                // End game menu
                GameController.EndCurrentState();
                // End game
                GameController.EndCurrentState();
                break;
            }

            case GAME_MENU_QUIT_BUTTON: {
                GameController.AddNewState(GameState.Quitting);
                break;
            }

            case GAME_MENU_MUTE_BUTTON:
            {
                //GameController.AddNewState(GameState.Quitting);
                if (Extentions.MusicPlaying == false)
                {
                    SwinGame.PlayMusic(GameResources.GameMusic("Background"));
                    Extentions.MusicPlaying     = true;
                    Extentions.MusicPlayingWord = "MUTE";
                    DrawButtons(GAME_MENU);
                }
                else if (Extentions.MusicPlaying == true)
                {
                    SwinGame.StopMusic();
                    Extentions.MusicPlaying     = false;
                    Extentions.MusicPlayingWord = "UNMUTE";
                    DrawButtons(GAME_MENU);
                    SwinGame.RefreshScreen();
                }
                GameController.EndCurrentState();
                break;
            }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// The game menu was clicked, perform the button's action.
        /// </summary>
        /// <param name="button">the button pressed</param>
        private static void PerformGameMenuAction(int button)
        {
            switch (button)
            {
            case GAME_MENU_RETURN_BUTTON:
                GameController.EndCurrentState();
                break;

            case GAME_MENU_SURRENDER_BUTTON:
                GameController.EndCurrentState();                         //end game menu
                GameController.EndCurrentState();                         //end game
                break;

            case GAME_MENU_QUIT_BUTTON:
                GameController.AddNewState(GameState.Quitting);
                break;
            }
        }
        /// <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(UtilityFunctions.EscapeKey))
            {
                GameController.AddNewState(GameState.ViewingGameMenu);
            }

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

            if (SwinGame.KeyTyped(UtilityFunctions.RandomKey))
            {
                GameController.HumanPlayer.RandomizeDeployment();
            }
            // ship colour change keys
            if (SwinGame.KeyTyped(UtilityFunctions.BlueKey))
            {
                //GameController.CurrentShipColour = ShipColour.Blue;
            }
            if (SwinGame.KeyTyped(UtilityFunctions.PinkKey))
            {
                //GameController.CurrentShipColour = ShipColour.Pink;
            }


            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.Pink)
                    {
                        GameController.HumanPlayer.Ship(_selectedShip).CurrentShipColour = ShipColour.Blue;
                    }
                    else
                    {
                        GameController.HumanPlayer.Ship(_selectedShip).CurrentShipColour = ShipColour.Pink;
                    }
                }
            }
        }