-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathescape_from_stamford_green.py
123 lines (112 loc) · 4.78 KB
/
escape_from_stamford_green.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import textwrap
# This dictionary contains the map of the school.
#
# Each entry in the dictionary is a room or other location. The key is the
# room name ("the_office"), and the value is another dictionary containing
# properties of that room, as follows:
#
# description: the text to be displayed when the player walks into this room.
#
# north, south, east, west: optional entries specifying the name of the room
# that the player arrives at when walking out of this room. If not
# specified, then the player cannot go that way. It is possible to
# arrive back at the same room; see maze1 and maze2!
#
school_map={
"the_office": {
"description": "You are standing outside the school office. You are surrounded by gleaming sofas made of solid gold. Paths lead in all directions.",
"north": "east_gate",
"east": "staff_room",
"west": "corridor",
"south": "hall"
},
"east_gate": {
"description": "You are standing outside the main door to the school. Your escape to the road is blocked by a deep muddy trench from The Great War. Beyond the trench you can see barbed wire across no-man's land. The door to the school is south.",
"south": "the_office"
},
"staff_room": {
"description": "You are in the staff room. There is a strong smell of garlic, socks and chocolate digestives. The only door leads west.",
"west": "the_office"
},
"hall": {
"description": "You are in the Great Viking Hall of Stamford Green. Long oak tables with silver goblets are lie across the room ready for a banquet, and Valkyries soar overhead. A sign on the wall says that the value of the month is 'Pillaging'. The office is north.",
"north": "the_office"
},
"corridor": {
"description": "You are in a corridor leading towards the West Wing. Cones, sirens, flashing lights and a 'DO NOT ENTER' sign suggest that construction is not quite finished. To the west, where the building should be, there is a currently a deep hole in the ground. You cannot see the bottom of the pit. A path east leads back to the office.",
"east": "the_office",
"west": "tunnel"
},
"tunnel": {
"description": "You are in a tunnel at the bottom of a pit, with a dark passage to the north, and a light to the east. Scratched on the wall are the cryptic letters 'AshLEy wiL nvR WIN'.",
"east": "corridor",
"north": "maze1"
},
"maze1": {
"description": "You are in an underground maze of twisting passages, all alike.",
"east": "tunnel",
"west": "maze2",
"north": "maze1",
"south": "maze2"
},
"maze2": {
"description": "You are in an underground maze of twisting passages, all alike. You can feel a warm gentle breeze.",
"east": "maze1",
"west": "maze2",
"north": "maze1",
"south": "escape"
},
"escape": {
"description": "You emerge into daylight at the top field beside a running track. The West Gate is open."
}
}
def look():
'''
Prints the description of the room named by the global variable 'location'.
'''
formatted_description=textwrap.fill(school_map[location]["description"])
print(formatted_description)
def go(direction):
'''
Returns the name of the room in the given direction ('north', 'east', 'south' or 'west')
from the player's current location, or None if the player cannot go that way.
'''
next_location=school_map[location].get(direction)
if next_location == None:
print("You can't go that way.")
return next_location
def help():
print("Escape From Stamford Green!")
print("---------------------------")
print("Instructions:")
print("1. Use 'north', 'east', 'south' or 'west' (or 'n', 'e', 's' or 'w') to move.")
print("2. Type 'look' to see what you can see.")
print("3. Display this message again by typing 'help'.")
# The main part of the program starts here
help()
print()
location="the_office" # Global variable containing the player's current location
look()
while location != "escape":
print()
command=input("> ").lower()
move_to_location=None
if command=="north" or command=='n':
move_to_location=go("north")
elif command=="south" or command=='s':
move_to_location=go("south")
elif command=="east" or command=='e':
move_to_location=go("east")
elif command=="west" or command=='w':
move_to_location=go("west")
elif command=="look":
look()
elif command=="help":
help()
else:
print("I don't understand that! Try 'north', 'south', 'east' or 'west', or 'help'.")
if move_to_location != None:
location=move_to_location
look()
print()
print("Congratulations, you have escaped from Stamford Green!")