/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit _keyboardState = Keyboard.GetState(); // Catch keys in menu. if (_controller.GameState.CurrentState == State.Menu) { _UpdateMenu(gameTime); _gameSoudStarted = false; } else if (_controller.GameState.CurrentState == State.Game) { _UpdateGame(gameTime); if (_keyboardState.IsKeyDown(Keys.Escape) && !_controller.IsGameFinished) { AudioPlayer.Stop(); AudioPlayer.PlayMenu(); _controller.GameState.CurrentState = State.UserInput; } else if (_keyboardState.IsKeyDown(Keys.Up)) { _controller.SpeedUp(); } else if (_keyboardState.IsKeyUp(Keys.Up)) { _controller.SlowDown(); } } else if (_controller.GameState.CurrentState == State.Paused) { _PauseGameIfNeeded(); } else if (_controller.GameState.CurrentState == State.Hits) { _hitList.Update(_keyboardState); if (_keyboardState.IsKeyDown(Keys.Escape)) { _controller.GameState.CurrentState = State.Menu; } } else if (_controller.GameState.CurrentState == State.UserInput) { _userInput.Update(_keyboardState); if (_userInput.IsInputFinished) { string userName = _userInput.UserName; string score = _userInput.Score; _hitList.AddUserData(new UserData() { Score = score, UserName = userName, CreationTime = DateTime.Now }); _controller.GameState.CurrentState = State.Hits; } } else { // Do nothing. } base.Update(gameTime); }