Beispiel #1
0
        //Take the user keypress and handles the case, depending on the the key that was pressed
        static State ParseCommand()
        {
            bool isValid = true;

            do
            {
                isValid = true;
                ConsoleKeyInfo keyInfo;
                keyInfo = Console.ReadKey(true);

                switch (keyInfo.Key)
                {
                case ConsoleKey.RightArrow:
                {
                    _player.MoveEast();
                    break;
                }

                case ConsoleKey.LeftArrow:
                {
                    _player.MoveWest();
                    break;
                }

                case ConsoleKey.UpArrow:
                {
                    _player.MoveNorth();
                    break;
                }

                case ConsoleKey.DownArrow:
                {
                    _player.MoveSouth();
                    break;
                }

                case ConsoleKey.I:
                {
                    break;
                }

                case ConsoleKey.B:
                {
                    return(State.Battle);
                }

                default:
                {
                    UI.WriteToInfoArea("Please choose a correct command.");
                    isValid = false;
                    break;
                }
                }

                return(State.Exploration);
            } while (!isValid);
        }