void AddPath(DungeonPath path) { addedPaths.Add(path); Paths.Add(path); if (!path.Portals[0].ConnectedPaths.Contains(path)) { path.Portals[0].ConnectedPaths.Add(path); } if (!path.Portals[1].ConnectedPaths.Contains(path)) { path.Portals[1].ConnectedPaths.Add(path); } }
void CheckRemovePath(DungeonPath path, List<DungeonPath> removeList) { if (removeList.Contains(path)) return; removeList.Add(path); foreach (var connectedPath in path.Portals[0].ConnectedPaths) { CheckRemovePath(connectedPath, removeList); } foreach (var connectedPath in path.Portals[1].ConnectedPaths) { CheckRemovePath(connectedPath, removeList); } }
/// <summary> /// 2つのポータルの間をつなぐ通路を生成 /// </summary> /// <param name="start"></param> /// <param name="end"></param> /// <param name="isHorizontal"></param> /// <returns></returns> DungeonPath GeneratePath(DungeonPortal start, DungeonPortal end, bool isHorizontal) { var result = new DungeonPath() { Rand = this.Rand }; start.ConnectedPaths.Add(result); result.Portals[0] = start; end.ConnectedPaths.Add(result); result.Portals[1] = end; result.IsHorizontal = isHorizontal; if (!result.GenerateSteps()) { start.ConnectedPaths.Remove(result); end.ConnectedPaths.Remove(result); result = null; } return result; }
void RemovePath(DungeonPath path) { var removeList = new List<DungeonPath>(); // つながっている先を再帰的に消したいので、まずチェックをつける CheckRemovePath(path, removeList); // 一気に消す foreach (var p in removeList) { removedPaths.Add(p); Paths.Remove(p); p.Portals[0].ConnectedPaths.Remove(p); p.Portals[1].ConnectedPaths.Remove(p); } }
/// <summary> /// ポータルのどちら側に通路がつながっているか /// </summary> /// <param name="path"></param> /// <returns>0:左 1:右 2:上 3:下</returns> int GetConnectedPathSide(DungeonPath path) { if (path.IsHorizontal) { if (path.Portals[0] == this) { if (path.Portals[0].Position.X < path.Portals[1].Position.X) { return 1; } else { return 0; } } else if (path.Portals[1] == this) { if (path.Portals[0].Position.X < path.Portals[1].Position.X) { return 0; } else { return 1; } } } else { if (path.Portals[0] == this) { if (path.Portals[0].Position.Y < path.Portals[1].Position.Y) { return 3; } else { return 2; } } else if (path.Portals[1] == this) { if (path.Portals[0].Position.Y < path.Portals[1].Position.Y) { return 2; } else { return 3; } } } return -1; }