Structures

This module contains many “helpers” classes to populate your game with structures. It contains many directly usable structures and some generic ones that can be turned in anything you like.

Wall(**kwargs) A Wall is a specialized Immovable object that as unmodifiable characteristics:
Treasure(**kwargs) A Treasure is an Immovable that is pickable and with a non zero value.
Door(**kwargs) A Door is a GenericStructure that is not pickable, overlappable and restorable.
GenericStructure(**kwargs) A GenericStructure is as the name suggest, a generic object to create all kind of structures.
GenericActionableStructure(**kwargs) A GenericActionableStructure is the combination of a GenericStructure and an Actionable.
class gamelib.Structures.Door(**kwargs)

Bases: gamelib.Structures.GenericStructure

A Door is a GenericStructure that is not pickable, overlappable and restorable. It has a value of 0 and a size of 1 by default. It is an helper class that allows to focus on game design and mechanics instead of small building blocks.

Parameters:
  • model (str) – The model that will represent the door on the map
  • value (int) – The value of the door, it is useless in that case. The default value is 0.
  • size (str) – The size of the door. Unless you make the door pickable (I have no idea why you would do that…), this parameter is not used.
  • type (str) – The type of the door. It is often used as a type identifier for your game main loop. For example: unlocked_door or locked_door.
  • pickable (Boolean) – Is this door pickable by the player? Default value is False.
  • overlappable (Boolean) – Is this door overlappable by the player? Default value is True.
  • restorable (Boolean) – Is this door restorable after being overlapped? Default value is True.

Note

All the options from GenericStructure are also available to this constructor.

Example:

door1 = Door(model=Sprites.DOOR,type='locked_door')
can_move()

Return the capability of moving of an item.

Obviously an Immovable item is not capable of moving. So that method always returns False.

Returns:False
Return type:bool
debug_info()

Return a string with the list of the attributes and their current value.

Return type:str
display()

Print the model WITHOUT carriage return.

overlappable()

This represent the capacity for a BoardItem to be overlapped by player or NPC.

To set this value please use set_overlappable()

Returns:False
Return type:bool
pickable()

This represent the capacity for a BoardItem to be picked-up by player or NPC.

To set this value please use set_pickable()

Returns:True or False
Return type:bool

See also

set_pickable()

restorable()

This represent the capacity for an Immovable BoardItem (in this case a GenericStructure item) to be restored by the board if the item is overlappable and has been overlapped by another Movable item.

The value of this property is set with set_restorable()

Returns:False
Return type:bool

See also

set_restorable()

set_overlappable(val)

Make the structure overlappable or not.

Parameters:val (bool) – True or False depending on the fact that the structure can be overlapped (i.e that a Player or NPC can step on it) or not.

Example:

myneatstructure.set_overlappable(True)
set_pickable(val)

Make the structure pickable or not.

Parameters:val (bool) – True or False depending on the pickability of the structure.

Example:

myneatstructure.set_pickable(True)
set_restorable(val)

Make the structure restorable or not.

Parameters:val (bool) – True or False depending on the restorability of the structure.

Example:

myneatstructure.set_restorable(True)
size()

Return the size of the Immovable Item.

Returns:The size of the item.
Return type:int
store_position(row, column)

Store the BoardItem position for self access.

The stored position is used for consistency and quick access to the self postion. It is a redundant information and might not be synchronized.

Parameters:
  • row (int) – the row of the item in the Board.
  • column (int) – the column of the item in the Board.

Example:

item.store_position(3,4)
class gamelib.Structures.GenericActionableStructure(**kwargs)

Bases: gamelib.Structures.GenericStructure, gamelib.Immovable.Actionable

A GenericActionableStructure is the combination of a GenericStructure and an Actionable. It is only a helper combination.

Please see the documentation for GenericStructure and Actionable for more information.

activate()

This function is calling the action function with the action_parameters.

Usually it’s automatically called by move() when a Player or NPC (see Characters)

can_move()

Return the capability of moving of an item.

Obviously an Immovable item is not capable of moving. So that method always returns False.

Returns:False
Return type:bool
debug_info()

Return a string with the list of the attributes and their current value.

Return type:str
display()

Print the model WITHOUT carriage return.

overlappable()

This represent the capacity for a BoardItem to be overlapped by player or NPC.

To set this value please use set_overlappable()

Returns:False
Return type:bool
pickable()

This represent the capacity for a BoardItem to be picked-up by player or NPC.

To set this value please use set_pickable()

Returns:True or False
Return type:bool

See also

set_pickable()

restorable()

This represent the capacity for an Immovable BoardItem (in this case a GenericStructure item) to be restored by the board if the item is overlappable and has been overlapped by another Movable item.

The value of this property is set with set_restorable()

Returns:False
Return type:bool

See also

set_restorable()

set_overlappable(val)

Make the structure overlappable or not.

Parameters:val (bool) – True or False depending on the fact that the structure can be overlapped (i.e that a Player or NPC can step on it) or not.

Example:

myneatstructure.set_overlappable(True)
set_pickable(val)

Make the structure pickable or not.

Parameters:val (bool) – True or False depending on the pickability of the structure.

Example:

myneatstructure.set_pickable(True)
set_restorable(val)

Make the structure restorable or not.

Parameters:val (bool) – True or False depending on the restorability of the structure.

Example:

myneatstructure.set_restorable(True)
size()

Return the size of the Immovable Item.

Returns:The size of the item.
Return type:int
store_position(row, column)

Store the BoardItem position for self access.

The stored position is used for consistency and quick access to the self postion. It is a redundant information and might not be synchronized.

Parameters:
  • row (int) – the row of the item in the Board.
  • column (int) – the column of the item in the Board.

Example:

item.store_position(3,4)
class gamelib.Structures.GenericStructure(**kwargs)

Bases: gamelib.Immovable.Immovable

A GenericStructure is as the name suggest, a generic object to create all kind of structures.

It can be tweaked with all the properties of BoardItem, Immovable and it can be made pickable, overlappable or restorable or any combination of these.

If you need an action to be done when a Player and/or a NPC touch the structure please have a look at gamelib.Structures.GenericActionableStructure.

Parameters:
  • pickable (bool) – Define if the structure can be picked-up by a Player or NPC.
  • overlappable (bool) – Define if the structure can be overlapped by a Player or NPC.
  • restorable (bool) – Define if the structure can be restored by the Board after a Player or NPC passed through. For example, you want a door or an activator structure (see GenericActionableStructure for that) to remain on the board after it’s been overlapped by a player. But you could also want to develop some kind of Space Invaders game were the protection block are overlappable but not restorable.

On top of these, this object takes all parameters of BoardItem and Immovable

Important

If you need a structure with a permission system please have a look at GenericActionableStructure. This class has a permission system for activation.

can_move()

Return the capability of moving of an item.

Obviously an Immovable item is not capable of moving. So that method always returns False.

Returns:False
Return type:bool
debug_info()

Return a string with the list of the attributes and their current value.

Return type:str
display()

Print the model WITHOUT carriage return.

overlappable()

This represent the capacity for a BoardItem to be overlapped by player or NPC.

To set this value please use set_overlappable()

Returns:False
Return type:bool
pickable()

This represent the capacity for a BoardItem to be picked-up by player or NPC.

To set this value please use set_pickable()

Returns:True or False
Return type:bool

See also

set_pickable()

restorable()

This represent the capacity for an Immovable BoardItem (in this case a GenericStructure item) to be restored by the board if the item is overlappable and has been overlapped by another Movable item.

The value of this property is set with set_restorable()

Returns:False
Return type:bool

See also

set_restorable()

set_overlappable(val)

Make the structure overlappable or not.

Parameters:val (bool) – True or False depending on the fact that the structure can be overlapped (i.e that a Player or NPC can step on it) or not.

Example:

myneatstructure.set_overlappable(True)
set_pickable(val)

Make the structure pickable or not.

Parameters:val (bool) – True or False depending on the pickability of the structure.

Example:

myneatstructure.set_pickable(True)
set_restorable(val)

Make the structure restorable or not.

Parameters:val (bool) – True or False depending on the restorability of the structure.

Example:

myneatstructure.set_restorable(True)
size()

Return the size of the Immovable Item.

Returns:The size of the item.
Return type:int
store_position(row, column)

Store the BoardItem position for self access.

The stored position is used for consistency and quick access to the self postion. It is a redundant information and might not be synchronized.

Parameters:
  • row (int) – the row of the item in the Board.
  • column (int) – the column of the item in the Board.

Example:

item.store_position(3,4)
class gamelib.Structures.Treasure(**kwargs)

Bases: gamelib.Immovable.Immovable

A Treasure is an Immovable that is pickable and with a non zero value. It is an helper class that allows to focus on game design and mechanics instead of small building blocks.

Parameters:
  • model (str) – The model that will represent the treasure on the map
  • value (int) – The value of the treasure, it is usually used to calculate the score.
  • size (str) – The size of the treasure. It is used by Inventory as a measure of space. If the treasure’s size exceed the Inventory size (or the cumulated size of all items + the treasure exceed the inventory max_size()) the Inventory will refuse to add the treasure.

Note

All the options from Immovable are also available to this constructor.

Example:

money_bag = Treasure(model=Sprites.MONEY_BAG,value=100,size=2)
print(f"This is a money bag {money_bag}")
player.inventory.add_item(money_bag)
print(f"The inventory value is {player.inventory.value()} and is at
    {player.inventory.size()}/{player.inventory.max_size}")
can_move()

Return the capability of moving of an item.

Obviously an Immovable item is not capable of moving. So that method always returns False.

Returns:False
Return type:bool
debug_info()

Return a string with the list of the attributes and their current value.

Return type:str
display()

Print the model WITHOUT carriage return.

overlappable()

This represent the capacity for a Treasure to be overlapped by player or NPC.

A treasure is not overlappable.

Returns:False
Return type:bool
pickable()

This represent the capacity for a Treasure to be picked-up by player or NPC.

A treasure is obviously pickable by the player and potentially NPCs. Board puts the Treasure in the Inventory if the picker implements has_inventory()

Returns:True
Return type:bool
restorable()

This represent the capacity for a Treasure to be restored after being overlapped.

A treasure is not overlappable, therefor is not restorable.

Returns:False
Return type:bool
size()

Return the size of the Immovable Item.

Returns:The size of the item.
Return type:int
store_position(row, column)

Store the BoardItem position for self access.

The stored position is used for consistency and quick access to the self postion. It is a redundant information and might not be synchronized.

Parameters:
  • row (int) – the row of the item in the Board.
  • column (int) – the column of the item in the Board.

Example:

item.store_position(3,4)
class gamelib.Structures.Wall(**kwargs)

Bases: gamelib.Immovable.Immovable

A Wall is a specialized Immovable object that as unmodifiable characteristics:

  • It is not pickable (and cannot be).
  • It is not overlappable (and cannot be).
  • It is not restorable (and cannot be).

As such it’s an object that cannot be moved, cannot be picked up or modified by Player or NPC and block their ways. It is therefor advised to create one per board and reuse it in many places.

Parameters:
  • model (str) – The representation of the Wall on the Board.
  • name (str) – The name of the Wall.
  • size (int) – The size of the Wall. This parameter will probably be deprecated as size is only used for pickable objects.
can_move()

Return the capability of moving of an item.

Obviously an Immovable item is not capable of moving. So that method always returns False.

Returns:False
Return type:bool
debug_info()

Return a string with the list of the attributes and their current value.

Return type:str
display()

Print the model WITHOUT carriage return.

overlappable()

This represent the capacity for a BoardItem to be overlapped by player or NPC.

Returns:False
Return type:bool
pickable()

This represent the capacity for a BoardItem to be pick-up by player or NPC.

Returns:False
Return type:bool

Example:

if mywall.pickable():
    print('Whoaa this wall is really light... and small...')
else:
    print('Really? Trying to pick-up a wall?')
restorable()

This represent the capacity for an Immovable Movable item. A wall is not overlappable.

Returns:False
Return type:bool
size()

Return the size of the Immovable Item.

Returns:The size of the item.
Return type:int
store_position(row, column)

Store the BoardItem position for self access.

The stored position is used for consistency and quick access to the self postion. It is a redundant information and might not be synchronized.

Parameters:
  • row (int) – the row of the item in the Board.
  • column (int) – the column of the item in the Board.

Example:

item.store_position(3,4)