コード例 #1
0
ファイル: test_itemadder.py プロジェクト: briguy47/pyherc
    def setup(self):
        """
        Setup the test case
        """
        self.floor_rock = 1
        self.wall_empty = 2
        self.rng = Random()
        self.level = Level((60, 40), self.floor_rock, self.wall_empty)
        self.level.set_location_type((10, 10), 'room')

        for x_loc in range(11, 30):
            self.level.set_location_type((x_loc, 10), 'corridor')

        item_config = ItemConfigurations(Random())

        item_config.add_item(
                    ItemConfiguration(name = 'dagger',
                                      cost = 2,
                                      weight = 1,
                                      icons = [500],
                                      types = ['weapon',
                                               'light weapon',
                                               'melee',
                                               'simple weapon'],
                                      rarity = 'common',
                                      weapon_configration = WeaponConfiguration(
                                            damage = 2,
                                            critical_range = 11,
                                            critical_damage = 2,
                                            damage_types = ['piercing',
                                                            'slashing'],
                                            weapon_class = 'simple')))

        item_config.add_item(
                    ItemConfiguration(name = 'red potion',
                                      cost = 150,
                                      weight = 1,
                                      icons = [100],
                                      types = ['potion'],
                                      rarity = 'rare',
                                      effect_handles = [EffectHandle(
                                            trigger = 'on drink',
                                            effect = 'cure medium wounds',
                                            parameters = None,
                                            charges = 1)]))

        self.item_generator = ItemGenerator(item_config)

        self.configuration = ItemAdderConfiguration(['crypt'])
        self.configuration.add_item(min_amount = 3,
                                    max_amount = 4,
                                    name = 'dagger')
        self.configuration.add_item(min_amount = 1,
                                    max_amount = 1,
                                    type = 'potion',
                                    location = 'room')
        self.item_adder = ItemAdder(self.item_generator,
                                    self.configuration,
                                    self.rng)

        self.item_adder.add_items(self.level)
コード例 #2
0
ファイル: test_itemadder.py プロジェクト: briguy47/pyherc
class TestItemAdder():
    """
    Tests for ItemAdder
    """
    def __init__(self):
        """
        Default constructor
        """
        self.rng = None
        self.level = None
        self.item_generator = None
        self.configuration = None
        self.item_adder = None
        self.floor_rock = None
        self.wall_empty = None

    def setup(self):
        """
        Setup the test case
        """
        self.floor_rock = 1
        self.wall_empty = 2
        self.rng = Random()
        self.level = Level((60, 40), self.floor_rock, self.wall_empty)
        self.level.set_location_type((10, 10), 'room')

        for x_loc in range(11, 30):
            self.level.set_location_type((x_loc, 10), 'corridor')

        item_config = ItemConfigurations(Random())

        item_config.add_item(
                    ItemConfiguration(name = 'dagger',
                                      cost = 2,
                                      weight = 1,
                                      icons = [500],
                                      types = ['weapon',
                                               'light weapon',
                                               'melee',
                                               'simple weapon'],
                                      rarity = 'common',
                                      weapon_configration = WeaponConfiguration(
                                            damage = 2,
                                            critical_range = 11,
                                            critical_damage = 2,
                                            damage_types = ['piercing',
                                                            'slashing'],
                                            weapon_class = 'simple')))

        item_config.add_item(
                    ItemConfiguration(name = 'red potion',
                                      cost = 150,
                                      weight = 1,
                                      icons = [100],
                                      types = ['potion'],
                                      rarity = 'rare',
                                      effect_handles = [EffectHandle(
                                            trigger = 'on drink',
                                            effect = 'cure medium wounds',
                                            parameters = None,
                                            charges = 1)]))

        self.item_generator = ItemGenerator(item_config)

        self.configuration = ItemAdderConfiguration(['crypt'])
        self.configuration.add_item(min_amount = 3,
                                    max_amount = 4,
                                    name = 'dagger')
        self.configuration.add_item(min_amount = 1,
                                    max_amount = 1,
                                    type = 'potion',
                                    location = 'room')
        self.item_adder = ItemAdder(self.item_generator,
                                    self.configuration,
                                    self.rng)

        self.item_adder.add_items(self.level)

    def test_adding_items(self):
        """
        Test basic case of adding items on the level
        """
        assert_that(self.level.items, has_length(greater_than(3)))
        assert_that(self.level.items, has_length(less_than(6)))

        assert_that(self.level, does_have_item('dagger',
                                        greater_than_or_equal_to(3)))
        assert_that(self.level, does_have_item('red potion', 1))

    def test_adding_to_location(self):
        """
        Test that ItemAdder will use location types passed to it
        """
        potion = [x for x in self.level.items
                  if x.name == 'red potion'][0]

        location = potion.location

        assert_that(located_in_room(potion))