public void Draw() { if (IsAlive) { wall = new Wall('#', ScoreLevel.Level); worm.Draw(); ScoreLevel.Draw(); food.Draw(); wall.Draw(); } }
public void PlayGame() { level = Gamelevel.First; worm = new Worm(new Point { X = 10, Y = 10 }, ConsoleColor.Gray, '*'); food = new Food(new Point { X = 10, Y = 20 }, ConsoleColor.Green, '+'); wall = new Wall(null, ConsoleColor.DarkMagenta, '#'); food.Draw(); wall.LoadLevel(Gamelevel.First); wall.Draw(); while (isAlive) { if (direction == right) { worm.Move(1, 0); } if (direction == left) { worm.Move(-1, 0); } if (direction == up) { worm.Move(0, -1); } if (direction == down) { worm.Move(0, 1); } if (worm.body.Count == 15) { level = Gamelevel.Second; wall.LoadLevel(Gamelevel.Second); } if (worm.body.Count == 30) { level = Gamelevel.Final; wall.LoadLevel(Gamelevel.Final); } Console.Clear(); worm.Draw(); if (worm.body.Count % 5 == 0) { speed = Math.Max(speed - 10, 1); } Thread.Sleep(speed); } Thread thread = new Thread(PlayGame); thread.Start(); while (isAlive) { ConsoleKeyInfo pressed = Console.ReadKey(); if (pressed.Key == ConsoleKey.UpArrow) { if (direction != down) { direction = up; } } if (pressed.Key == ConsoleKey.DownArrow) { if (direction != up) { direction = down; } } if (pressed.Key == ConsoleKey.RightArrow) { if (direction != left) { direction = right; } } if (pressed.Key == ConsoleKey.LeftArrow) { if (direction != right) { direction = left; } } if (pressed.Key == ConsoleKey.Escape) { mode = GameMode.Menu; } } if (worm.body[0].Equals(food.body[0])) { worm.body.Add(new Point { X = food.body[0].X, Y = food.body[0].Y }); do { food.body[0] = new Point { X = number.Next(0, BoardW - 2), Y = number.Next(0, BoardH - 2) }; }while (worm.body.Contains(food.body[0]) || wall.body.Contains(food.body[0])); } }