コード例 #1
0
        protected override void Update(GameTime gameTime)
        {
            Constants.UpdateKeyMouseReader();

            switch (currentState)
            {
            case GameState.MainMenu:
                mainMenu.Update(gameTime);
                if (mainMenu.newGameButton.CheckClicked() || Constants.gamePadState.IsButtonDown(Buttons.Start) && Constants.oldGamePadState.IsButtonUp(Buttons.Start))
                {
                    gameManager.Initialize();
                    currentState = GameState.MainGame;
                }
                if (mainMenu.newQuitButton.CheckClicked() || Constants.gamePadState.IsButtonDown(Buttons.Back) && Constants.oldGamePadState.IsButtonUp(Buttons.Back))
                {
                    Exit();
                }
                if (mainMenu.newHighscoreButton.CheckClicked() || Constants.gamePadState.IsButtonDown(Buttons.Y))
                {
                    currentState = GameState.HighScore;
                }
                break;

            case GameState.MainGame:
                gameManager.Update(gameTime);

                if (gameManager.gameOver)
                {
                    currentState = GameState.GameOver;
                }

                if (Constants.keyState.IsKeyDown(Keys.P) && Constants.oldKeyState.IsKeyUp(Keys.P) || Constants.gamePadState.IsButtonDown(Buttons.Start) && Constants.oldGamePadState.IsButtonUp(Buttons.Start))
                {
                    currentState = GameState.GamePause;
                }
                break;

            case GameState.GamePause:
                if (Constants.keyState.IsKeyDown(Keys.P) && Constants.oldKeyState.IsKeyUp(Keys.P) || Constants.gamePadState.IsButtonDown(Buttons.Start) && Constants.oldGamePadState.IsButtonUp(Buttons.Start))
                {
                    currentState = GameState.MainGame;
                }

                if (Constants.keyState.IsKeyDown(Keys.Escape) && Constants.oldKeyState.IsKeyUp(Keys.Escape) || Constants.gamePadState.IsButtonDown(Buttons.Back) && Constants.oldGamePadState.IsButtonUp(Buttons.Back))
                {
                    mainMenu.Initialize();
                    gameManager  = new GameManager();
                    currentState = GameState.MainMenu;
                }
                break;

            case GameState.GameOver:
                if (Highscore.CheckScore(gameManager.score))
                {
                    currentState = GameState.NameEntry;
                }
                else
                {
                    currentState = GameState.HighScore;
                }
                break;

            case GameState.HighScore:
                if (Constants.keyState.IsKeyDown(Keys.Enter) && Constants.oldKeyState.IsKeyUp(Keys.Enter) || Constants.gamePadState.IsButtonDown(Buttons.Start))
                {
                    mainMenu.Initialize();
                    gameManager  = new GameManager();
                    currentState = GameState.MainMenu;
                }
                break;

            case GameState.NameEntry:
                if (NameEntry.Entry())
                {
                    currentState = GameState.HighScore;
                }
                break;
            }

            base.Update(gameTime);
        }