[Tutor] python game error

bob gailer bgailer at gmail.com
Sun Oct 14 12:08:47 EDT 2018

More comments:

------------ User Friendly? ------------
I hope this game is not intended for actual use. No one will be able to 
guess the correct actions in a reasonable time. or 3 digit random code 
given 10 tries for any one code. I for one would give up pretty quickly.

The original colossal cave game is an excellent example of a 
user-friendly text adventure game. If you are using a Windows computer 
you can get a version from the Microsoft Store

- gives explicit directions
- keeps responses to a few words most chosen from a limited list or 
names of visible objects.

------------ Python coding "trick"1  ------------
when I build a map I omit the () after the class e.g. 'death' = Death, 
... and apply them to the item retrieved from the map.

use a decorator to build the map dictionary:

# the decorator function:
def add_to_map(cls, map={}): # map is initialized to a {} when function 
is "compiled"
     if cls:
         map[cls.__name__] = cls # add entry to dictionary
         return cls
     else: return map

# apply decorator to class definitions
# this will add 'Death': <class '__main__.Death'>
class Death(Scene):

  # ditto for all other classes based on Scene - then

class Map:
     scenes  = add_to_map() # note when map is called with no arguments 
it returns the dictionary

------------ Python coding "trick" 2 ------------
instead of:         print(Death.quips[randint(0, len(self.quips)-1)])
try:                     print(random.choice(Death.quips)

------------ Python coding "trick" 3 ------------
action = raw_input('>').title() # to make user input agree with class names

------------ Python coding "trick" 4 ------------

More information about the Tutor mailing list