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"