-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhero_rpg.py
487 lines (407 loc) · 17.8 KB
/
hero_rpg.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
from random import randint
class Character:
def __init__(self, name, health, power):
self.name = name
self.health = health
self.power = power
self.alive = True
self.armor = 0
self.evade = 0
self.inventory = {}
def attack(self, enemy):
if enemy.evade == 0:
enemy.health -= max(0, self.power - enemy.armor)
print(f"{self.name} does {self.power} damage to the {enemy.name}. \n")
elif enemy.evade == 2:
r = randint(1,10)
if r == 1:
print(f"The {self.name}'s attack missed the {enemy.name}!")
else:
enemy.health -= max(0, self.power - enemy.armor)
print(f"{self.name} does {self.power} damage to the {enemy.name}. \n")
elif enemy.evade == 4:
r = randint(1, 20)
if r < 4:
print(f"The {self.name}'s attack missed the {enemy.name}!")
else:
enemy.health -= max(0, self.power - enemy.armor)
print(f"{self.name} does {self.power} damage to the {enemy.name}. \n")
elif enemy.evade == 6:
r = randint(1,5)
if r == 1:
print(f"The {self.name}'s attack missed the {enemy.name}!")
else:
enemy.health -= max(0, self.power - enemy.armor)
print(f"{self.name} does {self.power} damage to the {enemy.name}. \n")
elif enemy.evade == 8:
r = randint(1,4)
if r == 1:
print(f"The {self.name}'s attack missed the {enemy.name}!")
else:
enemy.health -= max(0, self.power - enemy.armor)
print(f"{self.name} does {self.power} damage to the {enemy.name}. \n")
# def alive(self):
# if self.health > 0:
# return True
# else:
# return False
def print_status(self):
if self.alive:
print(f"{self.name} has {self.health} health, {self.power} power, and {self.armor} armor.")
else:
print(f"{self.name} has died.")
class Hero(Character):
def __init__(self, name, health, power):
super(Hero,self).__init__(name, health, power)
self.currency = 100
self.inventory = {}
def attack(self, enemy):
if not isinstance(enemy, Shadow):
crit = randint(1,5)
if crit == 1:
enemy.health -= (self.power * 2)
print("You've landed a critical hit!")
print(f"{self.name} does {self.power * 2} damage to the {enemy.name}. \n")
self.power = 5
else:
enemy.health -= max(0, self.power - enemy.armor)
print(f"{self.name} does {self.power} damage to the {enemy.name}. \n")
else:
enemy.noDamage(self)
class Shadow(Character):
def __init__(self, name, health, power):
super(Shadow,self).__init__(name, health, power)
self.bounty = 7
def noDamage(self, enemy):
chance = randint(1,10)
if chance == 1:
self.health -= enemy.power
print(f"{enemy.name} does {enemy.power} damage to the {self.name}")
else:
print(f"{enemy.name} does no damage to the {self.name}!")
class Goblin(Character):
def __init__(self, name, health, power):
super(Goblin,self).__init__(name, health, power)
self.bounty = 5
class Medic(Character):
def __init__(self, name, health, power):
super(Medic,self).__init__(name, health, power)
self.bounty = 4
def regenerate(self):
r = randint(1,5)
if r == 1:
self.health += 2
print(f"The {self.name} has regenerated 2 health!")
class Zombie(Character):
def __init__(self, name, health, power):
super(Zombie,self).__init__(name, health, power)
self.bounty = 10
self.inventory = {}
def alive(self):
if self.inventory.get('Zombicide', 0) > 0:
return False
else:
return True
class Theif(Character):
def __init__(self, name, health, power):
super(Theif,self).__init__(name, health, power)
self.bounty = 5
def attack(self, enemy):
chance = randint(1,5)
if chance == 1:
enemy.currency -= 1
self.bounty += 1
print(f"The {self.name} has stolen a coin from {enemy.name}!")
else:
enemy.health -= max(0, self.power - enemy.armor)
print(f"{self.name} does {self.power} damage to the {enemy.name}. \n")
class FinalBoss(Character):
def __init__(self, name, health, power):
super(FinalBoss,self).__init__(name, health, power)
self.bounty = 100
def attack(self, enemy):
enemy.health -= 0
print(f"The {self.name} just wants a burger.")
def mainMenu():
print(f"""
\n
-----------------------
What do you want to do?
1. Go to store
2. Look for an enemy
3. Fight Final Boss
4. End game
-----------------------
""")
def shopMenu(hero):
print(f"""
\n
-----------------------
What would you like to purchase?
1. Super Tonic - 15 coins
2. Armor - 20 coins
3. Evade - 25 coins
4. Zombicide - 50 coins
5. Burger - 1 coin
6. Leave
You currently have {hero.currency} coins.
-----------------------
""")
def fight_menu(enemy):
print(f"""
\n
-----------------------
What do you want to do?
1. fight {enemy.name}
2. use SuperTonic
3. use Zombicide
4. do nothing
5. flee
-----------------------
""")
def finalBossMenu(enemy):
print(f"""
\n
-----------------------
What do you want to do?
1. fight {enemy.name}
2. do nothing
3. flee
4. use Burger
-----------------------
""")
def goToStore(hero):
print(f"Welcome to H-E-B.")
while True:
shopMenu(hero)
selection = input()
if selection == '1': # SuperTonic
if hero.currency >= 15:
print("Nice!")
hero.currency -= 15
hero.inventory["SuperTonic"] = hero.inventory.get("SuperTonic", 0) + 1
else:
print(f"You do not have enough coins!")
elif selection == '2': # Armor
if hero.currency >= 20:
hero.currency -= 20
hero.armor += 2
print(f"Good for you! Your armor is now {hero.armor}")
else:
print(f"You do not have enough coins!")
elif selection == '3': # Evade
if hero.currency >= 25:
if hero.evade == 8:
print("You cannot purchase any more Evade!")
else:
hero.currency -= 25
hero.evade += 2
print(f"Neato! Your Evade is now {hero.evade}")
else:
print(f"You do not have enough coins!")
elif selection == '4': # Zombicide
if hero.currency >= 50:
hero.currency -= 50
hero.inventory["Zombicide"] = hero.inventory.get("Zombicide", 0) + 1
else:
print(f"You do not have enough coins!")
elif selection == '5': # Burger
if hero.currency >= 1:
hero.currency -= 1
hero.inventory["Burger"] = hero.inventory.get("Burger", 0) + 1
print(f"Hero has purchased a burger... for some reason")
else:
print(f"You do not have enough coins!")
elif selection == '6':
break
else:
print(f"Invalid input {selection}")
keepShopping = input("Do you want to keep shopping? y/n ")
if keepShopping == 'n':
break
elif keepShopping == 'y':
pass
else:
print(f"Invalid input {keepShopping}")
def combat(enemy, hero):
print(f"You've encountered a {enemy.name}.")
while enemy.alive and hero.alive:
fight_menu(enemy)
raw_input = input()
if raw_input == '1': # hero attacks and then the enemy attacks back
hero.attack(enemy)
if not isinstance(enemy, Zombie) and enemy.health <= 0:
enemy.alive = False
if isinstance(enemy, Medic):
enemy.regenerate()
hero.print_status()
enemy.print_status()
print("")
if enemy.alive:
enemy.attack(hero)
if hero.health <= 0:
hero.alive = False
enemy.print_status()
hero.print_status()
else:
hero.currency += enemy.bounty
print(f"You found {enemy.bounty} coins!")
print(f"You now have {hero.currency} coins.")
elif raw_input == '2': # hero uses a super tonic item
if hero.inventory.get('SuperTonic', 0) > 0:
hero.health += 10
hero.inventory["SuperTonic"] -= 1
print(f"Hero used SuperTonic! You now have {hero.health} health!")
# if enemy.alive():
enemy.attack(hero)
if hero.health <= 0:
hero.alive = False
enemy.print_status()
hero.print_status()
else:
print("You do not have a SuperTonic!")
elif raw_input == '3': # hero uses zombicide item
if hero.inventory.get('Zombicide', 0) > 0:
if isinstance(enemy, Zombie):
enemy.inventory["Zombicide"] = enemy.inventory.get("Zombicide", 0) + 1
hero.inventory.get("Zombicide", 0) - 1
hero.currency += enemy.bounty
enemy.alive = False
print(f"Hero used Zombicide to kill the Zombie!")
print(f"You found {enemy.bounty} coins!")
print(f"You now have {hero.currency} coins.")
else:
print("You cannot use Zombicide on this enemy!")
else:
print("You do not have a Zombicide!")
elif raw_input == '4': # hero does nothing but enemy attacks anyways
# if enemy.alive():
enemy.attack(hero)
if hero.health <= 0:
hero.alive = False
enemy.print_status()
hero.print_status()
elif raw_input == '5': # hero attempts to escape
q = randint(1,5)
if q == 1:
print(f"{hero.name} escaped, but barely!")
break
else:
print(f"{hero.name} failed to escape!")
if hero.health <= 0:
hero.alive = False
enemy.attack(hero)
enemy.print_status()
hero.print_status()
else:
print(f"Invalid input {raw_input}")
def finalBoss(enemy, hero):
print(f"You've encountered the {enemy.name}!")
while enemy.alive and hero.alive:
finalBossMenu(enemy)
raw_input = input()
if raw_input == '1': # hero attacks and then the enemy attacks back
hero.attack(enemy)
if not isinstance(enemy, Zombie) and enemy.health <= 0:
enemy.alive = False
if isinstance(enemy, Medic):
enemy.regenerate()
hero.print_status()
enemy.print_status()
print("")
if enemy.alive:
enemy.attack(hero)
if hero.health <= 0:
hero.alive = False
enemy.print_status()
hero.print_status()
else:
hero.currency += enemy.bounty
print(f"You found {enemy.bounty} coins!")
print(f"You now have {hero.currency} coins.")
elif raw_input == '2':
enemy.attack(hero)
if hero.health <= 0:
hero.alive = False
enemy.print_status()
hero.print_status()
elif raw_input == '3':
q = randint(1,5)
if q == 1:
print(f"{hero.name} escaped, but barely!")
break
else:
print(f"{hero.name} failed to escape!")
enemy.attack(hero)
enemy.print_status()
hero.print_status()
elif raw_input == '4':
if hero.inventory.get('Burger', 0) > 0:
enemy.inventory["Burger"] = enemy.inventory.get("Burger", 0) + 1
hero.inventory.get("Burger", 0) - 1
print(f"Hero has given the final boss a Burger! He is no longer hangry and the players are free from this never ending hellscape!!!")
print("""
┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼
███▀▀▀██┼███▀▀▀███┼███▀█▄█▀███┼██▀▀▀
██┼┼┼┼██┼██┼┼┼┼┼██┼██┼┼┼█┼┼┼██┼██┼┼┼
██┼┼┼▄▄▄┼██▄▄▄▄▄██┼██┼┼┼▀┼┼┼██┼██▀▀▀
██┼┼┼┼██┼██┼┼┼┼┼██┼██┼┼┼┼┼┼┼██┼██┼┼┼
███▄▄▄██┼██┼┼┼┼┼██┼██┼┼┼┼┼┼┼██┼██▄▄▄
┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼
███▀▀▀███┼▀███┼┼██▀┼██▀▀▀┼██▀▀▀▀██▄┼
██┼┼┼┼┼██┼┼┼██┼┼██┼┼██┼┼┼┼██┼┼┼┼┼██┼
██┼┼┼┼┼██┼┼┼██┼┼██┼┼██▀▀▀┼██▄▄▄▄▄▀▀┼
██┼┼┼┼┼██┼┼┼██┼┼█▀┼┼██┼┼┼┼██┼┼┼┼┼██┼
███▄▄▄███┼┼┼─▀█▀┼┼─┼██▄▄▄┼██┼┼┼┼┼██▄
┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼""")
quit()
else:
print("You do not have a burger!")
else:
print(f"Invalid input {raw_input}")
def generateEnemy():
randEnemy = randint(1,5)
if randEnemy == 1:
opponent = Goblin("Goblin", 6, 2)
elif randEnemy == 2:
opponent = Shadow("Shadow", 1, 1)
elif randEnemy == 3:
opponent = Zombie("Zombie", 3, 1)
elif randEnemy == 4:
opponent = Medic("Medic", 6, 1)
else:
opponent = Theif("Theif", 10, 1)
return opponent
def main():
hero = Hero("Hero", 10, 5)
while hero.alive:
mainMenu()
choice = input()
if choice == '1':
goToStore(hero)
elif choice == '2':
opponent = generateEnemy()
combat(opponent, hero)
elif choice == '3':
enemy = FinalBoss("Final Boss", float('inf'), 69)
finalBoss(enemy, hero)
elif choice == '4':
break
else:
print(f"Invalid input {choice}")
mainMenu()
print("""
┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼
███▀▀▀██┼███▀▀▀███┼███▀█▄█▀███┼██▀▀▀
██┼┼┼┼██┼██┼┼┼┼┼██┼██┼┼┼█┼┼┼██┼██┼┼┼
██┼┼┼▄▄▄┼██▄▄▄▄▄██┼██┼┼┼▀┼┼┼██┼██▀▀▀
██┼┼┼┼██┼██┼┼┼┼┼██┼██┼┼┼┼┼┼┼██┼██┼┼┼
███▄▄▄██┼██┼┼┼┼┼██┼██┼┼┼┼┼┼┼██┼██▄▄▄
┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼
███▀▀▀███┼▀███┼┼██▀┼██▀▀▀┼██▀▀▀▀██▄┼
██┼┼┼┼┼██┼┼┼██┼┼██┼┼██┼┼┼┼██┼┼┼┼┼██┼
██┼┼┼┼┼██┼┼┼██┼┼██┼┼██▀▀▀┼██▄▄▄▄▄▀▀┼
██┼┼┼┼┼██┼┼┼██┼┼█▀┼┼██┼┼┼┼██┼┼┼┼┼██┼
███▄▄▄███┼┼┼─▀█▀┼┼─┼██▄▄▄┼██┼┼┼┼┼██▄
┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼""")
main()