public static MazeWall Generate(MazeWall wall)
        {
            mazeWall = wall;

            //封闭全部墙壁
            mazeWall.ClosedAllWall();

            //递归分割
            RecursiveDivision(0, mazeWall.RowLength, 0, mazeWall.ColLength);

            //随机选择迷宫起点终点
            mazeWall.RandomOpenStartAndPoint();
            mazeWall.RandomOpenStartAndPoint();

            return(mazeWall);
        }
Example #2
0
        public static MazeWall Generate(MazeWall wall)
        {
            mazeWall = wall;
            walls.Clear();

            //封闭全部墙壁
            mazeWall.ClosedAllWall();

            //初始化并查集
            UnionFindSet set = new UnionFindSet
                                   (mazeWall.RowLength * mazeWall.ColLength);

            Init();


            while (walls.Count > 0)
            {
                int randomIndex = Random.Range(0, walls.Count);
                var _wall       = walls[randomIndex];



                if (set.Union(
                        GetUnionSetIndex(_wall.Key),
                        GetUnionSetIndex(_wall.Value)))
                {
                    mazeWall.OpenArea(_wall.Key, _wall.Value);
                }

                walls.RemoveAt(randomIndex);
            }



            //随机选择迷宫起点终点
            mazeWall.RandomOpenStartAndPoint();
            mazeWall.RandomOpenStartAndPoint();

            return(mazeWall);
        }
Example #3
0
        public static MazeWall Generate(MazeWall wall)
        {
            mazeWall = wall;
            walls.Clear();

            //封闭全部墙壁
            mazeWall.ClosedAllWall();

            //随机选择一个开始区域
            WallArea fistArea = RandChooseBeginArea();

            AddNerabyWall(fistArea);

            while (walls.Count > 0)
            {
                int randomIndex = Random.Range(0, walls.Count);
                var _wall       = walls[randomIndex];
                if (checkWall(_wall))
                {
                    mazeWall.OpenArea(_wall.Key, _wall.Value);
                    if (checkArea(_wall.Key))
                    {
                        AddNerabyWall(_wall.Key);
                    }
                    if (checkArea(_wall.Key))
                    {
                        AddNerabyWall(_wall.Value);
                    }
                }
                walls.Remove(_wall);
            }

            //随机选择迷宫起点终点
            mazeWall.RandomOpenStartAndPoint();
            mazeWall.RandomOpenStartAndPoint();

            return(mazeWall);
        }
Example #4
0
        public static MazeWall Generate(MazeWall wall)
        {
            mazeWall = wall;
            count    = 0;
            _stack.Clear();

            //封闭全部墙壁
            mazeWall.ClosedAllWall();

            int maxCount = mazeWall.RowLength * mazeWall.ColLength;

            //随机选择一个开始区域
            WallArea fistArea = RandChooseBeginArea();

            ++count;
            _stack.Push(fistArea);

            WallArea?curArea = fistArea;

            while (count < maxCount)
            {
                if (null == curArea)
                {
                    //退回上一个区域
                    _stack.Pop();
                    curArea = _stack.Peek();
                    continue;
                }
                curArea = CheckNearby((WallArea)curArea);
            }

            //随机选择迷宫起点终点
            mazeWall.RandomOpenStartAndPoint();
            mazeWall.RandomOpenStartAndPoint();

            return(mazeWall);
        }