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) { // Рисуем границы 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.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.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) { 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, 24); Console.SetWindowSize(80, 25); //HorizontalLine upLine = new HorizontalLine(0, 78, 0, '+'); //Draw(upLine); //HorizontalLine downLine = new HorizontalLine(0, 78, 24, '+'); //Draw(downLine); //VerticalLine leftLine = new VerticalLine(0, 24, 0, '+'); //VerticalLine rightLine = new VerticalLine(0, 24, 78, '+'); //Draw(leftLine); //Draw(rightLine); Walls walls = new Walls(80, 25); walls.Draw(); Point p = new Point(4, 5, '*'); Figure fSnake = new Snake(p, 4, Direction.RIGHT); Draw(fSnake); Snake snake = (Snake)fSnake; FoodCreator foodCreator = new FoodCreator(78, 24, '$'); Point food = foodCreator.CreateFood(); food.Draw(); while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { break; } if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); } else { snake.Move(); } Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } } //Console.ReadKey(); }
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) { Console.CursorVisible = false; Console.SetBufferSize(80, 25); //Рамочки HorizontalLine lineUp = new HorizontalLine(0, 78, 0, '+'); lineUp.Draw(); HorizontalLine lineDown = new HorizontalLine(0, 78, 24, '+'); lineDown.Draw(); VerticalLine lineLeft = new VerticalLine(0, 24, 0, '+'); lineLeft.Draw(); VerticalLine lineRight = new VerticalLine(0, 24, 78, '+'); lineRight.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 (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); } else { snake.Move(); } Thread.Sleep(200); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } } }
static void Main(string[] args) { Console.SetWindowSize(1, 1); Console.SetBufferSize(80, 25); 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.Draw(); FoodCreator foodCreator = new FoodCreator(80, 25, '$'); Point food = foodCreator.CreateFood(); food.Draw(); while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { Console.WriteLine("Game Over"); 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); } Thread.Sleep(100); snake.Move(); } }
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.SetBufferSize(120, 31); HorizontalLine GorizontalLine1 = new HorizontalLine(0, 120, 0, '+'); GorizontalLine1.Draw(); HorizontalLine GorizontalLine2 = new HorizontalLine(0, 120, 29, '+'); GorizontalLine2.Draw(); VerticalLine VerticalLine1 = new VerticalLine(0, 29, 0, '+'); VerticalLine1.Draw(); VerticalLine VerticalLine2 = new VerticalLine(0, 29, 119, '+'); VerticalLine2.Draw(); // точки Point p = new Point(4, 5, '*'); // p.Draw(); Snake snake = new Snake(p, 4, Direction.RIGHT); snake.Draw(); FoodCreator foodCreator = new FoodCreator(120, 31, '$'); 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.SetWindowSize(80, 25); Console.SetBufferSize(80, 25); Console.CursorVisible = false; // Отрисовка рамочки 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(); // Отрисовка точек 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 (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() { System.Console.SetWindowSize(80, 26); Console.CursorVisible = false; var walls = new Walls(80, 25); walls.Draw(); var startPoint = new Point(5, 5, '*'); var snake = new Snake(startPoint, 4, Direction.Right); snake.Draw(); ShowCounter(snake.GetCount()); var foodCreator = new FoodCreator(80, 25, '$'); var food = foodCreator.CreateFood(); food.Draw(); while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { break; } if (snake.Eat(food)) { ChangeCounter(snake.GetCount()); food = foodCreator.CreateFood(); food.Draw(); } else { snake.Move(); } Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo keyInfo = Console.ReadKey(); snake.ChangeDirection(keyInfo.Key); } } ShowGameOverMessage(); Console.ReadKey(); }
static void Main(string[] args) { Console.SetBufferSize(120, 30); Walls walls = new Walls(120, 30); walls.Draw(); // отрисовка точек Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.RIGHT); snake.Draw(); Console.CursorVisible = false; FoodCreator foodCreator = new FoodCreator(120, 30, '$'); Point food = foodCreator.CreateFood(); food.Draw(); while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { break; } if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); } else { snake.Move(); } Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } } // Console.ReadLine(); }
static void Main(string[] args) { bool IsGaming = true; SetWindowSize(80, 25); SetBufferSize(80, 25); var walls = new Walls(80, 25); walls.Draw(); Snake snake = new Snake(new Point(5, 3, '*'), 5, Direction.Down); snake.Draw(); var foodCreator = new FoodCreator(80, 25); Point food = foodCreator.CreateFood(); food.Draw(); while (IsGaming) { if (walls.IsHit(snake) || snake.IsHitTail()) { IsGaming = false; break; } if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); } if (KeyAvailable) { ConsoleKeyInfo key = ReadKey(); snake.HandleKey(key); } Thread.Sleep(100); snake.Move(); } if (!IsGaming) { Write("Game over! You've failed!\n"); Read(); } }
static void Main(string[] args) { Console.CursorVisible = false; //Console.SetBufferSize(80, 25); Thread myThread = new Thread(new ThreadStart(MissionImpossible)); Walls walls = new Walls(80, 25); myThread.Start(); // запускаем поток 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); } } WriteGameOver(); Console.ReadLine(); }
static void Main(string[] args) { Console.SetWindowSize(MAP_WIDTH, MAP_HEIGHT); Console.SetBufferSize(MAP_WIDTH, MAP_HEIGHT); Console.CursorVisible = false; Walls walls = new Walls(MAP_WIDTH, MAP_HEIGHT); walls.Draw(); 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()) { GameOver(); break; } if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); } else { snake.Move(); } Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } } Console.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) { //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); // Отрисовка рамки 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(); //Drawing the Snake Point p = new Point(4, 10, '*'); Snake snake = new Snake(p, 3, Direction.RIGHT); snake.Drow(); //генерируем еду FoodCreator foodCreator = new FoodCreator(80, 26, '$'); 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(70); // делаем задержку 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.Drow(); FoodCreator foodCreator = new FoodCreator(80, 25, '$'); Point food = foodCreator.CreateFood(); Console.ForegroundColor = ConsoleColor.Yellow; food.Draw(); Console.ForegroundColor = ConsoleColor.Red; while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { break; } if (snake.Eat(food)) { food = foodCreator.CreateFood(); Console.ForegroundColor = ConsoleColor.Yellow; food.Draw(); Console.ForegroundColor = ConsoleColor.Red; } else { snake.Move(); } Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandeKey(key.Key); } } WriteGameOver(); Console.ReadLine(); }
static void Main(string[] args) { Console.CursorVisible = false; Walls walls = new Walls(80, 25); walls.Draw(); Point p = new Point(7, 3, '*'); 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); } } WriteGameOver(); 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(X_MAX, Y_MAX); Console.CursorVisible = false; Wall walls = new Wall(X_MAX, Y_MAX); walls.Draw(); int centerX = (int)(X_MAX / 2); int centerY = (int)(Y_MAX / 2); Point start = new Point(centerX, centerY, '+'); Random rand = new Random(); Snake snake = new Snake(start, 3, (Direction)rand.Next(3)); snake.Draw(); FoodCreator creator = new FoodCreator(X_MAX, Y_MAX, '$'); Point food = creator.CreateFood(); food.Draw(); while (true) { if (walls.isHit(snake) || snake.isHitTale()) { break; } if (snake.IsSnakeEat(food)) { food = creator.CreateFood(); food.Draw(); } if (Console.KeyAvailable) { snake.HandleKey(Console.ReadKey()); } snake.Move(); snake.Draw(); Thread.Sleep(100); } }
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.SetWindowSize(80, 25); Console.SetBufferSize(80, 25); Console.CursorVisible = false; while (true) { 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()) { Menu menu = new Menu(); menu.Mn(); break; } else if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); } else { snake.Move(); } Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.Handl(key.Key); } } } }
static void Main(string[] args) { //Сделать курсор невидимым Console.CursorVisible = false; //Задаем размер поля и стен Console.SetBufferSize(120, 50); 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.ReadLine(); }
static void Main(string[] args) { Title title = new Title(); Walls walls = new Walls(); walls.Draw(); title.Menu(); Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.RIGHT); snake.Draw(); FoodCreator foodCreator = new FoodCreator(70, 27, '*'); Point food = foodCreator.CreateFood(); food.Draw(); while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { title.GameOver(walls, snake); break; } if (snake.Eat(food)) { food = foodCreator.CreateFood(); food.Draw(); } else { snake.Move(); } Thread.Sleep(90); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } } }
static void Main(string[] args) { Console.CursorVisible = false; Console.Clear(); Walls walls = new Walls(80, 20); walls.Draw(); Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.Right); snake.Draw(); FoodCreator foodCreator = new FoodCreator(80, 20, '$'); Point food = foodCreator.CreateFood(); food.Draw(); while (true) { if (walls.isHit(snake) || snake.isHitTail()) { break; } if (snake.Eat(food)) { food.Draw(); food = foodCreator.CreateFood(); food.Draw(); } else { snake.Move(); } Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo keyInfo = Console.ReadKey(); snake.HandleKey(keyInfo); } } }
static void Main(string[] args) { Console.SetBufferSize(HEIGHT, WIDTH); Walls walls = new Walls(HEIGHT, WIDTH); walls.Draw(); FoodCreator foodCreator = new FoodCreator(WIDTH, HEIGHT, 'p'); Point food = foodCreator.CreateFood(); Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.RIGHT); snake.Draw(); 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(); } if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key); } Thread.Sleep(100); snake.Move(); } Console.ReadLine(); }
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) { 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(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.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(); */ }