Advertisement
FedeCuci

Untitled

Apr 19th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | None | 0 0
  1. import random
  2. import time
  3. import os
  4.  
  5. php = 50
  6. phpmax = 50
  7. pdefence = 14
  8. pactions = ['attack','upgrade']
  9. pattackmax = 10
  10. enemydefense = 0
  11. pdamg = 0
  12.  
  13. # Logic for the turn of the player
  14. def playerturn(pdamg, pattackmax, enemydefense):
  15. print('it is your turn what do you do')
  16. print('possible actions are ' +str(pactions))
  17. action = input('please type an action ')
  18.  
  19. if action == 'attack':
  20. atkrll = random.randint(1,20)+2 # Generating a number between 1 and 20.
  21. if atkrll >= enemydefense: # 7/20 chance he is going to hit
  22. pdamg = random.randint(1,pattackmax) # Attack damage of player
  23. print('you hit your enemy dealing ' +str(pdamg) +' damage')
  24. else:
  25. print('you attacked your enemy and missed')
  26. elif action == 'upgrade':
  27. print('In function before', pattackmax)
  28. pattackmax += 1 # To revise
  29. print('In function after', pattackmax)
  30. print('you spend some time sharpening your blade, you can now deal a maximum of ' +str(pattackmax) +' damage in one attack')
  31.  
  32.  
  33. def enemyfight(coheal,ctsattack,cthit,ehp,adamagemax,hamountmax,name,armour, php, pdamg):
  34. while(True):
  35. ehpmax = ehp # Enemy max hit points are full
  36. if ehp > 0:
  37. pdamg = 0
  38. print('Before function call', pattackmax)
  39. playerturn(pdamg, pattackmax, armour)
  40. ehp -= pdamg
  41. #convert chance to heal to 100 minus the chance so that I can check independently for healing and special attack
  42. coheal = 100 - coheal
  43.  
  44. #generate number between 1 and 100 to determine action
  45. action = random.randint(1,100)
  46.  
  47. if action >= coheal and ehp < ehpmax:
  48. #making sure the enemy does not heal at full health
  49. if ehp < ehpmax:
  50. heal = random.randint(1,hamountmax)
  51.  
  52. ehp = ehp + heal
  53. healtext = f'{name} tends to it\'s wounds for a moment healing itself'
  54. print(healtext)
  55. # making sure the enemy's health is not over the maximum
  56.  
  57. if ehp > ehpmax:
  58. ehp = ehpmax
  59.  
  60. #checking to see whether the attack is critically hitting
  61. elif action <= ctsattack:
  62. #dealing twice the amount of damage than a normal attack
  63. damage = random.randint(1,adamagemax)*2
  64. php -= damage
  65. satktxt = f'{name} struck you with a critically hitting attack, dealing twice as much damage, it did {damage} damage'
  66. print(satktxt)
  67. else:
  68. # try to hit enemy and add the to hit bonus
  69. accuracy = random.randint(1,20)+cthit
  70. if accuracy >= pdefence:
  71. damage = random.randint(1,adamagemax)
  72. #deal damage
  73. php -= damage
  74. atktxt = f'{name} attacks you and deals {damage} damage'
  75. print(atktxt)
  76. #take away the amount of hitpoints that the enemy does damage
  77. else:
  78. txt=f'{name} attacked you and missed'
  79. print(txt)
  80. else:
  81. print('you killed your enemy')
  82. break
  83.  
  84. os.system('clear')
  85.  
  86. # Create enemy
  87. enemyfight(10,4,1,50,10,10,'potatoman',13, php, pdamg)
  88.  
  89. # Hey Andrew, once again, really nice game and good use of functions. This time you put comments which is good, but I would put them differently.
  90. # A good practice is to always put a comment above every function to explain exactly what it does. Most of the times, the name implies what the
  91. # Function does, but it makes it much more clear. Furthermore, whenever you create a new variable, explain what it is. That is really important to
  92. # Do. When you created the variable "ehpmax" it took me just a little longer to understand what it is. I figured out that you use "hp" for hitpoints,
  93. # But I would not have to if you put a comment. (Programmers are very lazy, and don't want to think too much ;). When you write comments think about
  94. # A programmer that has never made a game before. Everyone thinks differently, and so you must use comments to explain your train of thought.
  95.  
  96. # I would also avoid global variables. It is unbelievably easy to mix global variables up and it is a best practice not to have too many global variables.
  97. # You can see that I got rid of them and instead passed them as arguments in other functions. It is going to be a real pain debugging when there is a problem
  98. # With global variables.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement