Example #1
0
        public InputConsole(IPotatoChipGame game, GameState gameState)
            : base(125, 6)
        {
            this.game      = game;
            this.gameState = gameState;

            this.gameState.PromptTextChanged += () =>
            {
                //Prompt = gameState.PromptText ?? $"{gameState.CurrentRoom.Name} Command >>" ?? string.Empty;
                //Prompt = Prompt + " ";
                //Cursor.Print(Prompt);
            };

            _keyboardHandlerObject = new ClassicConsoleKeyboardHandler();

            // Assign our custom handler method from our handler object to this consoles keyboard handler.
            // We could have overridden the ProcessKeyboard method, but I wanted to demonstrate how you
            // can use your own handler on any console type.
            Components.Add(_keyboardHandlerObject);

            // Our custom handler has a call back for processing the commands the user types. We could handle
            // this in any method object anywhere, but we've implemented it on this console directly.
            _keyboardHandlerObject.EnterPressedAction = EnterPressedActionHandler;

            // Enable the keyboard and setup the prompt.
            UseKeyboard      = true;
            Cursor.IsVisible = true;

            // Startup description
            ClearText();

            Cursor.Position = new Point(0, 0);
            _keyboardHandlerObject.CursorLastY = 0;
            TimesShiftedUp = 0;

            Cursor.DisableWordBreak = true;
            Cursor.Print(Prompt);
            Cursor.DisableWordBreak = false;
        }
Example #2
0
        // This console domonstrates a classic MS-DOS or Windows Command Prompt style console.
        public DOSConsole()
            : base(80, 23)
        {
            IsVisible = false;

            // This is our cusotmer keyboard handler we'll be using to process the cursor on this console.
            _keyboardHandlerObject = new InputHandling.ClassicConsoleKeyboardHandler();

            // Our custom handler has a call back for processing the commands the user types. We could handle
            // this in any method object anywhere, but we've implemented it on this console directly.
            _keyboardHandlerObject.EnterPressedAction = EnterPressedActionHandler;

            // Enable the keyboard and setup the prompt.
            UseKeyboard      = true;
            Cursor.IsVisible = true;
            Prompt           = "Prompt> ";


            // Startup description
            ClearText();

            // Disable the cursor since our keyboard handler will do the work.
            Cursor.IsEnabled = false;
            Cursor.Position  = new Point(0, 24);
            Cursor.Print("Try typing in the following commands: help, ver, cls, look. If you type exit or quit, the program will end.").NewLine().NewLine();
            _keyboardHandlerObject.CursorLastY = 24;
            TimesShiftedUp = 0;

            Cursor.DisableWordBreak = true;
            Cursor.Print(Prompt);
            Cursor.DisableWordBreak = false;

            // Assign our custom handler method from our handler object to this consoles keyboard handler.
            // We could have overridden the ProcessKeyboard method, but I wanted to demonstrate how you
            // can use your own handler on any console type.
            SadComponents.Add(_keyboardHandlerObject);
        }