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(1, 24, 0, '+'); VerticalLine rightLine = new VerticalLine(1, 24, 78, '+'); upLine.Draw(); downLine.Draw(); leftLine.Draw(); rightLine.Draw(); Point p = new Point(1, 4, '*'); Snake snake = new Snake(p, 5, Direction.RIGHT); snake.Draw(); snake.Move(); Thread.Sleep(300); snake.Move(); Thread.Sleep(300); snake.Move(); Thread.Sleep(300); snake.Move(); Thread.Sleep(300); snake.Move(); Thread.Sleep(300); snake.Move(); Thread.Sleep(300); snake.Move(); Thread.Sleep(300); snake.Move(); Thread.Sleep(300); Console.ReadLine(); }
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(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) { var x = Console.WindowWidth; //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.DrawLine(); downLine.DrawLine(); leftLine.DrawLine(); rightLine.DrawLine(); Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.RIGHT); snake.DrawLine(); while (true) { if(Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } Thread.Sleep(100); snake.Move(); } Console.ReadKey(); }
static void Main(string[] args) { Console.SetWindowSize(1, 1); Console.SetBufferSize(80, 25); Console.SetWindowSize(80, 25); // Отрисовка рамочки HorizontalLine upLine = new HorizontalLine(0, 78, 0, '+'); upLine.Draw(); HorizontalLine downLine = new HorizontalLine(0, 78, 24, '+'); downLine.Draw(); VerticalLine leftLine = new VerticalLine(0, 0, 24, '+'); leftLine.Draw(); VerticalLine rightLine = new VerticalLine(78, 0, 24, '+'); rightLine.Draw(); //отрисовка точек Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.RIGHT); snake.Draw(); while(true) { if(Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } Thread.Sleep(100); snake.Move(); } // 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) { // Рисуем границы 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); 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(); } }
internal void MoveSnake(Direction direction) { switch (direction) { case Direction.Up: if (_snake.CurrentDirection != Direction.Down) { _snake.Move(direction); } break; case Direction.Right: if (_snake.CurrentDirection != Direction.Left) { _snake.Move(direction); } break; case Direction.Down: if (_snake.CurrentDirection != Direction.Up) { _snake.Move(direction); } break; case Direction.Left: if (_snake.CurrentDirection != Direction.Right) { _snake.Move(direction); } break; default: break; } }
static void Loop(object obj) { if (walls.IsHit(snake.GetHead()) || snake.IsHit(snake.GetHead())) { time.Change(0, Timeout.Infinite); } else if (snake.Eat(foodFactory.food)) { foodFactory.CreateFood(); } else { snake.Move(); } }
static void Main(string[] args) { int largestWidth = Console.LargestWindowWidth - 20; int largetstHeight = Console.LargestWindowHeight - 10; Console.SetBufferSize(largestWidth, largetstHeight); Console.SetWindowSize(largestWidth, largetstHeight); Walls walls = new Walls(largestWidth, largetstHeight); Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 2, Direction.RIGHT); snake.Draw(); FoodCreator foodCreator = new FoodCreator(largestWidth, largetstHeight, '$'); Point food = foodCreator.CreatFood(snake); food.Draw(); ConsoleKeyInfo key = Console.ReadKey(); while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { Console.WriteLine("ВЫ ПРОИГРАЛИ"); Console.ReadKey(); break; } if (snake.Eat(food)) { food = foodCreator.CreatFood(snake); food.Draw(); } if (Console.KeyAvailable) { while (Console.KeyAvailable) { key = Console.ReadKey(); } snake.HandleKey(key.Key); } Thread.Sleep(100); snake.Move(); } }
static void Main(string[] args) { //Set field size Console.SetBufferSize(80, 25); Walls walls = new Walls(80, 25); walls.Draw(); //Drow snake points Point p = new Point(4, 5, '*'); 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 (walls.IsHit(snake) || snake.IsHitTail()) { Console.ReadKey(); break; } if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); } else { snake.Move(); } Thread.Sleep(50); 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) { 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(); }
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); } }
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 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(); }
static void Main( string[] args ) { Console.SetWindowSize(1, 1); Console.SetBufferSize(80, 25); Console.SetWindowSize(80, 25); Point lefttop = new Point(0, 0, ' '); Point rightbottom = new Point(79, 23, ' '); // Рисуем рамочку char sym = '+'; Horizontalline topline = new Horizontalline(lefttop.x, rightbottom.x, lefttop.y, sym); Horizontalline bottomline = new Horizontalline(lefttop.x, rightbottom.x, rightbottom.y, sym); Verticalline leftline = new Verticalline(lefttop.x, lefttop.y++, rightbottom.y--, sym); Verticalline rightline = new Verticalline(rightbottom.x, lefttop.y++, rightbottom.y--, sym); topline.Draw(); bottomline.Draw(); leftline.Draw(); rightline.Draw(); Point p = new Point(3, 5, '█'); Snake snake = new Snake(p, 10, Direction.RIGHT); while (true) { if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(true); snake.HandleKey(key.Key); } System.Threading.Thread.Sleep(100); snake.Move(); } 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) { } }