Ejemplo n.º 1
0
 def __init__(self):
     """
     creation of inventory-related interface
     """
     # inventory is obligatory
     from machine.inventory import MetaInventory
     self.inventory = MetaInventory(self)
Ejemplo n.º 2
0
class InventoryInterface:
    """
    interface for all classes containing some inventory
    """

    def __init__(self):
        """
        creation of inventory-related interface
        """
        # inventory is obligatory
        from machine.inventory import MetaInventory
        self.inventory = MetaInventory(self)

    def get_inventory(self):
        """
        grant access to the inventory
        """
        return self.inventory

    def get_items_from(self, inventory):
        """
        choose and obtain items from an inventory
        """
        # by default choose all possible items
        items_ = inventory.choose_all()
        # remove all the items from original inventory (in order to avoid duplication)
        inventory.remove(*items_)
        return items_

    def add_items(self, *items_):
        """
        shortcut for adding items to inventory
        """
        self.inventory.add(*items_)

    def has_empty_inventory(self):
        """
        is the inventory of this object empty?
        """
        return self.inventory.is_empty()

    def count_items(self):
        """
        count the items in the inventory
        """
        return len(self.inventory.get_items())