3 hours ago · Tech · hide · 0 comments

Hello, loves! I have a bit of time where I can’t concentrate deeply but can probably do some easy things. A new class reduces DungeonLayout. Let’s see what we can find that might be useful. A bit of mess reduction. Here’s the code that turns a picture of a map into cells: class DungeonLayout: # probably should be separate object. def add_rooms_from_map(self, string_map): d = self.string_map_to_dictionary(string_map) self.add_from_dictionary(d) @staticmethod def string_map_to_dictionary(string_map): string_map = textwrap.dedent(string_map) strings = string_map.split('\n') strings = [string for string in strings if string] room_cells = dict() for y, line in enumerate(strings): for x, char in enumerate(line): if char != '.': if not char in room_cells: room_cells[char] = [] room_cells[char].append((x, y)) return room_cells def add_from_dictionary(self, name_to_xy): for name, tuples in name_to_xy.items(): cells = [ Cell(x,y) for x,y in tuples ] self.add_room(Room(cells, name)) Like the…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.