Question: I am doing the text based game in python. I can move between rooms and see the items in the rooms. When I use the
I am doing the text based game in python. I can move between rooms and see the items in the rooms. When I use the get command, i get the invalid command. I also have no idea if it adds the item to the inventory and removes the item from the rooms dictionary. here is my code so far: # Rooms dictionary with items
rooms
'Barracks': North: 'Officer Quarters', 'East': 'Courtyard', 'South': 'Stables', 'West': 'Arsenal'
'Arsenal': East: 'Barracks', 'South': 'Armory', 'item': 'Sword'
'Armory': North: 'Arsenal', 'items': Armor
'Stables': North: 'Barracks', 'South': 'Kitchen', 'item': 'Bolts'
'Kitchen': North: 'Stables', 'East': 'Great Hall', 'item': 'Liquid Courage'
'Officer Quarters': East: 'Lookout Tower', 'South': 'Barracks', 'item': 'Shield'
'Lookout Tower': East: 'Main Gate', 'South': 'Courtyard', 'West': 'Officer Quarters', 'item': 'Helmet'
'Main Gate': West: 'Lookout Tower', 'item': 'Spear'
'Courtyard': North: 'Lookout Tower', 'South': 'Great Hall', 'West': 'Barracks', 'item': 'Crossbox'
'Great Hall': North: 'Courtyard', 'West': 'Kitchen', 'villian' : 'The Goblin King'
# Player inventory
inventory
def displaystatusroom inventory:
printYou are in the", playerroom
printInventory: inventory
if 'item' in roomsplayerroom:
printYou see a roomsplayerroomitem
print
# List commands
movementlist Move North', 'Move South', 'Move East', 'Move West', 'Get', 'Inventory'
printfPlease use the following commands to move: movementlist
# Player's starting point
playerroom 'Barracks'
# Movement loop
while playerroom 'exit':
displaystatusrooms inventory
#printfYou currently stand in the playerroom
# Get player command
move input
"Make your next move. Beware The Goblin King! North South, East, West or type 'exit' to exit the game, 'move command' for the move commands list, 'get' to pick up an item, or 'inventory' to see your inventory: striplower
# Commands
if move 'exit':
playerroom 'exit'
elif move 'move command':
printfPlease use the following commands: movementlist
elif move in move north', 'move south', 'move east', 'move west':
direction move.splitcapitalize
if direction in roomsplayerroom:
playerroom roomsplayerroomdirection
printfYou swiftly and silently move direction to playerroom
else:
printfYou bang your head on the wall. You can't go direction from the playerroom
elif move 'get':
if 'item' in roomsplayerroom and roomsplayerroomitem:
item roomsplayerroomitempop # Remove the first item from the room
inventory.appenditem
printfYou picked up item
else:
printThere are no items to pick up in this room."
elif move 'inventory':
printYour inventory:"
for item in inventory:
printitem
else:
printInvalid command. Please enter a valid command."
printThank you for playing!"
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
