def __init__(self, danger_level=0, generation_type=LevelGen.Dungeon, tiles=None, locations=(), custom_creatures=(), creature_spawning=True): # Generation self.danger_level = danger_level self.generation_type = generation_type self.custom_creatures = list(custom_creatures) self.creature_spawning = creature_spawning self.creature_spawn_count = 99 # Normal usage if tiles is None: self.tiles = Array2D(default_level_dimensions) else: self.tiles = tiles self.locations = OneToOneMapping(locations) self.visible_change = Event() self.turn_scheduler = TurnScheduler() self.creatures = {} self.items = {} if self.generation_type.value > LevelGen.ExtendExisting.value: self.rows, self.cols = self.tiles.dimensions else: self.rows, self.cols = default_level_dimensions self.is_finalized = False
def test_one_to_one_mapping(): mapping = OneToOneMapping() mapping[0] = 0 mapping[1] = 1 mapping[2] = 2 mapping[3] = 3 mapping[4] = 4 assert mapping[0] == 0 assert mapping[1] == 1 assert mapping[2] == 2 assert mapping[3] == 3 assert mapping[4] == 4 mapping[0] = 5 assert mapping[0] == 5 assert mapping.getkey(5) == 0 with pytest.raises(ValueError): mapping[1] = 5 del mapping[4] with pytest.raises(KeyError): mapping.getkey(4) with pytest.raises(ValueError): mapping.update(**{"a": 10, "b": 10}) with pytest.raises(ValueError): mapping.update({"a": 10, "b": 10})