Загрузка данных


using System;

class Program
{
    static int w = 21;
    static int h = 11;
    static char[,] maze = new char[11, 21];
    static Random r = new Random();

    static void Main()
    {
        for (int y = 0; y < h; y++)
            for (int x = 0; x < w; x++)
                maze[y, x] = '#';

        Generate(1, 1);
        maze[1, 0] = ' ';
        maze[h - 2, w - 1] = ' ';

        for (int y = 0; y < h; y++)
        {
            for (int x = 0; x < w; x++)
                Console.Write(maze[y, x]);
            Console.WriteLine();
        }

        Console.ReadKey();
    }

    static void Generate(int x, int y)
    {
        maze[y, x] = ' ';

        int[] d = { 0, 1, 2, 3 };
        for (int i = 0; i < 4; i++)
        {
            int j = r.Next(4);
            int t = d[i];
            d[i] = d[j];
            d[j] = t;
        }

        for (int i = 0; i < 4; i++)
        {
            int dx = 0, dy = 0;

            if (d[i] == 0) dy = -2;
            if (d[i] == 1) dy = 2;
            if (d[i] == 2) dx = -2;
            if (d[i] == 3) dx = 2;

            int nx = x + dx;
            int ny = y + dy;

            if (nx > 0 && nx < w - 1 && ny > 0 && ny < h - 1 && maze[ny, nx] == '#')
            {
                maze[y + dy / 2, x + dx / 2] = ' ';
                Generate(nx, ny);
            }
        }
    }
}