def place_creatures(self, creatures, creature_list, level): """ Place creatures into a level :param creatures: creatures to place :type creatures: [Character] :param creature_list: specification where to place creatures :type creature_list: dict :param level: level to place creatures :type level: Level """ for creature in creatures: location_types = [x['location'] for x in creature_list if x['name'] == creature.name] if not location_types: location_types = ['any'] locations = [] for location_type in location_types: locations.extend([location for location in (get_locations_by_tag(level, location_type)) if safe_passage(level, location)]) if locations: location = self.rng.choice(locations) add_character(level, location, creature)
def place_creatures(self, creatures, creature_list, level): """ Place creatures into a level :param creatures: creatures to place :type creatures: [Character] :param creature_list: specification where to place creatures :type creature_list: dict :param level: level to place creatures :type level: Level """ for creature in creatures: location_types = [ x['location'] for x in creature_list if x['name'] == creature.name ] if not location_types: location_types = ['any'] locations = [] for location_type in location_types: locations.extend([ location for location in ( get_locations_by_tag(level, location_type)) if safe_passage(level, location) ]) if locations: location = self.rng.choice(locations) add_character(level, location, creature)
def test_get_rooms(self): """ Test that level can report what areas of it are marked as being room """ add_location_tag(self.level, (5, 5), 'room') add_location_tag(self.level, (5, 6), 'room') add_location_tag(self.level, (8, 8), 'room') add_location_tag(self.level, (9, 8), 'room') rooms = get_locations_by_tag(self.level, 'room') assert_that(rooms, contains_inanyorder((5, 5), (5, 6), (8, 8), (9, 8)))
def add_portal(self, level): """ Add given stairs to the level :param level: level to modify :type level: Level """ locations = [x for x in get_locations_by_tag(level, self.location_type) if safe_passage(level, x)] if locations: location = self.rng.choice(locations) portal = Portal(icons=self.icons, level_generator_name=self.level_generator_name) portal.exits_dungeon = self.escape_stairs add_portal(level, location, portal)
def test_get_locations_by_type_does_not_report_all_locations(self): """ Test that getting locations by type does not return all locations """ add_location_tag(self.level, (5, 5), 'room') add_location_tag(self.level, (5, 6), 'room') add_location_tag(self.level, (8, 8), 'room') add_location_tag(self.level, (9, 8), 'room') add_location_tag(self.level, (6, 5), 'corridor') add_location_tag(self.level, (6, 6), 'corridor') add_location_tag(self.level, (6, 7), 'corridor') add_location_tag(self.level, (6, 8), 'corridor') rooms = get_locations_by_tag(self.level, 'room') assert_that(rooms, contains_inanyorder((5, 5), (5, 6), (8, 8), (9, 8)))
def add_portal(self, level): """ Add given stairs to the level :param level: level to modify :type level: Level """ locations = [ x for x in get_locations_by_tag(level, self.location_type) if safe_passage(level, x) ] if locations: location = self.rng.choice(locations) portal = Portal(icons=self.icons, level_generator_name=self.level_generator_name) portal.exits_dungeon = self.escape_stairs add_portal(level, location, portal)
def place_items(self, items, level): """ Place items to level :param items: list of tupples (item_spec, item) :param level: level to place items :type level: Level """ for item in items: location_type = item[0]['location'] if location_type is None: location_type = 'any' locations = [location for location in (get_locations_by_tag(level, location_type)) if safe_passage(level, location)] if locations: location = self.rng.choice(locations) add_item(level, location, item[1])
def place_items(self, items, level): """ Place items to level :param items: list of tupples (item_spec, item) :param level: level to place items :type level: Level """ for item in items: location_type = item[0]['location'] if location_type is None: location_type = 'any' locations = [ location for location in (get_locations_by_tag(level, location_type)) if safe_passage(level, location) ] if locations: location = self.rng.choice(locations) add_item(level, location, item[1])