Esempio n. 1
0
    static void Main()
    {
        Console.SetBufferSize(80, 35);
        Console.SetWindowSize(80, 35);
        Thread.Sleep(3000);
        string start = "Игра начнется через: ";

        Console.WriteLine(start);
        Thread.Sleep(1000);
        Console.Write("...3");
        Thread.Sleep(1000);
        Console.Write("...2");
        Thread.Sleep(1000);
        Console.Write("...1");
        Thread.Sleep(1000);
        Console.Clear();
        Walls walls = new Walls(80, 35);

        walls.Draw();
        Barrier barrier = new Barrier(80, 35);

        barrier.Draw();
        Point p     = new Point(30, 20, '*');
        Snake snake = new Snake(p, 2, Direction.LEFT);

        snake.Draw();
        FoodCreator foodCreator = new FoodCreator(80, 35, '$');
        Point       food        = foodCreator.CreateFood();

        food.Draw();
        while (true)
        {
            if (walls.IsHit(snake) || barrier.IsHit(snake))
            {
                Console.Clear();
                Console.WriteLine("Игра окончена.\n\nНажмите Enter, чтобы выйти...");
                Console.ReadLine();
                break;
            }
            if (snake.Eat(food))
            {
                snake.Draw();
                food = foodCreator.CreateFood();
                food.Draw();
            }
            else
            {
                snake.Move();
            }
            if (Console.KeyAvailable)
            {
                ConsoleKeyInfo key = Console.ReadKey();
                snake.HandleKey(key.Key);
            }
            Thread.Sleep(100);
        }
    }