public BlockInfo[,] RandObstacleBlockInfoByChunk(ChunkInfoObstacle obstacleChunk)
        {
            var obstacleName = RandObstacle().Type;
            var subBlockMap  = TemplateChunkCharToBlockInfoTransformer.Transform(TemplateDictionary.Dic[obstacleName].Chunkchar);

            return(subBlockMap);
        }
示例#2
0
        private static void ConnectCross()
        {
            var obstacleBuildTimeTotal = LevelDescription.ObstacleRate * 10;

            for (int buildTime = 0; buildTime <= obstacleBuildTimeTotal; buildTime++)
            {
                // 一种简易的填充方式,遍历所有相邻四点,若均为道路或空则随机生成障碍,合法的新障碍不能分割连接性
                for (int i = Constant.OverBorderChunkSize; i < LevelDescription.MaxChunkX - Constant.OverBorderChunkSize; i++)
                {
                    for (int j = Constant.OverBorderChunkSize; j < LevelDescription.MaxChunkY - Constant.OverBorderChunkSize; j++)
                    {
                        // 检查是否为空旷四区块
                        var isOpenSpace = true;

                        for (int deltaI = 0; deltaI < 2; deltaI++)
                        {
                            for (int deltaJ = 0; deltaJ < 2; deltaJ++)
                            {
                                var chunkType = ChunkMap[i + deltaI, j + deltaJ].ChunkType;
                                if (chunkType == "Room" || chunkType == "Obstacle" || chunkType == "OverNone")
                                {
                                    isOpenSpace = false;
                                }
                            }
                        }

                        if (isOpenSpace)
                        {
                            // 随机选择一个区块
                            var delta  = RNG.RandInt(0, 3);
                            var deltaI = delta / 2;
                            var deltaJ = delta % 2;
                            // 检测新障碍是否合法,只要毗邻的8格子之存在一个连接体
                            var PosOffsetOfPoint = new Tuple <int, int> [9];
                            PosOffsetOfPoint[0] = new Tuple <int, int>(-1, -1);
                            PosOffsetOfPoint[1] = new Tuple <int, int>(-1, 0);
                            PosOffsetOfPoint[2] = new Tuple <int, int>(-1, 1);
                            PosOffsetOfPoint[3] = new Tuple <int, int>(0, 1);
                            PosOffsetOfPoint[4] = new Tuple <int, int>(1, 1);
                            PosOffsetOfPoint[5] = new Tuple <int, int>(1, 0);
                            PosOffsetOfPoint[6] = new Tuple <int, int>(1, -1);
                            PosOffsetOfPoint[7] = new Tuple <int, int>(0, -1);
                            PosOffsetOfPoint[8] = new Tuple <int, int>(-1, -1);

                            var crossToObstacleCount = 0;
                            for (int p = 0; p < 8; p++)
                            {
                                var nowX         = i + deltaI + PosOffsetOfPoint[p].Item1;
                                var nowY         = j + deltaJ + PosOffsetOfPoint[p].Item2;
                                var nowChunk     = ChunkMap[nowX, nowY];
                                var nowChunkType = nowChunk.ChunkType;

                                var nextX         = i + deltaI + PosOffsetOfPoint[p + 1].Item1;
                                var nextY         = j + deltaJ + PosOffsetOfPoint[p + 1].Item2;
                                var nextChunkType = ChunkMap[nextX, nextY].ChunkType;

                                if ((nowChunkType == "None" || nowChunkType == "Cross") && (nextChunkType == "Obstacle" || nextChunkType == "Room" || nextChunkType == "OverNone"))
                                {
                                    crossToObstacleCount++;
                                }
                                // 禁止在门附近生成障碍
                                if ((nowChunkType == "Room" && (nowChunk as ChunkInfoRoom).Dir != 0))
                                {
                                    crossToObstacleCount += 10;
                                }
                            }

                            if (crossToObstacleCount < 2)
                            {
                                ChunkMap[i + deltaI, j + deltaJ] = new ChunkInfoObstacle(i + deltaI, j + deltaJ);
                            }
                        }
                    }
                }
            }

            // 将剩余空白用道路填充
            for (int i = Constant.OverBorderChunkSize; i < LevelDescription.MaxChunkX - Constant.OverBorderChunkSize; i++)
            {
                for (int j = Constant.OverBorderChunkSize; j < LevelDescription.MaxChunkY - Constant.OverBorderChunkSize; j++)
                {
                    if (ChunkMap[i, j].ChunkType == "None")
                    {
                        ChunkMap[i, j] = new ChunkInfoCross(i, j);
                    }
                }
            }
        }