/// <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 if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { this.Exit(); } //If a new game is declared, recreate managers from the data in the WorldVariables. if (WorldVariables.newGame == true) { gameManager = new GameManager(graphics.GraphicsDevice.Viewport, new Vector2(WorldVariables.width, WorldVariables.height), WorldVariables.jewels, WorldVariables.difficulty, WorldVariables.time); menuManager = new MenuManager(); scoreManager.inputName = true; WorldVariables.newGame = false; } //If a transfer is declared, add the score from WorldVariables to the ScoreManager. if (WorldVariables.transfer == true) { scoreManager.currentScore = WorldVariables.score; WorldVariables.transfer = false; } //If we want to exit the game, exit the game. if (exit == true) { this.Exit(); } //Depending on which state is on, update a different manager and check the state of each. If a new one is found, reset the past one. switch (gameState) { case GameState.Game: gameManager.Update(gameTime); gameState = (GameState)gameManager.CheckState(); if (gameState != GameState.Game) { gameManager.ResetState(); } break; case GameState.Menu: menuManager.Update(gameTime); gameState = (GameState)menuManager.CheckState(); if (gameState != GameState.Menu) { menuManager.ResetState(); } break; case GameState.Score: scoreManager.Update(gameTime); gameState = (GameState)scoreManager.CheckState(); if (gameState != GameState.Score) { scoreManager.ResetState(); } break; case GameState.Quit: exit = true; break; default: break; } // TODO: Add your update logic here base.Update(gameTime); }