static void Main(string[] args) { int score = 0; Walls walls = new Walls(119, 29); walls.Draw(); Point snakeTail = new Point(5, 5, 's'); Snake snake = new Snake(snakeTail, 10, Direction.RIGHT); snake.Draw(); FoodGenerator foodGenerator = new FoodGenerator(119, 29, '$'); Point food = foodGenerator.GenerateFood(); food.Draw(); while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { break; } if (snake.Eat(food)) { food = foodGenerator.GenerateFood(); food.Draw(); Random rnd = new Random(); int num = rnd.Next(1, 3); if (num == 1) { score = score + 2; } else { score--; } } else { snake.Move(); } if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKeys(key.Key); } Thread.Sleep(300); } string str_score = Convert.ToString(score); WriteGameOver(str_score); Console.ReadLine(); }
private static void StartGame() { Graphics.initGraphics(Console.BufferWidth, Console.BufferHeight); Walls walls = new Walls(79, 25, '+'); walls.Draw(); Point point = new Point(4, 5, '*'); Snake snake = new Snake(point, 4, Direction.RIGHT); snake.Draw(); FoodCreator foodCreator = new FoodCreator(Console.BufferWidth, Console.BufferHeight, '$'); Point food = foodCreator.GenerateFood(); food.Draw(); int count = 0; while (game) { if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(true); switch (key.Key) { case ConsoleKey.RightArrow: snake.Turn(Direction.RIGHT); break; case ConsoleKey.LeftArrow: snake.Turn(Direction.LEFT); break; case ConsoleKey.UpArrow: snake.Turn(Direction.UP); break; case ConsoleKey.DownArrow: snake.Turn(Direction.DOWN); break; } } snake.Move(); if (snake.isHit(food)) { snake.Grow(); food = foodCreator.GenerateFood(); food.Draw(); count++; } if (snake.isHit(walls.GetPoints()) || snake.isDead(snake.GetPoints())) { snake.Clear(); food.Clear(); GameOver(count); } Thread.Sleep(100); } Console.ReadKey(); }
public void MenuSelect() { Console.Clear(); // Установка размера окна меню int width = 33; int height = 6; Console.SetWindowSize(width + 1, height + 1); Walls frame = new Walls(width, height, '*'); // Название игры и пункты меню TextItem title = new TextItem(1, 1, "~~~~~~~~~~~~ЗМЕЙКА~~~~~~~~~~~~".PadBoth(31)); // Передача пунктов в меню Menu menu = new Menu(new List <TextItem> { new TextItem(1, 2, "НАЧАТЬ ИГРУ".PadBoth(31)), new TextItem(1, 3, "НАСТРОЙКИ".PadBoth(31)), new TextItem(1, 4, "ВЫХОД".PadBoth(31)) }); // Цвета frame.SetColor(ConsoleColor.Black, ConsoleColor.Yellow); title.SetColor(ConsoleColor.DarkBlue, ConsoleColor.Green); menu.SetColor(ConsoleColor.DarkGreen, ConsoleColor.Green); // Отрисовка рамки вокруг меню frame.Draw(); // Показ названия и меню title.Show(); menu.Show(); // Индекс выбранного пункта int selected = menu.SelectItem(); switch (selected) { case 0: Game(); break; case 1: Settings(); break; case 2: Exit(); break; } }
public static void DificultyLevel() { //WriteLine("Dificulty level: "); int selectedDificultyClass = ConsoleHelper.MultipleChoice(true, "ease", "normal", "hard"); switch (selectedDificultyClass) { case 0: { Clear(); walls = new Walls(x, y, '.'); break; } // создание стен легкого уровня case 1: { Clear(); walls = new Walls(x, y, '.', 70, 5, 10, 21); break; } // создание стен среднего уровня case 2: { Clear(); walls = new Walls(x, y, '.', 70, 5, 10, 21, 60, 12); break; } // создание стен сложного уровня } diflevel = selectedDificultyClass; }
static void Main(string[] args) { int score = 0; Walls walls = new Walls(80, 25); walls.Draw(); Point snakeTail = new Point(15, 15, 's'); Snake snake = new Snake(snakeTail, 5, Direction.RIGHT); snake.Draw(); FoodGenerator foodGenerator = new FoodGenerator(80, 25, '$'); Point food = foodGenerator.GenerateFood(); food.Draw(); while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { break; } if (snake.Eat(food)) { food = foodGenerator.GenerateFood(); food.Draw(); score++; } else { snake.Move(); } if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKays(key.Key); } Thread.Sleep(300); } string str_score = Convert.ToString(score); WriteGameOver(str_score); Console.ReadLine(); }
static void Main() { Console.SetWindowSize(x + 1, y + 1); Console.SetBufferSize(x + 1, y + 1); Console.CursorVisible = false; walls = new Walls(x, y, '#'); snake = new Snake(x / 2, y / 2, 3); foodFactory = new FoodFactory(x, y, '@'); foodFactory.CreateFood(); time = new Timer(Loop, null, 0, 200); while (true) { if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.Rotation(key.Key); } } }// Main()
static void Main(string[] args) { string name; while (true) { Console.Write("Type your name: "); name = Console.ReadLine(); if (name.Length < 3) { Console.Clear(); Console.WriteLine("Name will be longer than 3 symbols."); continue; } else { Console.Clear(); break; } } bool soundSwitch; while (true) { Console.Write("Do you want to turn on sounds? (Y/N): "); ConsoleKeyInfo answerkey = Console.ReadKey(); if (answerkey.Key == ConsoleKey.Y) { Console.Clear(); soundSwitch = true; break; } else if (answerkey.Key == ConsoleKey.N) { Console.Clear(); soundSwitch = false; break; } else { Console.WriteLine("\nPress \'Y\' or \'N\' key."); continue; } } Score score = new Score(9); Level level = new Level(1); Params settings = new Params(); Sounds sound = new Sounds(settings.GetResourceFolder()); Sounds pointsound = new Sounds(settings.GetResourceFolder()); if (soundSwitch == true) { sound.Play(level.level); } Console.SetWindowSize(80, 26); Walls walls = new Walls(80, 25); walls.Draw(); Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.RIGHT); Console.ForegroundColor = ConsoleColor.Red; snake.Draw(); Console.ForegroundColor = ConsoleColor.White; FoodCreator foodCreator = new FoodCreator(80, 25, '$'); Point food = foodCreator.CreateFood(); Console.ForegroundColor = ConsoleColor.Yellow; food.Draw(); Console.ForegroundColor = ConsoleColor.White; while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { break; } if (snake.Eat(food, score, level, sound, soundSwitch)) { if (soundSwitch == true) { pointsound.Play("point"); } food = foodCreator.CreateFood(); Console.ForegroundColor = ConsoleColor.Yellow; food.Draw(); Console.ForegroundColor = ConsoleColor.White; } else { Console.ForegroundColor = ConsoleColor.Red; snake.Move(); Console.ForegroundColor = ConsoleColor.Yellow; } if (level.level == 1) { Thread.Sleep(100); } else if (level.level == 2) { Thread.Sleep(75); } else if (level.level == 3) { Thread.Sleep(50); } else { Thread.Sleep(40); } if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } } Messages gameover = new Messages(); gameover.WriteGameOver(name, score.score, level.level); if (soundSwitch == true) { sound.Stop(level.level); pointsound.Play("lose"); } ConsoleKeyInfo _key = Console.ReadKey(); if (_key.Key == ConsoleKey.Enter) { Application.Restart(); } }
static void Main() { Console.ForegroundColor = ConsoleColor.Green; Console.BackgroundColor = ConsoleColor.Black; Console.SetWindowSize(width, height); Console.WriteLine(" Приветствую в игре повелитель змея"); Console.WriteLine(" Выбери уровень сложности:" + "\n 1 - Easy peasy" + "\n 2 - Medium" + "\n 3 - Death"); int n = 0; n = Convert.ToInt32(Console.ReadLine()); Console.Clear(); if (n == 1) { int x1 = 10; int y1 = 10; walls = new Walls(x1, y1, '*'); snake = new Snake(x1 / 2, y1 / 2, 3); food = new FoodCreator(x1, y1, 'o'); } if (n == 2) { int x1 = 15; int y1 = 15; walls = new Walls(x1, y1, '*'); snake = new Snake(x1 / 2, y1 / 2, 3); //Выбор сложности размера поля food = new FoodCreator(x1, y1, 'o'); } if (n == 3) { int x1 = 20; int y1 = 20; walls = new Walls(x1, y1, '*'); snake = new Snake(x1 / 2, y1 / 2, 3); food = new FoodCreator(x1, y1, 'o'); } Console.SetWindowSize(width + 1, height + 1); Console.SetBufferSize(width + 1, height + 1); Console.CursorVisible = false; food.CreateFood(); switch (n) { case 1: { time = new Timer(Loop, null, 0, 400); break; } case 2: { time = new Timer(Loop, null, 0, 200); //Выбор сложности скорость break; } case 3: { time = new Timer(Loop, null, 0, 100); break; } } while (true) { if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.Rotation(key.Key); } } }
public void Game() { // Символы поля и стен char fieldCh = ' '; char wallCh = '#'; // Установка размера окна игры int width = 55; int height = 15; Console.SetWindowSize(width + 1, height + 1); // Размеры поля и стен int columns = 30; int rows = 15; // Инициализация статистики Stats.Initialize(32, 10); Stats.Score = 0; Stats.Moves = 0; Stats.Speed = speed; Stats.Length = length; Stats.Show(); // Отрисовка поля и стен Field field = new Field(columns, rows, fieldCh); Walls walls = new Walls(columns, rows, wallCh); // Отрисовка змейки Point tail = new Point(1, 1, 'o'); Snake snake = new Snake(tail, Stats.Length, Direction.Right); // Еда FoodSpawner foodSpawner = new FoodSpawner(walls.Width, walls.Height, "♥♦♣♠"); foodSpawner.Initialize(); // Ускорение змейки в процентах double modifier = 5; // Установка цвета field.SetColor(ConsoleColor.DarkCyan, ConsoleColor.Cyan); walls.SetColor(ConsoleColor.Black, ConsoleColor.DarkGreen); snake.SetColor(ConsoleColor.DarkCyan, ConsoleColor.Green); FoodSpawner.Food.SetColor(ConsoleColor.DarkCyan, ConsoleColor.Red); // Отображение field.Draw(); walls.Draw(); snake.Draw(); FoodSpawner.Food.Draw(); // Движение змейки while (true) { // Выбор следующего направления snake.HandleKey(); // Условия смерти змейки if (snake.IsWallHit(walls.Width, walls.Height) || snake.IsTailHit()) { GameOver(); Thread.Sleep(2000); MenuSelect(); } // Змейка ест if (snake.Eat(FoodSpawner.Food)) { do { foodSpawner.Initialize(); } while (snake.IsHit(FoodSpawner.Food)); FoodSpawner.Food.Draw(); // Увеличение очков Stats.Score += 10; // Параллельное увеличение рекорда if (Stats.Score >= Stats.HighScore) { Stats.HighScore = Stats.Score; } // Увеличение длины Stats.Length++; Stats.Speed += Stats.Speed / 100 * modifier; } else { // Движение змейки snake.Move(); // Увеличение шагов Stats.Moves++; } // Показ статистики Stats.Show(); // Установка скорости Thread.Sleep(1000 / (int)Stats.Speed); } }
static void Main(string[] args) { //Console.SetBufferSize(80, 25); Walls walls = new Walls(80, 25); walls.Draw(); //Рамочка HorizontalLines upline = new HorizontalLines(0, 78, 0, '+'); HorizontalLines downline = new HorizontalLines(0, 78, 24, '+'); VerticalLines leftline = new VerticalLines(0, 24, 0, '+'); VerticalLines rightline = new VerticalLines(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 (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); } } while (true) { if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } Thread.Sleep(100); snake.Move(); } }
static void Main(string[] args) { Console.SetWindowSize(80, 24); Console.SetBufferSize(80, 24); Menu(); // отрисовка рамки Walls walls = new Walls(80, 24); walls.Draw(); Point p = new Point(4, 4, '*'); Snake snake = new Snake(p, 4, Direction.RIGHT); snake.Drow(); FoodCreator foodCreator = new FoodCreator(78, 22, '$'); Point food = foodCreator.CreateFood(); food.Draw(); while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { Console.ForegroundColor = ConsoleColor.Red; WriteAt("G A M E O V E R", 34, 12); Console.ResetColor(); Console.ReadLine(); 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); } Thread.Sleep(70); } Console.ReadKey(); }
static void Main() { while (x < 0) { Console.Write("Выбери сложность (1-Низкая, 2-Средняя, 3-Высокая) : "); complexity = Convert.ToInt32(Console.ReadLine()); if (complexity == 1) { x = 40; y = 20; speed = 300; Console.Clear(); break; } else if (complexity == 2) { speed = 200; x = 50; y = 30; Console.Clear(); break; } else if (complexity == 3) { speed = 100; x = 50; y = 50; Console.Clear(); break; } else { Console.WriteLine("Введите правильную сложность!"); x = -10; } } //Сложность игры Console.SetWindowSize(x + 1, y + 1); Console.SetBufferSize(x + 1, y + 1); Console.CursorVisible = false; walls = new Walls(); walls.Wallsxy(x, y); snake = new Snake(x, y); Game game = new Game(); ConsoleKeyInfo button = Console.ReadKey(true); ConsoleKey Cashbutton = ConsoleKey.V; while (Gameover == false) { if (Console.KeyAvailable) { button = Console.ReadKey(true); Cashbutton = button.Key; } else { snake.Runsnake(button.Key, speed, ref Gameover); if (walls.checkWalls(snake.GetHead()) == true) { Console.SetCursorPosition(x / 2 - 15, y / 2); Console.WriteLine("Геймовер епта!"); Console.SetCursorPosition(x / 2 - 15, y / 2 - 1); Console.WriteLine("Твоя змейка не такая уж и большая"); Console.SetCursorPosition(x / 2 - 15, y / 2 - 2); Console.WriteLine($"Твой счёт = {snake.shakeLeng()}"); Gameover = true; } if (snake.checksnake() == true) { Console.SetCursorPosition(x / 2 - 15, y / 2); Console.WriteLine("Геймовер епта!"); Console.SetCursorPosition(x / 2 - 15, y / 2 - 1); Console.WriteLine("Твоя змейка не такая уж и большая"); Console.SetCursorPosition(x / 2 - 15, y / 2 - 2); Console.WriteLine($"Твой счёт = {snake.shakeLeng()}"); Gameover = true; } } } Console.ReadKey(); }
static void Main(string[] args) { int windowWidth = 100; int windowHeight = 50; Console.SetBufferSize(windowWidth, windowHeight); Console.SetWindowSize(windowWidth, windowHeight); Console.CursorVisible = false; Caption caption = new Caption(windowWidth, windowHeight); caption.Title("ДОБРО ПОЖАЛОВАТЬ В ИГРУ \"ЗМЕЙКА\"!"); caption.Subtitle("Нажмите любую клавишу, чтобы начать."); Console.ReadKey(true); caption.Clear(); Walls walls = new Walls(windowWidth, windowHeight, '#'); Point snakeTailStartPosition = new Point(windowWidth / 2, windowHeight / 2, '*'); Snake snake = new Snake(snakeTailStartPosition, 5, Direction.RIGHT, ConsoleColor.Green); Food food = new Food(windowWidth, windowHeight, '@', ConsoleColor.Yellow); Point foodPozition = food.Create(); int snakeSpeed = 150; int gameCount = 0; while (true) { if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(true); snake.directionChanger(key.Key); } snake.Move(); if (snake.Head.IsCrossed(foodPozition)) { snake.Eat(); foodPozition = food.Create(); snakeSpeed = snakeSpeed - (snakeSpeed / 10); gameCount++; } if (snake.Head.IsCrossed(walls) || snake.Head.IsCrossed(snake.Body)) { break; } if (snake.Direction == Direction.UP || snake.Direction == Direction.DOWN) { Thread.Sleep((int)(snakeSpeed * 1.25)); } else { Thread.Sleep(snakeSpeed); } } caption.Title($"Ваш счет: {gameCount}. Спасибо за игру!"); caption.Subtitle("Игра сделана Ольгой Н."); caption.Subtitle2("в рамках прохождения курса GeekBrains \"Основы ООП\""); while (true) { Console.ReadKey(true); } }
private static void Start() { Walls walls = new Walls(Width, Height); walls.Draw(); Point p = new Point(4, 5, '@'); Snake snake = new Snake(p, 4, Direction.RIGHT); snake.Draw(); FoodCreator foodCreator = new FoodCreator(Width, Height, '$'); Point food = foodCreator.CreateFood(snake); food.Draw(); int[,] s = new int[Width, Height]; while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { break; } if (snake.Eat(food)) { do { food = foodCreator.CreateFood(snake); } while (IsColision(snake, food)); food.Draw(); } else { for (int i = 0; i < Width; i++) { for (int j = 0; j < Height; j++) { s[i, j] = (int)Figures.EmptySpace; } } foreach (var item in walls.Points) { s[item.x, item.y] = (int)Figures.Barrier; } s[food.x, food.y] = (int)Figures.Destination; foreach (var item in snake.Points) { var first = snake.Points.Last(); if (item == first) { s[item.x, item.y] = (int)Figures.StartPosition; } else { s[item.x, item.y] = (int)Figures.Barrier; } } var li = new LeeAlgorithm(s); System.Drawing.Point head = new System.Drawing.Point(0, 0); System.Drawing.Point nextstep; if (!li.PathFound) { food = foodCreator.CreateFood(snake); } else { foreach (var item in li.Path) { if (item == li.Path.Last()) { s[item.Item1, item.Item2] = (int)Figures.StartPosition; head = new System.Drawing.Point(item.Item1, item.Item2); } else if (item == li.Path.First()) { s[item.Item1, item.Item2] = (int)Figures.Destination; } else { s[item.Item1, item.Item2] = (int)Figures.Path; } } nextstep = new System.Drawing.Point(li.Path[li.Path.Count - 2].Item1, li.Path[li.Path.Count - 2].Item2); var dir = GetDirection(head, nextstep); switch (dir) { case Direction.LEFT: snake.HandleKey(ConsoleKey.LeftArrow); break; case Direction.RIGHT: snake.HandleKey(ConsoleKey.RightArrow); break; case Direction.UP: snake.HandleKey(ConsoleKey.UpArrow); break; case Direction.DOWN: snake.HandleKey(ConsoleKey.DownArrow); break; } } int speed = 1; snake.Move(); Thread.Sleep(speed); } } WriteGameOver(); Console.ReadLine(); }