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); }
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; } } }
/// <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; } } } }