Beispiel #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 (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            // TODO: Add your update logic here
            if (gameState == GameState.Game)
            {
                if (board.IsGameOver && board.IsGameQuit == false)
                {
                    if (endOfGame == 0)
                    {
                        endOfGame = gameTime.TotalGameTime.Seconds;
                    }
                    else
                    {
                        if (endOfGame + 3 < gameTime.TotalGameTime.Seconds)
                        {
                            endOfGame = 0;
                            System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show("Would you like to start a new game?", "New Game", System.Windows.Forms.MessageBoxButtons.YesNo);
                            if (result.Equals(System.Windows.Forms.DialogResult.Yes))
                            {
                                board     = null;
                                gameState = GameState.Game;
                                CreateChessGame();
                            }
                            else
                            {
                                board     = null;
                                gameState = GameState.Menu;
                            }
                        }
                    }
                }
                else if (board.IsGameQuit)
                {
                    System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show("Would you like to start a new game?", "New Game", System.Windows.Forms.MessageBoxButtons.YesNo);
                    if (result.Equals(System.Windows.Forms.DialogResult.Yes))
                    {
                        board     = null;
                        gameState = GameState.Game;
                        CreateChessGame();
                    }
                    else
                    {
                        board     = null;
                        gameState = GameState.Menu;
                    }
                }
                else
                {
                    board.Update(gameTime);
                }
            }
            else if (gameState == GameState.Menu)
            {
                if (menu.PlayClicked)
                {
                    //Reset Game Then Start it
                    gameState        = GameState.Game;
                    menu.PlayClicked = false;
                    CreateChessGame();
                }
                else if (menu.QuitClicked)
                {
                    this.Exit();
                }
                menu.Update(gameTime);
            }

            base.Update(gameTime);
        }