示例#1
0
        static void Main(string[] args)
        {
            int   score = 0;
            Walls walls = new Walls(80, 25);

            walls.Draw();

            Point snakeTail = new Point(15, 15, 'X');
            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.HandelKeys(key.Key);
                }

                Thread.Sleep(300);
            }
            string str_score = Convert.ToString(score);

            WriteGameOver(str_score);
            Console.ReadLine();
        }
示例#2
0
        static void Main()
        {
            Console.WriteLine("Введите сложность игры 1,2,3");
            int n = 0;

            n = Convert.ToInt32(Console.ReadLine());



            if (n == 1)
            {
                int x1 = 10;
                int y1 = 10;
                walls = new Walls(x1, y1, '#');
                snake = new Snake(x1 / 2, y1 / 2, 3);

                foodFactory = new FoodFactory(x1, y1, '@');
            }
            if (n == 2)
            {
                int x1 = 15;
                int y1 = 15;
                walls = new Walls(x1, y1, '#');
                snake = new Snake(x1 / 2, y1 / 2, 3);

                foodFactory = new FoodFactory(x1, y1, '@');
            }
            if (n == 3)
            {
                int x1 = 20;
                int y1 = 20;
                walls = new Walls(x1, y1, '#');
                snake = new Snake(x1 / 2, y1 / 2, 3);

                foodFactory = new FoodFactory(x1, y1, '@');
            }


            Console.SetWindowSize(x + 1, y + 1);
            Console.SetBufferSize(x + 1, y + 1);
            Console.CursorVisible = false;


            foodFactory.CreateFood();



            switch (n)
            {
            case 1:
            {
                time = new Timer(Loop, null, 0, 300);
                break;
            }

            case 2:
            {
                time = new Timer(Loop, null, 0, 250);

                break;
            }

            case 3:
            {
                time = new Timer(Loop, null, 0, 200);

                break;
            }
            }

            while (true)
            {
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.Rotation(key.Key);
                }
            }
        }// Main()