-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpercivalsquest.py
214 lines (202 loc) · 8.12 KB
/
percivalsquest.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
"""
This is the main module for the Percival's Quest RPG.
To start the game, at the command prompt type:
prompt$ python percivalsquest.py
"""
#
# percivalsquest.py
# part of Percival's Quest RPG (duh)
logo = """
()
)(
o======o
||
|| ___ _ _ _ ____ _
|| / _ \___ _ __ ___(_)_ ____ _| ( )__ /___ \_ _ ___ ___| |_
|| / /_)/ _ \ '__/ __| \ \ / / _` | |/ __| // / / | | |/ _ \/ __| __|
|| / ___/ __/ | | (__| |\ V / (_| | |\__ \ / \_/ /| |_| | __/\__ \ |_
|| \/ \___|_| \___|_| \_/ \__,_|_||___/ \___,_\ \__,_|\___||___/\__|
||
|| copyright 2013
||
\/
"""
import pq_rpg as pqr
from pq_utilities import color, choose_from_list, confirm_quit, save, load, \
get_user_input, send_to_console
import shelve, os, textwrap
from colorama import init
init()
def town(rpg):
"""Maintain interactions with the town of North Granby."""
while True:
if rpg.character.dead:
send_to_console("You are dead!")
deadchar(rpg)
break
send_to_console("Where would you like to go?\n"+"Options: Home, " \
"Questhall, Shop, Shrine, or Dungeon [Level#] (max "+ \
str(rpg.maxdungeonlevel)+")")
destinations = ["Dungeon", "Home", "Questhall", "Quest", \
"Shop", "Shrine"] + ["Dungeon "+str(i) for i in \
range(1, rpg.maxdungeonlevel+1)]
goto = choose_from_list("Town> ", destinations, rand=False,
character=rpg.character, allowed=["sheet","help","equip"])
if goto == "Home":
send_to_console("You hit the sack. Once you've annoyed all " \
"the bedbugs with your ineffectual fists, "\
"you lay down and sleep.")
rpg.character.sleep()
save(rpg)
continue
elif goto in ["Questhall", "Quest"]:
send_to_console("You head to the Questhall.")
rpg.questhall()
continue
elif goto == "Shop":
send_to_console("You head into the shop.")
rpg.visit_shop()
continue
elif goto == "Shrine":
send_to_console("You head into the Shrine.")
rpg.visit_shrine()
continue
else:
goto = goto.split()
rpg.destination("start")
if goto[0] == "Dungeon" and len(goto) == 1:
rpg.dungeonlevel = 1
else:
rpg.dungeonlevel = int(goto[1])
send_to_console("You head into the Dungeon, level "+str(rpg.dungeonlevel)+".")
dungeon(rpg)
continue
def dungeon(rpg):
"""Maintain interaction with the dungeon"""
dothis = ""
while dothis != "Leave":
if rpg.character.dead:
return
actions = ["Explore","Leave"] if rpg.whereareyou == "start" \
else ["Explore","Backtrack"]
send_to_console("You're in the dank dark dungeon. What do you want to do?\n"+\
"Options: "+", ".join(actions))
dothis = choose_from_list("Dungeon> ", actions, rand=False,
character=rpg.character, allowed=["sheet","help","equip"])
if dothis == "Leave":
if rpg.whereareyou != "start":
send_to_console("You can't leave from here; you have to backtrack " \
"to the start of the level.")
dothis = ""
continue
else:
rpg.destination("town")
send_to_console("You head back to town.")
continue
elif dothis == "Backtrack":
if rpg.whereareyou == "start":
send_to_console("You're already at the beginning of the level, " \
"Captain Redundant.")
continue
if rpg.check_backtrack():
send_to_console("You successfully find your way back " \
"to the beginning of the level.")
rpg.destination("start")
continue
else:
send_to_console("On your way back, you get lost! You find yourself " \
"in another room of the dungeon...")
rpg.destination("dungeon")
rpg.explore()
continue
elif dothis == "Explore":
rpg.destination("dungeon")
rpg.explore()
if rpg.character.dead:
deadchar(rpg)
else:
continue
def deadchar(rpg):
"""Deal with character death"""
send_to_console("What would you like to do? Options: "\
"Generate (a new character), Load, Quit")
dothis = choose_from_list("Dead> ", ["Generate", "Load", "Quit"],
character=rpg.character, rand=False, allowed=["sheet", "help"])
if dothis == "Quit":
confirm_quit()
deadchar(rpg)
return
if dothis == "Load":
rpg = load(rpg)
if not rpg:
send_to_console("I'm sorry, that didn't work... maybe you deleted " \
"the save file? Anyway...")
deadchar(rpg)
return
else:
send_to_console("Game successfully loaded!")
send_to_console("You begin in the town square.")
rpg.character.tellchar()
rpg.destination("town")
town(rpg)
return
if dothis == "Generate":
rpg = generate(rpg)
send_to_console("You begin in the town square.")
town(rpg)
return
def generate(rpg):
"""Wrapper for making a new character"""
send_to_console("Time to make a new character! It'll be saved under this player name.")
rpg.character.chargen(rpg.player_name)
save(rpg)
msg = "In the town of North Granby, the town militia has recently " \
"discovered that the plague of monsters harrassing the townspeople " \
"originates from a nearby dungeon crammed with nasties. As the " \
"resident adventurer, the Mayor of North Granby (a retired " \
"adventurer by the name of Sir Percival) has recruited you to clear " \
"out the dungeon."
send_to_console(textwrap.fill(msg))
return rpg
def main():
"""Initialize and start the game session"""
send_to_console(logo)
send_to_console(textwrap.fill("Welcome to Percival's Quest! This is a solo random " \
"dungeoncrawl rpg written in python by the ever-resourceful (and " \
"extremely humble) sirpercival."))
player_name = get_user_input("Please enter your player name> ")
msg = "Welcome, "+player_name+"!"
rpg_instance = pqr.PQ_RPG(player_name)
newgame = False
temp_rpg = load(rpg_instance)
if temp_rpg:
msg += " You currently have a game saved. Would you like to load it?"
send_to_console(msg)
loadit = get_user_input("Load (y/n)> ", options = ['Yes','No','Y','N','Load'])
if loadit.lower() in ["y", "yes", "load"]:
rpg_instance = temp_rpg
del temp_rpg
send_to_console("Game successfully loaded.")
rpg_instance.character.tellchar()
else:
newgame = True
else:
send_to_console(msg + " You don't have a character saved...")
newgame = True
if newgame:
rpg_instance = generate(rpg_instance)
msg = "You begin in the town square. \n"
msg += "(Please note that at almost any prompt, you can choose Sheet " \
"to look at your charsheet, Equip to change your equipment, Help " \
"to enter the help library, or Quit to quit.)"
send_to_console(textwrap.fill(msg))
msg = "To the East is your humble abode and warm bed; " \
"to the North, the General Store where various and sundry goods " \
"may be purchased; to the West, the Questhall where the mayor " \
"makes his office; to the Northwest, the local Shrine to the " \
"Unknowable Gods; and to the South lie the gates of the city, " \
"leading out to the Dungeon."
send_to_console(textwrap.fill(msg))
town(rpg_instance)
if __name__ == '__main__':
main()