pygamelib.engine.Inventory

class pygamelib.engine.Inventory(max_size=10, parent=None)

A class that represent the Player (or NPC) inventory.

This class is pretty straightforward: it is an object container, you can add, get and remove items and you can get a value from the objects in the inventory.

The constructor takes only one parameter: the maximum size of the inventory. Each BoardItem that is going to be put in the inventory has a size (default is 1), the total addition of all these size cannot exceed max_size.

Parameters:
  • max_size (int) – The maximum size of the inventory. Deafult value: 10.
  • parent – The parent object (usually a BoardItem).

Note

You can print() the inventory. This is mostly useful for debug as you want to have a better display in your game.

Warning

The Game engine and Player takes care to initiate an inventory for the player, you don’t need to do it.

__init__(max_size=10, parent=None)

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__([max_size, parent]) Initialize self.
add_item(item) Add an item to the inventory.
delete_item(name) Delete the item corresponding to the name given in argument.
empty() Empty the inventory Example.
get_item(name) Return the item corresponding to the name given in argument.
items_name() Return the list of all items names in the inventory.
search(query) Search for objects in the inventory.
size() Return the cumulated size of the inventory.
value() Return the cumulated value of the inventory.