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(); }
static void Main(string[] args) { Console.SetBufferSize(80, 25); //отрисовка рамки HorizontalLine upline = new HorizontalLine(0, 78, 0, '+'); upline.Drow(); HorizontalLine downline = new HorizontalLine(0, 78, 24, '+'); downline.Drow(); VerticalLine leftline = new VerticalLine(0, 0, 24, '+'); leftline.Drow(); VerticalLine rigthline = new VerticalLine(78, 0, 24, '+'); rigthline.Drow(); //отрисовка точек Point p1 = new Point(7, 18, '*'); Snake snake = new Snake(p1, 4, Direction.RIGTH); snake.Drow(); //генерация еды FoodCreator foodCreator = new FoodCreator(80, 25, '%'); Point food = foodCreator.CreateFood(); food.Draw(); //движение змейки while (true) { if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); } else { snake.Move(); } Thread.Sleep(120); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.Handle(key.Key); } } }
static void Main(string[] args) { Console.SetBufferSize(81, 41); Console.CursorVisible = false; Console.WindowWidth = Console.BufferWidth; Console.WindowHeight = Console.BufferHeight; Wall w = new Wall(Console.BufferWidth, Console.BufferHeight); Snake snake = new Snake(new Point(4, 2, '*'), 4, Direction.RIGHT); Food food = new Food(Console.BufferWidth, Console.BufferHeight, '$', snake); food.Create(); new Point(40, 2, '%').Draw(); while (snake.Collide(w.pList)) { if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.Controle(key.Key); } Thread.Sleep(100); if (snake.Eat(food)) { food.Create(); } else { snake.Move(); } } //Console.SetCursorPosition(65, 2); //Console.ReadLine(); }