feat: initial project structure with Snake.Core, CLI and Avalonia skeleton

This commit is contained in:
Heller
2026-06-17 19:02:07 +00:00
commit 42fcaf8631
25 changed files with 661 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
using Snake.Core;
namespace Snake.CLI;
internal static class ConsoleRenderer
{
public static void Render(SnakeGame game)
{
Console.Clear();
Console.WriteLine($"Score: {game.Score}");
if (game.IsGameOver)
Console.WriteLine("Game Over! Press R to restart or Q to quit.");
var board = game.Board;
var snakeCells = game.Snake.Segments.ToHashSet();
var food = game.Food.Position;
Console.Write('+');
Console.Write(new string('-', board.Width * 2));
Console.WriteLine('+');
for (var y = 0; y < board.Height; y++)
{
Console.Write('|');
for (var x = 0; x < board.Width; x++)
{
var position = new Position(x, y);
var symbol = position == food
? '@'
: position == game.Snake.Head
? 'O'
: snakeCells.Contains(position)
? 'o'
: ' ';
Console.Write(symbol);
Console.Write(' ');
}
Console.WriteLine('|');
}
Console.Write('+');
Console.Write(new string('-', board.Width * 2));
Console.WriteLine('+');
Console.WriteLine("Controls: Arrow keys to move, R to restart, Q to quit.");
}
}