Rudimentary rendering and movement implemented

This commit is contained in:
morpha 2023-03-24 17:52:50 +01:00
parent d41481a6a2
commit 256a05b930

View File

@ -2,9 +2,76 @@
{ {
internal class Program internal class Program
{ {
public enum Direction
{
Up,
Down,
Left,
Right
}
private static Direction _direction = Direction.Up;
static void Main(string[] args) static void Main(string[] args)
{ {
Console.WriteLine("Hello, World!"); Console.SetCursorPosition(Console.WindowWidth/2, Console.WindowHeight/2);
for(int i = 1; ;++i)
{
HandleInput();
ProcessMovement();
DrawSnake();
Thread.Sleep(100);
}
}
private static void DrawSnake()
{
Console.Write('#');
--Console.CursorLeft;
}
private static void ProcessMovement()
{
switch (_direction)
{
case Direction.Up:
--Console.CursorTop;
break;
case Direction.Down:
++Console.CursorTop;
break;
case Direction.Right:
++Console.CursorLeft;
break;
case Direction.Left:
--Console.CursorLeft;
break;
}
}
static void HandleInput()
{
if (Console.KeyAvailable)
{
switch(Console.ReadKey(true).Key)
{
case ConsoleKey.UpArrow:
case ConsoleKey.W:
_direction = Direction.Up;
break;
case ConsoleKey.DownArrow:
case ConsoleKey.S:
_direction = Direction.Down;
break;
case ConsoleKey.LeftArrow:
case ConsoleKey.A:
_direction = Direction.Left;
break;
case ConsoleKey.RightArrow:
case ConsoleKey.D:
_direction = Direction.Right;
break;
}
}
} }
} }
} }