Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
def test_observable_event():
    event = Event()
    sub1 = None
    sub2 = None

    def sub_fun_1(x):
        nonlocal sub1
        sub1 = x

    def sub_fun_2(x):
        nonlocal sub2
        sub2 = x

    event.subscribe(sub_fun_1)
    event.subscribe(sub_fun_2)

    event.trigger(10)

    assert sub1 == sub2 == 10