escapy.protocols
Protocol (structural typing) interfaces for escapy.
This subpackage defines the abstract contracts that the game engine,
game objects, and UI implementations must satisfy. Using
typing.Protocol allows duck-typed interoperability without
forcing concrete inheritance.
Submodules
escapy.protocols.game
Game-engine protocol and the Command type alias.
- class escapy.protocols.game.GameProtocol(*args, **kwargs)[source]
Bases:
ProtocolStructural interface that every game-engine implementation must satisfy.
- rooms
Mapping of room IDs to
Roomdicts.- Type:
- current_room_id
ID of the room currently displayed.
- Type:
- is_finished
Trueafter the game has ended.- Type:
- in_hand_object_id
ID of the object currently held, or
None.- Type:
str | None
- current_room_id: str
- is_finished: bool
- interact(object_id)[source]
Interact with an object in the current room.
- interact_inventory(object_id)[source]
Interact with an inventory object or clear the hand.
escapy.protocols.objects
Protocol definitions for game-object capabilities.
Each protocol represents a single capability (interacting, being placed, being unlocked, etc.) and may be composed via multiple inheritance.
- class escapy.protocols.objects.Interactable(*args, **kwargs)[source]
Bases:
ProtocolAn object that can be interacted with when clicked in a room.
- interact
Command executed on interaction.
- Type:
escapy.protocols.game.Command
- interact: Command
- class escapy.protocols.objects.InventoryInteractable(*args, **kwargs)[source]
Bases:
ProtocolAn object that can be interacted with from the inventory panel.
- interact_inventory
Command executed on inventory interaction.
- Type:
escapy.protocols.game.Command
- interact_inventory: Command
- class escapy.protocols.objects.Placeable(*args, **kwargs)[source]
Bases:
ProtocolAn object that occupies visual space in the game area.
Dimensions are expressed as normalised fractions of the game area (same coordinate system as
Position).- width
Normalised width.
- Type:
- height
Normalised height.
- Type:
- width: float
- height: float
- class escapy.protocols.objects.Unlockable(*args, **kwargs)[source]
Bases:
ProtocolAn object that has a locked/unlocked state.
- state
Current lock state.
- Type:
Literal[‘locked’, ‘unlocked’]
- on_unlock
Command to execute when unlocked.
- Type:
escapy.protocols.game.Command
- state: Literal['locked', 'unlocked'] = 'locked'
- on_unlock: Command
- unlock()[source]
Transition the object to the unlocked state and return
on_unlock.- Return type:
Command
escapy.protocols.ui
Protocol definition for the game UI layer.
- class escapy.protocols.ui.GameUiProtocol(*args, **kwargs)[source]
Bases:
ProtocolStructural interface that every UI backend must implement.
The game loop calls these methods in order:
ui.init(game) while ui.is_running: ui.tick() events = ui.input() ui.handle(events) ui.render() ui.quit()
- is_running
Truewhile the UI is active.- Type:
- init(game)[source]
Initialise the UI with the given game instance.
- Parameters:
game (GameProtocol)
- Return type:
None
- tick()[source]
Regulate the frame rate / perform per-frame bookkeeping.
- Return type:
None
- handle(events)[source]
React to game events (e.g. display messages, switch states).
- render()[source]
Draw the current frame.
- Return type:
None
- quit()[source]
Tear down the UI and release resources.
- Return type:
None
- is_running: bool