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 PlayableEntity as 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 Game argument.

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 Game object.

update_state()

Automatically updates game state.

exception turnable.game.InvalidPlayerException

States

class turnable.state.States(value)

An enumeration.

IN_EMPTY_ROOM = 1
IN_FIGHT = 4
IN_FIGHT_ROOM_BEFORE_FIGHT = 3
IN_FIGHT_ROOM_DONE = 5
IN_REWARD_ROOM = 2
LOST = 6
START = 0
WON = 7