I'm designing a text based RPG in C# that has a graphical world editor. The "world" data structure consists of a List of type Room, where the room class looks like this:
class Room { public int id { get; set; } public string name { get; set; } public string shortDescription { get; set; } public string longDescription { get; set; } public Room northRoom { get; set; } public int northRoomId { get; set; } public Room southRoom { get; set; } public int southRoomId { get; set; } public Room eastRoom { get; set; } public int eastRoomId { get; set; } public Room westRoom { get; set; } public int westRoomId { get; set; } public Room inRoom { get; set; } public int inRoomId { get; set; } public Room outRoom { get; set; } public int outRoomId { get; set; } public List<Item> items; public List<Npc> npcs; public bool visited = false; public Room(int id, string name, string shortDescription, string longDescription, List<Item> items, List<Npc> npcs, int northRoomId, int southRoomId, int eastRoomId, int westRoomId, int inRoomId, int outRoomId) { this.id = id; this.name = name; this.shortDescription = shortDescription; this.longDescription = longDescription; this.items = items; this.npcs = npcs; this.northRoomId = northRoomId; this.southRoomId = southRoomId; this.eastRoomId = eastRoomId; this.westRoomId = westRoomId; this.inRoomId = inRoomId; this.outRoomId = outRoomId; } public Room() { } public void addItem(Item item) { items.Add(item); } public void removeItem(Item item) { items.Remove(item); } public void addNpc(Npc npc) { npcs.Add(npc); } public void removeNpc(Npc npc) { npcs.Remove(npc); } public List<Room> getExits() { List<Room> exits = new List<Room>(); if (northRoom != null) exits.Add(northRoom); if (southRoom != null) exits.Add(southRoom); if (eastRoom != null) exits.Add(eastRoom); if (westRoom != null) exits.Add(westRoom); if (inRoom != null) exits.Add(inRoom); if (outRoom != null) exits.Add(outRoom); return exits; } }
As you can see, each room can point to a number of other rooms. The world structure loads fine, I can walk around between the linked rooms, etc...
My dilemma is drawing this structure on the screen. I'd like to draw squares on a canvas with lines linking the rooms together for a visual representation of the world. I've tried numerous home grown algorithms which quickly get out of control in complexity. This seems to be a fairly abstract problem with many applications so I'm wondering if there is an algorithm (or category of algorithms) that would help me solve this problem.
Any help or suggestions would be greatly appreciated! Thank you!