using Snake.CLI; using Snake.Core; const int boardWidth = 20; const int boardHeight = 15; const int tickMs = 120; SnakeGame game = new(boardWidth, boardHeight); ConsoleRenderer.Render(game); while (true) { if (Console.KeyAvailable) { var key = Console.ReadKey(intercept: true).Key; switch (key) { case ConsoleKey.UpArrow: game.SetDirection(Direction.Up); break; case ConsoleKey.DownArrow: game.SetDirection(Direction.Down); break; case ConsoleKey.LeftArrow: game.SetDirection(Direction.Left); break; case ConsoleKey.RightArrow: game.SetDirection(Direction.Right); break; case ConsoleKey.Q: return; case ConsoleKey.R when game.IsGameOver: game = new SnakeGame(boardWidth, boardHeight); break; } } if (!game.IsGameOver) game.Tick(); ConsoleRenderer.Render(game); Thread.Sleep(tickMs); }