Advertisement
FedeCuci

Untitled

Apr 9th, 2019
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.25 KB | None | 0 0
  1. import os
  2. import random
  3. import time
  4.  
  5. os.system('clear')
  6. php = 60
  7. maxphp = 30
  8. Ghp = random.randint(20,60)
  9. maxghp = Ghp
  10. mmsl = 2 # Define these variables, what do they do?
  11. fbsl = 4 # Same for this one, what does this do?
  12. print('A wild Goblin appears Snarling, getting ready to attack. What do you do?')
  13. time.sleep(2)
  14.  
  15.  
  16. while Ghp > 0 and php > 0: # While both player and golbin are alive
  17. turnreset = 0 # Make a comment for this one. It is not immediately clear what it does.
  18. print('it is your turn what do you do. You have '+str(php) +' hp') # This is good, but you can also look at string foratting:
  19.  
  20. # https://realpython.com/python-f-strings/
  21.  
  22. Action = str(input('to make an action type: firebolt, magic missile, bow, longsword or heal '))
  23. os.system('clear')
  24. if Action == 'firebolt':
  25. if fbsl > 0:
  26. fireboltdmg=random.randint(1,10)+2
  27. fbar = random.randint(1,20)+2 # Why + 2?
  28. fbsl = fbsl - 1 # This is some sort of mana? (got this from league)
  29. if fbar > 15:
  30. Ghp = Ghp-fireboltdmg
  31. print('your firebolt hit the goblin doing '+str(fireboltdmg) +' damage')
  32. else:
  33. print ('your firebolt missed')
  34. else:
  35. print('as you try to conjure the magical energy required to cast firebolt you fail, you can\'t cast firebolt anymore.')
  36. turnreset = 1 # Define this too.
  37. elif Action == 'magic missile':
  38. if mmsl > 0:
  39. mmd = random.randint(3,12)+6
  40. Ghp = Ghp-mmd
  41. print('your magic missiles hit the goblin doing ' +str(mmd) +' damage')
  42. mmsl = mmsl - 1
  43. else:
  44. print('as you try to conjure the magical energy required to cast magic missile you fail, you can\'t cast magic missile anymore.')
  45. turnreset = 1
  46.  
  47. elif Action == 'bow':
  48. bd = random.randint(1,8)+2
  49. bar = random.randint(1,20)+2
  50. if bar > 15:
  51. Ghp = Ghp-bd
  52. print('your arrow slammed into the goblin\'s shoulder and did ' +str(bd) +' damage')
  53. else:
  54. print('you shot an arrow at the goblin and missed')
  55.  
  56. elif Action == 'longsword':
  57. lsd = random.randint(1,12)
  58. lsar = random.randint(1,20)+2 # Chance that you are going to attack
  59. if lsar > 15:
  60. Ghp = Ghp - lsd
  61. print('you slash at the goblin and hit dealing ' + str(lsd) +' damage')
  62. else:
  63. print('you slash at the goblin and miss')
  64.  
  65. elif Action == 'heal':
  66. heal = random.randint(1,8)
  67. php = php+heal
  68. print('you heal your wounds restoring ' +str(heal) +' health')
  69. if php > maxphp:
  70. php = maxphp
  71.  
  72. else:
  73. print('please enter a valid action and be sure not to type anything until the list prompt pops up, that causes an error and you have to wait again')
  74. turnreset=1
  75. time.sleep(5)
  76. print('you have ' +str(php) + ' health left')
  77.  
  78.  
  79. # Goblin's turn to attack
  80. time.sleep(3)
  81. os.system('clear')
  82. if turnreset == 0: # If the player did not perform an action
  83. if Ghp/maxghp > 0.8:
  84. Gaction = random.randint(1,7)
  85. if Gaction == 7:
  86. Ghp = Ghp + random.randint(1,4)
  87. elif Gaction <= 3:
  88. gar = random.randint(1,20)+1
  89. if gar > 13:
  90. gdmg = random.randint(1,8)+3
  91. php = php - gdmg
  92. print('the goblin stabs at you hits and deals ' + str(gdmg) +' damgage')
  93. else:
  94. print('the goblin tries to stab at you, but the goblin misses')
  95. else:
  96. gar = random.randint(1,20)+3
  97. gdmg = random.randint(1,12)+3
  98. if gar > 13:
  99. php = php - gdmg
  100. print('the goblin draws back it\'s longbow\'s string and releases, the arrow flies into your leg dealing ' +str(gdmg) +' damage')
  101. else:
  102. print('the goblin draws back it\'s longbow\'s string and releases, the arrow flies right past you doing nothing')
  103.  
  104.  
  105. elif Ghp/maxghp > 0.5 and Ghp/maxghp < 0.8:
  106. Gaction = random.randint(1,5)
  107. if Gaction < 3:
  108. gar = random.randint(1,20)+1
  109. if gar > 13:
  110. gdmg = random.randint(1,8)+3
  111. php = php - gdmg
  112. print('the goblin stabs at you hits and deals ' + str(gdmg) +' damgage')
  113. else:
  114. print('the goblin tries to stab at you, but the goblin misses')
  115. elif Gaction < 5:
  116. gar = random.randint(1,20)+3
  117. gdmg = random.randint(1,12)+3
  118. if gar > 13:
  119. php = php - gdmg
  120. print('the goblin draws back it\'s longbow\'s string and releases, the arrow flies into your leg dealing ' +str(gdmg) +' damage')
  121. else:
  122. print('the goblin draws back it\'s longbow\'s string and releases, the arrow flies right past you doing nothing')
  123. else:
  124. gheal = random.randint(1,4)
  125. Ghp = Ghp + gheal
  126. print('the goblin tends to it\'s wounds for a moment healing ' +str(gheal) +' hitpoints')
  127. # I would check here if the goblin's health is more than his maximum:
  128. # if Ghp > maxghp:
  129. # Ghp = maxghp
  130. elif Ghp/maxghp > 0.3:
  131. Gaction = random.randint(1,3)
  132. if Gaction == 3:
  133. gar = random.randint(1,20)+3
  134. gdmg = random.randint(1,12)+3
  135. if gar > 13:
  136. php = php - gdmg
  137. print('the goblin draws back it\'s longbow\'s string and releases, the arrow flies into your leg dealing ' +str(gdmg) +' damage')
  138. else:
  139. print('the goblin draws back it\'s longbow\'s string and releases, the arrow flies right past you doing nothing')
  140. elif Gaction == 2:
  141. gar = random.randint(1,20)+1
  142. if gar > 13:
  143. gdmg = random.randint(1,8)+3
  144. php = php - gdmg
  145. print('the goblin stabs at you hits and deals ' + str(gdmg) +' damgage')
  146. else:
  147. print('the goblin tries to stab at you, but the goblin misses')
  148. else:
  149. gheal = random.randint(1,5)
  150. Ghp = Ghp + gheal
  151. print('the goblin tends to it\'s wounds for a moment healing ' +str(gheal) +' hitpoints')
  152. else:
  153. gheal = random.randint(1,5)
  154. Ghp = Ghp + gheal
  155. print('the goblin tends to it\'s wounds for a moment healing ' +str(gheal) +' hitpoints')
  156. if Ghp > maxghp:
  157. Ghp = maxghp
  158. time.sleep(4)
  159. os.system('clear')
  160.  
  161.  
  162. if Ghp <= 0: # I would check if the goblin is dead before he does any action. That way he dies immediately before healing itself.
  163. print('the goblin falls to the ground, dead.')
  164. print('congratulations YOU WIN')
  165. else:
  166. print('the goblin has dealt the final blow, you lay on the ground unconscious')
  167. print('YOU DIED')
  168. print('GAME OVER')
  169. time.sleep(5)
  170. os.system('clear')
  171. exit()
  172.  
  173.  
  174.  
  175.  
  176. # Hey Andrew! This game is really awesome and the physics of it are actually really well thought. I am happy you spent some time
  177. # At home practicing. This is actually what I wanted to do on Thursday with the class, a text based RPG.
  178.  
  179. # The game works very well and I am actually quite impressed. One thing you need to make sure that you do is to add comments.
  180. # Comments help people like me revise your code and understand better what it does. Even though I could understand it, it
  181. # would have taken me less time to and would have been easier :) I wrote some comments in the code where I think you should change
  182. # Some things, so make sure to read those.
  183.  
  184. # I think you understand the logic pretty well, but to me the obvious next step would be to add functions. I am not going to explain
  185. # what they are here, but you can try look them up. Unfortunately I don't think we'll cover them in class this Thursday
  186. # since other people are still not at this level.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement