repl.it
@GeorgeIrvine_Fy/

Hero Legends

Python

Hero Legends - RPG Game Helper: Ezolite

fork
loading
Files
  • main.py
  • attack.py
  • Billy Bob the Snake Archer_yep.pickle
  • enemy.py
  • hero.py
  • morgz_yep i did that.pickle
  • patchnotes.txt
main.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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
# Import Plugins
import pickle, random, os, sys
from hero import Character
from enemy import Enemy
from attack import Attack
from replit import clear
from time import sleep

# Player Attacks: Attack("Name", Damage, Mana Cost)
melee = Attack("Melee",20,0)
snowball = Attack("Snowball",30,10)
fireball = Attack("Fireball",40,15)
spear = Attack("Spear",30,10)
sword = Attack("Sword",40,15)
bowArrow = Attack("Snake",50,3)
crossbow = Attack("Snake with Wings",140,6)

# Enemy Attacks:
meleeEnemy = Attack("Melee",8,0)

# Characters: Character("Name", HP, Max HP, Mana, Max Mana, Attack, Attack)
wizard = Character("Wizard",125,125,125,125,melee,snowball,fireball)
knight = Character("Knight",175,175,75,75,melee,spear,sword)
archer = Character("Snake Archer",150,150,180,100,melee,bowArrow,crossbow)

# Monsters & Bosses: Enemy("Name", HP, Max HP, Primary Attack)
monsterOne = Enemy("Monster",50,50,meleeEnemy)
monsterTwo = Enemy("Monster",75,75,meleeEnemy)
bossOne = Enemy("Boss",125,125,meleeEnemy)
bossTwo = Enemy("Boss",150,150,meleeEnemy)

# Print Functions
def characterStats():
	print("[Character]")
	print("{}".format(player.getName()))
	print("HP: ({}/{})".format(player.getHealth(),player.getMaxHealth()))
	print("Mana: ({}/{})\n".format(player.getMana(),player.getMaxMana()))

# Lists
monsterList = [monsterOne,monsterTwo]
bossList = [bossOne,bossTwo]

# Signup
def signup():
	global username, password, filename
	clear()
	print("Hero Legends\n")
	print("[Signup]")
	username = input("Username: ")
	password = input("Password: ")
	filename = ("{}_{}.pickle".format(username,password))
	if os.path.exists(filename):
		print("\nAccount Already Exists")
		sleep(0.75)
		gameMenu()
	preGame()

# Login
def login():
	global username, password, filename
	clear()
	print("Hero Legends\n")
	print("[Login]")
	username = input("Username: ")
	password = input("Password: ")
	filename = ("{}_{}.pickle".format(username,password))
	if os.path.exists(filename):
		load()
		gameHub()
	else:
		print("\nAccount Does Not Exist")
		sleep(0.75)
		gameMenu()

# Guest
def guest():
	global username
	clear()
	print("Hero Legends\n")
	print("[Guest]")
	username = input("Username: ")
	preGame()

# Load (Must Global)
def load():
	global player, autoSave
	with open(filename,'rb') as f:
		player = pickle.load(f)
		autoSave = pickle.load(f)
	clear()
	print("Progress Loaded")
	sleep(0.5)

# Save
def save():
	if os.path.exists(filename):
		os.remove(filename)
	with open(filename,'wb+') as f:
		pickle.dump(player,f)
		pickle.dump(autoSave,f)
	clear()
	print("Progress Saved")
	sleep(0.5)

# Main Menu
def gameMenu():
	global guestAccess
	while True:
		clear()
		print("Hero Legends")
		print("Please Fork Hero Legends (Unless You're Playing as a Guest!) to Save / Load Progress!\n")
		print("[Main Menu]")
		print("(1) Tutorial")
		print("(2) Login")
		print("(3) Signup")
		print("(4) Guest\n")
		mainMenu = input("> ")
		if mainMenu == "1":
			guestAccess = 0
			tutorial()
		if mainMenu == "2":
			guestAccess = 0
			login()
		if mainMenu == "3":
			guestAccess = 0
			signup()
		if mainMenu == "4":
			guestAccess = 1
			guest()

# Tutorial
def tutorial():
	while True:
		clear()
		print("Hero Legends\n")
		print("[Tutorial]")
		print("In Hero Legends, heroes fight monsters and bosses to level up and prestige.")
		print("Once they hit level 100, they prestige and gain stat boosts.")
		print("Every 5 levels, you will receive an upgrade token to use at the upgrade table.")
		print("You can boost your attack, defense and also the coins and gems you get from chests.\n")
		print("(1) Main Menu\n")
		tutorialInput = input("> ")
		if tutorialInput == "1":
			gameMenu()

# Pre Game Calibration
def preGame():
	global player, autoSave
	while True:
		clear()
		print("Hero Legends\n")
		print("(1) Wizard \nStats: HP:{}, Mana:{}".format(wizard.getHealth(),wizard.getMana()))
		print("(2) Knight \nStats: HP:{}, Mana:{}".format(knight.getHealth(),knight.getMana()))
		print("(3) Archer \nStats: HP:{}, Mana:{}\n".format(archer.getHealth(),archer.getMana()))
		characterInput = input("> ")
		if characterInput == "1":
			player = wizard
			break
		elif characterInput == "2":
			player = knight
			break
		elif characterInput == "3":
			player = archer
			break
	# Auto Calibrate
	while True:
		if guestAccess == 1:
			break
		clear()
		print("Do you want to Auto Save Game on Exit? (Y/N)")
		autoDetect = input("> ")
		if autoDetect.lower() == "y":
			autoSave = 1
			break
		if autoDetect.lower() == "n":
			autoSave = 0
			break
	if guestAccess == 0:
		save()
	gameHub()

# Game Hub
def gameHub():
	while True:
		player.calcMaxXp()
		clear()
		print("Hero Legends\n")
		print("[Account]")
		print("{}".format(username))
		print("Coins: {}".format(player.getCoins()))
		print("Gems: {}\n".format(player.getGems()))
		characterStats()
		print("Level: {}".format(player.getLevel()))
		print("XP: ({}/{})\n".format(player.getXp(), player.getMaxXp()))
		print("[Game Hub]")
		print("(a) Play Level")
		print("(b) Upgrade Table")
		print("(c) Shop [WIP]\n")
		print("[Options]")
		if guestAccess == 0:
			print("(1) Save")
		print("(2) Settings")
		print("(3) Exit\n")
		hubInput = input("> ")
		if hubInput == "a":
			play()
		if hubInput == "b":
			upgradeTable()
		if hubInput == "c":
			shop()
		if hubInput == "d":
			player.upgradeTokens += 10
		if hubInput == "1":
			if guestAccess == 0:
				save()
		if hubInput == "2":
			settings()
		if hubInput == "3":
			if guestAccess == 0:
				if autoSave == 1:
					save()	
			sys.exit(0)

# Play
def play():
	global monsterCount, bossCount, chestMonsterCount, chestBossCount
	clear()
	# Choose Number of Monsters and Bosses
	monsterCount = random.randrange(2,6)
	bossCount = random.randrange(1,3)
	chestMonsterCount = monsterCount
	chestBossCount = bossCount
	# Level
	while True:
		if monsterCount > 0 or bossCount > 0:
			fightMonster()
		elif monsterCount == 0 and bossCount == 0:
			player.healAll()
			chest()
			break

# Play: Monster Fight
def fightMonster():
	global monsterCount, bossCount, chosenAttackWeapon, pickedMonster
	if monsterCount > 0:
		pickedMonster = random.choice(monsterList)
		currentEnemy = "monster"
	elif monsterCount == 0 and bossCount > 0:
		pickedMonster = random.choice(bossList)
		currentEnemy = "boss"
	while True:
		clear()
		if pickedMonster.health <= 0:
			print("Hero Legends\n")
			print("You defeated a {}".format(pickedMonster.getName()))
			# Give Xp
			if pickedMonster.name == "Monster":
				xpCount = (player.lvl * 5)
			if pickedMonster.name == "Boss":
				xpCount = (player.lvl * 10)
			player.gainXp(xpCount)
			print("You got {} Xp!".format(xpCount))
			input("\nPress 'Enter' to Continue!")
			clear()
			pickedMonster.healAll()
			if currentEnemy == "monster":
				monsterCount -= 1
			if currentEnemy == "boss":
				bossCount -= 1
			break
		if player.health <= 0:
			player.healAll()
			clear()
			randomCoins = random.randint(5,11)
			if player.coins > randomCoins:
				player.coins -= randomCoins
			else:
				randomCoins = player.coins
				player.coins -= randomCoins
			print("Hero Legends\n")
			print("[Stats]")
			print("You Died!")
			if randomCoins > 0:
				print("You Lost {} Coins!".format(randomCoins))
			input("\nPress 'Enter' to Return to Hub!")
			gameHub()
		print("Hero Legends\n")
		print("[Enemy Count]")
		if monsterCount > 0:
			print("Monster Count: {}".format(monsterCount))
		print("Boss Count: {}\n".format(bossCount))
		characterStats()
		print("[Enemy]")
		print("{}".format(pickedMonster.getName()))
		print("HP: ({}/{})\n".format(pickedMonster.health,pickedMonster.maxHealth))
		print("[Attack]")
		print("(a) Default Attack [{}]".format(player.defaultAttack.getName()))
		print("Damage: {}".format(player.defaultAttack.getDamage()))
		if player.defaultAttack.manaCost > 0:
			print("Mana Cost: {}".format(player.defaultAttack.getManaCost()))
		print("(b) Primary Attack [{}]".format(player.attackOne.getName()))
		print("Damage: {}".format(player.attackOne.getDamage()))
		if player.attackOne.manaCost > 0:
			print("Mana Cost: {}".format(player.attackOne.getManaCost()))
		print("(c) Secondary Attack: [{}]".format(player.attackTwo.getName()))
		print("Damage: {}".format(player.attackTwo.getDamage()))
		if player.attackTwo.manaCost > 0:
			print("Mana Cost: {}\n".format(player.attackTwo.getManaCost()))
		print("[Options]")
		print("(1) Run Away\n")
		attackInput = input("> ")
		if attackInput == "a":
			chosenAttackWeapon = player.defaultAttack
			attackDamage()
		if attackInput == "b":
			chosenAttackWeapon = player.attackOne
			attackDamage()
		if attackInput == "c":
			chosenAttackWeapon = player.attackTwo
			attackDamage()
		if attackInput == "1":
			runawayChance = random.randint(0,101)
			if runawayChance < 25:
				player.healAll()
				pickedMonster.healAll()
				print("\nYou Successfully Ranaway!")
				sleep(1.5)
				gameHub()
			else:
				print("\nYou Were Unsuccessful in Running Away!")
				sleep(1)
				doDamage = random.randint(4,pickedMonster.attackOne.damage)
				player.health -= doDamage
				print("{} did {} Damage to your {}".format(pickedMonster.getName(),doDamage,player.getName()))
				sleep(1)
				clear()

# Play: Attack
def attackDamage():
	# Player Hits Enemy if Mana >= Cost
	if player.mana >= chosenAttackWeapon.manaCost:
		pickedMonster.health -= chosenAttackWeapon.damage
		player.mana -= chosenAttackWeapon.manaCost
		print("\n{} used {} and did {} Damage to the {}".format(player.getName(),chosenAttackWeapon.getName(),chosenAttackWeapon.getDamage(),pickedMonster.getName()))
		sleep(1)
		if chosenAttackWeapon.manaCost > 0:
			print("Mana Lost: {}".format(chosenAttackWeapon.getManaCost()))
			sleep(1.5)
		# Enemy Hits Player
		if pickedMonster.health > 0:
			enemyHitChance = random.randint(0,101)
			if enemyHitChance < 75:
				doDamage = random.randint(4,pickedMonster.attackOne.damage)
				player.health -= doDamage
				print("\n{} did {} Damage to your {}".format(pickedMonster.getName(),doDamage,player.getName()))
				sleep(1)
				clear()
			else:
				print("\n{} Missed Attack".format(pickedMonster.getName()))
				sleep(1)
				clear()
	else:
		print("\nNot Enough Mana!")
		sleep(1)
		clear()

# Play: Chest
def chest():
	chestGems = 0
	# Randomize
	chestMonsterCoins = random.randint(chestMonsterCount, (5*chestMonsterCount))
	chestBossCoins = random.randint(chestBossCount, (10*chestBossCount))
	chestGemsChance = random.randint(0,101)
	# Amounts
	totalChestCoins = chestMonsterCoins + chestBossCoins + player.coinBoost
	if chestGemsChance < 10 + player.gemBoost:
		chestGems = 1
	clear()
	print("Hero Legends\n")
	print("[Items]")
	player.coins += totalChestCoins
	print("Coins Earned: {}".format(totalChestCoins))
	if chestGems > 0:
		player.gems += chestGems
		print("Gems Earned: {}".format(chestGems))
	input("\nPress 'Enter' to Close Chest!")
	if guestAccess == 0:
		if autoSave == "1":
			save()

# Upgrade Table
def upgradeTable():
	while True:
		clear()
		print("Hero Legends")
		print("Upgrade Tokens: {}\n".format(player.getUpgradeTokens()))
		print("[Upgrade Table]")
		print("(a) Health Cap {+10} [Cost: 1]")
		print("(b) Mana Cap {+10} [Cost: 1]")
		print("(c) Coin Boost {+2} [Cost: 1]")
		print("(d) Gem Boost {+1%} [Cost: 1]\n")
		print("[Menu]")
		print("(1) Exit Upgrade Table\n")
		upgradeTableInput = input("> ")
		if upgradeTableInput == "1":
			gameHub()
		if upgradeTableInput == "a" or upgradeTableInput == "b" or upgradeTableInput == "c" or upgradeTableInput == "d":
			if player.upgradeTokens > 0:
				player.upgradeTokens -= 1
				if upgradeTableInput == "a":
					player.maxHealth += 10
					player.healAll()
					print("\nSuccessfully Upgraded Health Cap by 10")
					input("Press 'Enter' to Continue!")
				if upgradeTableInput == "b":
					player.maxMana += 10
					player.healAll()
					print("\nSuccessfully Upgraded Mana Cap by 10")
					input("Press 'Enter' to Continue!")
				if upgradeTableInput == "c":
					player.coinBoost += 2
					print("\nSuccessfully Upgraded Coin Boost by 2")
					input("Press 'Enter' to Continue!")
				if upgradeTableInput == "d":
					player.gemBoost += 1
					print("\nSuccessfully Upgraded Gem Boost by 1%")
					input("Press 'Enter' to Continue!")
			else:
				print("\nNot Enough Upgrade Tokens!")
				input("Press 'Enter' to Continue!")

# Shop
def shop():
	while True:
		clear()
		print("Hero Legends\n")
		print("[Shop]")
		print("(a) Food Menu [HP & Mana]")
		print("(b) Weapon Menu [Primary & Secondary]")
		print("\n[Menu]")
		print("(1) Exit Shop\n")
		shopInput = input("> ")
		if shopInput == "a":
			shopFood()
		if shopInput == "b":
			shopWeapon()
		if shopInput == "1":
			gameHub()

# Shop: Food
def shopFood():
	while True:
		clear()
		print("Hero Legends")
		print("Coins: {}\n".format(player.getCoins()))
		print("[Food]")
		print("(a) Apple [Cost: 2 Coins] [Heals: 20HP]")
		print("(b) Emergency Kit [Cost: 10 Coins] [Heals: Full HP]")
		print("\n[Options]")
		print("(1) Back to Shop")
		print("(2) Game Hub\n")
		foodInput = input("> ")
		if foodInput == "1":
			shop()
		if foodInput == "2":
			gameHub()

# Shop: Weapons
def shopWeapon():
	while True:
		clear()
		print("Hero Legends")
		print("Coins: {}".format(player.getCoins()))
		print("\n[Weapons]")
		print("\n[Options]")
		print("(1) Back to Shop")
		print("(2) Game Hub\n")
		weaponInput = input("> ")
		if weaponInput == "1":
			shop()
		if weaponInput == "2":
			gameHub()

# Gamble
def gamble():
	while True:
		clear()
		print("Hero Legends")
		print("Coins: {}".format(player.getCoins()))
		print("\n[Gamble]")
		print("\n[Options]")
		print("(1) Game Hub")
		gambleInput = input("> ")
		if gambleInput == "1":
			gameHub()

# Settings
def settings():
	while True:
		# Auto Save
		if guestAccess == 0:
			if autoSave == 1:
				autoSaveSetting = "On"
			elif autoSave == 0:
				autoSaveSetting = "Off"
		clear()
		print("Hero Legends\n")
		print("[Settings]")
		if guestAccess == 0:
			print("(a) Auto Save: {}".format(autoSaveSetting))
		print("\n[Settings Menu]")
		print("(1) Game Menu\n")
		settingsMenu = input("> ")
		if settingsMenu == "1":
			gameHub()
		if settingsMenu == "a":
			if guestAccess == 0:
				toggleAutoSave()

# Settings: Toggle Auto Save
def toggleAutoSave():
	global autoSave
	clear()
	if autoSave == 1:
		print("Auto Save: On")
	elif autoSave == 0:
		print("Auto Save: Off")
	print("Do you want to turn Auto Save ON or OFF (ON/OFF)")
	changeAutoSave = input("> ")
	if changeAutoSave.lower() == "on" and autoSave == 0:
		autoSave += 1
		clear()
		print("Turned on Auto Save!")
	elif changeAutoSave.lower() == "off" and autoSave == 1:
		autoSave -= 1
		clear()
		print("Turned off Auto Save!")
	else:
		clear()
		print("Error!")
	sleep(1)
	save()

# Run Game
gameMenu()