Exemple #1
0
        static void WriteGameOver(int ochki)
        {
            Console.Clear(); // Очистка консоли, чтоб на экране не мешали остатки змейки
            Console.ForegroundColor = ConsoleColor.White;
            Walls walls = new Walls(sizeX, sizeY);

            walls.Draw();

            int xOffset = 25;
            int yOffset = 8;

            Console.ForegroundColor = ConsoleColor.Red;
            Console.SetCursorPosition(xOffset, yOffset++);
            WriteText("=============================", xOffset, yOffset++);
            WriteText("И Г Р А    О К О Н Ч Е Н А", xOffset + 1, yOffset++);
            yOffset++;
            WriteText("         ВАШ СЧЕТ:  " + ochki + "", xOffset, yOffset++);
            WriteText("=============================", xOffset, yOffset++);
            yOffset++;
            yOffset++;
            WriteText("Для продолжения нажмите ENTER", xOffset, yOffset++);
            WriteText("  Для выхода нажмите ESCAPE  ", xOffset, yOffset++);
        }
        static void Main(string[] args)
        {
            Console.SetWindowSize(X + 10, Y + 10);
            Console.SetBufferSize(X + 10, Y + 10);

            Console.CursorVisible = false;

            walls = new Walls(X, Y - 1, '#');

            foodFactory = new FoodFactory(X, Y, '@');
            foodFactory.CreateFood();

            snake = new Snake(X / 2, (Y - 1) / 2, 3);
            time  = new Timer(Loop, null, 0, 200);

            while (true)
            {
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.Rotation(key.Key);
                }
            }
        }
Exemple #3
0
        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();
        }