Game¶
The Game module contains the Game, which is the core of any Turnable application.
- class turnable.game.Game(name: str, player: turnable.chars.PlayableEntity, map_: turnable.map.Map, inputstream: turnable.streams.BaseInputStream, outputstream: Optional[turnable.streams.BaseOutputStream], endgame_condition: Callable = <function endgame_player_dead>)¶
Main game object. It handles game loops and basic logic. It’s also in charge of sending data to the outputstream.
At the moment Turnable only supports single user play. You must pass an instance of a
PlayableEntityas the player param.map_ receives an instance of :py:class:turnable.map.Map:
name is not used meaningfully yet.
- add_hook(type_: turnable.hooks.HookType, callback: Callable[[turnable.game.Game], Any])¶
Adds a hook callback. The callback must accept a single
Gameargument.
- endgame(state)¶
Ends game.
- level_loop()¶
Handles the level loop. While the player is alive and the level is not finished it will keep calling
play_turn().
- main_loop()¶
Handles the main loop of the game. While the game is not done it will keep advancing levels and calling
level_loop().
- play_turns()¶
Handles game turn. Player moves first, then enemies (if any). Game state gets updated accordingly.
- start()¶
Start game.
- trigger_hook(type_: turnable.hooks.HookType)¶
Executes hook passing a refence to the
Gameobject.
- update_state()¶
Automatically updates game state.
- exception turnable.game.InvalidPlayerException¶