public void Menu() { Console.SetCursorPosition(30, 10); Console.ForegroundColor = ConsoleColor.Green; Console.Write("SNAKE THE GAME\n"); Console.SetCursorPosition(24, 14); Console.ForegroundColor = ConsoleColor.White; Console.Write("Нажми Enter для начала игры"); Console.ReadLine(); Console.Clear(); Walls walls = new Walls(); walls.Draw(); Console.SetCursorPosition(15, 10); Console.Write("Управление: единичное короткое нажатие на стрелки\n"); Console.SetCursorPosition(27, 12); Console.Write("UP DOWN LEFT RIGHT\n"); Console.SetCursorPosition(27, 16); Console.Write("Жми Enter и погнали!"); Console.ReadLine(); Console.Clear(); walls.Draw(); }
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) { 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.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.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) { 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) { // Рисуем границы 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) { 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) { //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(); }
public static void Main(string[] args) { // size of map int MaxMapWidth = 80; int MaxMapHeight = 25; Console.SetBufferSize(MaxMapWidth, MaxMapHeight); // drow frame Walls walls = new Walls(MaxMapWidth, MaxMapHeight); walls.Draw(); // drow point draw snake Point point = new Point(5, 10, '*'); Snake snake = new Snake (point, 5, Direction.RIGHT); snake.Draw (); // draw food FoodCreater foodCreator = new FoodCreater (MaxMapWidth, MaxMapHeight, '$'); Point food = foodCreator.CreateFood (); //Console.ForegroundColor = ConsoleColor.Cyan; food.Draw (); while (true) { // data de perete if (walls.IsHit (snake) || snake.IsHitTail()) break; // daca maninca if(snake.Eat(food)){ food = foodCreator.CreateFood (); food.Draw (); } else snake.Move (); Thread.Sleep (200); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey (); snake.Hadlekey (key.Key); if (key.Key == ConsoleKey.Escape) break; } } // END Console.ForegroundColor = ConsoleColor.Red; Console.SetCursorPosition(MaxMapWidth/3 , 10); Console.WriteLine ("--=***=-- E N D --=***=--"); Console.SetCursorPosition(MaxMapWidth/3 , 12); //Thread.Sleep (300); //Console.ReadLine (); }
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(); }
public void GameInit() { Console.CursorVisible = false; Console.Clear(); snake.Draw(); walls.Draw(); food.FoodGenerate(); food.Draw(); }
static void Main(string[] args) { Walls walls = new Walls(120, 30); walls.Draw(); FoodCreator foodCreator = new FoodCreator(110, 25, '$'); Point food = foodCreator.CreateFood(); food.Draw(); Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.RIGHT); snake.Draw(); while (true) { if (snake.Eat(food)) { snake.Draw(); food = foodCreator.CreateFood(); food.Draw(); } if (walls.IsHit(snake) || snake.IsHitTail()) { break; } else { snake.Move(); } if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); walls.Draw(); } Thread.Sleep(85); } Console.Clear(); Console.WriteLine("Игра окончена"); Console.ReadLine(); }
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) { // Рисуем границы 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); } } }
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); } }
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) { //Начальное положение змейки 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) { 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); } } }
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) { 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); 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.SetWindowSize(1, 1); Console.SetBufferSize(80, 25); Console.SetWindowSize(80, 25); Console.CursorVisible = false; Console.WriteLine("Правила игры: Нельзя врезаться в стену. Чтобы змейка росла - нужно есть @!"); Console.ReadLine(); 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(); snake.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(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.DrawLine(); //еда 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, '*'); //List < Figure > figures= new List<Figure>() { new HorizontalLine(0, 78, 0, '+'), //new HorizontalLine(0, 78, 24, '+'), //new VerticalLine(0, 24, 0, '+'), //new VerticalLine(0, 24, 78, '+') //}; //foreach (Figure f in figures) //{ // f.Draw(); //} //HorizontalLine hl1 = new HorizontalLine(0, 78, 0, '+'); //HorizontalLine hl2 = new HorizontalLine(0, 78, 24, '+'); //VerticalLine vl1 = new VerticalLine(0, 24, 0, '+'); //VerticalLine vl2 = new VerticalLine(0, 24, 78, '+'); //hl1.Draw(); vl1.Draw(); hl2.Draw(); vl2.Draw(); 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); } Thread.Sleep(100); snake.Move(); } }
static void Main(string[] args) { int x = 120; int y = 50; Console.SetWindowSize(x, y); Console.SetBufferSize(x, y); Walls walls = new Walls(x, y); walls.Draw(); Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.Right); snake.Draw(); FoodGenerator foodGenerator = new FoodGenerator(x, y, '$', new Random()); Point food = foodGenerator.SpawnFood(); int score = 0; while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { break; } if (snake.Eat(food)) { score++; food = foodGenerator.SpawnFood(); } else { snake.Move(); } Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.Handle(key.Key); } } Console.SetCursorPosition(x / 2, y / 2); Console.WriteLine($"Game over. Score: {score}"); Console.ReadKey(); }
private static void Main(string[] args) { int x = 80, y = 25; Console.SetWindowSize(x, y); Walls walls = new Walls(x, y); 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.SetCursorPosition(x / 2 - 5, y / 2); Console.Write("GAME OVER!"); Console.ReadKey(); 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.SetWindowSize(80, 25); Console.SetBufferSize(80, 25); // границы карты Walls walls = new Walls(80, 25); walls.Draw(); //создание еды FoodCreator foodCreator = new FoodCreator(80, 25, '$'); Point food = foodCreator.CreateFood(); food.Draw(); //создание змейки Point d2 = new Point(6, 9, '*'); Snake snake = new Snake(d2, 3, Directions.RIGHT); snake.Drow(); //управляемое движение змейки while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { Console.Write("Игра закончена!"); Console.ReadLine(); 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 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(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(); }
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) { 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(); */ }
static void Main(string[] args) { // Dimensions //int winW = Console.WindowWidth - 1; //int winH = Console.WindowHeight - 1; int winH = 20; int winW = 34; ushort level = 1; // Border Walls walls = new Walls(winW, winH); walls.Draw(); // Snake Point tl = new Point(10, 10, '*'); Snake snake = new Snake(tl, 3, Direction.RIGHT); // Food FoodFactory foodfactory = new FoodFactory(winH, winW, '$'); Point food = foodfactory.createFood(snake); Console.ForegroundColor = ConsoleColor.Yellow; food.Draw(); Console.ResetColor(); // Infinite loop while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { // Snake dies Console.SetCursorPosition(2, 2); Console.ForegroundColor = ConsoleColor.Red; Console.Write("Snake collapsed..."); break; } if (snake.Eat(food)) { food = foodfactory.createFood(snake); Console.ForegroundColor = ConsoleColor.Yellow; food.Draw(); Console.ResetColor(); // level up every 5 feeds and level cap is 40 (121 - level * 3 must be > 0) if (snake.length % 5 == 0 && level < 40) level++; } else { snake.Move(); } if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(true); snake.HandleKey(key.Key); if (key.Key == ConsoleKey.Q) break; // Get the hell out of this infinite loop } // Thread.Sleep(80); // Control FPS here Thread.Sleep(121 - level * 3); Console.SetCursorPosition(2, 1); Console.Write("Length: " + snake.length + " Level: " + level); } // Print banner and wait for Enter key Console.ForegroundColor = ConsoleColor.Yellow; int endplaneX = Math.Abs((winW / 2) - 15); Console.SetCursorPosition(endplaneX, 7); Console.Write("==============================="); Console.SetCursorPosition(endplaneX, 8); Console.Write("| Thank you for playing. Bye! |"); Console.SetCursorPosition(endplaneX, 9); Console.Write("| Press Enter key to quit. |"); Console.SetCursorPosition(endplaneX, 10); Console.Write("==============================="); while (Console.ReadKey(true).Key != ConsoleKey.Enter) { } }