static void Move(object obj) { if (walls.IsHit(snake.GetHead()) || snake.IsHit(snake.GetHead())) { time.Change(0, Timeout.Infinite); } else if (snake.Eat(food.food)) { food.CreateFood(); } else { snake.Move(); } }
static void Main(string[] args) { Console.SetBufferSize(80, 25); //рисуем границы Walls walls = new Walls(80, 25); walls.Draw(); Point pStart = new Point(4, 5, 'O'); Snake snake = new Snake(pStart, 4, Directions.RIGHT); snake.Draw(); FoodCreator foodCreator = new FoodCreator(80, 25, '$'); Point food = foodCreator.CreateFood(); food.Draw(); while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { break; } if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); } else { snake.Move(); } Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } } WriteGameOver(); Console.ReadLine(); }