public void ProcessInput(KeyboardState currentKeyState, KeyboardState lastKeyState) { if (lastKeyState.IsKeyDown(Keys.Down) && currentKeyState.IsKeyUp(Keys.Down)) { NextMenuItem(); } else if (lastKeyState.IsKeyDown(Keys.Up) && currentKeyState.IsKeyUp(Keys.Up)) { PrevMenuItem(); } else if (lastKeyState.IsKeyDown(Keys.Enter) && currentKeyState.IsKeyUp(Keys.Enter)) { switch(currentButtonIndex) { case 0: stateSwitchFlag = gameStateType.GameScreen; break; case 1: stateSwitchFlag = gameStateType.HighScoreScreen; break; case 2: stateSwitchFlag = gameStateType.ExitGame; break; } } }
protected override void Update(GameTime gameTime) { currentKeyState = Keyboard.GetState(); if (currentKeyState.IsKeyDown(Keys.Escape)) this.Exit(); currentGameState.ProcessInput(currentKeyState,prevKeyState); currentGameState.Update((float)gameTime.ElapsedGameTime.TotalSeconds); prevKeyState = currentKeyState; if (currentGameStateFlag != currentGameState.stateSwitch()) { currentGameStateFlag = currentGameState.stateSwitch(); switch (currentGameStateFlag) { case gameStateType.GameScreen: currentGameState = new GameScreen(); break; case gameStateType.HighScoreScreen: currentGameState = new HighScoreScreen(); break; case gameStateType.MenuScreen: currentGameState = new MenuScreen(); break; case gameStateType.ExitGame: this.Exit(); break; } } base.Update(gameTime); }