static void Main(string[] args) { //Рамка Console.SetBufferSize(80, 25); Wall wall = new Wall(80, 25); wall.Draw(); //Точки Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.Right); snake.Draw(); FoodCreator fCreator = new FoodCreator(25, 80, '&'); Point food = fCreator.CreateFood(); food.Draw(); while (true) { if (wall.IsHit(snake) || snake.IsHitTail()) { break; } if (snake.Eat(food)) { food = fCreator.CreateFood(); food.Draw(); } else { snake.Move(); } Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.GKey(key.Key); } } WriteGameOver(); Console.ReadLine(); }
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); } } }
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(); }
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(); }