Пример #1
0
        /// <summary>
        /// The BeingStrategy_UserInput builds a Command based on keyboard input.
        /// It may take thousands of Update() callbacks before a Command
        /// other than CommandIncomplete is returned.
        /// </summary>
        public Command GetCommand(IBeing being)
        {
            var press = Messager.GetNextKeyPress();

            // Most of the time, we'll have no human input, hence no command.
            if (press.Key == Keys.None)
            {
                return(commandIncomplete);
            }

            // Most commands take multiple keystrokes to resolve.
            // When that's true, we've stored the next step to take for when
            // we have the next keystroke(s) to get us closer to a Command.
            if (IsAssemblingCommand)
            {
                return(nextStep(press, being));
            }

            // Otherwise, if we've got a direction key, do that
            var dir = DirectionOf(press);

            if (dir != CmdDirection.None)
            {
                return(Direction(being, dir));
            }

            // Or dispatch the beginning of another Command
            switch (press.Key)
            {
            case Keys.C: return(Consume(being));

            case Keys.D: return(Drop(being));

            case Keys.H: return(Help());

            case Keys.I: return(Inventory(being));

            case Keys.S: return(SaveGame());

            case Keys.U: return(Use(being));

            case Keys.W: return(Wield(being));

            case Keys.OemComma: return(PickUp(being));

            default:
                if (press.Character != default(char))
                {
                    WriteLine($"Command [{press.Character}] is unknown.");
                }
                return(commandIncomplete);
            }
        }
Пример #2
0
        /// <summary> If more input is ready, skip prompt and go to the next step </summary>
        private Command NextStepIs(Func <AsciiKey, IBeing, Command> nextStep, string prompt, IBeing being)
        {
            this.nextStep = nextStep;
            var press = Messager.GetNextKeyPress();

            if (press.Key != Keys.None)
            {
                return(this.nextStep(press, being));
            }

            Messager.Prompt(prompt);
            return(commandIncomplete);
        }
Пример #3
0
        private void HandleGameMenu()
        {
            for (AsciiKey press = Messager.GetNextKeyPress(); press.Key != Keys.None; press = Messager.GetNextKeyPress())
            {
                string readable = Readable(press);
                Log.Info($"At menu, pressed [{readable}]");

                // Quit
                if (press.Key == Keys.Q)
                {
                    if (ConfirmExit())
                    {
                        Game.Instance.Exit();
                    }
                }

                //0.0: Load saved game and resume play
                if (press.Key == Keys.L)
                {
                    GameMode.PopEngineMode();
                    MenuWindow.Hide();
                    LoadSavedGame();

                    // 1.+.SAVE: Hardcore/roguelike load game mode:
                    // delete save file

                    return;
                }

                if (GameInProgress)
                {
                    // Return to game
                    if (press.Key == Keys.R || press.Key == Keys.Escape)
                    {
                        GameMode.PopEngineMode();
                        MenuWindow.Hide();
                        return;
                    }

                    //0.0: Save current game
                    if (press.Key == Keys.S)
                    {
                        SaveTheGame();

                        // 1.+.SAVE: Hardcore/roguelike save game mode:
                        // GameInProgress = false;
                        // UnloadGane();
                        // redraw menu options
                    }
                }
                else
                {
                    // Begin new game
                    if (press.Key == Keys.B)
                    {
                        GameMode.PopEngineMode();
                        MenuWindow.Hide();
                        BeginNewGame();
                        return;
                    }

                    //0.0: Generate new seed, or enter new seed
                }
            }
        }