Advertisement
Guest User

hey hut

a guest
Oct 16th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.93 KB | None | 0 0
  1. # Combat RPG
  2. # By Ethan Dee © 2019
  3.  
  4. import math
  5. import random as rd
  6. import os
  7.  
  8.  
  9. # Common class shared by all classes
  10. class Common:
  11. def __init__(self):
  12. self.fullhp = 100
  13. self.hp = 100
  14. self.damage = 0
  15.  
  16. def is_not_used(self):
  17. pass
  18.  
  19. # Main attack function
  20. def attack(self, weapon):
  21. if self == enemy:
  22. if self.hp > 0:
  23. prevhp = player.hp
  24. player.hp -= enemy.damage
  25. print(f"The {enemy.name} attacks you and deals {prevhp - player.hp} damage")
  26. if "shield" in str(player.inv):
  27. player.hp += 5
  28. print("You had a shield and blocked 5 damage")
  29. input("Press enter to continue...")
  30. clear()
  31. else:
  32. input("Press enter to continue...")
  33. clear()
  34. else:
  35. prevhp = enemy.hp
  36. if weapon == 0:
  37. enemy.hp -= player.damage
  38. print(f"You punch the {enemy.name} and deal {prevhp - enemy.hp} damage.")
  39. else:
  40. if "shield" in str(weapon):
  41. print("You can't attack with a shield!")
  42. input("Press enter to continue...")
  43. clear()
  44. else:
  45. weapondamage = weapons[weapon]
  46. enemy.hp -= weapondamage
  47. print(f"You strike the {enemy.name} with your {weapon} and deal {prevhp - enemy.hp} damage.")
  48.  
  49.  
  50. # Enemy class shared by all enemies
  51. class Enemy(Common):
  52. def health(self):
  53. return f"Enemy Health:{self.hp}/{self.fullhp}"
  54.  
  55.  
  56. # Player class
  57. class Player(Common):
  58. def __init__(self):
  59. super(Common, self).__init__()
  60. self.fullhp = 100
  61. self.hp = 100
  62. self.damage = rd.randint(3, 7)
  63. self.inv = []
  64. self.infected = False
  65.  
  66. # Print health bar
  67. def health_bar(self):
  68. healthbar = (math.floor(self.hp / 10))
  69. t1 = "#" * int(healthbar)
  70. num = 10 - healthbar
  71. t2 = " " * num
  72. return f"Health:[{t1 + t2}]{self.hp}/100"
  73.  
  74.  
  75. # ####Enemy Classes#### #
  76. class Wolf(Enemy):
  77. def __init__(self):
  78. super(Enemy, self).__init__()
  79. self.name = "Wolf"
  80. self.fullhp = 50
  81. self.hp = 50
  82. self.damage = rd.randint(5, 10)
  83. self.dead = False
  84.  
  85.  
  86. class TaintedWarrior(Enemy):
  87. def __init__(self):
  88. super(Enemy, self).__init__()
  89. self.name = "Tainted Warrior"
  90. self.fullhp = 110
  91. self.hp = 110
  92. self.damage = rd.randint(10, 15)
  93. self.dead = False
  94.  
  95.  
  96. class Zombie(Enemy):
  97. def __init__(self):
  98. super(Enemy, self).__init__()
  99. self.name = "Zombie"
  100. self.fullhp = 15
  101. self.hp = 15
  102. self.damage = rd.randint(5, 10)
  103. self.dead = False
  104.  
  105. def bite(self):
  106. self.is_not_used()
  107. if "shield" in str(player.inv):
  108. print("You had a shield wich protected you from the zombie bite")
  109. elif rd.randint(1, 4) == 2:
  110. print("The zombie bites you and infects you which deals 5 damage to you each turn.")
  111. player.infected = True
  112. input("Press enter to continue...")
  113.  
  114.  
  115. # Function used to clear screen and print player health and enemy health
  116. def clear():
  117. os.system("cls")
  118. print(player.health_bar())
  119. print(f"Enemy:{enemy.name}")
  120. print(enemy.health())
  121. print(f"Infected:{player.infected}")
  122. print(f"Inventory:{player.inv}\n")
  123.  
  124.  
  125. weapons = {"rusty broadsword": 20,
  126. "knight's broadsword": 40,
  127. "battle axe": 75,
  128. "boko shield": 0}
  129.  
  130. enemies = [Zombie(), Wolf(), TaintedWarrior()]
  131. player = Player()
  132. enemy = rd.choice(enemies)
  133.  
  134. # Main loop
  135. while player.hp > 0:
  136. enemy = rd.choice(enemies)
  137. enemy.hp = enemy.fullhp
  138. clear()
  139. print(f"You encountered a {enemy.name}.")
  140. while enemy.hp > 0 or enemy.dead is False:
  141. if enemy.hp <= 0:
  142. break
  143. if player.hp <= 0:
  144. res = input("You Died! Play again?")
  145. if res == "yes":
  146. player.hp = 100
  147. player.inv = []
  148. player.infected = False
  149. break
  150. else:
  151. break
  152. if player.infected is True:
  153. clear()
  154. print("Player infected, loose 5 hp")
  155. player.hp -= 5
  156. choice = input("What do you want to do?\n1.Fight \n2.Run \n3.Cry\n")
  157. if choice == "1":
  158. clear()
  159. if len(player.inv) == 0:
  160. if enemy.name == "Zombie":
  161. player.attack(0)
  162. enemy.attack(0)
  163. enemy.bite()
  164.  
  165. else:
  166. player.attack(0)
  167. enemy.attack(0)
  168. else:
  169. if enemy.name == "Zombie":
  170. enemy.bite()
  171. yn = input("Your inventory contains 1 or more weapons. \nWould you like to use one? yes/no\n")
  172. if yn == "yes":
  173. wepdict = {}
  174. for i in range(len(player.inv)):
  175. print(f"{i}.{player.inv[i]}")
  176. wepdict[i] = player.inv[i]
  177. wepchoice = input("Which one?")
  178. player.attack(wepdict[int(wepchoice)])
  179. enemy.attack(0)
  180. input("Press enter to continue...")
  181. clear()
  182. else:
  183. if enemy.name == "Zombie":
  184. enemy.bite()
  185. player.attack(0)
  186. enemy.attack(0)
  187.  
  188. elif choice == "2":
  189. if rd.randint(1, 2) == 1:
  190. clear()
  191. randweapon = rd.choice(list(weapons))
  192. if randweapon in player.inv:
  193. randweapon = rd.choice(list(weapons))
  194. else:
  195. print(f"As you run you pick up a {randweapon}.")
  196. player.inv += [randweapon]
  197. input("Press enter to continue...")
  198. clear()
  199. if rd.randint(1, 2) == 1:
  200. clear()
  201. print(f"You were able to escape the {enemy.name}.")
  202. enemy.dead = True
  203. input("Press enter to continue...")
  204. clear()
  205. else:
  206. clear()
  207. print(f"The {enemy.name} is still hot on your heels and you can't escape.")
  208. enemy.attack(0)
  209. elif choice == "3":
  210. clear()
  211. print(f"You cry against a tree and are brutally murdered by the {enemy.name}.\n")
  212. player.hp = 0
  213. input("Press enter to continue...")
  214. if enemy.hp <= 0:
  215. print(f"The {enemy.name} dies and you continue on your journey.")
  216. input("Press enter to continue...")
  217. input("Press enter to close...")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement