public Point CreateFood(MapObjectsList mapObjectsList) { int x, y; Point p; do { x = random.Next(2, mapObjectsList.mapWidht - 2); y = random.Next(2, mapObjectsList.mapHeight - 2); p = new Point(x, y, sym); } while (mapObjectsList.isHit(p)); return(p); }
public bool Move(MapObjectsList fList) { Point tail = pList.First(); pList.Remove(tail); Point head = GenNextPoint(); if (fList.isHit(head)) { return(false); } pList.Add(head); tail.Clear(); head.Draw(); return(true); }
public static void Main(string[] args) { Console.CursorVisible = false; //Console.SetWindowSize (200, 100); //Console.SetBufferSize (200, 100); int level = 1; MapObjectsList mapObjectsList = new MapObjectsList(Console.BufferWidth, Console.BufferHeight, level); Point p = new Point(6, 2, '*'); Snake snake = new Snake(p, 4, Direction.RIGHT); mapObjectsList.Add(snake); mapObjectsList.Draw(); FoodCreator foodCreator = new FoodCreator('$'); Point food = foodCreator.CreateFood(mapObjectsList); food.Draw(); while (true) { if (snake.Eat(food)) { food = foodCreator.CreateFood(mapObjectsList); food.Draw(); snake.Draw(); } else { if (!snake.Move(mapObjectsList)) { Console.Write("Ты проиграл"); break; } } Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } } Console.ReadLine(); }