-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadventure_game.py
121 lines (95 loc) · 3.77 KB
/
adventure_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
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
# Adventure_Game_The_Warlock's_Curse.py
# Written by Katherine Piette & Nathan Reckley
# Some assistance and guidance was provided by Scott Piette in regards
# to the development of the data retrieval process.
import csv
def intro():
print("-----------------------------------------------------------")
print("WELCOME to THE WARLOCK'S CURSE!!!!")
print("-----------------------------------------------------------")
print("This is a text based adventure game! Full of fun,")
print("adventure, and magic... three very important things.")
print("You will be playing as Sam, a lively youth with a taste ")
print("for adventure. It is your job to get Sam out of this adventure")
print("safely. To make sure this program runs correctly, please make")
print("sure the program and the file KatieAdventureList.csv are saved on")
print("your computer's desktop.")
print()
command = input("Would you like the game's instructions? (y/n) ")
if command[0] == 'y' or command[0] == 'Y':
instructions()
def instructions():
print()
print("In this magical world you move between rooms. In each room you can")
print("'look' and 'go' but you need to specify the direction you want to 'look'")
print("or 'go'. Valid directions are 'north', 'south', 'east', 'west'. For")
print("example 'look north' will tell you what you see looking north and 'go")
print("north' will take you there.")
print("Alright, let the adventure begin!")
def prompt():
x = input("What do you want to do? ")
x.lower()
return x
def search(name, rooms):
return[element for element in rooms if element['room_name'] == name]
def navigate(next_room):
print()
print(next_room['description'])
print()
while True:
x = prompt()
x.lower()
j = x.split()
print()
if j[0] == 'look':
if j[1] == 'north':
print(next_room['look_north'])
print()
elif j[1] == 'south':
print(next_room['look_south'])
print()
elif j[1] == 'west':
print(next_room['look_west'])
print()
elif j[1] == 'east':
print(next_room['look_east'])
print()
else:
print("Please type a real direction.")
goto_room = 'bad'
elif j[0] == 'go':
if j[1] == 'north':
goto_room = next_room['go_north']
elif j[1] == 'south':
goto_room = next_room['go_south']
elif j[1] == 'west':
goto_room = next_room['go_west']
elif j[1] == 'east':
goto_room = next_room['go_east']
else:
goto_room = 'bad'
if goto_room == 'bad':
print("Please type a real direction")
print()
else:
if goto_room != 'None':
return goto_room
else:
print("You can't go that way")
else:
print("I don't understand your command, commands are look and go")
def main():
room_list = []
intro()
# Imports KatieAdventureList.csv and saves it as a dictionary.
room_list = [row for row in csv.DictReader
(open("../Desktop/KatieAdventureList.csv"))]
next_room = 'start' # This is the first room the game starts in.
while next_room != 'exit' and next_room != 'victory' :
room = search(next_room, room_list)
next_room = navigate(room[0]) # Room 0 in the csv file is the 'start'room
if next_room == 'exit':
print("YOU HAVE LOST")
if next_room == 'victory':
print("YOU HAVE WON! CONGRADULATIONS")
main()