Example #1
0
        private static string ProduceGraphs(MapData map, LevelMap levelMap)
        {
            var maximumLocationSize = levelMap.AllRooms.Max(room => room.Locations.Count);
            var minimumSize         = 1.0;
            var maximumSize         = 15.0;

            var contentBuilder = new StringBuilder();

            contentBuilder.AppendLine("graph {");
            contentBuilder.AppendLine($"label=\"{map.Name}\";");

            contentBuilder.AppendLine("{");

            var roomNameMap = new Dictionary <IRoom, string>();

            foreach (var room in levelMap.AllRooms)
            {
                var isStartingRoom = room == levelMap.StartingRoom;
                var isEndingRoom   = levelMap.EndingRooms.Contains(room);

                var roomName = NameRoom(room, isStartingRoom, isEndingRoom, roomNameMap);

                contentBuilder.Append($"\"{roomName}\" [");
                if (isStartingRoom)
                {
                    contentBuilder.Append("color=palegreen, style=filled, ");
                }
                else if (isEndingRoom)
                {
                    contentBuilder.Append("color=tomato, style=filled, ");
                }
                else if (room.HasGoldKey && room.HasSilverKey)
                {
                    contentBuilder.Append("color=cyan, style=filled, ");
                }
                else if (room.HasGoldKey)
                {
                    contentBuilder.Append("color=gold, style=filled, ");
                }
                else if (room.HasSilverKey)
                {
                    contentBuilder.Append("color=azure3, style=filled, ");
                }

                var roomSize = (double)room.Locations.Count / maximumLocationSize * maximumSize;
                if (roomSize < minimumSize)
                {
                    roomSize = minimumSize;
                }
                contentBuilder.AppendLine($"shape=circle, width={roomSize:F2}, fontsize=22];");
            }

            contentBuilder.AppendLine("}");

            foreach (var room in levelMap.AllRooms)
            {
                foreach (var passageRoomPair in room.AdjacentRooms)
                {
                    var leftRoomName  = roomNameMap[room];
                    var rightRoomName = roomNameMap[passageRoomPair.Value];

                    contentBuilder.Append($"\"{leftRoomName}\" -- \"{rightRoomName}\"");

                    if (passageRoomPair.Key.Any(passage => passage.LockLevel == LockLevel.Gold))
                    {
                        contentBuilder.Append(" [color=gold, penwidth=5]");
                    }
                    if (passageRoomPair.Key.Any(passage => passage.LockLevel == LockLevel.Silver))
                    {
                        contentBuilder.Append(" [color=azure3, penwidth=5]");
                    }
                    if (passageRoomPair.Key.Any(passage => passage.LockLevel == LockLevel.Both))
                    {
                        contentBuilder.Append(" [color=cyan, penwidth=5]");
                    }

                    contentBuilder.AppendLine(";");
                }
            }

            contentBuilder.AppendLine("}");

            return(contentBuilder.ToString());
        }
Example #2
0
        public static string BuildGraphDefinition(MapData data, LevelMap levelMap)
        {
            var graphDefinition = ProduceGraphs(data, levelMap);

            return(graphDefinition);
        }