示例#1
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);
            //рисуем границы
            Walls walls = new Walls(80, 25);

            walls.Draw();

            Point pStart = new Point(4, 5, 'O');
            Snake snake  = new Snake(pStart, 4, Directions.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);
                }
            }
            WriteGameOver();
            Console.ReadLine();
        }
示例#2
0
        static void Main()
        {
            Console.WriteLine("Выберете сложность игры: 1 - легко, 2 - средне, 3 - сложно");
            int n = 0;
            n = Convert.ToInt32(Console.ReadLine());
            Console.Clear();
            if (n == 1)
            {
                int x1 = 10;
                int y1 = 10;
                walls = new Walls(x1, y1, '0');
                snake = new Snake(x1 / 2, y1 / 2, 3);
                food = new Food(x1, y1, '+');
            }
            if (n == 2)
            {
                int x1 = 15;
                int y1 = 15;
                walls = new Walls(x1, y1, '0');
                snake = new Snake(x1 / 2, y1 / 2, 3);

                food = new Food(x1, y1, '+');
            }
            if (n == 3)
            {
                int x1 = 20;
                int y1 = 20;
                walls = new Walls(x1, y1, '0');
                snake = new Snake(x1 / 2, y1 / 2, 3);
                food = new Food(x1, y1, '+');

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

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

                        break;
                    }
                case 3:
                    {
                        time = new Timer(Move, null, 0, 200);

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