0

After editing the code, I have been able to see the items in the room now, and all other movements are working properly. However, when I enter into the Gym, I cannot pick up the corresponding item. Instead it prints the cannot find the item statement. Any time I try to fix this, it ends up braking something else.

def clear():
    os.system('cls' if os.name == 'nt' else 'clear')


# dictionary
rooms = {
    'Locker Room': {'South': 'Dressing Room'},  # starting room
    'Dressing Room': {'East': 'Ring', 'North': 'Locker Room', 'Item': 'Rics Robe'},
    'Ring': {'North': 'Gym', 'South': 'Steel Cage', 'West': 'Dressing Room', 'East': 'Office', 'Item': 'Chair'},
    'Gym': {'South': 'Ring', 'East': 'Garage', 'Item': 'RKO Promo'},
    'Garage': {'West': 'Gym', 'Item': 'Blueprint'},
    'Steel Cage': {'North': 'Ring', 'East': 'Green Room', 'Item': 'Mr.Socko'},
    'Green Room': {'West': 'Steel Cage', 'Item': 'StoneCold Beer'},
    'Office': {'West': 'Ring', 'Boss': 'Vance McMan'}  # villain


}

# list of vowels
vowels = ['a', 'e', 'i', 'o', 'u']

# directions
direction = ['north', 'south', 'east', 'west']

# track inventory
inventory = []

# track the current room
current_room = 'Locker Room'

Item = rooms[current_room].get('Item')
# results of the players previous move
msg = ''

clear()
prompt()

# gameplay loop until exit
while True:
    clear()
    # display info to player
    print(f"You are in the {current_room}\nInventory : {inventory}\n{' - ' * 27}")

    # display the msg
    print(msg)

    # indicate items
    if 'Item' in rooms[current_room].keys():
        nearby_item = rooms[current_room]["Item"]

        if nearby_item not in inventory:

            if nearby_item[-1] == 's':
                print(f'You see {nearby_item}')

            elif nearby_item[0] in vowels:
                print(f'You see an {nearby_item}')

            else:
                print(f'You see a {nearby_item}')

    # boss encounter
    if 'Boss' in rooms[current_room].keys():
        # lose
        if len(inventory) < 6:
            print(f"Game over! You lost a fight with {rooms[current_room]['Boss']}")

        # win
        else:
            print(f"You beat {rooms[current_room]['Boss']}")

    # accept the player move as input
    move = input('Which direction will you go?\n')

    # split the move into words
    next_move = move.split(' ')

    # the first word is an action
    action = next_move[0].title()

    if len(next_move) > 1:
        Item = next_move[1:]
        direction = next_move[1].title()

        Item = ' '.join(Item).title()

    # move in between rooms
    if action == 'Go':
        try:
            current_room = rooms[current_room][direction]
            msg = f'You go {direction}.'

        except:
            msg = f'You cannot go that way.'

    # picking up items
    elif action == "Get":
        if Item == rooms[current_room]['Item']:

            if Item not in inventory:
                inventory.append(rooms[current_room]['Item'])
                msg = f"{Item} retrieved!"

            else:
                msg = f"You already have the {Item} in your inventory."

        else:
            msg = f"Cannot find the {Item}"

    # exit the game
    if move == 'Exit':
        current_room = 'exit'
        print('Game over. Thank you for playing!')
        break

    # any other commands invalid
    else:
        msg = f"Invalid command"
  • 1
    Hint: what is the result of `'rko promo'.title()` ? – slothrop Aug 13 '23 at 20:27
  • I am still stumped, sorry I am completely new to this. Any chance for a second hint? – Rashy415635 Aug 13 '23 at 22:51
  • If the user enters "get rko promo" (or "Get RKO Promo" or the same thing in any combination of upper and lower case letters), then `Item` will be `'Rko Promo'` because of the use of `title()`. But the rooms dictionary has `'RKO Promo'`. So `if Item == rooms[current_room]['Item']` will always be false. – slothrop Aug 14 '23 at 08:04

0 Answers0