コード例 #1
0
        public static void DrawAdjacentCells(Cell cell, GridDungeonModel model, Color color)
        {
            foreach (var adjacentId in cell.AdjacentCells)
            {
                var adjacentCell = model.GetCell(adjacentId);
                if (adjacentCell == null)
                {
                    return;
                }
                var centerA = Vector3.Scale(cell.Bounds.CenterF(), model.Config.GridCellSize);
                var centerB = Vector3.Scale(adjacentCell.Bounds.CenterF(), model.Config.GridCellSize);
                Debug.DrawLine(centerA, centerB, color, 0, false);
            }

            foreach (var adjacentId in cell.FixedRoomConnections)
            {
                var adjacentCell = model.GetCell(adjacentId);
                if (adjacentCell == null)
                {
                    return;
                }
                var centerA = Vector3.Scale(cell.Bounds.CenterF(), model.Config.GridCellSize) + new Vector3(0, 0.2f, 0);
                var centerB = Vector3.Scale(adjacentCell.Bounds.CenterF(), model.Config.GridCellSize) + new Vector3(0, 0.2f, 0);
                Debug.DrawLine(centerA, centerB, Color.red, 0, false);
            }
        }
コード例 #2
0
ファイル: GridDungeonModel.cs プロジェクト: Borgeshc/Game
        public static Cell[] FindFurthestRooms(GridDungeonModel model)
        {
            var bestLength = 0;
            var result     = new Cell[2];

            foreach (var startCell in model.Cells)
            {
                var queue     = new Queue <LongestPathBFSData>();
                var visited   = new HashSet <int>();
                var startData = new LongestPathBFSData {
                    cell = startCell, length = 0
                };
                LongestPathBFSData endData = startData;

                queue.Enqueue(startData);
                while (queue.Count > 0)
                {
                    var front = queue.Dequeue();
                    visited.Add(front.cell.Id);

                    foreach (var childId in front.cell.FixedRoomConnections)
                    {
                        if (visited.Contains(childId))
                        {
                            continue;
                        }
                        var child     = model.GetCell(childId);
                        var childData = new LongestPathBFSData {
                            cell = child, length = front.length + 1
                        };
                        queue.Enqueue(childData);
                    }

                    if (queue.Count == 0)
                    {
                        endData = front;
                    }
                }

                if (endData.length > bestLength)
                {
                    bestLength = endData.length;
                    result[0]  = startData.cell;
                    result[1]  = endData.cell;
                }
            }

            return(result);
        }