예제 #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
        static string CalculateWithPattern(string lastposition, int x, int y, string instructions) //chainofresponsibility
        {
            Handler h1 = new LeftHandler();
            Handler h2 = new RightHandler();
            Handler h3 = new MHandler3();

            h1.SetNext(h2);
            h2.SetNext(h3);
            foreach (char instruction in instructions)
            {
                var tupple = h1.HandleRequest(instruction, lastposition, x, y);
                lastposition = tupple.Item1;
                x            = tupple.Item2;
                y            = tupple.Item3;
            }

            return(x.ToString() + y + lastposition);
        }
예제 #4
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;
                }
                }
            }
        }