Beispiel #1
0
        public void HandleKeys(Game1 game)
        {
            //update current key state
            currentKeyState = Keyboard.GetState();

            //if the gameState is playing, then do the following stuff,
            if (game.currentGameState == game.playingGameState)
            {
                if (KeyPressed(Keys.T))
                {

                }

                //if you hit espace exit
                if (KeyPressed(Keys.Escape))
                {
                    game.Exit();
                }

                if (KeyPressed(Keys.P))
                {
                    game.messageArea.PauseMessageArea();
                }
                if (KeyPressed(Keys.U))
                {
                    game.messageArea.PauseMessageArea(true);
                }

                //scroll messages back  5 lines
                if (KeyPressed(Keys.W))
                {
                    game.messageArea.ScrollMessageArea(-5);
                }
                //scroll messages forward 5 lines
                if (KeyPressed(Keys.S))
                {
                    game.messageArea.ScrollMessageArea(5);
                }

                if (KeyPressed(Keys.F))
                {
                    game.messageArea.msgList.Add("<Color.Magenta.bold>This is bold and magenta text </Color.Magenta.bold> <i> Press F do do this again</i>");
                }

            }
            else if (game.currentGameState == game.typingGameState)
            {
                //check is a key was released
                foreach (Keys key in lastKeyState.GetPressedKeys())
                {
                    if (KeyPressed(key))
                    {
                        TextEntry castedElem = (TextEntry)activeElement;

                        // TODO: BUG: if you backspace when there aren't any chars
                        // left to backspace away, it'll crash.

                        //if the key was backspace, remove last item in typed
                        if (key == Keys.Back)
                        {
                            castedElem.typed.RemoveAt(castedElem.typed.Count - 1);
                        }

                        else if (key == Keys.Escape)
                        {
                            theGame.currentGameState = theGame.playingGameState;
                        }
                        else
                        {
                            castedElem.typed.Add(key.ToString());
                        }

                    }

                }

                //save the current keystate as last keystate for next loop

            }
            lastKeyState = currentKeyState;
        }