Game Common Package#
Subpackages#
- Items Package
- Map Package
- Submodules
- GameBoard Class
- Occupiable Class
OccupiableOccupiable.from_json()Occupiable.get_occupied_by()Occupiable.get_stack_list()Occupiable.get_top_of_stack()Occupiable.is_occupied_by_game_object()Occupiable.is_occupied_by_object_type()Occupiable.occupied_byOccupiable.place_on_top_of_stack()Occupiable.remove_game_object_from_occupied_by()Occupiable.remove_object_type_from_occupied_by()Occupiable.to_json()
- Tile Class
- Wall Class
- Module contents
- Stations Package
Submodules#
Action Class#
- class game.common.action.Action[source]#
Bases:
objectAction Class:
This class encapsulates the different actions a player can execute while playing the game.
NOTE: This is not currently implemented in this version of the Byte Engine. If you want more complex actions, you can use this class for Objects instead of the enums.
Avatar Class#
- class game.common.avatar.Avatar(position: Vector | None = None, max_inventory_size: int = 10)[source]#
Bases:
GameObjectAvatar Inventory Notes:
The avatar’s inventory is a list of items. Each item has a quantity and a stack_size (the max amount of an item that can be held in a stack. Think of the Minecraft inventory).
This upcoming example is just to facilitate understanding the concept. The Dispensing Station concept that will be mentioned is completely optional to implement if you desire. The Dispensing Station is used to help with the explanation.
- Items:
Every Item has a quantity and a stack_size. The quantity is how much of the Item the player currently has. The stack_size is the max of that Item that can be in a stack. For example, if the quantity is 5, and the stack_size is 5 (5/5), the item cannot be added to that stack
Picking up items:
- Example 1:
:: When you pick up an item (which will now be referred to as picked_up_item), picked_up_item has a given quantity. In this case, let’s say the quantity of picked_up_item is 2.
Imagine you already have this item in your inventory (which will now be referred to as inventory_item), and inventory_item has a quantity of 1 and a stack_size of 10 (think of this as a fraction: 1/10).
When you pick up picked_up_item, inventory_item will be checked. If picked_up_item’s quantity + inventory_item < stack_size, it’ll be added without issue. Remember, for this example: picked_up_item quantity is 2, and inventory_item quantity is 1, and stack_size is 10.
Inventory_item quantity before picking up: 1/10
2 + 1 < 10 --> True
Inventory_item quantity after picking up: 3/10
- Example 2:
For the next two examples, the total inventory size will be considered.
Let’s say inventory_item has quantity 4 and a stack_size of 5. Now say that picked_up_item has quantity 3.
Recall: if picked_up_item’s quantity + inventory_item < stack_size, it will be added without issue
Inventory_item quantity before picking up: 4/5
3 + 4 < 5 --> False
What do we do in this situation? If you want to add picked_up_item to inventory_item and there is an overflow of quantity, that is handled for you.
Let’s say that your inventory size (which will now be referred to as max_inventory_size) is 5. You already have inventory_item in there that has a quantity of 4 and a stack_size of 5. An image of the inventory is below. ‘None’ is used to help show the max_inventory_size. Inventory_item quantity and stack_size will be listed in parentheses as a fraction.
Inventory: [ inventory_item (4/5), None, None, None, None ]
Now we will add picked_up_item and its quantity of 3:
Inventory before: [ inventory_item (4/5), None, None, None, None ] 3 + 4 < 5 --> False
inventory_item (4/5) will now be inventory_item (5/5) picked_up_item now has a quantity of 2 instead of 3 Since we have a surplus, we will append the same item with a quantity of 2 in the inventory.
The result is: [ inventory_item (5/5), inventory_item (2/5), None, None, None ]
Example 3: For this last example, assume your inventory looks like this:
[ inventory_item (5/5), inventory_item (5/5), inventory_item (5/5), inventory_item (5/5), inventory_item (4/5) ]
You can only fit one more inventory_item into the last stack before the inventory is full. Let’s say that picked_up_item has quantity of 3 again.
Inventory before: [ inventory_item (5/5), inventory_item (5/5), inventory_item (5/5), inventory_item (5/5), inventory_item (4/5) ] 3 + 4 < 5 --> False
inventory_item (4/5) will now be inventory_item (5/5) picked_up_item now has a quantity of 2 However, despite the surplus, we cannot add it into our inventory, so the remaining quantity of picked_up_item is left where it was first found.
Inventory after: [ inventory_item (5/5), inventory_item (5/5), inventory_item (5/5), inventory_item (5/5), inventory_item (5/5) ]
- drop_held_item() Item | None[source]#
Call this method when a station is taking the held item from the avatar.
This method can be modified more for different scenarios where the held item would be dropped (e.g., you make a game where being attacked forces you to drop your held item).
If you want the held item to go somewhere specifically and not become None, that can be changed too.
Make sure to keep clean_inventory() in this method.
- property inventory: list[game.common.items.item.Item | None]#
- property max_inventory_size: int#
- property score: int#
- take(item: Item | None) Item | None[source]#
To use this method, pass in an item object. Whatever this item’s quantity is will be the amount subtracted from the avatar’s inventory. For example, if the item in the inventory is has a quantity of 5 and this method is called with the parameter having a quantity of 2, the item in the inventory will have a quantity of 3.
Furthermore, when this method is called and the potential item is taken away, the clean_inventory method is called. It will consolidate all similar items together to ensure that the inventory is clean.
Reference test_avatar_inventory.py and the clean_inventory method for further documentation on this method and how the inventory is managed.
- Parameters:
item –
- Returns:
Item or None
Enums File#
- class game.common.enums.ActionType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
Enum- INTERACT_CENTER = 10#
- INTERACT_DOWN = 7#
- INTERACT_LEFT = 8#
- INTERACT_RIGHT = 9#
- INTERACT_UP = 6#
- MOVE_DOWN = 3#
- MOVE_LEFT = 4#
- MOVE_RIGHT = 5#
- MOVE_UP = 2#
- NONE = 1#
- PLACE_ITEM_DOWN = 22#
- PLACE_ITEM_LEFT = 23#
- PLACE_ITEM_RIGHT = 24#
These last 10 enums are for selecting a slot from the Avatar class’ inventory. You can add/remove these as needed for the purposes of your game.
- PLACE_ITEM_UP = 21#
- SELECT_SLOT_0 = 11#
- SELECT_SLOT_1 = 12#
- SELECT_SLOT_2 = 13#
- SELECT_SLOT_3 = 14#
- SELECT_SLOT_4 = 15#
- SELECT_SLOT_5 = 16#
- SELECT_SLOT_6 = 17#
- SELECT_SLOT_7 = 18#
- SELECT_SLOT_8 = 19#
- SELECT_SLOT_9 = 20#
- class game.common.enums.DebugLevel(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
Enum- CLIENT = 2#
- CONTROLLER = 3#
- ENGINE = 4#
- NONE = 1#
- class game.common.enums.ObjectType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
Enum- ACTION = 2#
- AVATAR = 4#
- GAMEBOARD = 5#
- ITEM = 9#
- NONE = 1#
- OCCUPIABLE = 10#
- OCCUPIABLE_STATION = 12#
- OCCUPIABLE_STATION_EXAMPLE = 15#
- PLAYER = 3#
- STATION = 11#
- STATION_EXAMPLE = 13#
- STATION_RECEIVER_EXAMPLE = 14#
- TILE = 7#
- VECTOR = 6#
- WALL = 8#
GameObject Class#
- class game.common.game_object.GameObject(**kwargs)[source]#
Bases:
objectGameObject Class Notes:
This class is widely used throughout the project to represent different types of Objects that are interacted with in the game. If a new class is created and needs to be logged to the JSON files, make sure it inherits from GameObject.
Player Class#
- class game.common.player.Player(code: object | None = None, team_name: str | None = None, actions: list[game.common.enums.ActionType] = [], avatar: Avatar | None = None)[source]#
Bases:
GameObjectPlayer Class Notes:
The Player class is what represents the team that’s competing. The player can contain a list of Actions to execute each turn. The avatar is what’s used to execute actions (e.g., interacting with stations, picking up items, etc.). For more details on the difference between the Player and Avatar classes, refer to the README document.
- property actions: list[game.common.enums.ActionType] | list#
- property error: str | None#
- property file_name: str | None#
- property functional: bool#
- property object_type: ObjectType#
- property team_name: str | None#