コード例 #1
0
    void Generate(int width, int height)
    {
        if (width % 2 == 0 || height % 2 == 0)
        {
            throw new System.Exception("The stage must be odd-sized.");
        }

        mBounds    = new Rect(0, 0, width, height);
        mLevelGrid = new LevelGrid <TileType>(width, height);
        mLevelGrid.Fill(TileType.Wall);

        mRegions = new LevelGrid <int>(width, height);
        mRegions.Fill(-1);

        AddRooms();

        // Fill in all of the empty space with mazes.
        for (int y = 1; y < mBounds.height; y += 2)
        {
            for (int x = 1; x < mBounds.width; x += 2)
            {
                var pos = new Vector2Int(x, y);
                if (mLevelGrid[pos] != TileType.Wall)
                {
                    continue;
                }

                GrowMaze(pos);
            }
        }

        ConnectRegions();

        if (removeDeadEnds)
        {
            RemoveDeadEnds();
        }

        StartCoroutine(SetAllTiles());
    }