I'm new to coding and working on a text based game moving from room to room. The code works in pycharm but according to an instant feedback program I entered it into, it gave some tips on it and I am not exactly sure how how to improve upon it. Here is what it gave me:
- 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) do I need a def main() command?
- Consolidate multiple print commands into one function
- Make condition simpler by using non-complex conditions. With simple operators that don't look for a contain within the string 5.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.")