Ejemplo n.º 1
0
def test_add_object_with_location():
    level = Level(100, 100)
    coordinates = (10, 10)
    game_object = GameObject(name="Loc")
    game_object.register_component(components.Location())
    game_object.location.set_local_coords(coordinates)
    level.add_object(game_object)

    assert game_object in level.get_objects_by_coordinates(coordinates)
Ejemplo n.º 2
0
def game_objects():
    # noinspection PyShadowingNames
    game_objects = []
    for i in range(0, 10):
        game_object = GameObject(blocking=bool(random.randint(0, 1)),
                                 name=str(i))
        game_object.register_component(components.Location())
        game_object.location.set_local_coords(
            (random.randint(0, 100), random.randint(0, 100)))
        game_objects.append(game_object)

    return game_objects
Ejemplo n.º 3
0
def test_adjust_coordinates_for_object():
    level = Level(100, 100)
    coordinates = (10, 10)
    new_coordinates = (50, 50)
    game_object = GameObject(name="Loc")
    game_object.register_component(components.Location())
    game_object.location.set_local_coords(coordinates)
    level.add_object(game_object)
    level.adjust_coordinates_for_object(game_object, new_coordinates)

    assert game_object not in level.get_objects_by_coordinates(coordinates)
    assert game_object in level.get_objects_by_coordinates(new_coordinates)
Ejemplo n.º 4
0
def character():
    char_components = [
        components.CharacterStats(AbilityScoreSet.set_all(8, strength=14)),
        components.CharacterClass(classes.Fighter),
        components.Skills(),
    ]

    char = GameObject(None)

    for component in char_components:
        char.register_component(component)

    return char
Ejemplo n.º 5
0
def test_remove_object_with_display():
    level = Level(100, 100)
    game_object = GameObject(name="Displayable")
    game_object.register_component(
        components.Display(Colors.DARK_RED,
                           Colors.BLACK,
                           '!',
                           priority=DisplayPriority.Item))
    level.add_object(game_object)
    level.remove_object(game_object)

    for key, display_objects in level.displays.items():
        assert game_object not in display_objects
Ejemplo n.º 6
0
    def create_new(self, base_item):
        recipe = listing.get_recipe(base_item)
        if recipe is None:
            raise Exception("Found no recipes for item {}".format(base_item))

        item_components = self.get_recursive_components(base_item, recipe)
        new = GameObject(game=self.game,
                         base=base_item,
                         blocking=False,
                         name=base_item.name)
        new.flags.add(flags.GameObjectFlags.Character)
        for component in item_components:
            new.register_component(component)

        return new
Ejemplo n.º 7
0
    def create_blank_player(self):
        new_character = GameObject(game=self.game, blocking=True)
        new_character.register_component(components.Location())
        new_character.register_component(bf_components.Combat())
        new_character.register_component(components.Inventory())
        new_character.register_component(components.Effects())
        new_character.register_component(components.Vision(20))
        new_character.register_component(components.Player())
        new_character.register_component(bf_components.Skills())
        new_character.register_component(
            components.Display(self._player_fg_color, self._player_bg_color,
                               self._player_symbol,
                               self._player_display_priority))
        new_character.flags.add(flags.GameObjectFlags.Character)

        return new_character
Ejemplo n.º 8
0
    def create_new(self, base_monster):
        recipe = listing.get_recipe(base_monster)
        if recipe is None:
            raise Exception("Found no recipes for monster {}".format(base_monster))

        item_components = self.get_recursive_components(base_monster, recipe)
        new = GameObject(
            game=self.game,
            base=base_monster,
            blocking=True,
            name=base_monster.name
        )
        new.flags.add(flags.GameObjectFlags.Character)
        for component in item_components:
            new.register_component(component)

        if new.equipment:
            new.register_component(components.Inventory())

            if base_monster.treasure_type:
                items = TreasureFactory.create_new(base_monster.treasure_type)
                for item in items:
                    if not item.wearable or not new.equipment.wear(item):
                        new.inventory.add(item)

        if recipe.outfits:
            outfit = random.choice(recipe.outfits)
            outfit.apply(self.game, new)

        if not new.vision:
            new.register_component(components.SimpleVision())

        new.register_component(components.Effects())
        new.register_component(components.Alliance())

        return new