Exemplo n.º 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)
 {
     currKeyboardState = Keyboard.GetState();
     if (Keyboard.GetState().IsKeyDown(Keys.Escape))
     {
         this.Exit();
     }
     switch (currState)
     {
         case State.main:
             MainMenuKeys();
             break;
         case State.playing:
             beat.Update(gameTime);
             if (beat.isGameOver())
             {
                 Database conn = new Database();
                 conn.insertHighScore(currentUserId, beat.getFinalScore());
                 conn.close();
                 Console.WriteLine("Closed db connection after writing highscore");
                 beat = null;
                 currState = State.highscores;
             }
             break;
         case State.instructions:
             username += GetChars();
             if (currKeyboardState.IsKeyDown(Keys.Back) && currKeyboardState != prevKeyboardState && username.Length > 0)
             {
                 username = username.Remove(username.Length - 1);
             }
             break;
         case State.highscores:
             break;
         case State.credits:
             break;
         case State.quiz:
             quiz.Update(gameTime);
             if (quiz.isQuizOver())
             {
                 correctAnswers = quiz.getCorrectAnswers();
                 beat = new Playing(this.Content, correctAnswers, currentUserId);
                 currState = State.playing;
             }
             break;
         default:
             break;
     }
     base.Update(gameTime);
     prevKeyboardState = currKeyboardState;
 }