Answer:
# ModuleSixMilestone.py
# By [Your Name]
# A dictionary for the simplified dragon text game
# The dictionary links a room to other rooms.
rooms = {
'Great Hall': {'South': 'Bedroom'},
'Bedroom': {'North': 'Great Hall', 'East': 'Cellar'},
'Cellar': {'West': 'Bedroom'}
}
# Set the player's starting room
current_room = 'Great Hall'
# Output the player's starting room
print('You are in the', current_room)
# Game loop
while True:
# Prompt the player for input
command = input('What would you like to do? ')
# Split the input into a list of words
words = command.split()
# If the player wants to move
if words[0].lower() == 'go':
# Check if the player entered a valid direction for the current room
if words[1].title() in rooms[current_room]:
# Move the player to the new room
current_room = rooms[current_room][words[1].title()]
# Output the new room
print('You are in the', current_room)
else:
# Output an error message for invalid input
print('You cannot go that way.')
# If the player wants to exit the game
elif words[0].lower() == 'exit':
# Set the player's room to exit
current_room = 'exit'
# End the game loop
break
else:
# Output an error message for invalid input
print('Invalid command.')
# Output a farewell message
print('Thank you for playing the game!')
- If the player enters a valid direction, the game will move them to the correct room as specified in the dictionary. For example, if the player is in the Great Hall and enters "South," they will be moved to the Bedroom.
- If the player enters an invalid direction, the game should output an error message to the player, letting them know that their command was not recognized.
- If the player enters "exit," the game should set their current room to "exit," which will end the gameplay loop and exit the game.
Hope this helps!