I am creating a text-based game for my Python class and I can't get it to display the item when entering the room. I can collect it, and the inventory gets displayed. Just not the item that is in the room. I have put in the code I am using currently, I have tried adjusting it but then I get errors thrown at me.
# Welcome message to the player
def prompt():
print("\t\t\tWelcome to professional wrestling!\n\nVance McMan has locked all wrestlers into an evil "
"contract.\n\n"
"You must collect all 6 items and defeat Vance to free all the wrestlers.\n\n"
f"To move:\t'go {direction}' \n\
\t 'get item name' \n\n")
input('Press any key to continue...')
# clear the screen after the welcome message
def clear():
os.system('cls' if os.name == 'nt' else 'clear')
# dictionary
rooms = {
'Ring': {'North': 'Gym', 'South': 'Steel Cage', 'East': 'Dressing Room', 'West': 'Office', 'Item': 'Chair'},
'Office': {'West': 'Ring', 'Boss': 'Vance McMan'}, # villain
'Gym': {'South': 'Ring', 'East': 'Garage', 'Item': 'RKO Promo Video'},
'Garage': {'West': 'Gym', 'Item': 'Blueprint'},
'Steel Cage': {'North': 'Ring', 'East': 'Greenroom', 'Item': 'Mr.Socko'},
'Green Room': {'West': 'Steel Cage', 'Item': 'StoneCold Beer'},
'Dressing Room': {'East': 'Ring', 'North': 'Locker Room', 'Item': 'Rics Robe'},
'Locker Room': {'South': 'Dressing Room'} # starting room
}
# 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"`