Ejemplo n.º 1
0
        public Maze Generate(int width, int height, IRandomizer randomizer)
        {
            if (width < 3 || height < 3)
            {
                throw new ArgumentException("Minimal size of generated maze is 3x3");
            }

            _randomizer = randomizer;

            _cells = new MazeCellType[width, height];

            for (int x = 0; x < _cells.GetLength(0); x++)
            {
                for (int y = 0; y < _cells.GetLength(1); y++)
                {
                    _cells[x, y] = MazeCellType.Wall;
                }
            }

            int startX = _randomizer.GetRandomX(width - 2) + 1;
            int startY = _randomizer.GetRandomY(height - 2) + 1;

            _cells[startX, startY] = MazeCellType.Start;

            CarvePassages(startX, startY);

            return(Maze.Create(_cells));
        }