escapy.game

Core game engine that manages state and dispatches player actions.

class escapy.game.Game(objects, rooms, inventory, first_room_id)[source]

Bases: GameProtocol

Concrete implementation of GameProtocol.

Holds the mutable game state (rooms, inventory, current room, etc.) and routes player actions to the appropriate object behaviours.

Parameters:
  • objects (dict[str, object]) – Mapping of object IDs to their game-object instances.

  • rooms (dict[str, Room]) – Mapping of room IDs to Room dicts.

  • inventory (list[str]) – Initial list of object IDs the player carries.

  • first_room_id (str) – ID of the room the game starts in.

quit()[source]

End the game and return a GameEndedEvent.

Return type:

list[Event]

interact(object_id)[source]

Interact with an object in the current room.

If the object is present in the current room and satisfies the Interactable protocol, its interact command is executed.

Parameters:

object_id (str) – Identifier of the object to interact with.

Returns:

Events produced by the interaction, or an empty list.

Return type:

list[Event]

interact_inventory(object_id)[source]

Interact with an inventory object, or clear the hand.

  • If object_id is None, the hand item is cleared and a PutOffHandEvent is emitted.

  • If the object is in the inventory and satisfies InventoryInteractable, its interact_inventory command is executed.

Parameters:

object_id (str | None) – Inventory object ID, or None to deselect.

Returns:

Events produced by the interaction, or an empty list.

Return type:

list[Event]

insert_code(object_id, code)[source]

Submit a code to a Decodable object.

Parameters:
  • object_id (str) – Identifier of the object to decode.

  • code (str) – The code string entered by the player.

Returns:

Events produced by the decode action, or an empty list if the object does not implement Decodable.

Return type:

list[Event]