128,978 views
30 votes
30 votes
Can someone tell me why this keeps exiting no matter what move and how I can fix it I honestly hate this class... you guys can have 100 points

#Andrew
#IT140
#ModuleSixMilestone
rooms = {'Manor Entrance': {'South': 'Foyer'},
'Foyer': {'North': 'Manor Entrance', 'West': 'Cellar'},
'Cellar': {'East': 'Foyer'},
'Exit': {'Exit': 'Exit'}} # The dictionary links a room to other rooms.

currentRoom = 'Manor Entrance' # Start the player in the Manor Entrance.


print('Move commands: North, South, East, West, Exit.')
print(' ------------------- ')
print('You are in the Manor Entrance.')
print('Enter your move or exit the game. -> ')
# User input a command to either move to another room or exit the game.
# If the player enters "exit", the game should move them to the "exit" room.
moveCommands = ['North', 'South, ''East', 'West', 'Exit']
command = input()

# Gameplay loop for moving to different rooms.

if currentRoom == rooms['Manor Entrance']:
if command == 'Exit': # If the player enters "exit", the game should move them to the "exit" room.
print('The virus will destroy the world now that you have quit.')
elif command == 'South':
print('You entered the Foyer!')
print(currentRoom[1])
elif command <= 'South':
print('Error. Try again!') # Print an error message if the player enters an invalid direction.

if currentRoom == rooms['Foyer']:
if command == 'Exit': # If the player enters "exit", the game should move them to the "exit" room.
print('The virus will destroy the world now that you have quit.')
elif command == 'West':
print('You entered the Cellar!')
print(currentRoom[2])
elif command <= 'West':
print('Error. Try again!') # Print an error message if the player enters an invalid direction.

if currentRoom == rooms['Cellar']:
print('You win! You have made it to the Cellar and destroyed the Nemesis!')
if command == 'Exit': # If the player enters "exit", the game should move them to the "exit" room.
print('You have eradicated the Virus.')

User Morganfree
by
3.1k points

1 Answer

21 votes
21 votes

Answer:

Something like this?

The only requirement this doesn't exactly hit is moving the user to the "exit" room. It doesn't make use of that entry in the dictionary. However, this is the best way of doing it to avoid multiple "if" statements.

Can someone tell me why this keeps exiting no matter what move and how I can fix it-example-1
User TWhite
by
2.9k points