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