Example #1
0
    def test_adding_items(self):
        """
        Test basic case of adding items on the level
        """
        assert_that(list(get_items(self.level)), has_length(greater_than(3)))
        assert_that(list(get_items(self.level)), 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))
Example #2
0
    def test_adding_items(self):
        """
        Test basic case of adding items on the level
        """
        assert_that(list(get_items(self.level)), has_length(greater_than(3)))
        assert_that(list(get_items(self.level)), 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))
Example #3
0
    def _matches(self, item):
        """
        Check if match

        :param item: match against this item
        """
        if self.item in item.inventory:
            self.fail_reason = 'item not dropped'
            return False

        if self.item.level is None:
            self.fail_reason = 'item in limbo'
            return False

        if self.item.location != item.location:
            self.fail_reason = 'item dropped to incorrect location'
            return False

        if not self.item in get_items(self.item.level):
            self.fail_reason = 'item not in level'
            return False

        self.old_time = get_history_value(item, 'tick')
        self.new_time = item.tick
        if not self.old_time < self.new_time:
            self.fail_reason = 'time did not pass'
            return False

        return True
Example #4
0
    def _matches(self, item):
        """
        Check if match

        :param item: match against this item
        """
        if self.item in item.inventory:
            self.fail_reason = 'item not dropped'
            return False

        if self.item.level is None:
            self.fail_reason = 'item in limbo'
            return False

        if self.item.location != item.location:
            self.fail_reason = 'item dropped to incorrect location'
            return False

        if not self.item in get_items(self.item.level):
            self.fail_reason = 'item not in level'
            return False

        self.old_time = get_history_value(item, 'tick')
        self.new_time = item.tick
        if not self.old_time < self.new_time:
            self.fail_reason = 'time did not pass'
            return False

        return True
Example #5
0
    def update_inventory(self):
        """
        Update items being displayed

        .. versionadded:: 0.6
        """
        self.items_carried.show_items(self.character.inventory)
        items = list(get_items(self.character.level, self.character.location))
        self.items_in_ground.show_items(items)
        self.character_inventory.show_character()
    def test_picking_up(self):
        """
        Test that item can be picked up
        """
        pick_up(self.character,
                self.item)

        assert(self.item in self.character.inventory)
        assert(not self.item in get_items(self.level))
        assert(self.item.location == ())
Example #7
0
    def test_adding_to_location(self):
        """
        Test that ItemAdder will use location types passed to it
        """
        potion = [x for x in get_items(self.level)
                  if x.name == 'red potion'][0]

        location = potion.location

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

        location = potion.location

        assert_that(located_in_room(potion))
Example #9
0
    def update_inventory(self):
        """
        Update items being displayed

        .. versionadded:: 0.6
        """
        self.items_carried.show_items(self.character.inventory)
        items = list(get_items(self.character.level, self.character.location))
        self.items_in_ground.show_items(items)
        self.character_inventory.show_character()
Example #10
0
    def test_picking_up(self):
        """
        Test that item can be picked up
        """
        pick_up(self.character,
                self.item)

        assert(self.item in self.character.inventory)
        assert(not self.item in get_items(self.level))
        assert(self.item.location == ())
Example #11
0
    def test_picking_up_not_correct_location(self): #pylint: disable=C0103
        """
        Test that item is not picked up from wrong location
        """
        self.character.location = (6, 6)

        assert(self.character.location == (6, 6))
        assert(self.item.location == (5, 5))

        pick_up(self.character,
                self.item)

        assert(not self.item in self.character.inventory)
        assert(self.item in get_items(self.level))
Example #12
0
    def test_picking_up_not_correct_location(self): #pylint: disable=C0103
        """
        Test that item is not picked up from wrong location
        """
        self.character.location = (6, 6)

        assert(self.character.location == (6, 6))
        assert(self.item.location == (5, 5))

        pick_up(self.character,
                self.item)

        assert(not self.item in self.character.inventory)
        assert(self.item in get_items(self.level))
Example #13
0
    def _matches(self, item):
        """
        Check if matcher matches item

        :param item: object to match against
        :returns: True if matching, otherwise False
        :rtype: Boolean
        """
        count = 0

        for item in get_items(item):
            if item.name == self.item:
                count = count + 1

        return self.amount.matches(count)
Example #14
0
    def _action_a(self, key, modifiers):
        """
        Process action a key

        :param key: key triggering the processing
        :type key: int
        """
        player = self.model.player
        level = player.level
        items = list(get_items(level, player.location))

        if items is not None and len(items) > 0:
            pick_up(player, items[0])

        elif pyherc.vtable["\ufdd0:is-move-legal"](player, 9):
            pyherc.vtable["\ufdd0:move"](player, 9)

        elif is_dig_legal(player):
            dig(player)
Example #15
0
    def _action_a(self, key, modifiers):
        """
        Process action a key

        :param key: key triggering the processing
        :type key: int
        """
        player = self.model.player
        level = player.level
        items = list(get_items(level, player.location))

        if items is not None and len(items) > 0:
            pick_up(player, items[0])

        elif pyherc.vtable['\ufdd0:is-move-legal'](player, 9):
            pyherc.vtable['\ufdd0:move'](player, 9)

        elif is_dig_legal(player):
            dig(player)