private void Form1_Paint(object sender, PaintEventArgs e) { graphics = this.CreateGraphics(); snake.Draw(graphics); food.Draw(graphics); }
static void Main(string[] args) { Console.SetBufferSize(sizeX, sizeY); // Размер консольки Console.Title = "Змейка"; startProgramm: // Метка для начала работы программы Console.Clear(); Console.ForegroundColor = ConsoleColor.White; Walls walls = new Walls(sizeX, sizeY); walls.Draw(); // Отрисовка точек Point p = new Point(4, 5, '*'); Snake snake = new Snake(p, 4, Direction.RIGHT); snake.Draw(); byte snakeSpeed = 150; int ochki = 0; FoodCreator foodCreator = new FoodCreator(sizeX, sizeY, '$'); Point food = foodCreator.CreateFood(); food.Draw(); while (true) { if (walls.IsHit(snake) || snake.IsHitTail()) { break; } Thread.Sleep(snakeSpeed); if (snake.Eat(food)) { food = foodCreator.CreateFood(); ochki++; food.Draw(); if ((snakeSpeed <= 70) && (snakeSpeed > 55)) { snakeSpeed -= 15; } else if ((snakeSpeed <= 55) && (snakeSpeed > 45)) { snakeSpeed -= 10; } else if ((snakeSpeed <= 45) && (snakeSpeed > 35)) { snakeSpeed -= 5; } else if ((snakeSpeed <= 35) && (snakeSpeed > 20)) { snakeSpeed -= 3; } else if (snakeSpeed <= 20) { snakeSpeed = 20; } else { snakeSpeed -= 20; } } else { snake.Move(); } if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); snake.HandleKey(key.Key); } } metka1: WriteGameOver(ochki); ConsoleKeyInfo key1 = Console.ReadKey(); if ((key1.Key != ConsoleKey.Enter) && (key1.Key != ConsoleKey.Escape)) { goto metka1; } else if (key1.Key == ConsoleKey.Enter) { goto startProgramm; } else if (key1.Key == ConsoleKey.Escape) { return; } }
static void Main(string[] args) { StartOfTheGame.StartText(); int snakeSpeed = 100; bool correctLevel = false; string userLevel = Console.ReadLine(); while (!correctLevel) { if (int.TryParse(userLevel, out int choosedLevel)) { if (choosedLevel == 1 || choosedLevel == 2 || choosedLevel == 3 || choosedLevel == 4) { snakeSpeed = Levels.ReturnSpeed(choosedLevel); correctLevel = true; } else { Console.WriteLine("Incorrect level. Try again"); userLevel = Console.ReadLine(); } } else { Console.WriteLine("Error! It wasn`t a number. Please, try again"); userLevel = Console.ReadLine(); } } Console.Clear(); int mapWeidth = 80; int mapHeight = 25; Random rnd = new Random(); Walls walls = new Walls(mapWeidth, mapHeight); walls.Draw(); Point startTailPoint = new Point(rnd.Next(5, mapWeidth - 5), rnd.Next(5, mapHeight - 5), '*'); Snake snake = new Snake(startTailPoint, 5, Direction.Right); snake.Draw(); FoodCreator foodCreator = new FoodCreator(mapWeidth - 2, mapHeight - 2); Point foodForSnake = foodCreator.CreateFood(snake); foodCreator.Draw(); while (true) { if (walls.IsHit(snake) || snake.IsHitWithTail()) { break; } if (snake.Eat(foodForSnake)) { foodForSnake = foodCreator.CreateFood(snake); foodCreator.Draw(); } else { snake.Move(); } Thread.Sleep(snakeSpeed); if (Console.KeyAvailable) { ConsoleKeyInfo enteredKey = Console.ReadKey(); snake.EnteredKey(enteredKey); } } EndOfGame theEnd = new EndOfGame(); theEnd.EndGameResult(snake, mapWeidth, mapHeight); theEnd.DrawEndGameResult(); Console.ReadLine(); }