Hi I am new to coding and creating a text based game in python. I am writing the code to move from room to room. I need some help cleaning up what I have done so far. I ran it through an instant feedback program and got these tips and not exactly sure how to correct it:
- The Great Hall string is a key in main dictionary. Revise code so it is not a key in main dictionary.
- It said it can not classify my code (not sure what that means)
- consolidate multiple print commands into one function
- make condition simpler by using non-complex conditions
- Better practice to use while True: and the break reserved word to stop the loop when you require it to stop
data setup
rooms = {'Great Hall': {'name': 'Great Hall', 'South': 'Bedroom', 'North': 'Dungeon', 'West':
'Library', 'East': 'Kitchen'},
'Bedroom': {'name': 'Bedroom', 'East': 'Cellar', 'North': 'Great Hall'},
'Cellar': {'name': 'Cellar', 'West': 'Bedroom'},
'Library': {'name': 'Library', 'East': 'Great Hall'},
'Kitchen': {'name': 'Kitchen', 'West': 'Great Hall', 'North': 'Dining Room'},
'Dining Room': {'name': 'Dining Room', 'South': 'Kitchen'},
'Dungeon': {'name': 'Dungeon', 'South': 'Great Hall', 'East': 'Gallery'},
'Gallery': {'name': 'Gallery', 'West': 'Dungeon'},
}
directions = ['North', 'South', 'East', 'West']
current_room = rooms['Great Hall']
game loop
while True:
# display current location
print()
print('You are in the {}.'.format(current_room['name']))
# get user input
command = input('\nWhat direction do you want to go? ').strip()
# movement
if command in directions:
if command in current_room:
current_room = rooms[current_room[command]]
else:
# bad movement
print("You can't go that way.")
# Exit game
elif command.lower() in ('q', 'quit'):
break
# bad command
else:
print("I don't understand that command.")