public Game() { isAlive = true; gameLevel = GameLevel.First; worm = new Worm(new Point { X = 10, Y = 10 }, ConsoleColor.Green, '*'); food = new Food(new Point { X = 20, Y = 10 }, ConsoleColor.Red, '+'); wall = new Wall(null, ConsoleColor.Yellow, '#'); wall.LoadLevel(GameLevel.First); g_objects.Add(worm); g_objects.Add(food); g_objects.Add(wall); }
static void Main(string[] args) { Worm worm = new Worm(); Food food = new Food(); Wall wall = new Wall(1); while (worm.isAlive) { Console.Clear(); worm.Draw(); food.Draw(); wall.Draw(); ConsoleKeyInfo pressedKey = Console.ReadKey(); switch (pressedKey.Key) { case ConsoleKey.UpArrow: worm.Move(0, -1); break; case ConsoleKey.DownArrow: worm.Move(0, 1); break; case ConsoleKey.LeftArrow: worm.Move(-1, 0); break; case ConsoleKey.RightArrow: worm.Move(1, 0); break; case ConsoleKey.Escape: worm.isAlive = false; break; } if (worm.CanEat(food)) { food = new Food(); } } }