-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.py
52 lines (38 loc) · 1.31 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from locations.entrance import entrance
from locations.hallway import hallway
from locations.hall import hall
welcome_message = """Welcome to CODE World Campus!
You can navigate with directions such as 'east'.
You can look around with 'look'.
You can exit the game with 'exit'.
~~~~~~~~~~~~~~~~~~~~~
"""
locations = {
"entrance": entrance,
"hallway1": hallway,
"hall": hall,
}
current_location = locations["entrance"]
print(welcome_message)
print(current_location["look"]["output"]())
def output_and_change_location(output, next_location_id):
global current_location
print(output)
if next_location_id:
current_location = locations[next_location_id]
print(current_location["look"]["output"]())
while True:
user_input = input("> ")
if user_input == "exit":
print("Thanks for playing!")
break
elif user_input in current_location:
output = current_location[user_input]["output"]()
next_location_id = current_location[user_input]["next_location_id"]
output_and_change_location(output, next_location_id)
elif "fallback" in current_location:
output = current_location["fallback"]["output"](user_input)
next_location_id = current_location["fallback"]["next_location_id"]
output_and_change_location(output, next_location_id)
else:
print("Please enter a valid command.")