Moving between rooms debug


Below is the code for the first part of the text game I am having to create for class. Everything works until you toss it in the debugger and start testing the commands.

I don’t really know how to use the debugger one effectivly. So I figured here would be a good choice to ask a question.
S0 an example of something that gives me a error.Wwhen I say GO WEst or make it all CAPS
amoung some other things it gives me error codes.

# The dictionary links a room to other rooms.
# saving for items = {} inventory for next step.
Rooms = {
    'Upper Room1': {'west': 'Upstairs'},
    'Upstairs': {'south': 'The Counter', 'east': 'Upper Room1'},
    'Side Room': {'east': 'The Counter'},
    'The Counter': {'south': 'Backroom', 'west': 'Side Room', 'east': 'Storage Room', 'north': 'Upstairs'},
    'Storage Room': {'west': 'The Counter', 'north': 'Hidden Storage',},
    'Hidden Storage': {'south': 'Storage Room'},
    'Backroom': {'north': 'The Counter', 'east': 'The Villain'},
    'The Villain': {'west': 'Bedroom'}
# Start the player in the first room
currentRoom = 'The Counter'

print('Welcome to the Drink Quest!') # Welcomes player to the game
print("Move commands: go North, go East, go West, go South, exit") # Informs the player of the commands of the game
# loop forever
while True:
    if currentRoom.lower() == 'exit':

    # print current status
    print(' ---------------------------')
    print('You are in ' + currentRoom)

    # get action from user
    print("Where do you want to go? ")
    navigate = input('>')

    navigate = navigate.split()

    # Navigation
    if navigate[0].lower() == 'go':
        if navigate[1].lower() in Rooms[currentRoom]:
            currentRoom = Rooms[currentRoom][navigate[1]]
            print('You can\'t go that way!')
    elif navigate[0].lower() == 'exit':
        currentRoom = 'exit'
        print("Invalid Choice choose a different path!")
print("Thanks for playing Drink Quest!!")


The line

currentRoom = Rooms[currentRoom][navigate[1]]

should be changed to

currentRoom = Rooms[currentRoom][navigate[1].lower()]

Alternatively: Create two variables command and direction to avoid repeated .lower() calls. Then use them as follows:

# Navigation
command = navigate[0].lower()
direction = navigate[1].lower()

if command  == 'go':
    if direction  in Rooms[currentRoom]:
        currentRoom = Rooms[currentRoom][direction]

Answered By – Felix

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published