-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
253 lines (238 loc) · 10.2 KB
/
app.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
from flask import Flask, render_template, request, redirect
import util,random
inv=["HPmk0"]
app=Flask(__name__)
@app.route('/',methods=['POST','GET'])
def root():
global event_number
event_number=0
global ch
ch=100.0 #Sets health to 100
tool=[]
for i in range(3):
tool.append(util.tool().keys()[0])#Makes a list of 3 random tools
return render_template('main.html',story='Dave the superstar sloth has to save the princess in a forest.',instruction='What tool do you pick up?',tools=tool, health=util.get_health(ch),enmHealth=0.0)
#Loads main.html with the variables filled in
@app.route('/inv',methods=['POST','GET'])
def useItem():
global ct
if inv==[]:
inv.append("HPmk0")
if request.method=="POST":
global ch
heal=request.form['itemUsed']#If an item was just used, increases your health
inv.remove(heal)
restore=float(heal[-1])*5
if restore != 0:
ch+=restore+5
if ch>100.0:
ch=100.0#Insures health does not go above 100
global itemUsed
itemUsed=True
return redirect("/fight")
elif request.method=="GET":
ct=util.get(ct.keys()[0])
return render_template('main.html',itemInv=inv,ct=ct.keys()[0],health=ch,att=ct.values()[0][0],spd=ct.values()[0][1],scav=ct.values()[0][2],enmHealth=(act.values()[0][3])*10)
@app.route('/invBoss',methods=['POST','GET'])
def invBoss():
global ct
if inv==[]:
inv.append("HPmk0")
if request.method=="POST":
global ch
heal=request.form['itemUsed']#If an item was just used, increases your health
inv.remove(heal)
restore=float(heal[-1])*5
if restore != 0:
ch+=restore+10
if ch>100.0:
ch=100.0#Insures health does not go above 100
global itemUsed
itemUsed=True
return redirect("/final")
elif request.method=="GET":
ct=util.get(ct.keys()[0])
return render_template('final.html',itemInv=inv,ct=ct.keys()[0],health=ch,att=ct.values()[0][0],spd=ct.values()[0][1],scav=ct.values()[0][2],enmHealth=(act.values()[0][3])*10)
@app.route('/event',methods=['POST','GET'])
def event():
if 'item' in request.form:
inv.append(request.form['item'])
else:
global ct
ct=util.get(request.form['tool'])
if request.method=="POST":
global act
act={}
act=util.newEvent()#Makes a global variable with the current event
ct=util.get(ct.keys()[0])
return render_template('main.html',story=act.keys()[0],instruction='Use your tool or flee',ct=ct.keys()[0],att=ct.values()[0][0],spd=ct.values()[0][1],scav=ct.values()[0][2],opt='yes',health=ch,enmHealth=(act.values()[0][3])*10,photo=act.values()[0][4])
elif request.method=="GET":#util.get() stores the current tool in util.py
return redirect('/')
else:
return 'yo'
@app.route('/newtool', methods=['POST','GET'])
def newtool():
global ct
if request.method=='GET':
return rediect('/')
if event_number>=15:
return redirect('/final')
global dif
dif=0
if request.form['choice']=='Run away':
if act.values()[0][1]>ct.values()[0][1]:#If the user runs away and their speed is lower than the event's, they lose the difference between the event's speed and their speed, times 10
global ch
dif=(act.values()[0][1]-ct.values()[0][1])*10
ch-=dif
elif request.form['choice']=='Use tool':
if act.values()[0][2]==-1:#If the event has no scavenging (is a fight), and the user uses tool, redirects to route "/fight"
global itemUsed
itemUsed=False
return redirect("/fight")
else:#If the event has scavenging (is a store) redirects user to /store route
if act.values()[0][2]<=ct.values()[0][2]:
return redirect('/store')
elif request.form['choice']=='Use potion':
return redirect("/inv")
if ch<=0:
return render_template('lose.html')
tool=[]
for i in range(3):#Selects 3 new random tools
tool.append(util.tool().keys()[0])
tool.append(ct.keys()[0])
ct=util.get(ct.keys()[0])
return render_template('main.html',story='Pick a new tool',tools=tool,ct=ct.keys()[0],att=ct.values()[0][0],spd=ct.values()[0][1],scav=ct.values()[0][2],health=ch,enmHealth=(act.values()[0][3])*10,action="You lost %s health"%dif)
@app.route('/store')
def store():
global ct
try:
ct
except NameError:
return redirect('/')
item=[]
scav=ct.values()[0][2]-act.values()[0][2]#sets the value of scav to the user's scavenging minus the event's scavenging and generates that number of options for potions
item.append('HPmk0')
for i in range(int(scav)+1):
item.append("HPmk"+str(i+1))
ct=util.get(ct.keys()[0])
return render_template('main.html',items=item,ct=ct.keys()[0],att=ct.values()[0][0],spd=ct.values()[0][1],scav=ct.values()[0][2],health=ch,enmHealth=(act.values()[0][3])*10)
@app.route("/fight")
def fight():
global ct
global itemUsed
if itemUsed==False:
if act.values()[0][0]>ct.values()[0][0]:
global ch
dif=(act.values()[0][0]-ct.values()[0][0])*10
ch-=dif
else:
ch-=2.5
enmDif=0
enmDif=(ct.values()[0][0]-act.values()[0][0])+0.5
if enmDif<0.5:
enmDif=0.5
act.values()[0][3]-=enmDif
if ch<=0:
return render_template('lose.html')
elif act.values()[0][3]>0:
ct=util.get(ct.keys()[0])
return render_template('main.html',story=act.keys()[0],instruction='Use your tool or flee',ct=ct.keys()[0],att=ct.values()[0][0],spd=ct.values()[0][1],scav=ct.values()[0][2],opt='yes',health=ch,enmHealth=(act.values()[0][3])*10,photo=act.values()[0][4])
else:
tool=[]
for i in range(3):#Selects 3 new random tools
tool.append(util.tool().keys()[0])
global event_number
event_number+=1
if event_number>=10:
return redirect('/final')
tool.append(ct.keys()[0])
ct=util.get(ct.keys()[0])
return render_template('main.html',story='Pick a new tool',tools=tool,ct=ct.keys()[0],att=ct.values()[0][0],spd=ct.values()[0][1],scav=ct.values()[0][2],health=ch,action="You win!",enmHealth=0.0)
@app.route('/final',methods=['POST','GET'])
def final():
try:
ct
except NameError:
return redirect('/')
act={'Dragon':[3.0,3.0,-1,25.0]}
if request.method=='GET':
global ct
global dh
dh=act.values()[0][3]
return render_template('final.html',health=ch,ct=ct.keys()[0],att=ct.values()[0][0],spd=ct.values()[0][1],scav=ct.values()[0][2],opt='yes',message='yes',enmHealth=dh*10)
elif request.method=='POST':
global ch
global ct
dif=0
if request.form['choice']=='Run away':
if act.values()[0][1]>ct.values()[0][1]:#If the user runs away and their speed is lower than the event's, they lose the difference between the event's speed and their speed, times 10
global ch
dif=(act.values()[0][1]-ct.values()[0][1])*10
ch-=dif
elif request.form['choice']=='Use tool':#If the user uses tool, and the user's attack is lower than the event's, then the user loses the difference between the event's attack and theirs
if act.values()[0][0]>ct.values()[0][0]:
global ch
dif=(act.values()[0][0]-ct.values()[0][0])*10
ch-=dif
else:
enmDif=0
enmDif=(ct.values()[0][0]-act.values()[0][0])+0.5
if enmDif<0.5:
enmDif=0.5
global dh
dh-=enmDif
global ch
ch-=2.5
elif request.form['choice']=="Use potion":
return redirect("/invBoss")
if ch<=0:
return render_template('lose.html')
elif dh<=0:
return render_template("final.html",killDrag='yes')
return render_template('final.html',health=ch,ct=ct.keys()[0],att=ct.values()[0][0],spd=ct.values()[0][1],scav=ct.values()[0][2],message='yes',opt='yes',enmHealth=dh*10,killDrag='no')
@app.route('/finaltest',methods=['POST','GET'])
def finaltest():
ct=util.get('scythe')
ch=100
act={'Dragon':[3.0,3.0,-1,25.0]}
if request.method=='GET':
global ct
global dh
dh=act.values()[0][3]
return render_template('final.html',health=ch,ct=ct.keys()[0],att=ct.values()[0][0],spd=ct.values()[0][1],scav=ct.values()[0][2],opt='yes',message='yes',enmHealth=dh*10)
elif request.method=='POST':
global ch
global ct
dif=0
if request.form['choice']=='Run away':
if act.values()[0][1]>ct.values()[0][1]:#If the user runs away and their speed is lower than the event's, they lose the difference between the event's speed and their speed, times 10
global ch
dif=(act.values()[0][1]-ct.values()[0][1])*10
ch-=dif
elif request.form['choice']=='Use tool':#If the user uses tool, and the user's attack is lower than the event's, then the user loses the difference between the event's attack and theirs
if act.values()[0][0]>ct.values()[0][0]:
global ch
dif=(act.values()[0][0]-ct.values()[0][0])*10
ch-=dif
else:
enmDif=0
enmDif=(ct.values()[0][0]-act.values()[0][0])+0.5
if enmDif<0.5:
enmDif=0.5
global dh
dh-=enmDif
global ch
ch-=2.5
elif request.form['choice']=="Use potion":
return redirect("/invBoss")
if ch<=0:
return render_template('lose.html')
elif dh<=0:
return render_template("final.html",killDrag='yes')
return render_template('final.html',health=ch,ct=ct.keys()[0],att=ct.values()[0][0],spd=ct.values()[0][1],scav=ct.values()[0][2],message='yes',opt='yes',enmHealth=dh*10,killDrag='no')
@app.route('/<url>')
def error(url):
return redirect('/')
if __name__=='__main__':
app.debug=True
app.run(host='0.0.0.0')