Question: in my python text based game, the get commnad does not function and returns and invalid command. Here is the code: # Rooms dictionary with
in my python text based game, the get commnad does not function and returns and invalid command. Here is the code: # 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': 'Crossbow'
'Great Hall': North: 'Courtyard', 'West': 'Kitchen', 'villain': 'The Goblin King'
# Player inventory
inventory
def displaystatusplayerroom, inventory:
printYou are in the", playerroom
printInventory: inventory
if 'item' in roomsplayerroom:
printYou see a roomsplayerroomitem
print
# List commands
commandlist Move North', 'Move South', 'Move East', 'Move West', 'Get', 'Inventory'
printPlease use the following commands:", commandlist
# Player's starting point
playerroom 'Barracks'
# Movement loop
while playerroom 'exit':
displaystatusplayerroom, inventory
# Get player command
move inputMake your next move. Beware The Goblin King! North South, East, West, 'exit' to exit the game, 'commands' for commands, 'get' to pick up an item, or 'inventory' to see inventory: striplower
# Commands
if move 'exit':
playerroom 'exit'
elif move 'command':
printPlease use the following commands:", commandlist
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 can't go direction from the playerroom
elif move 'get':
if 'item' in roomsplayerroom and roomsplayerroomitem:
items roomsplayerroompopitem # Remove the item from the room
inventory.appenditems # Add the item to the inventory
printfYou picked up items
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!"You are in the officer quarters
Inventory:
You see a shield
Make your next move. Beware The Goblin King! North South, East, West, 'exit' to exit the game, 'commands' for commands, 'get' to pick up an item, or 'inventory' to see inventory: get shield Invalid command. Please enter a valid command.
You are in the officer quarters
Inventory:
You see a Shield
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
