static void Main(string[] args) { const int X = 100; const int Y = 30; Console.SetWindowSize(X, Y); Console.SetBufferSize(X, Y); Console.CursorVisible = false; new Walls(X, Y); Point point = new Point(5, 4, '*'); Snake snake = new Snake(point, 2, Direction.RIGHT); snake.Draw(); Console.ForegroundColor = ConsoleColor.Red; Food foodCreate = new Food(80, 25, '@'); Point food = foodCreate.CreateFood(); food.Draw(); Console.ForegroundColor = ConsoleColor.White; ConsoleKeyInfo key = Console.ReadKey(); while (true) { if (snake.EqualityCoordinatesTail()) { Console.ForegroundColor = ConsoleColor.Red; Console.SetCursorPosition(X / 2 - 5, Y / 2); Console.WriteLine("Game over!!"); Console.SetCursorPosition(X / 2 - 10, Y / 2 + 1); Console.WriteLine("Press any key to exit."); Console.ReadKey(); break; } if (snake.Eat(food)) { Console.ForegroundColor = ConsoleColor.Red; food = foodCreate.CreateFood(); food.Draw(); Console.ForegroundColor = ConsoleColor.White; } else { snake.Move(); } Thread.Sleep(100); if (Console.KeyAvailable) { key = Console.ReadKey(); snake.Motion(key.Key); } } }
static void Main(string[] args) { Console.WriteLine("DIMA BOBROVICH"); HorizontalLine topLine = new HorizontalLine(0, 60, 1, '+'); HorizontalLine botLine = new HorizontalLine(0, 60, 20, '+'); VerticalLine leftLine = new VerticalLine(0, 1, 20, '+'); VerticalLine RightLine = new VerticalLine(60, 1, 20, '+'); topLine.Draw(); botLine.Draw(); leftLine.Draw(); RightLine.Draw(); Point p1 = new Point(1, 4, '*'); Snake snake = new Snake(p1, 4, Direction.RIGHT); Food f = new Food(60, 20, '@'); Point food = f.CreateFood(); food.Draw(); var i = 0; while (true) { if (i > 8) { i = 0; } if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); if (key.Key == ConsoleKey.LeftArrow) { snake.direction = Direction.LEFT; } if (key.Key == ConsoleKey.RightArrow) { snake.direction = Direction.RIGHT; } if (key.Key == ConsoleKey.UpArrow) { snake.direction = Direction.DOWN; } if (key.Key == ConsoleKey.DownArrow) { snake.direction = Direction.UP; } } Thread.Sleep(200); snake.Move(i); if (snake.Eat(food)) { food = f.CreateFood(); food.Draw(); } i++; } }
static void Main(string[] args) { int mapWidth = 80; int mapHeight = 50; Console.SetWindowSize(mapWidth, mapHeight); Console.SetBufferSize(mapWidth, mapHeight); Walls walls = new Walls(mapWidth, mapHeight); walls.Draw(); Point p = new Point(40, 25, '*'); Snake snake = new Snake(p, 4, Direction.DOWN); snake.Draw(); Food foodCreator = new Food(mapWidth, mapHeight, '@'); 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(); //Создаём змеючку Snake snake = new Snake(new Point(2, 2, '+'), 5, Direaction.RIGHT); snake.Draw(); //Создаём кушанье Food foodWork = new Food(80, 25); Point food = foodWork.CreateFood(snake); food.Draw(); //Старт while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { break; } if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } if (snake.Eat(food)) { food = foodWork.CreateFood(snake); food.Draw(); } Thread.Sleep(100); snake.Move(); } Console.ReadLine(); }
public void EatFood() { if (snake.SnakeRec[0].IntersectsWith(food.FoodObj)) { food.CreateFood(); snake.IncreaseLength(); score.AddScore(); } }
public void Draw() { food.Draw(); wall.Draw(); while (true) { worm.Move(); if (worm.body[0].Equals(food.body[0])) { worm.body.Add(new Point { X = food.body[0].X, Y = food.body[0].Y }); food.body[0] = food.CreateFood(wall.body, worm.body); } else { foreach (Point p in wall.body) { if (p.Equals(worm.body[0])) { Console.Clear(); Console.SetCursorPosition(10, Game.boardH / 2); Console.WriteLine("GAME OVER!!!"); isAlive = false; Console.ForegroundColor = ConsoleColor.Black; Stop(); } } } worm.Draw(); food.Draw(); Thread.Sleep(Game.interval); } }
static void Main(string[] args) { Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; Console.SetWindowSize(1, 1); Console.SetBufferSize(80, 25); Console.SetWindowSize(80, 25); Vert VertL = new Vert(0, 24, 0, "*"); VertL.Draw(); Gor GorD = new Gor(0, 78, 24, "*"); GorD.Draw(); Vert VertR = new Vert(0, 24, 78, "*"); VertR.Draw(); Gor GorUp = new Gor(0, 78, 0, "*"); GorUp.Draw(); Walls walls = new Walls(80, 25); walls.Draw(); Point p = new Point(4, 5, "+"); //Vert vl = new Vert(0, 10, 5, "%"); //Draw(vl); //Point p = new Point(4, 5, "*"); //Figure fsnake = new Snake(p, 4, Direction.right); //Draw(fsnake); //Snake snake = (Snake)fsnake; //Gor gl = new Gor(0, 5, 6, "#"); //Draw(gl); //List<Figure> figures = new List<Figure>(); //figures.Add(fsnake); //figures.Add(vl); //figures.Add(gl); //foreach(var f in figures) //{ // f.Draw(); //} Snake snake = new Snake(p, 4, Direction.right); snake.Draw(); Food FoodCreator = new Food(80, 25, "$"); Point food = FoodCreator.CreateFood(); food.Draw(ConsoleColor.Black); tttt tttt = new tttt(0); while (true) { int a = 0; if (walls.IsHit(snake) || snake.IsHitTail()) { break; } if (snake.Eat(food)) { food = FoodCreator.CreateFood(); food.Draw(ConsoleColor.Red); } else { snake.move(); } Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.handl(key.Key); } } WriteScore(); Console.ReadLine(); }
public void Draw() { food.Draw(); Console.ForegroundColor = ConsoleColor.Blue; Console.SetCursorPosition(15, 24); Console.WriteLine("SCORE:{0}", score); wall.Draw(); while (true) { worm.Move(); Console.ForegroundColor = ConsoleColor.Blue; Console.SetCursorPosition(15, 24); Console.WriteLine(" "); Console.SetCursorPosition(15, 24); Console.WriteLine("SCORE:{0}", score); if (worm.body[0].Equals(food.body[0])) { worm.body.Add(new Point { X = food.body[0].X, Y = food.body[0].Y }); food.body[0] = food.CreateFood(wall.body, worm.body); score++; } else { foreach (Point p in wall.body) { if (p.Equals(worm.body[0])) { Console.Clear(); Console.SetCursorPosition(10, Game.boardH / 2); Console.WriteLine("GAME OVER!!!"); isAlive = false; Console.ForegroundColor = ConsoleColor.Black; Stop(); } } } if (score == 3) { wall.CleanBody(); interval = 200; gameLevel = GameLevel.Second; wall.LoadLevel(GameLevel.Second); Console.Clear(); wall.Draw(); food.body[0] = food.CreateFood(wall.body, worm.body); worm.body.Clear(); worm.body.Add(new Point { X = 24, Y = 16 }); score++; continue; } worm.Draw(); food.Draw(); Thread.Sleep(Game.interval); } }
static void Main(string[] args) { int Width = 40; int Height = 20; int delay = Width * Height / 100; int Score = 1; Console.SetWindowSize(Width, Height); Console.SetBufferSize(Width, Height); Console.CursorVisible = false; Console.Title = "Счет : 0"; Snake snake = new Snake(); Food food = new Food(); ConsoleKey key; snake.Render(); food.CreateFood(Width, Height, snake); food.Render(); do { while (!Console.KeyAvailable) { if (snake.SnakeHead.X == 0 || snake.SnakeHead.X == Width || snake.SnakeHead.Y == 0 || snake.SnakeHead.Y == Height) { return; } if (snake.FoodCollider(food)) { food.CreateFood(Width, Height, snake); Console.Title = "Счет: " + Score; Score++; } snake.Push(snake.SnakeHead); if (snake.Length >= Score) { snake.RemoveFirst(); } Thread.Sleep(500); switch (snake.Moving) { case "left": snake.SnakeHead.X--; break; case "right": snake.SnakeHead.X++; break; case "up": snake.SnakeHead.Y--; break; case "down": snake.SnakeHead.Y++; break; } Console.Clear(); food.Render(); snake.Render(); } key = Console.ReadKey(true).Key; snake.SnakeHeadMove(key); Thread.Sleep(delay); Console.Clear(); food.Render(); snake.Render(); } while (key != ConsoleKey.Escape); }