Esempio n. 1
0
        // The game menu was clicked, perform the button's action.
        // Parameter: button - The button pressed
        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;

            case GAME_MENU_MUTE_MUSIC_ACTION:
                if (Audio.MusicPlaying())
                {
                    UtilityFunctions.StopMusic();
                }
                else
                {
                    UtilityFunctions.PlayMusic();
                }
                break;

            case GAME_MENU_MUTE_SFX_ACTION:
                if (UtilityFunctions.SFX_ACTIVE)
                {
                    UtilityFunctions.RemoveSFX();
                }
                else
                {
                    UtilityFunctions.LoadSFX();
                }
                break;
            }
        }
Esempio n. 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();
        }
Esempio n. 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();
        }
Esempio n. 4
0
        // Summary: Draws the game during the attack phase.
        // Remarks: Isuru -  Updated keycodes
        public static void DrawDiscovery()
        {
            const int SCORES_LEFT = 172;
            const int SHOTS_TOP   = 157;
            const int HITS_TOP    = 206;
            const int SPLASH_TOP  = 256;

            const int BACK_BUTTON_LEFT   = 710;
            const int BACK_BUTTON_TOP    = 5;
            const int BACK_BUTTON_WIDTH  = 60;
            const int TOP_BUTTONS_HEIGHT = 46;



            //sets parameter to true if the player presses key combination of Shift + C
            if ((SwinGame.KeyDown(KeyCode.vk_RSHIFT) | SwinGame.KeyDown(KeyCode.vk_LSHIFT)) & SwinGame.KeyDown(KeyCode.vk_c))
            {
                UtilityFunctions.DrawField(GameController.HumanPlayer.EnemyGrid, GameController.ComputerPlayer, true, false);
            }
            else
            {
                UtilityFunctions.DrawField(GameController.HumanPlayer.EnemyGrid, GameController.ComputerPlayer, true, true);
            }

            if (UtilityFunctions.IsMouseInRectangle(BACK_BUTTON_LEFT, BACK_BUTTON_TOP, BACK_BUTTON_WIDTH, TOP_BUTTONS_HEIGHT) && SwinGame.MouseClicked(MouseButton.LeftButton))
            {
                GameController.AddNewState(GameState.ViewingGameMenu);
            }

            UtilityFunctions.DrawSmallField(GameController.HumanPlayer.PlayerGrid, GameController.HumanPlayer);
            UtilityFunctions.DrawMessage();

            SwinGame.DrawBitmap(GameResources.GameImage("Back"), BACK_BUTTON_LEFT, BACK_BUTTON_TOP);

            SwinGame.DrawText(GameController.HumanPlayer.Shots.ToString(), Color.White, GameResources.GameFont("Menu"), SCORES_LEFT, SHOTS_TOP);
            SwinGame.DrawText(GameController.HumanPlayer.Hits.ToString(), Color.White, GameResources.GameFont("Menu"), SCORES_LEFT, HITS_TOP);
            SwinGame.DrawText(GameController.HumanPlayer.Missed.ToString(), Color.White, GameResources.GameFont("Menu"), SCORES_LEFT, SPLASH_TOP);
        }
        //Summary: Draw the end of the game screen, shows the win/lose state
        //Remarks: Isuru: Updated to new swingame call
        public static void DrawEndOfGame()
        {
            UtilityFunctions.DrawField(GameController.ComputerPlayer.PlayerGrid, GameController.ComputerPlayer, true, false);
            UtilityFunctions.DrawSmallField(GameController.HumanPlayer.PlayerGrid, GameController.HumanPlayer);

            Rectangle toDraw = new Rectangle();

            toDraw.X      = 0;
            toDraw.Y      = 250;
            toDraw.Width  = SwinGame.ScreenWidth();
            toDraw.Height = SwinGame.ScreenHeight();
            String whatShouldIPrint = "I have long variable names";

            if (GameController.HumanPlayer.IsDestroyed)
            {
                whatShouldIPrint = "YOU LOSE!";
            }
            else
            {
                whatShouldIPrint = "-- WINNER --";
            }
            //SwinGame.DrawText(whatShouldIPrint, Color.White, Color.Transparent, GameResources.GameFont("ArialLarge"), FontAlignment.AlignCenter, toDraw);
        }
Esempio n. 6
0
        /// <summary>
        /// Draws the game during the attack phase.
        /// </summary>s
        public static void DrawDiscovery()
        {
            const int SCORES_LEFT = 172;
            const int SHOTS_TOP   = 157;
            const int HITS_TOP    = 206;
            const int SPLASH_TOP  = 256;

            if ((SwinGame.KeyDown(KeyCode.vk_LSHIFT) | SwinGame.KeyDown(KeyCode.vk_RSHIFT)) & SwinGame.KeyDown(KeyCode.vk_c))
            {
                UtilityFunctions.DrawField(GameController.HumanPlayer.EnemyGrid, GameController.ComputerPlayer, true);
            }
            else
            {
                UtilityFunctions.DrawField(GameController.HumanPlayer.EnemyGrid, GameController.ComputerPlayer, false);
            }

            UtilityFunctions.DrawSmallField(GameController.HumanPlayer.PlayerGrid, GameController.HumanPlayer);
            UtilityFunctions.DrawMessage();

            SwinGame.DrawText(GameController.HumanPlayer.Shots.ToString(), Color.White, GameResources.GameFont("Menu"), SCORES_LEFT, SHOTS_TOP);
            SwinGame.DrawText(GameController.HumanPlayer.Hits.ToString(), Color.White, GameResources.GameFont("Menu"), SCORES_LEFT, HITS_TOP);
            SwinGame.DrawText(GameController.HumanPlayer.Missed.ToString(), Color.White, GameResources.GameFont("Menu"), SCORES_LEFT, SPLASH_TOP);
        }
Esempio n. 7
0
        // Summary: Handles user input for the Deployment phase of the game.

        /*
         * Remarks: Involves selecting the ships, deloying ships, changing the direction
         * of the ships to add, randomising deployment, and then ending deployment
         * Isuru: Updated Keycodes
         */
        public static void HandleDeploymentInput()
        {
            //Shows menu when esc key pressed
            if (SwinGame.KeyTyped(KeyCode.vk_ESCAPE))
            {
                GameController.AddNewState(GameState.ViewingGameMenu);
            }

            //Moves ships direction to vertical when down or up key pressed

            if (SwinGame.KeyTyped(KeyCode.vk_UP) || SwinGame.KeyTyped(KeyCode.vk_DOWN))
            {
                _currentDirection = Direction.UpDown;
            }

            //Moves ships direction to horizontal when left or right key pressed

            if (SwinGame.KeyTyped(KeyCode.vk_LEFT) || SwinGame.KeyTyped(KeyCode.vk_RIGHT))
            {
                _currentDirection = Direction.LeftRight;
            }

            //Randomises ship deploymeny when R key pressed
            if (SwinGame.KeyTyped(KeyCode.vk_r))
            {
                GameController.HumanPlayer.RandomizeDeployment();
            }

            //Selects ship if ship placed at cursor location, deploys ship otherwise.
            //Also checks for button presses onscreen.
            if (SwinGame.MouseClicked(MouseButton.LeftButton))
            {
                ShipName selected = default(ShipName);
                selected = GetShipMouseIsOver();
                if (selected != ShipName.None)
                {
                    _selectedShip = selected;
                }
                else
                {
                    DoDeployClick();
                }

                if (help_screen == false)
                {
                    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(CLEAR_BUTTON_LEFT, TOP_BUTTONS_TOP, CLEAR_BUTTON_WIDTH, CLEAR_BUTTON_HEIGHT))
                    {
                        //clears board
                        GameController.HumanPlayer.PlayerGrid.ClearBoard();
                    }
                    else if (UtilityFunctions.IsMouseInRectangle(BACK_BUTTON_LEFT, BACK_BUTTON_TOP, BACK_BUTTON_WIDTH, TOP_BUTTONS_HEIGHT))
                    {
                        //Goes back to main menu
                        GameController.AddNewState(GameState.ViewingMainMenu);
                    }
                    else if (UtilityFunctions.IsMouseInRectangle(HELP_BUTTON_LEFT, TOP_BUTTONS_TOP, CLEAR_BUTTON_WIDTH, CLEAR_BUTTON_HEIGHT))
                    {
                        if (help_screen)
                        {
                            help_screen = false;
                        }
                        else
                        {
                            help_screen = true;
                        }
                    }
                }
                else
                {
                    help_screen = false;
                }
            }
        }
Esempio n. 8
0
        // Summary: Draws the deployment screen showing the field and the ships that the player can deploy.
        public static void DrawDeployment()
        {
            UtilityFunctions.DrawField(GameController.HumanPlayer.PlayerGrid, GameController.HumanPlayer, true, false);

            //Draw the Left/Right and Up/Down buttons
            if (_currentDirection == Direction.LeftRight)
            {
                SwinGame.DrawBitmap(GameResources.GameImage("LeftRightButton"), LEFT_RIGHT_BUTTON_LEFT, TOP_BUTTONS_TOP);
                //SwinGame.DrawText("U/D", Color.Gray, GameFont("Menu"), UP_DOWN_BUTTON_LEFT, TOP_BUTTONS_TOP)
                //SwinGame.DrawText("L/R", Color.White, GameFont("Menu"), LEFT_RIGHT_BUTTON_LEFT, TOP_BUTTONS_TOP)
            }
            else
            {
                SwinGame.DrawBitmap(GameResources.GameImage("UpDownButton"), LEFT_RIGHT_BUTTON_LEFT, TOP_BUTTONS_TOP);
                //SwinGame.DrawText("U/D", Color.White, GameFont("Menu"), UP_DOWN_BUTTON_LEFT, TOP_BUTTONS_TOP)
                //SwinGame.DrawText("L/R", Color.Gray, GameFont("Menu"), LEFT_RIGHT_BUTTON_LEFT, TOP_BUTTONS_TOP)
            }

            //displays current game difficulty
            SwinGame.DrawText("Difficulty: " + GameController.AIDifficulty, Color.White, 530, 570);

            //clear button
            SwinGame.DrawBitmap(GameResources.GameImage("Clear"), 620, TOP_BUTTONS_TOP);

            SwinGame.DrawBitmap(GameResources.GameImage("Back"), BACK_BUTTON_LEFT, BACK_BUTTON_TOP);

            //draw help button
            SwinGame.DrawBitmap(GameResources.GameImage("Help"), HELP_BUTTON_LEFT, TOP_BUTTONS_TOP);


            //DrawShips
            foreach (ShipName sn in Enum.GetValues(typeof(ShipName)))
            {
                int i = 0;
                i = ((int)sn) - 1;
                if (i >= 0)
                {
                    if (sn == _selectedShip)
                    {
                        SwinGame.DrawBitmap(GameResources.GameImage("SelectedShip"), SHIPS_LEFT, SHIPS_TOP + i * SHIPS_HEIGHT);
                        //    SwinGame.FillRectangle(Color.LightBlue, SHIPS_LEFT, SHIPS_TOP + i * SHIPS_HEIGHT, SHIPS_WIDTH, SHIPS_HEIGHT)
                        //Else
                        //    SwinGame.FillRectangle(Color.Gray, SHIPS_LEFT, SHIPS_TOP + i * SHIPS_HEIGHT, SHIPS_WIDTH, SHIPS_HEIGHT)
                    }

                    //SwinGame.DrawRectangle(Color.Black, SHIPS_LEFT, SHIPS_TOP + i * SHIPS_HEIGHT, SHIPS_WIDTH, SHIPS_HEIGHT)
                    //SwinGame.DrawText(sn.ToString(), Color.Black, GameFont("Courier"), SHIPS_LEFT + TEXT_OFFSET, SHIPS_TOP + i * SHIPS_HEIGHT)
                }
            }

            if (GameController.HumanPlayer.ReadyToDeploy)
            {
                SwinGame.DrawBitmap(GameResources.GameImage("PlayButton"), PLAY_BUTTON_LEFT, TOP_BUTTONS_TOP);
                //SwinGame.FillRectangle(Color.LightBlue, PLAY_BUTTON_LEFT, PLAY_BUTTON_TOP, PLAY_BUTTON_WIDTH, PLAY_BUTTON_HEIGHT)
                //SwinGame.DrawText("PLAY", Color.Black, GameFont("Courier"), PLAY_BUTTON_LEFT + TEXT_OFFSET, PLAY_BUTTON_TOP)
            }

            SwinGame.DrawBitmap(GameResources.GameImage("RandomButton"), RANDOM_BUTTON_LEFT, TOP_BUTTONS_TOP);
            UtilityFunctions.DrawMessage();

            if (help_screen)
            {
                UtilityFunctions.DrawHelp(new string[] { "Up Arrow: chagen direction of the ships to vertical", "Right Arrow: change direction of ships to horizontal", "Random button: to change position of ships randomly", "Play button : start the game", "Esc key : to esc this mode" });
            }

            //hover placement
            DeploymentController.ShipOverlay();
        }
        /*
         * Summary: Draws the player's grid and ships.
         * Parameter: grid - the grid to show
         * Parameter: thePlayer - the player to show the ships of
         * Parameter: small - true if the small grid is shown
         * Parameter: showShips - true if ships are to be shown
         * Parameter: left - the left side of the grid
         * Parameter: top - the top of the grid
         * Parameter: width - the width of the grid
         * Parameter: height - the height of the grid
         * Parameter: cellWidth - the width of each cell
         * Parameter: cellHeight - the height of each cell
         * Parameter: cellGap - the gap between the cells
         */

        private static void DrawCustomField(ISeaGrid grid, Player thePlayer, bool small, bool showShips, int left, int top, int width, int height, int cellWidth, int cellHeight, int cellGap, bool showonlydestroyed)
        {
            //SwinGame.FillRectangle(Color.Blue, left, top, width, height)

            int rowTop  = 0;
            int colLeft = 0;

            //Draw the grid
            for (int row = 0; row <= 9; row++)
            {
                rowTop = top + (cellGap + cellHeight) * row;

                for (int col = 0; col <= 9; col++)
                {
                    colLeft = left + (cellGap + cellWidth) * col;

                    Color fillColor = default(Color);
                    bool  draw      = false;

                    draw = true;

                    switch (grid[row, col])
                    {
                    //case TileView.Ship:
                    //draw = false;
                    //break;

                    //If small Then fillColor = _SMALL_SHIP Else fillColor = _LARGE_SHIP
                    case TileView.Miss:
                        if (small)
                        {
                            fillColor = SMALL_MISS;
                        }
                        else
                        {
                            fillColor = LARGE_MISS;
                        }
                        break;

                    case TileView.Hit:
                        if (small)
                        {
                            fillColor = SMALL_HIT;
                        }
                        else
                        {
                            fillColor = LARGE_HIT;
                        }
                        break;

                    case TileView.Sea:
                    case TileView.Ship:
                        if (small)
                        {
                            fillColor = SMALL_SEA;
                        }
                        else
                        {
                            draw = false;
                        }
                        break;
                    }

                    if (draw)
                    {
                        SwinGame.FillRectangle(fillColor, colLeft, rowTop, cellWidth, cellHeight);
                        if (!small)
                        {
                            SwinGame.DrawRectangle(OUTLINE_COLOR, colLeft, rowTop, cellWidth, cellHeight);
                        }
                    }
                }
            }

            if (!showShips)
            {
                return;
            }
            UtilityFunctions.DrawShips(grid, thePlayer, small, showShips, rowTop, colLeft, left, top, width, height, cellWidth, cellHeight, cellGap, showonlydestroyed);
        }