-
Notifications
You must be signed in to change notification settings - Fork 0
/
cave_game.py
executable file
·35 lines (27 loc) · 944 Bytes
/
cave_game.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
import shelve
locations = shelve.open("locations")
vocabulary = shelve.open("vocabulary")
loc = "1"
while True:
availableExits = ", ".join(locations[loc]["exits"].keys())
print(locations[loc]["desc"])
if loc == "0":
break
else:
allExits = locations[loc]["exits"].copy()
allExits.update(locations[loc]["namedExits"])
direction = input("Available exits are " + availableExits).upper()
print()
# Parse the user input, using our vocabulary dictionary if necessary
if len(direction) > 1: # more than 1 letter, so check vocab
words = direction.split()
for word in words:
if word in vocabulary: # does it contain a word we know?
direction = vocabulary[word]
break
if direction in allExits:
loc = allExits[direction]
else:
print("You cannot go in that direction")
locations.close()
vocabulary.close()