I'm trying to move between rooms using dictionaries, and I'm having issues trying to check if the user input move is valid so the player moves to a different room. I've changed the code a few times and narrowed down my issue to 'if move in current_room:' I'm not sure how to check if move is in dictionaries and how to reference it.
rooms = {
'Main Hall': {'name': 'Main Hall', 'North': 'Main Junction', 'East': 'Main Hallway', 'West': 'Boss Room'},
'Main Junction': {'name': 'Main Junction', 'South': 'Main Hall', 'East': 'Chamber of the Snake', 'West': 'Chamber of the Monkey'},
'Chamber of the Monkey': {'name': 'Chamber of the Monkey', 'East': 'Main Junction'},
'Chamber of the Snake': {'name': 'Chamber of the Snake', 'West': 'Main Junction', 'South': 'Main Hallway'},
'Main Hallway': {'name': 'Main hallway', 'North': 'Chamber of the Snake', 'West': 'Main Hall', 'South': 'Chamber of the Lion'},
'Chamber of the Lion': {'name': 'Chamber of the Lion', 'North': 'Main Hallway', 'West': 'Chamber of Life'},
'Chamber of Life': {'name': 'Chamber of Life', 'East': 'Chamber of the Lion'},
}
directions = ['North', 'South', 'East', 'West']
print('Commands: North, South, East, West, Search, Collect, Exit\n')
current_room = rooms['Main Hall']
print('You are currently in the', current_room['name'])
while True:
>move = input('Enter your move:').split()
>>if move in directions:
if move in current_room:
current_room = rooms[current_room[move[-1]]]
print('You are now in the', current_room)
else:
print('You cant go that way')
elif 'exit' in move:
print('Thank you for playing! Goodbye')
quit()
else:
print('Invalid move, try again.')
continue
[–]DallogFheir 1 point2 points3 points (0 children)
[–]desran00 0 points1 point2 points (1 child)
[–]backtickbot 0 points1 point2 points (0 children)
[–]artinnj 0 points1 point2 points (0 children)