static void Keys(Wall wall, Worm worm, Food food) { System system = new System(wall, worm); while (worm.isAlive) { Console.Clear(); worm.Draw(); food.Draw(); Console.ForegroundColor = ConsoleColor.Yellow; wall.Draw(); Console.WriteLine(" Your points:"); Console.WriteLine(Global.points); Console.WriteLine(" Your level:"); Console.WriteLine(Global.level); 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: Serialize(system); worm.isAlive = false; break; case ConsoleKey.Backspace: Console.Clear(); Console.WriteLine(Global.points); break; case ConsoleKey.Spacebar: Serialize(system); break; case ConsoleKey.F2: Console.Clear(); System system2 = Deserialize(); food.WhereisFood(system2.wall, system2.worm); Keys(system.wall, system.worm, food); break; } if (worm.IsDead(wall)) { worm.isAlive = false; } if (worm.body.Count > 3) { Global.level++; Global.points = +50; Worm newworm = new Worm(); Console.Clear(); Wall newwall = new Wall(Global.level); newwall.Draw(); Food newfood = new Food(); newfood.WhereisFood(newwall, newworm); worm.isAlive = true; Keys(newwall, newworm, newfood); } if (worm.CanEat(food)) { food = new Food(); food.WhereisFood(wall, worm); Global.points += 10; } Serialize(system); if (worm.IsDead(wall)) { Console.Clear(); Console.WriteLine(); Console.WriteLine("GAME OVER"); Console.WriteLine("Your points:"); Console.WriteLine(Global.points); Console.WriteLine("max level:"); Console.WriteLine(Global.level); } } }