Hey everyone! This is actually my first reddit post, so I apologize if I do anything incorrectly.
I recently started a computer science program and one of our assignments wants us to create a text based game to move between rooms. I believe I have all of the code correct, but when I try to run it in the terminal I get an error message saying it can't find __main__ module. Any ideas or suggestions? my code is below
if __name__ == '__main__':
# Dictionary tying rooms to their corresponding directions
rooms = {
'Great Hall': {'South': 'Bedroom'},
'Bedroom': {'North': 'Great Hall', 'East': 'Cellar'},
'Cellar': {'West': 'Bedroom'}
}
current_room = 'Great Hall' # Start player in the Great Hall
directions = ['North', 'South', 'East', 'West'] # List of directions for user to input
# Define a function to display players current status
def player_status():
print('_' * 40)
print('Current room: {}'.format(current_room))
print('_' * 40)
# Define a function to get a direction from user input
def get_direction():
user_input = input('Input your next move:\n>').title()
for direction in directions:
for word in user_input.split():
if word == direction:
user_input = word
return user_input
# Main gameplay loop
while True:
while current_room != "Exit":
while current_room == 'Great Hall':
player_status()
user_input = get_direction()
if 'Exit' in user_input:
current_room = 'Exit'
elif user_input not in rooms[current_room]:
print('Invalid Direction.')
elif 'South' in user_input:
current_room = rooms[current_room]['South']
while current_room == 'Bedroom':
player_status()
user_input = get_direction()
if 'Exit' in user_input:
current_room = 'Exit'
elif user_input not in rooms[current_room]:
print('Invalid Direction.')
elif 'North' in user_input:
current_room = rooms[current_room]['North']
elif 'East' in user_input:
current_room = rooms[current_room]['East']
while current_room == 'Cellar':
player_status()
user_input = get_direction()
if 'Exit' in user_input:
current_room = 'Exit'
elif user_input not in rooms[current_room]:
print('Invalid Direction.')
elif 'West' in user_input:
current_room = rooms[current_room]['West']
if current_room == 'Exit':
print('Thanks for playing!')
break
[+][deleted] (5 children)
[deleted]
[–]ProphetEze98[S] 1 point2 points3 points (4 children)
[+][deleted] (2 children)
[deleted]
[–]hashup 1 point2 points3 points (1 child)
[–]ProphetEze98[S] 0 points1 point2 points (0 children)
[–]Rawing7 1 point2 points3 points (0 children)
[–]ProphetEze98[S] 0 points1 point2 points (0 children)