Database Reference
In-Depth Information
def
def describe_item ( item ):
'''Add a 'description' field to the given item'''
result = dict ( item )
iif item [ 'bonus' ]:
description = ' %+d %s ' % ( item [ 'bonus' ], item [ 'name' ])
else
else :
description = item [ 'name' ]
result [ 'description' ] = description
return
return result
def
def get_armor_for_display ( character , item_index ):
'''Given a character document, return an 'armor' value
suitable for display'''
result = dict ( head = [], hands = [], feet = [], body = [])
for
for piece iin character [ 'armor' ]:
item = describe_item ( item_index [ piece [ 'id' ]])
result [ piece [ 'region' ]] . append ( item )
return
return result
In order to actually display the armor, then, we'd use the following code:
>>>
>>> item_index = get_item_index (
...
...
character [ 'inventory' ] + character [ 'location' ][ 'inventory' ])
>>>
>>> armor = get_armor_for_dislay ( character , item_index )
Note in particular that we're building an index not only for the items the character is actually
carrying in inventory, but also for the items that the player might interact with in the room.
Similarly, in order to display the weapon information, we need to build a structure such as the
following:
{
"left" : None ,
"right" : None ,
"both" : { "description" : "+2 quarterstaff" }
}
The helper function is similar to that for get_armor_for_display :
Search WWH ::




Custom Search