Advertisement
BoomPow

Python Dungeon

Jul 26th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.50 KB | None | 0 0
  1. from sys import exit
  2. from random import randint, randrange
  3. import math
  4. import time
  5.  
  6. """
  7. A lot of these is inefficient and quite useless, i'l rewrite it later when it's functioning
  8.  
  9. The mechanic is technically finished except the variable random part
  10. """
  11.  
  12. #################################################################################################################
  13. # Player
  14. player_exp = 0
  15. exp_limit = 50
  16. player_level = 1
  17.  
  18. player_maxhp = 100
  19. player_hp = 100
  20.  
  21. player_atk = 0
  22. player_agi = 0
  23. player_misc = 0
  24. stat_limit = 8
  25.  
  26.  
  27. # Equipped
  28. eq_punch = True
  29. eq_sword1 = False
  30. eq_sword2 = False
  31. eq_rapier1 = False
  32. eq_rapier2 = False
  33. eq_axe1 = False
  34. eq_axe2 = False
  35.  
  36. eq_shield = False
  37. eq_armor = False
  38.  
  39. potion_count = 0
  40. potion_limit = 3
  41.  
  42. weapon1_drop = randint(40, 60)
  43. weapon2_drop = randint(10, 30)
  44. potion_drop = randint(20, 50)
  45.  
  46. # Weapon Stats
  47. punch_atk = 6
  48. punch_hitchance = 100
  49. punch_critchance = 0
  50.  
  51. sword1_atk = 10
  52. sword1_hitchance = 40
  53. sword1_critchance = 10
  54.  
  55. sword2_atk = 14
  56. sword2_hitchance = 50
  57. sword2_critchance = 10
  58.  
  59. rapier1_atk = 8
  60. rapier1_hitchance = 50
  61. rapier1_critchance = 15
  62.  
  63. rapier2_atk = 10
  64. rapier2_hitchance = 60
  65. rapier2_critchance = 7
  66.  
  67. axe1_atk = 18
  68. axe1_hitchance = 30
  69. axe1_critchance = 20
  70.  
  71. axe2_atk = 24
  72. axe2_hitchance = 40
  73. axe2_critchance = 25
  74.  
  75. shield_red = 10
  76. armor_red = 20
  77.  
  78. potion_count = 0
  79. potion_limit = 3
  80.  
  81. # Trigger
  82. room1 = False
  83. mini_boss = False
  84. boss = False
  85. exit_key = False
  86.  
  87. # Monsters
  88. name_rat = "Rat"
  89. rat_hp = randint(10, 15)
  90. rat_atk = randint(1, 2)
  91. rat_crit = 3
  92. rat_evade = 15
  93. rat_exp = randrange(1, 3)
  94. rat_chance = randint(60, 80)
  95.  
  96. name_rat2 = "Giant Rat"
  97. rat2_hp = randint(20, 45)
  98. rat2_atk = randint(5, 10)
  99. rat2_crit = 5
  100. rat2_evade = 2
  101. rat2_exp = randint(5, 10)
  102. rat2_chance = randint(30, 50)
  103.  
  104. name_goblin = "Goblin"
  105. goblin_hp = randint(20, 40)
  106. goblin_atk = randint(3, 7)
  107. goblin_crit = 15
  108. goblin_evade = 20
  109. goblin_exp = randint(7, 10)
  110. goblin_chance = randint(50, 70)
  111.  
  112. name_slime = "Red Slime"
  113. slime_hp = randint(100, 200)
  114. slime_atk = randint(1, 2)
  115. slime_crit = 60
  116. slime_evade = 10
  117. slime_exp = randint(1, 5)
  118. slime_chance = randint(50, 60)
  119.  
  120. name_slime2 = "Green Slime"
  121. slime2_hp = randint(40, 80)
  122. slime2_atk = randint(15, 20)
  123. slime2_crit = 5
  124. slime2_evade = 10
  125. slime2_exp = randint(10, 40)
  126. slime2_chance = randint(30, 50)
  127.  
  128. name_slime3 = "Blue Slime"
  129. slime3_hp = randint(10, 15)
  130. slime3_atk = 0
  131. slime3_crit = 0
  132. slime3_evade = 0
  133. slime3_exp = randint(1, 2)
  134. slime3_chance = randint(10, 30)
  135.  
  136. name_askeleton = "Armored Skeleton"
  137. skeleton_hp = randint(120, 180)
  138. skeleton_atk = randint(5, 10)
  139. skeleton_crit = 2
  140. skeleton_evade = 10
  141. skeleton_exp = randint(15, 25)
  142. skeleton_chance = randint(30, 45)
  143.  
  144. name_askeleton2 = "Swordsman Skeleton"
  145. skeleton2_hp = randint(50, 80)
  146. skeleton2_atk = randint(10, 18)
  147. skeleton2_crit = 5
  148. skeleton2_evade = 10
  149. skeleton2_exp = randint(15, 25)
  150. skeleton2_chance = randint(30, 45)
  151.  
  152. name_zombie = "A Lone Zombie"
  153. zombie_hp = randint(40, 80)
  154. zombie_atk = randint(10, 15)
  155. zombie_crit = 10
  156. zombie_evade = 10
  157. zombie_exp = randint(10, 20)
  158. zombie_chance = randint(30, 40)
  159.  
  160. name_gargoyle = "Stone Gargoyle"
  161. gargoyle_hp = randint(100, 200)
  162. gargoyle_atk = randint(10, 20)
  163. gargoyle_crit = 5
  164. gargoyle_evade = 20
  165. gargoyle_exp = randint(20, 30)
  166. gargoyle_chance = randint(20, 40)
  167.  
  168.  
  169. name_minotaur = "Minotaur"
  170. minotaur_hp = randint(80, 120)
  171. minotaur_atk = randint(10, 20)
  172. minotaur_crit = 5
  173. minotaur_evade = 15
  174. minotaur_exp = randint(20, 40)
  175. minotaur_chance = randint(10, 20)
  176.  
  177. name_boss = "Troglodyte"
  178. boss_hp = 800
  179. boss_atk = 25
  180. boss_crit = 10
  181. boss_evade = 10
  182. boss_exp = randint(50, 80)
  183. boss_chance = randint(1,3)
  184.  
  185. #################################################################################################################
  186.  
  187. def rng(): # RNG
  188. return randint(0, 100)
  189.  
  190. def dead(reason): # End
  191. print(reason, "Restart?\n1. Yes\n2. No")
  192. choice = input("> ")
  193.  
  194. if choice == "1":
  195. print("Do you wish to recreate your character?\n1. Yes\n2. No")
  196. choice = input("> ")
  197.  
  198. if choice == "1":
  199. print("Recreating character...")
  200. time.sleep(1)
  201. char_create()
  202. else:
  203. print("Restarting...")
  204. time.sleep(1)
  205. start()
  206. else:
  207. print("Thank you for playing")
  208. exit(0)
  209.  
  210. def exp_check(enemy_exp): # Check player exp for level up
  211. global exp_limit, player_level, player_exp, player_hp, player_maxhp, potion_limit
  212.  
  213. player_exp += enemy_exp
  214.  
  215. if player_level >= 15:
  216. player_exp = exp_limit
  217. print("Warning: Max Level Reached!")
  218. elif player_exp == exp_limit:
  219. player_exp -= exp_limit
  220. exp_limit += 25
  221. player_level += 1
  222. player_maxhp += 20
  223. player_hp = player_maxhp
  224.  
  225. print("You are now Level:", player_level)
  226. if player_level % 4 == 0:
  227. potion_limit += 1
  228. print("Potion limit increased")
  229. print(f"You now can hold {potion_limit} potion")
  230. level_up()
  231.  
  232.  
  233. def level_up(): # Player level up
  234. global player_atk, player_agi, player_misc
  235.  
  236. print("You gained a skill point!")
  237. print("What do you want to add ?")
  238. print(f"1.ATK: {player_atk}/{stat_limit} 2. AGI: {player_agi}/{stat_limit} 3. MISC: {player_misc}/{stat_limit}")
  239. choice = input("> ")
  240.  
  241. if choice == "1":
  242. if player_atk >= 8:
  243. print("Error: Stat is already maxed")
  244. time.sleep(1)
  245. level_up()
  246. else:
  247. player_atk += 1
  248. elif choice == "2":
  249. if player_agi >= 8:
  250. print("Error: Stat is already maxed")
  251. time.sleep(1)
  252. level_up()
  253. else:
  254. player_agi += 1
  255. elif choice == "3":
  256. if player_misc >= 8:
  257. print("Error: Stat is already maxed")
  258. time.sleep(1)
  259. level_up()
  260. else:
  261. player_misc += 1
  262. else:
  263. print("Error: Not a number")
  264. level_up()
  265.  
  266. def health_check(): # Checks player health
  267. if player_hp <= 0:
  268. dead("You ran out of health")
  269.  
  270. def weapon_check(): # Check player weapon
  271. if eq_sword1 == True:
  272. return sword1_atk
  273. elif eq_sword2 == True:
  274. return sword2_atk
  275. elif eq_rapier1 == True:
  276. return rapier1_atk
  277. elif eq_rapier2 == True:
  278. return rapier2_atk
  279. elif eq_axe1 == True:
  280. return axe1_atk
  281. elif eq_axe2 == True:
  282. return axe2_atk
  283. else:
  284. return punch_atk
  285.  
  286. def armor_check(): # Check player's armor
  287. if eq_shield and eq_armor == True:
  288. return shield_red + armor_red
  289. elif eq_shield == True:
  290. return shield_red
  291. elif eq_armor == True:
  292. return armor_red
  293. else:
  294. return 1
  295.  
  296. def hit_chance(): # Player hit chance
  297. if eq_sword1 == True:
  298. return (sword1_hitchance + (player_atk * 5))
  299. elif eq_sword2 == True:
  300. return (sword2_hitchance + (player_atk * 5))
  301. elif eq_rapier1 == True:
  302. return (rapier1_hitchance + (player_atk * 5))
  303. elif eq_rapier2 == True:
  304. return (rapier2_hitchance + (player_atk * 5))
  305. elif eq_axe1 == True:
  306. return (axe1_hitchance + (player_atk * 5))
  307. elif eq_axe2 == True:
  308. return (axe2_hitchance + (player_atk * 5))
  309. else:
  310. return (punch_hitchance + (player_atk * 5))
  311.  
  312. def crit_chance(): # Player crit chance
  313. if eq_sword1 == True:
  314. return (sword1_critchance + (player_misc * 2))
  315. elif eq_sword2 == True:
  316. return (sword2_critchance + (player_misc * 2))
  317. elif eq_rapier1 == True:
  318. return (rapier1_critchance + (player_misc * 2))
  319. elif eq_rapier2 == True:
  320. return (rapier2_critchance + (player_misc * 2))
  321. elif eq_axe1 == True:
  322. return (axe1_critchance + (player_misc * 2))
  323. elif eq_axe2 == True:
  324. return (axe2_critchance + (player_misc * 2))
  325. else:
  326. return (punch_critchance + (player_misc * 2))
  327.  
  328. def battle(enemy_name, enemy_hp, enemy_atk, enemy_crit, enemy_evade, enemy_exp):# Battle sequence
  329.  
  330. time.sleep(1)
  331.  
  332. print("===============================================================================")
  333. while enemy_hp > 0:
  334. global player_hp, potion_count
  335.  
  336. health_check()
  337. print("-------------------------------------------------------------------------------")
  338. print(f"{enemy_name}'s Stats:")
  339. print(f"HP: {enemy_hp} Power: {enemy_atk} Crit Chance: {enemy_crit}% Evade: {enemy_evade}%\n")
  340. print("Your Stats:")
  341. print(f"Level: {player_level} EXP: {player_exp}/{exp_limit} HP: {player_hp}/{player_maxhp} Power: {player_atk + weapon_check()} Potion: {potion_count}/{potion_limit}")
  342. print(f"Hit Chance: {hit_chance()}% Parry Chance: {player_agi * 8}% Crit Chance: {crit_chance()}% Evade Chance: {player_agi * 5}%")
  343. print("-------------------------------------------------------------------------------")
  344. print("Action:\n1. Attack\n2. Parry\n3. Use Potion")
  345. choice = input("> ")
  346.  
  347.  
  348. if choice == "1":
  349. if rng() <= enemy_evade or not rng() <= hit_chance():
  350. print("Miss!")
  351. elif rng() <= hit_chance() and rng() <= crit_chance():
  352. print("Critical Hit!")
  353. enemy_hp -= ((player_atk + weapon_check()) * 2)
  354. health_check()
  355. else:
  356. print("Succesful Hit!")
  357. enemy_hp -= player_atk + weapon_check()
  358.  
  359. if rng() <= player_agi * 5:
  360. print("Hit Evaded!")
  361. elif rng() <= enemy_crit:
  362. print("Enemy Critical Hit!")
  363. player_hp -= math.ceil((armor_check() * 0.01) * (enemy_atk * 2))
  364. else:
  365. print("You are hit")
  366. player_hp -= math.ceil((armor_check() * 0.01) * enemy_atk)
  367. health_check()
  368. time.sleep(1)
  369.  
  370. elif choice == "2":
  371. if rng() <= enemy_evade:
  372. print("Parry Evaded!")
  373. player_hp -= math.ceil((armor_check() * 0.01) * enemy_atk)
  374. elif rng() <= player_agi * 8 and rng() <= enemy_crit:
  375. print("Critical Parry!")
  376. enemy_hp -= math.ceil((enemy_atk * 2) * 0.8)
  377. elif rng() <= player_agi * 8:
  378. print("Parry Succesful!")
  379. enemy_hp -= math.ceil(enemy_atk * 0.8)
  380. player_hp -= math.ceil(((armor_check() * 0.01) * enemy_atk) * 0.1)
  381. else:
  382. print("Parry Failed")
  383. player_hp -= math.ceil((armor_check() * 0.01) * enemy_atk)
  384.  
  385. if rng() <= player_agi * 5:
  386. print("Enemy Miss!")
  387. elif rng() <= enemy_crit:
  388. print("Enemy Critical Hit!")
  389. player_hp -= math.ceil((armor_check() * 0.01) * (enemy_atk * 2))
  390. else:
  391. print("You are hit!")
  392. player_hp -= math.ceil(((armor_check() * 0.01) * enemy_atk) * 0.1)
  393. health_check()
  394. time.sleep(1)
  395.  
  396. elif choice == "3":
  397. if potion_count == 0:
  398. print("You don't have a potion")
  399. time.sleep(1)
  400. else:
  401. potion_count -= 1
  402. print(f"You used a potion, you have {potion_count} potion left.")
  403. player_hp += 30 + (player_misc * 15)
  404. time.sleep(1)
  405. else:
  406. print("Error: Not a number")
  407.  
  408. print(f"{enemy_name} killed")
  409. print(f"You gained {enemy_exp} EXP")
  410. exp_check(enemy_exp)
  411. print(f"Your EXP is now {player_exp}/{exp_limit}")
  412. print("===================================================================================")
  413. time.sleep(2)
  414.  
  415. def weapon_change(): # Change player weapon
  416. if eq_sword1 == True:
  417. return eq_sword1 == False
  418. elif eq_sword2 == True:
  419. return eq_sword2 == False
  420. elif eq_rapier1 == True:
  421. return eq_rapier1 == False
  422. elif eq_rapier2 == True:
  423. return eq_rapier2 == False
  424. elif eq_axe1 == True:
  425. return eq_axe1 == False
  426. elif eq_axe2 == True:
  427. return eq_axe2 == False
  428. else:
  429. return eq_punch == False
  430.  
  431. ##########################################################################################################################
  432.  
  433.  
  434. def char_create():
  435. global player_atk, player_agi, player_misc
  436. stat_allocate = 10
  437.  
  438. print("You have", stat_allocate, "Skill Points.")
  439. print("ATK affect your hit chance with weapon and the damage you dealt.")
  440. print("Each point will increase hit chance by '5%' and add point of damage")
  441. print("Enter a number between 0-8 for your ATK.")
  442. player_atk = int(input("> "))
  443. stat_allocate -= player_atk
  444. print("--------------------------------------------------------------------------------------------------------------")
  445.  
  446. print("You have", stat_allocate, "Skill Point(s) remaining.")
  447. print("AGI affect your chance to parry enemy attack.")
  448. print("Each AGI point will increase parry chance by '8%' and evade by '5%'")
  449. print("A successful pary wil decrease damage received to '10%' and the enemy will receive '80%' of their own damage.")
  450. print("Enter a number between 0-8 for your AGI.")
  451. player_agi = int(input("> "))
  452. stat_allocate -= player_agi
  453. print("--------------------------------------------------------------------------------------------------------------")
  454.  
  455. print("You have", stat_allocate, "Skill Point(s) remaining")
  456. print("MISC skill will affect your chances of landing a critical and increase potion effectiveness.")
  457. print("Each MISC point wil increase crit chances with weapon '2%' and potion effectiveness by 15 Points")
  458. print("Enter a number between 0-8 for your MISC")
  459. player_misc = int(input("> "))
  460. stat_allocate -= player_misc
  461. print("--------------------------------------------------------------------------------------------------------------")
  462.  
  463. if stat_allocate > 0:
  464. print("You have", stat_allocate, "Skill points remaining. Do you want to restart?\n1. Yes\n2. No")
  465. choice = input("> ")
  466.  
  467. if choice == "1":
  468. print("Restarting...")
  469. time.sleep(2)
  470. char_create()
  471. else:
  472. print("Starting...")
  473. time.sleep(2)
  474. start()
  475.  
  476. elif stat_allocate < 0:
  477. print("Error: Stat exceed maximum")
  478. print("Restarting...")
  479. time.sleep(2)
  480. char_create()
  481. else:
  482. print("Starting...")
  483. time.sleep(3)
  484. start()
  485.  
  486. def start():
  487. global eq_sword1, room1
  488. if start == False:
  489. print("You wake up in a dark room")
  490. print("You see an unfamiliar roof")
  491. print("You try to get a grasp of your surrounding")
  492. print("Only to be startled by a rat hissing at you")
  493. battle(name_rat, rat_hp, rat_atk, rat_crit, rat_evade, rat_exp)
  494. room1 = True
  495.  
  496. if rng() < weapon1_drop:
  497. print("The enemy dropped a rusty sword")
  498. print("Rusty Sword Stats")
  499. print(f"ATK: {sword1_atk}, Hit Chance: {sword1_hitchance} Crit Chance: {sword1_critchance}")
  500. print("Do you wish to take it?\n1. Yes\n2. No")
  501. choice = input("> ")
  502.  
  503. if choice == "1":
  504. weapon_change()
  505. eq_sword1 = True
  506. print("Rusty Sword equipped")
  507. time.sleep(1)
  508. else:
  509. print("You leave the Rusty Sword")
  510. time.sleep(1)
  511. else:
  512. if rng() < secret_chance:
  513. print("You saw a black slave")
  514. print("He's charging at you full speed")
  515. battle(name_secret, secret_hp, secret_atk, secret_crit, secret_evade, secret_exp)
  516. print("Suddenly, there are police siren")
  517. print("You are arrested for being racist")
  518. dead("You are racist")
  519. if rng() < rat_chance:
  520. print("You look around the room")
  521. print("Only to be startled by a rat hissing at you")
  522. battle(name_rat, rat_hp, rat_atk, rat_crit, rat2_evade, rat_exp)
  523. if rng() < weapon1_drop:
  524. print("The enemy dropped a rusty sword")
  525. print("Rusty Sword Stats:")
  526. print(f"ATK: {sword1_atk}, Hit Chance: {sword1_hitchance} Crit Chance: {sword1_critchance}")
  527. print("Do you wish to take it?\n1. Yes\n2. No")
  528. choice = input("> ")
  529.  
  530. if choice == "1":
  531. weapon_change()
  532. eq_sword1 = True
  533. print("Rusty Sword equipped\n")
  534. time.sleep(1)
  535. else:
  536. print("You leave the Rusty Sword\n")
  537. time.sleep(1)
  538.  
  539. print("The room is gloomy")
  540. print("The walls are cracked")
  541. print("There are shackles and cages along the wall")
  542. print("You see 2 door\n1. East Door\n2. South Door")
  543. choice = input("> ")
  544.  
  545. if choice == "1":
  546. print("You entered the East Door")
  547. time.sleep(1)
  548. room2()
  549. elif choice == "2":
  550. print("You went through the South Door")
  551. time.sleep(1)
  552. room6()
  553.  
  554. def room2():
  555. global potion_count
  556. if rng() <= slime3_chance:
  557. print("You encountered a blue slime")
  558. print("It have a pointy head")
  559. print("It's humping at you")
  560. print("You didn't feel anything")
  561. battle(name_slime3, slime3_hp, slime3_atk, slime3_atk, slime3_evade, slime3_exp)
  562. print("Maybe the slime isn't that bad?")
  563. if rng() < potion_drop:
  564. print("The enemy dropped a Health Potion")
  565. print(f"You have {potion_count}/{potion_limit} Health Potion")
  566. print("Do you wish to take it?\n1. Yes\n2. No")
  567. choice = input("> ")
  568.  
  569. if choice == "1":
  570. if potion_count < potion_limit:
  571. potion_count += 1
  572. print("You took the Health Potion\n")
  573. else:
  574. print("Warning: Potion Limit Reached")
  575. else:
  576. print("You leave the Health Potion\n")
  577. elif rng() <= rat2_chance:
  578. print("A giant rat is blocking the hallway")
  579. print("You prepared yourself to attack it")
  580. battle(name_rat2, rat2_hp, rat2_atk, rat2_crit, rat2_evade, rat2_exp)
  581.  
  582. print("You entered a hallway")
  583. print("Your surroundings is lit by torches on the walls")
  584. print("There are 2 doors\n1. South Door\n2. West Door")
  585. choice = input("> ")
  586.  
  587. if choice == "1":
  588. print("You went through the South Door")
  589. time.sleep(1)
  590. room5()
  591. elif choice == "2":
  592. print("You chose to go through the West Door")
  593. time.sleep(1)
  594. start()
  595.  
  596. else:
  597. print("Not a number")
  598.  
  599. char_create()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement