Replaced for-loop with while-loop as main loop

Implemented end-game condition triggered by pressing ESC
master
morpha 2023-03-24 17:57:33 +01:00
parent 256a05b930
commit 1ae55c0484
1 changed files with 5 additions and 1 deletions

View File

@ -10,11 +10,12 @@
Right Right
} }
private static bool _running = true;
private static Direction _direction = Direction.Up; private static Direction _direction = Direction.Up;
static void Main(string[] args) static void Main(string[] args)
{ {
Console.SetCursorPosition(Console.WindowWidth/2, Console.WindowHeight/2); Console.SetCursorPosition(Console.WindowWidth/2, Console.WindowHeight/2);
for(int i = 1; ;++i) while(_running)
{ {
HandleInput(); HandleInput();
ProcessMovement(); ProcessMovement();
@ -70,6 +71,9 @@
case ConsoleKey.D: case ConsoleKey.D:
_direction = Direction.Right; _direction = Direction.Right;
break; break;
case ConsoleKey.Escape:
_running = false;
break;
} }
} }
} }