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 display_status(room, inventory):
print("You are in the", player_room)
print("Inventory:", inventory)
if 'item' in rooms[player_room]:
print("You see a", rooms[player_room]['item'])
print("----------------------")
# List commands
movement_list =['Move North', 'Move South', 'Move East', 'Move West', 'Get', 'Inventory']
print(f"Please use the following commands to move: {movement_list}")
# Player's starting point
player_room = 'Barracks'
# Movement loop
while player_room != 'exit':
display_status(rooms, inventory)
#print(f"You currently stand in the {player_room}.")
# 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): ").strip().lower()
# Commands
if move == 'exit':
player_room = 'exit'
elif move == 'move command':
print(f"Please use the following commands: {movement_list}")
elif move in ['move north', 'move south', 'move east', 'move west']:
direction = move.split()[1].capitalize()
if direction in rooms[player_room]:
player_room = rooms[player_room][direction]
print(f"You swiftly and silently move {direction} to {player_room}.")
else:
print(f"You bang your head on the wall. You can't go {direction} from the {player_room}.")
elif move == 'get':
if 'item' in rooms[player_room] and rooms[player_room]['item']:
item = rooms[player_room]['item'].pop(0) # Remove the first item from the room
inventory.append(item)
print(f"You picked up {item}!")
else:
print("There are no items to pick up in this room.")
elif move == 'inventory':
print("Your inventory:")
for item in inventory:
print(item)
else:
print("Invalid command. Please enter a valid command.")
print("Thank you for playing!")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!