mardi 8 décembre 2020

Moving room to room text adventure

in the code below I am trying to move room to room. My professor told me to use a while loop, but I am having trouble getting it started. ANy pointers would be helpful. Thank you!

I do not get any errors with this loop, but I do get stuck in a room.

rooms = {
        'Living Room': {'south': 'Master Bedroom'},#modified to fi my theme (video said I could)
        'Master Bedroom': {'north': 'Living Room', 'east': 'Master Bath'},
        'Master Bath': {'west': 'Master Bedroom'}
    }

user_move = input('Which way are you running? ').lower().strip()

user_location = rooms['Living Room']
compass = 'north', 'south','east','west'
for current, direction in rooms.items():
    for nextrm in user_location:

        if user_move in user_location:
            print('You are in the', user_location[nextrm])
            user_move = input('Which way are you running? ').lower().strip()
            user_location = user_move[nextrm] 
            
`I think the problem in my code is the line above. I cannot figure out how to populate user_location with the next room`

        elif user_move == 'exit':
            print('Good Bye')
            break

        elif user_move in compass:
            print('Can''t move that way')
            user_move = input('Which way are you running? ').lower().strip()

        else:
            print('Invalid')
            user_move = input('Which way are you running? ').lower().strip()

Aucun commentaire:

Enregistrer un commentaire