text_game_maker.player package

Submodules

class text_game_maker.player.player.Player(start_tile=None, input_prompt=None)

Bases: text_game_maker.game_objects.living.LivingGameEntity

Base class to hold player related methods & data

__init__(start_tile=None, input_prompt=None)
Parameters:
  • start_tile (text_game_maker.game_objects.tile.Tile) – Starting tile
  • input_prompt (str) – Custom string to prompt player for game input
add_coins(value=1)

Give player some coins

Parameters:value (int) – number of coins to add
buy_item_from(person)

Show player a listing of items this person has and allow them to select one to purchase (if they have enough coins)

Parameters:person (text_game_maker.game_objects.person.Person) – person object
can_see()

Check if the player can see their surroundings in the current game location. Takes the following things into account;

  • Is the current tile dark?
  • Does the player have a light source equipped?
  • Does the light source need fuel, and if so, does it have some?
Returns:True if the player can see their surroundings, False otherwise
Return type:bool
clear_task(task_id)

Clear a specific scheduled task by task ID

Parameters:task_id (int) – task ID of the task to remove
Returns:False if the provided task ID was not found in the pending scheduled tasks list, True otherwise
Return type:bool
clear_tasks()

Clear all pending scheduled tasks (tasks which have been added but whose timers have not expired)

darkness_message()

Return the message to print when the player enters an area which is dark and they do not have a working light source

Returns:message to print when player cannot see surrounding area
Return type:str
death()

Called whenever the player dies

decrement_energy(val=1)

Decrement player energy

Parameters:val (int) – number to decrement player energy by
describe_current_tile()

Returns the full descriptive text for the tile player is currently on, including everything contained in the tile and all adjacent tiles visible to the player

Returns:text description of current game state
Return type:str
describe_current_tile_contents(capitalize=True)

Return a string that describes the game state at the players current, location, including people, objects and scenery on the players current tile, and any adjacent tiles that connect to the players current tile.

Parameters:capitalize (bool) – if True, the first letter of each sentence will be capitalized
Returns:string describing the players current loca
full_class_name = u'text_game_maker.player.player.Player'
get_equipped()

Get player equipped item

Returns:equipped item. None if no item is equipped.
Return type:text_game_maker.game_objects.items.Item
get_special_attrs()

Serialize any attributes that you want to handle specially here. Any attributes present in the dict returned by this function will not be serialized by the main get_attrs method. Intended for subclasses to override

Returns:serializable dict of special attributes
Return type:dict
has_item(item)

Check if an item is in the player’s inventory

Parameters:item (text_game_maker.game_objects.generic.Item) – item to check
Returns:True if item is in the player’s inventory, False otherwise
Return type:bool
increment_energy(val=1)

Increment player energy

Parameters:val (int) – number to increment player energy by
injure(health_points=1)

Injure player by removing a specific number of health points. Player will die if resulting health is less than or equal to 0.

param int health_points: number of health points to remove from player

inventory_space()

Check number of remaining items the players inventory can fit. When players inventory is full, this method will return 0.

Returns:number of remaining items player’s inventory has space for

;rtype: int

on_smell()

Called when player smells themselves

on_taste()

Called when player tastes themselves

previous_tile()

Get the tile that the player was on before the current tile

Returns:previous tile object
Return type:text_game_maker.tile.tile.Tile
read_player_name_and_set()

Helper function to read a name from the user and set as the player’s name

remove_coins(value=1)

Take some coins from player

Parameters:value (int) – number of coins to remove
save_to_file(filename, compression=True)

Serialize entire map and player state and write to a file

Parameters:
  • filename (str) – name of file to write serialized state to
  • compression (bool) – whether to compress string
save_to_string(compression=True)

Serialize entire map and player state and return as a string

Parameters:compression (bool) – whether to compress string
Returns:serialized game state
Return type:str
schedule_task(callback, turns=1)

Add a function that will be invoked after the player has taken some number of moves (any valid input from the player counts as a move)

The function should accept one parameter, and return a bool:

def callback(player, turns):
pass

Callback parameters:

  • player (text_game_maker.player.player.Player): player instance
  • turns (int): number of turns this callback was scheduled for
  • Return value (bool): if True, this task will be scheduled again with the same number of turns
Parameters:
  • callback (str) – function that returns the message to print
  • turns (int) – number of turns to pass before callback will be invoked
Returns:

task ID

Return type:

int

scheduler_tick()

‘tick’ function for task scheduler. Called on each move the player makes (unparseable or otherwise invalid input does not incur a ‘tick’), and executes any tasks scheduled for that move.

sell_item_to(person)

Show player a listing of this person’s shopping list, and allow player to sell something to person if the player has it

Parameters:person (text_game_maker.game_objects.person.Person) – person object
set_alternate_names(tile)
set_name(name)

Set player name

Parameters:name (str) – new player name
set_special_attrs(attrs, version)

Deserialize any attributes that you want to handle specially here. Make sure to delete any specially handled attributes from the return dict so that they are not deserialized by the main set_attrs method

Parameters:
  • attrs (dict) – all serialized attributes for this object
  • version (str) – object model version of serialized attributes
Returns:

all attributes not serialized by this method

Return type:

dict

skip_attrs = ['parser', 'new_game_event']
text_game_maker.player.player.load_from_file(filename, compression=True)

Load a serialized state from a file and create a new player instance

Parameters:
  • filename (str) – name of save file to read
  • compression (bool) – whether data is compressed
Returns:

new Player instance

Return type:

text_game_maker.player.player.Player

text_game_maker.player.player.load_from_string(strdata, compression=True)

Load a serialized state from a string and create a new player instance

Parameters:
  • strdata (str) – string data to load
  • compression (bool) – whether data is compressed
Returns:

new Player instance

Return type:

text_game_maker.player.player.Player