コード例 #1
0
    public CellMap Generate(MazeMap maze, SegmentMask masks)
    {
        CellMap map = new CellMap(maze.Width() * masks.SegmentWidth(), maze.Height() * masks.SegmentHeight());

        BakeMask(map, maze, masks);
        SeedMap(map);

        for (int n = 0; n < passes; n++)
        {
            DoPass(map);
        }

        return(map);
    }
コード例 #2
0
    public MazeMap Generate(int sizeX, int sizeY)
    {
        MazeMap map = new MazeMap(sizeX, sizeY);

        List <MapPos> pending = new List <MapPos>();

        pending.Add(new MapPos(map.Width() / 2, map.Height() / 2));

        EnumDirection?lastDir = null;

        while (pending.Count > 0)
        {
            MapPos curPos             = pending[0];
            int    curSeg             = map.GetSegment(curPos);
            List <EnumDirection> dirs = GetEmptySides(map, curPos, lastDir);

            if (lastDir.HasValue)
            {
                curSeg |= lastDir.Value.Opposite().BitMask();
                map.SetSegment(curPos, curSeg);
            }

            if (dirs.Count <= 0)
            {
                lastDir = null;
                pending.RemoveAt(0);
                pending.Shuffle(rand);
            }
            else
            {
                EnumDirection nxtDir = dirs[rand.Next(dirs.Count)];
                curSeg |= nxtDir.BitMask();
                map.SetSegment(curPos, curSeg);
                lastDir = nxtDir;

                if (dirs.Count == 1)
                {
                    pending.RemoveAt(0);
                }

                pending.Insert(0, curPos.Offset(nxtDir));
            }
        }

        return(map);
    }
コード例 #3
0
    private void BakeMask(CellMap map, MazeMap maze, SegmentMask masks)
    {
        for (int i1 = 0; i1 < maze.Width(); i1++)
        {
            for (int j1 = 0; j1 < maze.Height(); j1++)
            {
                int segID = maze.GetSegment(new MapPos(i1, j1));

                for (int i2 = 0; i2 < masks.SegmentWidth(); i2++)
                {
                    for (int j2 = 0; j2 < masks.SegmentHeight(); j2++)
                    {
                        MapPos pos = new MapPos(i1 * masks.SegmentWidth() + i2, j1 * masks.SegmentHeight() + j2);
                        map.SetSegment(pos, masks.GetMask(segID).GetSegment(new MapPos(i2, j2)));
                    }
                }
            }
        }
    }