/// <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); }
//When custom data has been inputed in the menu, this function will be used to create a manager with this data. public void EnterGameData(int jewels, int width, int height, int difficulty, int time) { gameManager = new GameManager(graphics.GraphicsDevice.Viewport, new Vector2(width, height), jewels, difficulty, time); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); //Sends data to my super-class for all to use. Position.content = Content; Position.ScreenWidth = graphics.GraphicsDevice.Viewport.Width; Position.ScreenHeight = graphics.GraphicsDevice.Viewport.Height; //Create and load my High Scores. highScore = new HighScoreClass(Content); highScore.LoadScores(); highScore.SetScores(); //Create my managers. gameManager = new GameManager(graphics.GraphicsDevice.Viewport, new Vector2(50, 50), 10, 3, 100); menuManager = new MenuManager(); scoreManager = new ScoreManager(highScore, Content); // TODO: use this.Content to load your game content here }