示例#1
0
        /// <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 (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            // Increment 2: change game state if game state is GameState.Menu and user presses Enter
            if (Keyboard.GetState().IsKeyDown(Keys.Enter) && gameState == GameState.Menu)
            {
                gameState = GameState.Play;
            }

            // if we're actually playing, update mouse state and update board
            if (gameState == GameState.Play)
            {
                MouseState mouse = Mouse.GetState();
                restart = board.Update(gameTime, mouse);

                if (restart)
                {
                    soundBank.PlayCue("applause");
                    StartGame();
                }
            }

            base.Update(gameTime);
        }
示例#2
0
        /// <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 (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            // Increment 2: change game state if game state is GameState.Menu and user presses Enter
            if (gameState == GameState.Menu && Keyboard.GetState().IsKeyDown(Keys.Enter))
            {
                gameState = GameState.Play;
            }

            // if we're actually playing, update mouse state and update board
            MouseState mouse = Mouse.GetState();

            //start game again if correct number is guessed
            if (numberBoard.Update(gameTime, mouse))
            {
                soundBank.PlayCue("newGame");
                StartGame();
            }

            base.Update(gameTime);
        }
示例#3
0
文件: Game1.cs 项目: demoded/Coursera
        /// <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)
        {
            bool numberGuessed = false;
            //get mouse state
            MouseState mouse = Mouse.GetState();

            // Allows the game to exit
            if ((GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) ||
                Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }


            // Increment 2: change game state if game state is GameState.Menu and user presses Enter
            if (Keyboard.GetState().IsKeyDown(Keys.Enter) && gameState == GameState.Menu)
            {
                gameState = GameState.Play;
            }

            // if we're actually playing, update mouse state and update board
            if (gameState == GameState.Play)
            {
                numberGuessed = numberBoard.Update(gameTime, mouse);
            }
            if (numberGuessed)
            {
                soundBank.PlayCue("newGame");
                StartGame();
            }

            base.Update(gameTime);
        }
示例#4
0
        /// <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)
        {
            KeyboardState keyboard = Keyboard.GetState();

            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || keyboard.IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }


            if (gameState == GameState.Menu && Keyboard.GetState().IsKeyDown(Keys.Enter))
            {
                gameState = GameState.Play;
            }

            // if we're actually playing, update mouse state and update board

            if (gameState == GameState.Play)
            {
                MouseState mouse = Mouse.GetState();
                isCorrectNumber = numberBoard.Update(gameTime, mouse);
                if (isCorrectNumber)
                {
                    soundBank.PlayCue("newGame");
                    StartGame();
                }
            }
            base.Update(gameTime);
        }
        /// <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)
        {
            KeyboardState keyboard = Keyboard.GetState();

            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
                Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            // Increment 2: change game state if game state is GameState.Menu and user presses Enter
            if (gameState == GameState.Menu && Keyboard.GetState().IsKeyDown(Keys.Enter))
            {
                gameState = GameState.Play;
            }

            // if we're actually playing, update mouse state and update board
            if (gameState == GameState.Play)
            {
                bool guessedNumber = numberBoard.Update(gameTime, Mouse.GetState());
                if (guessedNumber)
                {
                    soundBank.PlayCue("newGame");
                    StartGame();
                }
            }

            base.Update(gameTime);
        }
示例#6
0
        /// <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
            // 70. Change the if statement at the top of the Game1 Update method to exit if the <Esc> key is pressed
            // (Chapter 15, Week 7)
            if ((GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) ||
                (Keyboard.GetState().IsKeyDown(Keys.Escape)))
            {
                this.Exit();
            }



            // Increment 2: change game state if game state is GameState.Menu and user presses Enter
            // 18. In the Game1 Update method, add an if statement that changes the game state to GameState.Play if
            //the current game state is GameState.Menu and the Enter key is pressed. The following code returns
            //true if the Enter key is pressed and false otherwise:
            //Keyboard.GetState().IsKeyDown(Keys.Enter)
            //and the following code changes the game state to GameState.Play
            //gameState = GameState.Play;
            //(Chapter 7, Week 3)
            if ((gameState == GameState.Menu) && (Keyboard.GetState().IsKeyDown(Keys.Enter)))
            {
                gameState = GameState.Play;
            }

            // if we're actually playing, update mouse state and update board
            // 29. In the Game1 Update method, if the current game state is GameState.Play get the current mouse
            // state and call the NumberBoard Update method (Chapter 8, Week 4)
            if (gameState == GameState.Play)
            {
                MouseState mouse = Mouse.GetState();

                //54. In the Game1 Update method, change the call to the NumberBoard Update method to declare a
                //    variable to tell whether or not the correct number has been guessed and put the returned
                //    value from the
                //    method call into that variable (Chapter 4, Week 2)
                bool guessed = numberBoard.Update(gameTime, mouse);

                //56. In the Game1 Update method, add an if statement right after the call to the NumberBoard Update
                //    method to check if the correct number has been guessed. If it has, call the StartGame method (Chapter 7,
                //    Week 3)
                if (guessed)
                {
                    //69. In the Game1 Update method, add code to play the newGame cue before calling the StartGame
                    //    method. We do this here rather than in the StartGame method because we don't want this cue to play for
                    //    the first game (Chapter 14, Week 7)
                    soundBank.PlayCue("correctGuess");
                    this.StartGame();
                }
            }


            base.Update(gameTime);
        }
示例#7
0
        /// <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();
            }

            // Increment 2: change game state if game state is GameState.Menu and user presses Enter
            if (gameState == GameState.Menu && Keyboard.GetState().IsKeyDown(Keys.Enter))
            {
                gameState = GameState.Play;
            }

            // if we're actually playing, update mouse state and update board
            if (gameState == GameState.Play)
            {
                MouseState mouse = Mouse.GetState();
                numberBoard.Update(gameTime, mouse);
            }

            base.Update(gameTime);
        }