Example #1
0
        public static void HandleVolumeMenuInput(int primaryMenu)
        {
            if (SwinGame.KeyTyped(KeyCode.EscapeKey))
            {
                GameController.EndCurrentState();
                return;
            }
            else if (SwinGame.MouseClicked(MouseButton.LeftButton))
            {
                if (UtilityFunctions.IsMouseInRectangle(VOLUME_BUTTON_X, VOLUME_BUTTON_Y, VOLUME_BUTTON_SIZE, VOLUME_BUTTON_SIZE))
                {
                    // Plus button
                    UtilityFunctions.VolumeLevel += 0.1f;
                    Audio.SetMusicVolume(UtilityFunctions.VolumeLevel);
                }
                else if (UtilityFunctions.IsMouseInRectangle(VOLUME_BUTTON_X + VOLUME_BUTTON_SIZE + VOLUME_BUTTON_GAP,
                                                             VOLUME_BUTTON_Y, VOLUME_BUTTON_SIZE, VOLUME_BUTTON_SIZE))
                {
                    // Minus button
                    UtilityFunctions.VolumeLevel -= 0.1f;
                    Audio.SetMusicVolume(UtilityFunctions.VolumeLevel);
                }
                else
                {
                    // None clicked, so exit menu
                    GameController.EndCurrentState();
                    // And handle any clicks for primary menu
                    if (primaryMenu == MAIN_MENU)
                    {
                        HandleMainMenuInput();
                    }
                    else if (primaryMenu == GAME_MENU)
                    {
                        HandleGameMenuInput();
                    }
                }
            }

            //return false;
        }
Example #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();
        }
Example #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();
        }
        /// <summary>
        /// Draws the deployment screen showing the field and the ships
        /// that the player can deploy.
        /// </summary>
        public static void DrawDeployment()
        {
            UtilityFunctions.DrawField(GameController.HumanPlayer.PlayerGrid, GameController.HumanPlayer, true);

            // Draw the Left/Right and Up/Down buttons.
            if (_currentDirection == Direction.LeftRight)
            {
                SwinGame.DrawBitmap(GameResources.GameImage("LeftRightButton", GameResources.GameTheme), LEFT_RIGHT_BUTTON_LEFT, TOP_BUTTONS_TOP);
            }
            else
            {
                SwinGame.DrawBitmap(GameResources.GameImage("UpDownButton", GameResources.GameTheme), LEFT_RIGHT_BUTTON_LEFT, TOP_BUTTONS_TOP);
            }

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

            if (GameController.HumanPlayer.ReadyToDeploy)
            {
                SwinGame.DrawBitmap(GameResources.GameImage("PlayButton", GameResources.GameTheme), PLAY_BUTTON_LEFT, TOP_BUTTONS_TOP);
            }

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

            UtilityFunctions.DrawMessage();
        }
Example #5
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.ShiftKey) | SwinGame.KeyDown(KeyCode.RightShiftKey)) & SwinGame.KeyDown(KeyCode.CKey))
            {
                UtilityFunctions.DrawField(GameController.HumanPlayer.EnemyGrid, GameController.ComputerPlayer, true);
            }
            else
            {
                UtilityFunctions.DrawField(GameController.HumanPlayer.EnemyGrid, GameController.ComputerPlayer, false);
            }

            UtilityFunctions.DrawSmallField((ISeaGrid)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);
        }
Example #6
0
        /// <summary>
        /// Draw the end of the game screen, shows the win/lose state
        /// </summary>
        public static void DrawEndOfGame()
        {
            Rectangle toDraw = default(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);
        }
 // '' <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);
 }
 public static void AddSplash(int row, int col)
 {
     UtilityFunctions.AddAnimation(row, col, "Splash");
 }
Example #9
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);
        }
Example #10
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();
        }