Advertisement
rangga_hrdme

oop python: simple-edit

Apr 9th, 2021 (edited)
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.28 KB | None | 0 0
  1. class Hero:
  2.     def __init__(self, name, health, attackPower, armorNumber):
  3.         self.name           = name
  4.         self.health         = health
  5.         self.attackPower    = attackPower
  6.         self.armorNumber    = armorNumber
  7.  
  8.     def attack(self, enemy):
  9.         print(self.name, " attack ", enemy.name)
  10.         enemy.attackBy(self, self.attackPower)
  11.  
  12.     def attackBy(self, enemy, attackPower_enemy):
  13.         print(self.name, " attacked by ", enemy.name)
  14.         attack_taken = (attackPower_enemy * 10) / attackPower_enemy
  15.         print("Getting attack: ", str(attack_taken))
  16.         self.health = self.health - attack_taken if self.health > attack_taken else 0
  17.         print("blood " + self.name + " balance: " + str(self.health))
  18.  
  19. sniper      = Hero("sniper", 20, 100, 10)
  20. rikimaru    = Hero("rikimaru", 19, 200, 4)
  21.  
  22. if sniper.armorNumber < rikimaru.armorNumber:
  23.     for x in range(rikimaru.armorNumber):
  24.         if sniper.health > 0 and rikimaru.health > 0:
  25.             print("\n", x, "first condition")
  26.             sniper.attack(rikimaru)
  27.             if rikimaru.health == 0 and sniper.health > 0:
  28.                 break
  29.         if rikimaru.health > 0 and sniper.health > 0:
  30.             print(" === ")
  31.             rikimaru.attack(sniper)
  32.             if sniper.health == 0 and rikimaru.health > 0:
  33.                 break
  34. elif sniper.armorNumber > rikimaru.armorNumber:
  35.     for y in range(sniper.armorNumber):
  36.         if sniper.health > 0 and rikimaru.health > 0:
  37.             print("\n", y, "second condition")
  38.             rikimaru.attack(sniper)
  39.             if sniper.health == 0 and rikimaru.health > 0:
  40.                 break
  41.         if rikimaru.health > 0 and sniper.health > 0:
  42.             print(" === ")
  43.             sniper.attack(rikimaru)
  44.             if rikimaru.health == 0 and sniper.health > 0:
  45.                 break
  46. else:
  47.     print("THE END")
  48.  
  49. if sniper.health == 0:
  50.     print("\n", "Rikimaru Win")
  51. else:
  52.     print("Sniper WIN")
  53.  
  54. # SIMPLE GAME IN CLI: ATTACK EACH OTHER
  55. # 2 OBJECT(HERO): sniper & rikimaru
  56. # If hero attack each other:
  57. # 1. display attack to other
  58. # 2. display attacked by other
  59. # 3. amount of attack
  60. # 4. blood/health balance
  61. # link: https://www.youtube.com/watch?v=6F0T4IEzke4&list=PLZS-MHyEIRo7ab0-EveSvf4CLdyOECMm0&index=5
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement