static void Main(string[] args) { //Console.SetBufferSize(80,25); //Отрисовка рамки Walls walls = new Walls(80, 25); walls.Draw(); /* * HorizontalLine upLine = new HorizontalLine(0, 78, 0, '+'); * HorizontalLine downLine = new HorizontalLine(0, 78, 24, '+'); * VerticalLine leftLine = new VerticalLine(0, 24, 0, '+'); * VerticalLine rightLine = new VerticalLine(0, 24, 78, '+'); * * upLine.Drow(); * downLine.Drow(); * leftLine.Drow(); * rightLine.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.Draw(); while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { break; } if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); } else { snake.Move(); } Thread.Sleep(300); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } snake.Move(); } }
static void Main(string[] args) { Console.SetBufferSize(80, 25); Walls w = new Walls(80, 25); w.Draw(); Snake snake = new Snake(new Point(2, 5, '*'), 4, Direction.DOWN); FoodCreator foodCreator = new FoodCreator(25, 80, '&'); Point food = foodCreator.getFood(); food.Draw(); snake.Draw(); while (true) { if (w.isStrike(snake) || snake.isStrike()) { break; } if (snake.Eat(food)) { food = foodCreator.getFood(); food.Draw(); } else { snake.Move(); } if (Console.KeyAvailable) { snake.keyHandler(Console.ReadKey().Key); } Thread.Sleep(200); } }
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()) { 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) { int points = 0; //Установка размера окна консоли (блокировка изменения размера окна и прокрутки) 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(); points++; food.Draw(); } else { snake.Move(); } //скорость движения змейки if (points <= 25) { Thread.Sleep(300 - (points * 10)); } else { Thread.Sleep(50); } if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } } WriteGameOver(points); Console.ReadLine(); }
static void Main(string[] args) { Console.Title = "Счет: 0"; Console.SetWindowSize(101, 27); Walls w = new Walls(100, 26); Snake snake = new Snake(10, 10, 'o', 7, Direction.RIGHT); snake.Draw(); snake.Move(); FoodCreator fc = new FoodCreator(); while (true) { if (snake.CrashedIntoItself() || snake.CrashedIntoTheWall(w)) { break; } if (Console.KeyAvailable) { ConsoleKeyInfo keyInfo = Console.ReadKey(); snake.ChangeDirection(keyInfo); } if (snake.NextStepWithFood(fc.F)) { snake.Eat(fc.F); fc = new FoodCreator(); } Thread.Sleep(100); snake.Move(); } }
static void Main(string[] args) { Console.OutputEncoding = Encoding.UTF8; Console.Write("Enter your name: "); string name = Console.ReadLine(); Console.SetWindowSize(75, 25); Walls walls = new Walls(62, 25); walls.Draw(); // Отрисовка точек Point p = new Point(4, 8, '*', ConsoleColor.Red); Snake snake = new Snake(p, 4, Direction.RIGHT); snake.Draw(); FoodCreator foodCreator = new FoodCreator(62, 25, '$', ConsoleColor.Green); Point food = foodCreator.CreateFood(); food.Draw(); Score score = new Score(0, 1); //score-0, level-1 score.speed = 50; score.ScoreWrite(); while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { break; } if (snake.Eat(food)) { score.ScoreUp(); score.ScoreWrite(); food = foodCreator.CreateFood(); food.Draw(); if (score.ScoreUp()) { score.speed -= 10; } } else { snake.Move(); } Thread.Sleep(score.speed); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } } WriteGameOver(name); Console.ReadLine(); }
static void Main(string[] args) { Point StartPoint = new Point(4, 5, '*'); Snake snake = new Snake(StartPoint, 4, Direction.RIGHT); snake.Draw(); 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(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } } }
static void Main(string[] args) { //Point FirstPoint = new Point(10, 5, '*'); //FirstPoint.drawPoint(); //Console.ReadLine(); Console.SetBufferSize(80, 25); //HorizontalLine upLine = new HorizontalLine(0, 78, 0, '+'); //HorizontalLine downLine = new HorizontalLine(0, 78, 24, '+'); //VerticalLine leftLine = new VerticalLine(0, 24, 0, '+'); //VerticalLine rightLine = new VerticalLine(0, 24, 78, '+'); //upLine.Draw(); //downLine.Draw(); //leftLine.Draw(); //rightLine.Draw(); 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.DrawPoint(); while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { break; } if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.DrawPoint(); } else { snake.Move(); } Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } } //Console.ReadLine(); }
static void Main(string[] args) { Console.SetBufferSize(80, 25); Walls walls = new Walls(80, 25); walls.Draw(); Point p = new Point(1, 5, '*'); Snake snake = new Snake(p, 20, Direktion.RIGHT); snake.Drow(); FoodCreator foodCreator = new FoodCreator(80, 25, '$'); Point food = foodCreator.CreateFood(snake); food.Draw(); while (true) { Thread.Sleep(100); if (Console.KeyAvailable && walls.IsHit(snake) == false) { ConsoleKeyInfo key = Console.ReadKey(); snake.HendleKey(key.Key); } if (snake.IsHitTail()) { break; } if (snake.Eat(food, -77, -23)) { food = foodCreator.CreateFood(snake); food.Draw(); } if (snake.Eat(food, 1, 1)) { food = foodCreator.CreateFood(snake); food.Draw(); } if (walls.IsHit(snake)) { snake.Move(-77, -23); walls.Draw(); } else { snake.Move(1, 1); } } WriteGameOver(); Console.ReadLine(); }
static void Main(string[] args) { int timeSleep = 100; Console.CursorVisible = false; Console.SetWindowSize(80, 25); 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()) { break; } if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); timeSleep -= 15; if (timeSleep < 1) { timeSleep = 10; } } else { snake.Move(); } Thread.Sleep(timeSleep); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } } WriteGameOver(); Console.ReadLine(); }
static void Main(string[] args) { // Рисуем границы Walls wall = new Walls(80, 25); wall.Draw(); //рисуем змею Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 5, Direction.RIGHT); snake.Draw(); //создаём еду FoodCreator foodCeator = new FoodCreator(78, 23, '$'); Point food = foodCeator.CreateFood(); food.Draw(); while (true) { if (snake.crossingWall() || snake.crossingBody()) // проверка столкновения { Console.Clear(); Console.WriteLine("Ты проиграл!"); Console.ReadLine(); break; } if (snake.Eat(food)) { food = foodCeator.CreateFood(); while (true) { if (snake.goodEat(food)) { food.Draw(); break; } else { food = foodCeator.CreateFood(); } } } else { snake.Move(); } Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.iMoveTo(key.Key); } } }
static void Main(string[] args) { // установка размера консоли Console.SetBufferSize(80, 25); // отрисовка рамочки HorizontalLine upline = new HorizontalLine(0, 78, 0, '+'); upline.Drown(); HorizontalLine downline = new HorizontalLine(0, 78, 24, '+'); downline.Drown(); VerticalLine leftline = new VerticalLine(0, 24, 0, '+'); leftline.Drown(); VerticalLine rightline = new VerticalLine(0, 24, 78, '+'); rightline.Drown(); // отрисовка точки Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.right); snake.Drown(); 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(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } } }
static void Main(string[] args) { Music music = new Music(); music.MainMusic(); Walls walls = new Walls(100, 25); walls.Draw(); Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.RIGHT); snake.Draw(); FoodCreator foodCreator = new FoodCreator(100, 25, '$'); Point food = foodCreator.CreateFood(); food.Draw(); int xOffsetO4ki = 40; int yOffsetO4ki = 26; int o4ki = 0; WriteText("Баллы:" + o4ki, xOffsetO4ki, yOffsetO4ki); while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { break; } if (snake.Eat(food)) { music.EatSound(); food = foodCreator.CreateFood(); food.Draw(); o4ki++; Console.SetCursorPosition(xOffsetO4ki, yOffsetO4ki); WriteText("Баллы:" + o4ki, xOffsetO4ki, yOffsetO4ki); } else { snake.Move(); } Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } } music.GameOver(); WriteGameOver(o4ki); Console.ReadLine(); }
static void Main(string[] args) { //Point p1 = new Point(1, 3, '*'); //p1.Draw(); //Point p2 = new Point(4, 5, '#'); //p2.Draw(); //bool error = false; //bool end = false; HorizontalLine line = new HorizontalLine(0, 40, 0, '+'); HorizontalLine line1 = new HorizontalLine(0, 40, 22, '+'); VerticalLine line2 = new VerticalLine(1, 21, 0, '+'); VerticalLine line3 = new VerticalLine(1, 21, 40, '+'); line.Draw(); line1.Draw(); line2.Draw(); line3.Draw(); Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.RIGHT); snake.Draw(); FoodCreator foodCreator = new FoodCreator(18, 19, '$'); Point food = foodCreator.CreateFood(); food.Draw(); while (true) { if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); } else { snake.Move(); } Thread.Sleep(500); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } snake.Move(); } }
static void Main(string[] args) { //Console.WriteLine(Console.BufferHeight.ToString()); //Console.WriteLine(Console.BufferWidth.ToString()); //Console.WriteLine(Console.SetWindowSize); //Console.WriteLine(Console.LargestWindowWidth); //Console.SetBufferSize(80, 25); Console.SetWindowSize(80, 25); Console.CursorVisible = false; Walls walls = new Walls(80, 25); walls.Draw(); // отрисовка точек Point p1 = new Point(4, 5, '*'); Snake snake = new Snake(p1, 4, Direction.RIGHT); snake.Draw(ConsoleColor.Green); FoodCreator foodCreator = new FoodCreator(80, 25, '@'); Point food = foodCreator.CreateFood(); food.Draw(ConsoleColor.Yellow); while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { break; } if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(ConsoleColor.Yellow); } else { snake.Move(); } if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } Thread.Sleep(100); //snake.Move(); } Console.SetCursorPosition(35, 12); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Game over!"); Console.ReadKey(); }
static void Main(string[] args) { //Setting Console size and constrainting it Console.SetWindowSize(80, 25); Console.SetBufferSize(80, 25); //Drawing the frame HorizontalLine hLine1 = new HorizontalLine(0, 78, 0, '+'); HorizontalLine hLine2 = new HorizontalLine(0, 78, 24, '+'); VerticalLine vLine1 = new VerticalLine(0, 24, 0, '+'); VerticalLine vLine2 = new VerticalLine(0, 24, 78, '+'); hLine1.Draw(); hLine2.Draw(); vLine1.Draw(); vLine2.Draw(); //Drawing a dot Dot d = new Dot(4, 5, '*'); //Drawing a snake itself Snake snake = new Snake(d, 4, Direction.RIGHT); snake.Draw(); //Creating food for snake FoodCreator foodCreator = new FoodCreator(80, 25, '*'); Dot food = foodCreator.CreateFood(); food.Draw(); //Controlled snake movement while (true) { if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); snake.Draw(); } else { snake.Move(); } Thread.Sleep(300); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } Thread.Sleep(300); snake.Move(); } }
static void Main(string[] args) { // Рисуем границы Walls wall = new Walls(80, 25); wall.Draw(); //рисуем змею Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 5, Direction.RIGHT); snake.Draw(); //создаём еду FoodCreator foodCeator = new FoodCreator(78, 23, '$'); Point food = foodCeator.CreateFood(); food.Draw(); while (true) { if (snake.crossingWall() || snake.crossingBody()) // проверка столкновения { Console.Clear(); Console.WriteLine("Ты проиграл!"); Console.ReadLine(); break; } if (snake.Eat(food)) { food = foodCeator.CreateFood(); while (true) { if (snake.goodEat(food)) { food.Draw(); break; } else food = foodCeator.CreateFood(); } } else { snake.Move(); } Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.iMoveTo(key.Key); } } }
static void Main(string[] args) { Console.SetBufferSize(80, 25); Walls walls = new Walls(80, 25); walls.Draw(); HorisontalLine lowLine = new HorisontalLine(0, 78, 0, '+'); lowLine.Drow(); HorisontalLine upperLine = new HorisontalLine(0, 78, 24, '+'); upperLine.Drow(); VerticalLine leftLine = new VerticalLine(0, 0, 24, '+'); leftLine.Drow(); VerticalLine rightLine = new VerticalLine(78, 0, 24, '+'); rightLine.Drow(); Point p1 = new Point(4, 4, '*'); Snake snake = new Snake(p1, 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); } } }
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()) { break; } // змейка кушает if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); } else { snake.Move(); } Thread.Sleep(200); // проверка на нажатие какой либо клавиши if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandlKey(key.Key); } } WriteGameOver(); Console.ReadKey(); }
static void Main(string[] args) { Walls walls = new Walls(1, 80); walls.Draw(); //Отрисовка рамки //HotizontalLine line = new HotizontalLine(1,60,0,'-'); //line.Drow(); //HotizontalLine line1 = new HotizontalLine(1, 60, 25, '-'); //line1.Drow(); //VerticalLine line2 = new VerticalLine(1, 24, 1, '|'); //line2.Drow(); //VerticalLine line3 = new VerticalLine(1, 24, 60, '|'); //line3.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.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); } } }
public void game_draw() { Console.Clear(); Console.Title = "Snake"; Console.SetWindowSize(101, 26); Walls walls = new Walls(101, 26); walls.Draw(); Point p = new Point(4, 5, '*', ConsoleColor.Red); Snake snake = new Snake(p, 4, Direction.RIGHT); snake.Draw(); FoodCreator foodCreator = new FoodCreator(101, 26, '¤', ConsoleColor.Green); Point food = foodCreator.CreateFood(); food.Draw(); Score score = new Score(0, 1);//score =0, level=1 score.speed = 135; score.ScoreWrite(); while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { break; } if (snake.Eat(food)) { score.ScoreUp(); score.ScoreWrite(); food = foodCreator.CreateFood(); food.Draw(); //sound.Stop("stardust.mp3"); if (score.ScoreUp()) { score.speed -= 10; } } else { snake.Move(); } Thread.Sleep(score.speed); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(true); snake.HandleKey(key.Key); } } }
static void Main(string[] args) { Console.SetBufferSize(80, 25); int speed = 100; GameObjects gameObjects = new GameObjects(); char sym = '$'; // Создадим и отобразим стены. Так же занесём их в список объектов Walls walls = new Walls('+'); gameObjects.Add(walls); // Создадим змейку Snake snake = new Snake(new Point(2, 3, '*'), 3, Direction.RIGHT); gameObjects.Add(snake); // Создадим еду FoodCreator foodCreator = new FoodCreator('$'); foodCreator.CreateFood(gameObjects, 1); gameObjects.Add(foodCreator); while(true) { if (gameObjects.Intersect(snake)) { Figure intersectFigure = new Figure(); int intersectObjectNum = gameObjects.GetIntersectObjectNum(snake); intersectFigure = gameObjects.GetObject(intersectObjectNum); if(intersectFigure.GetObjectType() == ObjectTypes.FOOD) { gameObjects.DeleteObject(intersectObjectNum); snake.Eat(); FoodCreator foodCreator2 = new FoodCreator('$'); foodCreator2.CreateFood(gameObjects, 2); gameObjects.Add(foodCreator2); } else { Console.SetCursorPosition(10, 10); Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("Game Over"); Console.ReadLine(); break; } } // Проверим нажата ли кнопка if (Console.KeyAvailable) { // Если таки нажата, то изменим направление в соответсвии с нажатием ConsoleKeyInfo key = Console.ReadKey(); snake.HandelKey(key.Key); } Thread.Sleep(speed); snake.Move(); } }
static void Main() { Console.SetBufferSize(150, 50); Console.WindowHeight = 50; Console.WindowWidth = 150; Console.CursorVisible = false; Walls walls = new Walls(148, 49); walls.Draw(); Point p1 = new Point(10, 10, '*'); Snake snake = new Snake(p1, 7, Direction.RIGHT); snake.Draw(); snake.Move(); FoodCreator foodCreator = new FoodCreator(149, 48, '$'); Point food = foodCreator.CreateFood(); food.Draw(); while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { Console.Clear(); Console.SetCursorPosition(75, 25); Console.WriteLine("GAME OVER"); Console.ReadKey(); } if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); } else { snake.Move(); } if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key); } Thread.Sleep(100); } }
static void Main(string[] args) { //Размер экрана const int screenWidth = 100; const int screenHeight = 30; //Настраиваем консоль Console.SetWindowSize(screenWidth, screenHeight); Console.SetBufferSize(screenWidth, screenHeight); //Отрисовка рамочки HorizontalLine topLine = new HorizontalLine(0, screenWidth - 2, 0, '+'); HorizontalLine bottomLine = new HorizontalLine(0, screenWidth - 2, screenHeight - 1, '+'); VerticalLine leftLine = new VerticalLine(0, screenHeight - 1, 0, '+'); VerticalLine rightLine = new VerticalLine(0, screenHeight - 1, screenWidth - 2, '+'); topLine.Draw(); bottomLine.Draw(); leftLine.Draw(); rightLine.Draw(); //Инициализация змейки Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.RIGHT); snake.Draw(); // FoodCreator foodCreator = new FoodCreator(screenWidth, screenHeight, '$'); Point food = foodCreator.CreateFood(); food.Draw(); while (true) { if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); } else { snake.Move(); } Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.SetDirection(key.Key); } } }
static void Main(string[] args) { //Начальное положение змейки Point p1 = new Point(1, 3, '*'); //Создание и отрисовка стен-рамки Walls walls = new Walls(Console.WindowWidth, Console.WindowHeight); walls.Draw(); //Создание и отрисовка змейки Snake snake = new Snake(p1, 4, Direction.Right); snake.Draw(); //Создание генератора еды FoodCreator foodCreator = new FoodCreator(Console.WindowWidth - 1, Console.WindowHeight - 1, '$'); Point food = foodCreator.CreateFood(); food.Draw(); //Отключение отображения курсора Console.CursorVisible = false; //Цикл игры 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(true); snake.HandleKey(key.Key); } } Console.ReadKey(); }
static void Main(string[] args) { Console.SetBufferSize(82, 27); //Отрисовка рамочки. HorisontalLine lowLine = new HorisontalLine(1, 78, 25, '='); HorisontalLine topLine = new HorisontalLine(1, 78, 2, '='); VerticalLine leftLine = new VerticalLine(1, 3, 24, '|'); VerticalLine rightLine = new VerticalLine(78, 3, 24, '|'); lowLine.DrawLine(); topLine.DrawLine(); leftLine.DrawLine(); rightLine.DrawLine(); //Отрисовка еды. FoodCreator foodCreator = new FoodCreator(82, 27, '@'); Point food = foodCreator.CreateFood(); food.Draw(); //Отрисовка змейки. Point startPoint = new Point(3, 4, '*'); Snake snake = new Snake(startPoint, 4, Direction.RIGHT); snake.DrawLine(); while (true) { if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); } else { snake.Move(); } Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.Control(key.Key); } //Thread.Sleep(100); //snake.Move(); } Console.ReadLine(); }
static void Main(string[] args) { const int MAP_WIDTH = 80; const int MAP_HEIGHT = 25; Console.SetWindowSize(MAP_WIDTH, MAP_HEIGHT + 2); Console.SetBufferSize(MAP_WIDTH, MAP_HEIGHT + 2); Walls walls = new Walls(MAP_WIDTH, MAP_HEIGHT); walls.Draw(); DrawScore(MAP_HEIGHT, 0); Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.Right); snake.Draw(); FoodCreator foodCreator = new FoodCreator(MAP_WIDTH, MAP_HEIGHT, '$'); Point food = foodCreator.CreateFood(); food.Draw(); while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { DrawGameOver(); DrawScore(1, snake.Score); break; } if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); DrawScore(MAP_HEIGHT, snake.Score); } else { snake.Move(); } Thread.Sleep(100); if (Console.KeyAvailable) { snake.HandleKey(Console.ReadKey().Key); } } Console.ReadKey(); }
static void Main(string[] args) { Walls walls = new Walls(80, 25); walls.Draw(); //*ОТРИСОВКА РАМОЧКИ //HorizontalLine upLine = new HorizontalLine(0, Console.BufferWidth - 1, 0, 'X'); //HorizontalLine downLine = new HorizontalLine(0, Console.BufferWidth - 1, 28, 'X'); //VerticalLine leftLine = new VerticalLine(0, 28, 0, 'X'); //VerticalLine rightLine = new VerticalLine(0, 28, Console.BufferWidth - 1, 'X'); //upLine.Drow(); //downLine.Drow(); //leftLine.Drow(); //rightLine.Drow(); //Отрисовка точек 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) { int DispHeight = 20; int DispWidth = 80; //Console.SetBufferSize(DispWidth, DispHeight); Console.CursorVisible = false; Borders board = new Borders(DispHeight, DispWidth); board.Draw(); Point p = new Point { x = 60, y = 14, sym = '*' }; Snake snake = new Snake(p, 4, Direction.RIGHT); snake.Draw(); FoodCreator foodCreator = new FoodCreator(DispWidth, DispHeight, '$'); Point food = foodCreator.CreateFood(); food.Draw(); while (true) { board.Draw(); if (board.IsHit(snake) || snake.IsHitTail()) { break; } if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); } else { snake.Move(); } System.Threading.Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HadleKey(key.Key); } } }
static void Main(string[] args) { Console.SetWindowSize(1, 1); Console.SetBufferSize(80, 25); Console.SetWindowSize(80, 25); Console.CursorVisible = false; Point p1 = new Point(1, 3, '*'); p1.Draw(); HorizontalLine upLline = new HorizontalLine(0, 78, 0, '+'); HorizontalLine downLline = new HorizontalLine(0, 78, 23, '+'); VerticalLine leftLine = new VerticalLine(0, 24, 0, '+'); VerticalLine rightLine = new VerticalLine(0, 24, 78, '+'); upLline.Draw(); downLline.Draw(); leftLine.Draw(); rightLine.Draw(); Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.Right); snake.Draw(); FoodCreator foodCreator = new FoodCreator(80, 23, '$'); Point food = foodCreator.CreateFood(); food.Draw(); while (true) { 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); } Thread.Sleep(100); } }
public Game() { Console.SetWindowSize(100, 30); Walls walls = new Walls(80, 25); walls.Draw(); Point p = new Point(4, 5, 'x'); Snake snake = new Snake(p, 4, Direction.RIGHT); snake.Draw(); FoodCreator foodCreator = new FoodCreator(80, 25, 'o'); Point food = foodCreator.CreateFood(); food.Draw(); Params settings = new Params(); Sounds sound = new Sounds(settings.GetResourceFolder()); sound.PlayBackground(); Score count = new Score(0); count.ScoreInGame(); Sounds soundEat = new Sounds(settings.GetResourceFolder()); while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { break; } if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); count.ScoreUp(); count.ScoreInGame(); soundEat.PlayEat(); } else { snake.Move(); } Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.Button(key.Key); } } new GameOverSnake(); sound.PlayEnd(); Thread.Sleep(5000); new EndScore(count.GetScore(), settings.GetResourceFolder()); }
static void Main(string[] args) { Console.SetWindowSize(150, 40); Console.CursorVisible = false; Console.Title = "Snake"; Console.SetBufferSize(150, 40); HorizontalLine lineTopH = new HorizontalLine(0, 149, 0, '-'); lineTopH.Draw(); HorizontalLine lineDownH = new HorizontalLine(0, 149, 38, '-'); lineDownH.Draw(); VerticalLine lineLeftV = new VerticalLine(1, 37, 0, '#'); lineLeftV.Draw(); VerticalLine lineRightV = new VerticalLine(1, 37, 149, '#'); lineRightV.Draw(); Point p = new Point(5, 7, '*'); Snake snake = new Snake(p, 5, Direction.RIGHT); snake.Draw(); 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(100); 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.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(); } if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } Thread.Sleep(100); } Console.ForegroundColor = ConsoleColor.Yellow; int y = 9; WriteLine("============================", 26, y++); WriteLine("Game over", 35, y++); WriteLine("", 26, y += 2); WriteLine("Created by: Oleg Glytenko", 28, y++); WriteLine("My first game!!!", 32, y++); WriteLine("============================", 26, y++); Console.SetCursorPosition(0, 0); Thread.Sleep(1000); Console.ReadKey(); }
static void Main(string[] args) { Console.SetBufferSize(80,25); // Отрисовка рамки HorizontalLine upLine = new HorizontalLine(0, 78, 0, '+'); HorizontalLine downLine = new HorizontalLine(0, 78, 24, '+'); VerticalLine leftLine = new VerticalLine(0, 24, 0, '+'); VerticalLine rightLine = new VerticalLine(0, 24, 78, '+'); upLine.Drow(); downLine.Drow(); leftLine.Drow(); rightLine.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.Draw(); while (true) { 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); } Thread.Sleep(100); snake.Move(); } }
static void Main(string[] args) { Console.SetBufferSize(Console.WindowWidth, Console.WindowHeight); // Рамка Walls walls = new Walls(Console.WindowWidth, Console.WindowHeight); walls.Draw(); //Змея Point p = new Point(4,5); Snake snake = new Snake(p, 4, Direction.RIGHT); snake.Draw(); //Еда FoodCreator foodCreator = new FoodCreator(Console.WindowWidth, Console.WindowHeight, '$'); Point food = foodCreator.CreateFood(); Console.ForegroundColor = ConsoleColor.Cyan; food.Draw(); Console.ResetColor(); //Двигаем while(true) { if (walls.IsHit(snake) || snake.IsHitTail()) break; if (snake.Eat(food)) { food = foodCreator.CreateFood(); Console.ForegroundColor = ConsoleColor.Cyan; food.Draw(); Console.ResetColor(); } else snake.Move(); Thread.Sleep(200); if (Console.KeyAvailable) { snake.HandleKey(Console.ReadKey().Key); } } Console.SetCursorPosition(Console.WindowWidth / 2, Console.WindowHeight / 2); snake.Clear(); food.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Good Bye!"); Console.ResetColor(); Console.ReadLine(); }
static void Main(string[] args) { Walls walls = new Walls(80,25); walls.Draw(); Point tale = new Point(2, 12, '*'); Snake snake = new Snake(tale,7,Direction.right); snake.Draw(); FoodCreator foodCreator = new FoodCreator(78,25,'$'); Point food = foodCreator.CreateFood(); food.Show(); Console.SetCursorPosition(0, 0); Console.Write("Score: 0"); int s = 0; while (true) { if (walls.isHit(snake.points.Last()) || snake.IsHit()) { break; } if (snake.Eat(food)) { s++; Console.SetCursorPosition(0, 0); Console.Write("Score: "+s); Thread.Sleep(10); food = foodCreator.CreateFood(); food.Show(); } if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } Thread.Sleep(150); snake.Move(); } Console.SetCursorPosition(30, 12); Console.WriteLine("OLOLO!!!!!!!!!!!!!!!!!"); Console.ReadLine(); }
static void Main(string[] args) { Console.SetBufferSize(80, 25); Wall wall = new Wall(80, 25, '%'); wall.Drow(); /*VerticalLine vert_line_left = new VerticalLine(24, 0, 79, '%'); vert_line_left.Drow(); VerticalLine vert_line_right = new VerticalLine(24, 0, 0, '%'); vert_line_right.Drow(); HorizontalLine hor_line_bottom = new HorizontalLine(0, 78, 24, '%'); hor_line_bottom.Drow(); HorizontalLine hor_line_top = new HorizontalLine(0, 78, 0, '%'); hor_line_top.Drow();*/ Point start = new Point(15, 5, '*'); Snake snake = new Snake(start, 8, Direction.RIGHT); snake.Drow(); FoodCreator createfood = new FoodCreator(80, 25, '$'); Point food = createfood.CreateFood(); food.Drow(); while(true) { if(wall.IsHit(snake) || snake.IsHitTail() ) { break; } if(snake.Eat(food)) { food = createfood.CreateFood(); food.Drow(); } if(Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key); } Thread.Sleep(100); snake.Move(); } }
static void Main(string[] args) { Console.SetBufferSize(120, 30); //The frame is drawn HorizontalLine upLine = new HorizontalLine(0, 118, 0, '+'); HorizontalLine downLine = new HorizontalLine(0, 118, 29, '+'); VerticalLine leftLine = new VerticalLine(0, 29, 0, '+'); VerticalLine rightLine = new VerticalLine(0, 29, 118, '+'); upLine.Draw(); downLine.Draw(); leftLine.Draw(); rightLine.Draw(); //The points are drawn Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.RIGHT); snake.Draw(); FoodCreator foodCreator = new FoodCreator(129, 30, '$'); Point food = foodCreator.CreateFood(); food.Draw(); while (true) { if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); } else { snake.Move(); } Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandlKey(key.Key); } } }
static void Main(string[] args) { int Width = 80; int Height = 45; Console.SetBufferSize(Width, Height); Console.SetWindowSize(Width - 1, Height - 1); Obstacles border = new Obstacles(); border.setBorder(Width, Height); border.setObstacles(Width, Height); Point p1 = new Point(2, 2, '*'); Snake snake = new Snake(p1, 3, Direction.Right); snake.Drow(); FoodCreator foodCreator = new FoodCreator(Width - 3, Height - 3, '#'); Point food = foodCreator.CreateFood(); food.Draw(); int k = 150; while (true) { if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); k -= 5; } if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.Pressure(key.Key); } Thread.Sleep(k); snake.Move(); Console.SetCursorPosition(0, 0); } }
static void Main(string[] args) { int t; Console.WriteLine(" Выберите свой уровень игры:\nвысокий - 1, средний - 2 или низкий - 3"); ConsoleKeyInfo cinf= Console.ReadKey(); t = (cinf.KeyChar - 48) * 100; Console.Clear(); Console.SetBufferSize(80, 25); Walls wall = new Walls(80, 25); wall.Drow(); Point p1 = new Point(3, 3, '*',ColorSnake.WHITE); Snake sn = new Snake(p1, 5, Direction.RIGHT); sn.Draw(); FoodCreator fc = new FoodCreator(80, 25, '$',ColorSnake.YELLOW); Point food = fc.CreateFood(); food.Draw(); while (true) { if (wall.IsHit(sn) || sn.IsHitTail()) break; if (sn.Eat(food)) { food = fc.CreateFood(); food.Draw(); } else sn.Move(); Thread.Sleep(t); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); sn.HandleKey(key.Key); } } Console.Clear(); Console.WriteLine(" Игра окончена! \nСпасибо за внимание."); Console.ReadLine(); }
public static void Main(string[] args) { Walls walls = new Walls( 79, 24 ); walls.Draw(); // Отрисовка точек Point p = new Point( 4, 5, '*' ); Snake snake = new Snake( p, 4, Direction.RIGHT ); snake.Draw(); FoodCreator foodCreator = new FoodCreator( 77, 22, '$' ); 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.ForegroundColor = ConsoleColor.Green; // Welcome to the Matrix Console.SetBufferSize(120, 30); // Set console window size Point point = new Point(4, 5, '@'); // Start snake position and default snake symbol Hero snake = new Hero(point, 4, Direction.RIGHT); // point = start dir. position and snake symbol, 4 = default snake lenght, default direction snake.DrawFigure(); FoodCreator foodCreator = new FoodCreator(100, 25, '#'); // Max range of food spawn and default food symbol Point foodPoint = foodCreator.CreateFood(); foodPoint.DrawPoint(); Walls walls = new Walls(120, 25); // Max x and y position of walls walls.DrawWalls(); while (true) { if (snake.Eat(foodPoint)) { foodPoint = foodCreator.CreateFood(); foodPoint.DrawPoint(); } else { snake.MoveHero(); } Thread.Sleep(300); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.ChangeDirectionKey(key.Key); } } }
static void Main(string[] args) { int TARGET_SNAKE_LENGTH; int result; TARGET_SNAKE_LENGTH = 10; Console.SetBufferSize(80, 25); Walls walls = new Walls(80, 25); walls.Draw(); ShowMenu(); while (true) { ConsoleKeyInfo action = Console.ReadKey(); if (action.Key == ConsoleKey.S) { Console.Clear(); walls.Draw(); result = 0; Point p = new Point(40, 12, '*'); Snake snake = new Snake(p, 5, Direction.LEFT); snake.Draw(); FoodCreator foodCreator = new FoodCreator(80, 25, '&'); Point food = foodCreator.CreateFood(); food.Draw(); while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { result = 0; break; } if (snake.GetLength() >= TARGET_SNAKE_LENGTH) { result = 1; break; } if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); } else { snake.Move(); } Thread.Sleep(300); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } } Console.Clear(); walls.Draw(); ShowMenu(); if (result==1) ShowMessage("ПОЗДРАВЛЯЕМ! ВЫ ВЫИГРАЛИ."); else ShowMessage("ВЫ ПРОИГРАЛИ. ПОПРОБУЙТЕ ЕЩЁ РАЗ."); } else if (action.Key == ConsoleKey.E) { break; } } /* Console.SetCursorPosition(32, 12); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("==============="); Console.SetCursorPosition(33, 13); Console.WriteLine("ИГРА ОКОНЧЕНА"); Console.SetCursorPosition(32, 14); Console.WriteLine("==============="); Console.ReadLine(); */ }