示例#1
0
        protected override void Update(GameTime gameTime)
        {
            _keyboardState = Keyboard.GetState();

            if (CheckKey(Keys.F1))
            {
                if (!_gameIsOn)
                {
                    SetActiveScreen(_startScreen);
                    _gameIsOn = false;
                    MediaPlayer.IsRepeating = true;
                    if (!_gameOverScreen.IshighScore)
                    {
                        MediaPlayer.Play(_menuSong);
                    }
                }
            }
            if (CheckKey(Keys.Escape))
            {
                Exit();
            }

            if (CheckKey(Keys.Back))
            {
                SetActiveScreen(_startScreen);
            }

            if (_activeScreen == _startScreen)
            {
                if (CheckKey(Keys.Enter))
                {
                    if (_startScreen.SelectedIndex == 0)
                    {
                        _gameIsOn = true;
                        _menuClickSelected.Play();
                        _actionScreen.ResetGame();
                        _gameOverScreen.IshighScore        = false;
                        GameTimerHandler.TotalGameTime     = 0;
                        GameTimerHandler.LastGameStartTime = (int)gameTime.TotalGameTime.TotalSeconds;
                        MediaPlayer.IsRepeating            = true;
                        MediaPlayer.Play(_gamePlaySong);
                        SetActiveScreen(_actionScreen);
                    }

                    if (_startScreen.SelectedIndex == 1)
                    {
                        _menuClickSelected.Play();
                        _gameOverScreen.IshighScore = true;
                        _gameOverScreen.GetHighScoreFromLeaderBoard();
                        SetActiveScreen(_gameOverScreen);
                    }
                    if (_startScreen.SelectedIndex == 2)
                    {
                        Exit();
                    }
                }
            }

            if (_actionScreen.CheckIfGameIsOver())
            {
                if (_gameIsOn)
                {
                    _gameIsOn = false;
                    MediaPlayer.IsRepeating = false;
                    MediaPlayer.Play(_dead);


                    _gameOverScreen.GetHighScoreFromLeaderBoard();



                    SetActiveScreen(_gameOverScreen);
                    _gameOverScreen.SetScoreText();
                }
            }

            base.Update(gameTime);
            _oldKeyboardState = _keyboardState;
        }