dork package

Submodules

dork.cli module

Basic CLI Dork.

dork.cli.main(*args)[source]

Main CLI runner for Dork

dork.repl module

This is the REPL which parses commands and passes them to a Game object.

dork.repl.repl()[source]

read evaluate print loop

Depending on the user’s input prints an action, if input = .rq, quits game

Parameters:output (str) – If output is equal to new game, a new game is created
Returns:returns a new game if equal to a new game, quit when .rq
Return type:output (str)

dork.types module

Base types for the Dork game

class dork.types.Adjacent[source]

Bases: dork.types.Grandparent

adjacency object for rooms

class dork.types.Attackable[source]

Bases: dork.types.Usable

Any object that can be swung will say it was swung

static use(target, name)[source]

Concrete use call for weapons

This method is called by weapons to be attack. Changes state of target player by calling the target’s damage method.

Parameters:
  • target (Player) – passes Player as target to attack
  • name (str) – passed as name of item used
Returns:

returns that player swings weapon at target

Return type:

blurb (str)

class dork.types.Coord[source]

Bases: dork.types.Grandparent

coordinate object for rooms

class dork.types.Game[source]

Bases: object

An instance of Dork

dataaa = {}
verbose = False
class dork.types.Gamebuilder[source]

Bases: object

Build an instance of Game

static build(player_name)[source]

Instantiate a game of Dork from dictionary

Creates an instance of a game from a dictionary of game data

Parameters:
  • data (dict) – Saves the state of the game, player, and items
  • () (game) – Class instance of the game
Returns:

returns the state of the current game game (): returns the updated location, player, and items

Return type:

data (dict)

static load_game(player)[source]

Load the save file associated with player

Loads a saved yaml file based on what the user named their player

Parameters:data (dict) – dictionary of the game state from yaml file
Returns:returns the game state based upon the player’s name
Return type:data (dict)
static save_game(player, data)[source]

Save a game instance to a yaml file if it exists, else create one

Gets data on game state from saved yaml file

Parameters:
  • data (dict) – dictionary of game state
  • player (str) – string of the player’s name
Returns:

returns the dictionary state of the game from yaml player (str): returns the yaml file depending on the player’s name

Return type:

data (dict)

class dork.types.Grandparent[source]

Bases: object

common parent of holder, adjacent, and coord

class dork.types.Holder[source]

Bases: dork.types.Grandparent

A holder/container of items

get_items(caller, data, verbose)[source]

Print all inventory items

Displays all items held by self<player instance> or not. Verbose print displays more information about inventory.

Parameters:
  • out (str) – Inventory
  • verbose (str) – Displays detailed inventory
Returns:

Returns a formated/detailed inventory of player.

Return type:

verbose (str)

class dork.types.Item[source]

Bases: dork.types.Stats

An obtainable/usable item

make(item)[source]

Make an item

Creates the name, description, and type of item in game world

Parameters:
  • name (str) – Generates a random item name
  • description (str) – Generates a random item description
  • type (str) – Generates a definition what type of item is generated
  • usable (str) – Is the item usable or not
Returns:

returns the item name description (str): returns item description type (str): returns the type of item usable (str): returns the usability of item

Return type:

name (str)

set_usable(new_use)[source]

method that sets usable on runtime

This method changes the use behavior, provide usable class as argument

Defines whether an item’s type is usable or not

Parameters:new_use (dict) – checks if item’s type is usable or not
use(target, name)[source]

Strategy pattern call

This method is called by items to be used

Calls its own behavior class called a Usable

Parameters:
  • target (Player) – passes Player as target to be used on
  • name (str) – passed as name of item used
Returns:

returns output for repl from specific usage

Return type:

blurb (str)

class dork.types.NotUsable[source]

Bases: dork.types.Usable

Any object that cannot be used

static use(target, name)[source]

Useless use method

This method is called by filler items to be used

Concrete unusable item class use method

Parameters:
  • target (Player) – passes Player as target to be used on
  • name (str) – passed as name of item used
Returns:

returns “You find no use of this item”

Return type:

blurb (str)

class dork.types.Openable[source]

Bases: dork.types.Usable

Object opening behavior class

static use(target, name)[source]

Opens object targeted if possible

This method is called by key items to be used

Parameters:
  • target (Player) – passes Player as target to be used on
  • name (str) – passed as name of item used
Returns:

returns item has been inserted

Return type:

blurbs (str)

class dork.types.Payable[source]

Bases: dork.types.Usable

Any object that can be used as gold

static use(target, name)[source]

Gold use method This method is called by gold items to be used

Parameters:
  • target (Player) – passes Player as target to be used on
  • name (str) – passed as name of item used
Returns:

returns that you pay with item

Return type:

blurb (str)

class dork.types.Player[source]

Bases: dork.types.Holder

A player or npc in the game

blurbs = {'Calm': {'damage': 'Ouch..Your gonna get it!', 'talk': 'Hello'}, 'Dead': {'damage': 'You monster, stop hitting the dead!', 'talk': 'That person is dead...blab away'}, 'Hostile': {'damage': 'UGH\nYou dealt a death blow', 'talk': "I guess you are ok...I'll calm down"}}
damage()[source]

damage method called by items to inflict damage on players

This method is by items and changes the state of the callee player and returns blurb associated.

Returns:returns blurb from hitting player
Return type:uses (str)
instances = []
move(cardinal, maze)[source]

walk this way

Moves the player from one location to another in the game/maze

Parameters:Out (str) – describes where the player is located
Returns:returns if the player can move to next location
Return type:out (str)
next_state(action)[source]

Method that changes state of Player This method updates players state based on name of method called

Parameters:uses (str) – passed as name action or method used on player
states = {'damage': {'Calm': 'Hostile', 'Dead': 'Dead', 'Hostile': 'Dead'}, 'talk': {'Calm': 'Calm', 'Dead': 'Dead', 'Hostile': 'Calm'}}
talk()[source]

Talk method called by players

This method is called by user to produce a text blurb based on player’s state

Returns:returns applicable blurb
Return type:uses (str)
class dork.types.Room[source]

Bases: dork.types.Adjacent, dork.types.Coord, dork.types.Holder

A room on the worldmap

get_players(hero, data, verbose)[source]

display a printout of the players present in this room

instances = []
class dork.types.Statable[source]

Bases: dork.types.Usable

Any object that can change stats

static use(target, name)[source]

Stat change use method

This method is called by items to be used

Parameters:
  • target (Player) – passes Player as target to be used on
  • name (str) – passed as name of item used
Returns:

states that item took effect

Return type:

blurb (str)

class dork.types.Stats[source]

Bases: object

stats for items

class dork.types.Usable[source]

Bases: abc.ABC

Strategy pattern inspired by refactoring.guru

static use(target, name)[source]

use method defaults to doing nothing

This method is the parent method inherited by
all behavior classes’ uses
Parameters:
  • target (Player) – passes Player as target to
  • used on children (be) –
  • name (str) – passed as name of item used in children

Module contents

Dork game main module