static void Init() { FoodFactory.Food.Clear(); snake?.Dispose(); gg?.Clear(); walls = new Walls(x, y, '#'); foodFactory.CreateFood(); snake = new Snake(x / 2, y / 2, 4); time = new Timer(Loop, null, 0, 95); }
static void Main(string[] args) { Console.SetBufferSize(80, 25); Walls walls = new Walls(80, 25); walls.Draw(); //Отрисовка точек Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.RIGHT); snake.Drow(); 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); } } Console.ForegroundColor = ConsoleColor.Cyan; Console.SetCursorPosition(33, 11); Console.WriteLine("GAME OVER"); Console.SetCursorPosition(33, 12); Console.WriteLine("Thanks for Watching"); Console.SetCursorPosition(33, 13); Console.WriteLine("Maks EMS production with GeekBrains"); Console.SetCursorPosition(33, 14); Console.WriteLine("Press Enter for exit"); Console.ReadLine(); }
static void Main(string[] args) { Console.WindowWidth = 85; Console.WindowHeight = 25; Console.SetBufferSize(85, 25); Console.CursorVisible = false; Walls walls = new Walls(85, 25); walls.Draw(); Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 3, Direction.RIGHT); snake.Draw(); Food newFood = new Food(85, 25, '$'); Point food = newFood.Create(); food.Draw(); while (true) { if (walls.Hit(snake) || snake.HitTail()) { break; } if (snake.Eat(food)) { food = newFood.Create(); food.Draw(); } else { snake.Move(); } Thread.Sleep(150); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.Handle(key.Key); } } Console.Clear(); walls.Draw(); Console.SetCursorPosition(37, 12); Console.WriteLine("You Lose!"); Console.ReadKey(); }
static void Main(string[] args) { Console.SetBufferSize(88, 25); //Отрисовка стен - рамочки Walls walls = new Walls(88, 25); walls.Draw(); //Отрисовка змейки Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.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); // изменяем направление змейки } } //Чтобы не отображался курсор Console.CursorVisible = false; }
static void Main(string[] args) { // создаем границы консоли Arkasha Console.SetBufferSize(80, 25); Walls walls = new Walls(80, 25); walls.Draw(); //отрисовка точек Point p = new Point(10, 10, '*'); Snake snake = new Snake(p, 3, Direction.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.SetWindowSize(mapWidth, mapHeight); Console.SetBufferSize(mapWidth, mapHeight); Walls walls = new Walls(mapWidth, mapHeight); walls.Draw(); Snake snake = new Snake(new Point(50, 20, '*'), 6, Direction.RIGHT); snake.Draw(); FoodCreatot foodCreatot = new FoodCreatot(mapWidth, mapHeight, '&', '%', '$', '#'); Point food = foodCreatot.CreateFood(); food.Draw(); while (true) { if (walls.Collision(snake) || snake.TailCollision()) { Console.Beep(); break; } if (snake.Eat(food)) { food = foodCreatot.CreateFood(); food.Draw(); } else { snake.Move(); } if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.KeyHandler(key.Key); } Thread.Sleep(100); } Console.Clear(); Console.SetCursorPosition((mapWidth / 2) - 4, mapHeight / 2); Console.WriteLine(" GAME OVER "); Console.ReadKey(); }
static void Main(string[] args) { Console.SetWindowSize(80, 25); Console.SetBufferSize(80, 25); Console.CursorVisible = false; Walls walls = new Walls(80, 25); walls.Draw(); //Отрисовка точек Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.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); } } }
static void Main(string[] args) { Console.SetBufferSize(120, 30); Walls walls = new Walls(120, 30); walls.Draw(); //Отрисовка точек point p = new point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.right); snake.Draw(); FoodCreator foodCreator = new FoodCreator(120, 30, '$'); 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); //установить размер окна и убрать возможность перемотки Walls walls = new Walls(80, 25); walls.Draw(); //Отрисовка змеи Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.RIGHT); snake.Draw(); FoodCreator foodCreator = new FoodCreator(80, 25, '$'); Point food = foodCreator.CreateFood(); food.Draw(); while(true) { if (walls.IsHit(snake) || snake.IsHitTail()) { Console.Clear(); Console.SetCursorPosition(37, 7); Console.Write("YOU LOSE"); 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); } } Console.ReadKey(); }
static void Main(string[] args) { // Console.SetBufferSize(60, 20); Walls walls = new Walls(60, 20); walls.Draw(); //отрисовка точек Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.Right); snake.Draw(); FoodCreator foodCreator = new FoodCreator(60, 20, '$'); Point food = foodCreator.CreateFood(); food.Draw(); while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { break; } else if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); } else { snake.Move(); } Thread.Sleep(150); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } } }
static void Main(string[] args) { Console.SetBufferSize(80, 25); Walls walls = new Walls(80, 25); walls.Drow(); //Отрисовка точек Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.RIGHT); snake.Drow(); FoodCreator foodCreator = new FoodCreator(80, 25, '$'); Point food = foodCreator.CreateFood(); food.Drow(); while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { break; } if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Drow(); } else { snake.Move(); } Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } } }
static void Main(string[] args) { Walls walls = new Walls(fieldWidth, fielHeigth); walls.draw(); FoodCreator foodCreator = new FoodCreator(fieldWidth, fielHeigth, '$'); Point food = foodCreator.createFood(); food.draw(); Snake snake = new Snake(new Point(4, 4, '+'), 5, Directions.RIGTH); snake.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); } } }
static void Main(string[] args) { Walls walls = new Walls(80, 25); walls.Draw(); //рисуем точки Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.RIGHT); snake.Draw(); FoodCreator foodcreat = new FoodCreator(80, 25, '&'); Point food = foodcreat.CreateFood(); food.Draw(); while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { break; } if (snake.Eat(food)) { food = foodcreat.CreateFood(); food.Draw(); } else { snake.Move(); } if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.Go(key.Key); } Thread.Sleep(100); snake.Move(); } }
static void Main(string[] args) { //Ограничение окна //Console.SetBufferSize(80, 25); #region Wall Walls walls = new Walls(80, 25); walls.Draw(); #endregion #region SnakeBody point p = new point(4, 5, '*'); Snakee snake = new Snakee(p, 4, Direction.RIGHT); snake.DrawLine(); #endregion #region Food foodCreator foodCreator = new foodCreator(80, 25, '$'); point food = foodCreator.CreateFood(); food.Draw(); #endregion while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { break; //Console.Write("Game OVER"); } 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); } } #region Handle Key while (true) { if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } Thread.Sleep(100); snake.Move(); } #endregion //Console.ReadKey(); }