예제 #1
0
        //public UtilityFunctions Utility {
        //    get {
        //        return _utility;
        //    }
        //}

        public GameController(GameResources res)
        {
            _state = new Stack <GameState>();
            //bottom state will be quitting. If player exits main menu then the game is over
            _state.Push(GameState.Quitting);

            //at the start the player is viewing the main menu
            _state.Push(GameState.ViewingMainMenu);

            _resources = res;

            _utility    = new UtilityFunctions();
            _menu       = new MenuController();
            _deployment = new DeploymentController();
            _discovery  = new DiscoveryController();
            _endGame    = new EndingGameController();
            _highScore  = new HighScoreController();

            _highScore.LoadHighScore();
        }
예제 #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.AlteringShips:
                MenuController.DrawShipsMenu();
                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.AlteringShips:
                MenuController.HandleShipsMenuInput();
                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 game during the attack phase
         *</summary>
         */
        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);
        }
예제 #5
0
        /*<summary>
         * Draw the end of the game screen, shows the win/lose state
         *</summary>
         */
        public static void DrawEndOfGame()
        {
            Rectangle toDraw = new Rectangle();
            string    whatShouldIPrint;

            UtilityFunctions.DrawField(GameController.ComputerPlayer.PlayerGrid, GameController.ComputerPlayer, true);
            UtilityFunctions.DrawSmallField(GameController.HumanPlayer.PlayerGrid, GameController.HumanPlayer);

            toDraw.X      = 0;
            toDraw.Y      = 250;
            toDraw.Width  = SwinGame.ScreenWidth();
            toDraw.Height = SwinGame.ScreenHeight();

            if (GameController.HumanPlayer.IsDestroyed)
            {
                whatShouldIPrint = "YOU LOSE!";
            }
            else
            {
                whatShouldIPrint = "-- WINNER --";
            }

            SwinGame.DrawTextLines(whatShouldIPrint, Color.White, Color.Transparent, GameResources.GameFont("ArialLarge"), FontAlignment.AlignCenter, toDraw);
        }
예제 #6
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;
                selected = GetShipMouseIsOver();
                if (GameController.ShipsToDeploy == 3)
                {
                    if ((selected != ShipName.None))
                    {
                        if ((selected != ShipName.Tug) && (selected != ShipName.Submarine))
                        {
                            _selectedShip = selected;
                        }
                    }
                    else
                    {
                        DeploymentController.DoDeployClick();
                    }
                }
                else if (GameController.ShipsToDeploy == 4)
                {
                    if (selected != ShipName.None)
                    {
                        if (selected != ShipName.Tug)
                        {
                            _selectedShip = selected;
                        }
                    }
                    else
                    {
                        DeploymentController.DoDeployClick();
                    }
                }
                else if ((selected != ShipName.None))
                {
                    _selectedShip = selected;
                }
                else
                {
                    DeploymentController.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();
                }
            }
        }
예제 #7
0
 /*<summary>
  * Draws a large field using the grid and the indicated player's ships.
  *</summary>
  *<param name="grid">the grid to draw</param>
  *<param name="thePlayer">the players ships to show</param>
  *<param name="showShips">indicates if the ships should be shown</param>
  */
 public static void DrawField(ISeaGrid grid, Player thePlayer, bool showShips)
 {
     UtilityFunctions.DrawCustomField(grid, thePlayer, false, showShips, FIELD_LEFT, FIELD_TOP, FIELD_WIDTH, FIELD_HEIGHT, CELL_WIDTH, CELL_HEIGHT, CELL_GAP);
 }
예제 #8
0
 public static void AddSplash(int row, int col)
 {
     UtilityFunctions.AddAnimation(row, col, "Splash");
 }
예제 #9
0
 public static void AddExplosion(int row, int col)
 {
     UtilityFunctions.AddAnimation(row, col, "Explosion");
 }