Esempio n. 1
0
        private (int, int) GetInput()
        {
            var consoleInputController = new ConsoleInputController();

            consoleInputController.AddKeybind(ConsoleKey.H, delegate {
                ToggleHelp?.Invoke();
                var helpInputController = new ConsoleInputController();
                helpInputController.AddKeybind(ConsoleKey.H, delegate { ToggleHelp?.Invoke(); });
                helpInputController.Run();
                consoleInputController.Run();
            });
            consoleInputController.AddKeybind(ConsoleKey.R, Restart);
            consoleInputController.AddKeybind(ConsoleKey.E, () => Environment.Exit(0));

            (int, int)result = (-1, -1);
            AddKeybind(ConsoleKey.D1, ConsoleKey.NumPad1, () => result = (2, 0));
            AddKeybind(ConsoleKey.D2, ConsoleKey.NumPad2, () => result = (2, 1));
            AddKeybind(ConsoleKey.D3, ConsoleKey.NumPad3, () => result = (2, 2));
            AddKeybind(ConsoleKey.D4, ConsoleKey.NumPad4, () => result = (1, 0));
            AddKeybind(ConsoleKey.D5, ConsoleKey.NumPad5, () => result = (1, 1));
            AddKeybind(ConsoleKey.D6, ConsoleKey.NumPad6, () => result = (1, 2));
            AddKeybind(ConsoleKey.D7, ConsoleKey.NumPad7, () => result = (0, 0));
            AddKeybind(ConsoleKey.D8, ConsoleKey.NumPad8, () => result = (0, 1));
            AddKeybind(ConsoleKey.D9, ConsoleKey.NumPad9, () => result = (0, 2));


            consoleInputController.Run();
            return(result);

            void AddKeybind(ConsoleKey key1, ConsoleKey key2, Action action)
            {
                consoleInputController.AddKeybind(key1, action);
                consoleInputController.AddKeybind(key2, action);
            }
        }
Esempio n. 2
0
        static void Main()
        {
            SetUpAndStartGame();
            var consoleInputController = new ConsoleInputController();

            consoleInputController.AddKeybind(ConsoleKey.A, () => ShowResult(gameController.StartGame()));
            consoleInputController.AddKeybind(ConsoleKey.M, () => SetUpAndStartGame());
            consoleInputController.AddKeybind(ConsoleKey.E, () => { });

            while (consoleInputController.key != ConsoleKey.E)
            {
                consoleInputController.Run();
            }
        }