Question: I am doing a text based game in python. I have done the movement but am having a hard time with the 'get' for items
I am doing a text based game in python. I have done the movement but am having a hard time with the 'get' for items located in those rooms. I can make a sperate items dictionary or add it to the rooms. Either way when the pick up it up and add to the inventory, the item needs to be deleted from the dictionary. Here is the code i have so far:
# Rooms dictionary
rooms
'Barracks': North: 'Officer Quarters', 'East': 'Courtyard', 'South': 'Stables', 'West': 'Arsenal'
'Arsenal': East: 'Barracks', 'South': 'Armory'
'Armory': North: 'Arsenal'
'Stables': North: 'Barracks', 'South': 'Kitchen'
'Kitchen': North: 'Stables', 'East': 'Great Hall'
'Officer Quarters': East: 'Lookout Tower', 'South': 'Barracks'
'Lookout Tower': East: 'Main Gate', 'South': 'Courtyard', 'West': 'Officer Quarters'
'Main Gate': West: 'Lookout Tower'
'Courtyard': North: 'Lookout Tower', 'South': 'Great Hall', 'West': 'Barracks'
'Great Hall': North: 'Courtyard', 'West': 'Kitchen'
#List commands
movementlist Move North', 'Move South', 'Move East', 'Move West'
printfPlease use the following commands to move: movementlist
#Players starting point
playerroom 'Barracks'
#Movement loop
while playerroom exit:
printfYou currently stand in the playerroom
#get player coomand
move inputMake your next move. Beware The Goblin King! North South, East, West or type exit to exit the game or move command for the move commands list: striplower
#Commands
if move 'exit':
playerroom exit
elif move 'move command':
printfPlease use the following command to move: movementlist #list move commands if forgotten
elif move in move north', 'move south', 'move east', 'move west':
direction move.splitcapitalize #extracts and capitalizes direction for rooms dict
if direction in roomsplayerroom:
playerroom roomsplayerroomdirection
printfYou swiftly and silently move direction to playerroom #moves you to a room
else:
printfYou bang your head on the wall.You can't go direction from the playerroom #bangs head if you can't go that way
else:
printInvalid command. Please enter a valid command." #invalid command if anything else typed beside commands
printThank you for moving around my fort!" #goodbye
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
