Пример #1
0
        public bool ProcessKey(ConsoleKey key)
        {
            switch (key)
            {
            case ConsoleKey.LeftArrow:
                LeftHandler?.Invoke();
                break;

            case ConsoleKey.RightArrow:
                RightHandler?.Invoke();
                break;

            case ConsoleKey.UpArrow:
                TopHandler?.Invoke();
                break;

            case ConsoleKey.DownArrow:
                DownHandler?.Invoke();
                break;

            default:
                return(false);
            }
            return(true);
        }
Пример #2
0
        public void Run()
        {
            while (true)
            {
                var key = Console.ReadKey();
                switch (key.Key)
                {
                case ConsoleKey.UpArrow:
                    UpHandler?.Invoke();
                    break;

                case ConsoleKey.DownArrow:
                    DownHandler?.Invoke();
                    break;

                case ConsoleKey.LeftArrow:
                    LeftHandler?.Invoke();
                    break;

                case ConsoleKey.RightArrow:
                    RightHandler?.Invoke();
                    break;

                case ConsoleKey.Escape:
                    return;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Class for moving by pressing arrow buttons
        /// </summary>
        public void Move()
        {
            while (true)
            {
                var key = Console.ReadKey(true);
                switch (key.Key)
                {
                case ConsoleKey.LeftArrow:
                {
                    LeftHandler?.Invoke(this, EventArgs.Empty);
                    break;
                }

                case ConsoleKey.RightArrow:
                {
                    RightHandler?.Invoke(this, EventArgs.Empty);
                    break;
                }

                case ConsoleKey.UpArrow:
                {
                    UpHandler?.Invoke(this, EventArgs.Empty);
                    break;
                }

                case ConsoleKey.DownArrow:
                {
                    DownHandler?.Invoke(this, EventArgs.Empty);
                    break;
                }

                default:
                {
                    Console.WriteLine("Wrong key was pressed");
                    break;
                }
                }
            }
        }