feat: initial project structure with Snake.Core, CLI and Avalonia skeleton
This commit is contained in:
44
Snake.CLI/Program.cs
Normal file
44
Snake.CLI/Program.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user