Basic Sample Code

#Initialise
#set up dictionaries
MAP = {'foyer_forward':'back door',
       'foyer_right':'lounge',
        'foyer_backward':'front door',
       'foyer_left':'bedroom',
        'bedroom_right':'foyer',      
        'front door_forward':'foyer'}
 
DESC = {'foyer':'You are in the foyer. It is dark and scary. You want to get out! ',
         'back door':'Congratulations, you have escaped via the back door! ',
         'bedroom':'You are in the bedroom. It has been redecorated.',
         'lounge':'You are in the loungeroom. Carpet covers broken boards. You fall through.',
         'front door':'The front door is locked!'}
 
#set up list of items that end the game
FINISH = ['back door','lounge','quit' ]
 
#starting location
room = 'foyer'
 
#Start of game code
name = input('What is your name? ')
print ('Hello',name)
 
#loops continuously until a break. Note capital letter in boolean value True
while True:
    print (DESC[room])
    if room in FINISH:
        break
    direction = input( 'Enter a direction? Choose from forward, backward, left, right or quit ')
    if direction in FINISH:
        break
    key = room + '_' + direction
    if key in MAP:
        room = MAP[key]
    else :
        print ('You can\'t go ' +direction+'. ' )
print ('Game over!')