Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Hero:
- def __init__(self, name, health, attackPower, armorNumber):
- self.name = name
- self.health = health
- self.attackPower = attackPower
- self.armorNumber = armorNumber
- def attack(self, enemy):
- print(self.name, " attack ", enemy.name)
- enemy.attackBy(self, self.attackPower)
- def attackBy(self, enemy, attackPower_enemy):
- print(self.name, " attacked by ", enemy.name)
- attack_taken = (attackPower_enemy * 10) / attackPower_enemy
- print("Getting attack: ", str(attack_taken))
- self.health = self.health - attack_taken if self.health > attack_taken else 0
- print("blood " + self.name + " balance: " + str(self.health))
- sniper = Hero("sniper", 20, 100, 10)
- rikimaru = Hero("rikimaru", 19, 200, 4)
- if sniper.armorNumber < rikimaru.armorNumber:
- for x in range(rikimaru.armorNumber):
- if sniper.health > 0 and rikimaru.health > 0:
- print("\n", x, "first condition")
- sniper.attack(rikimaru)
- if rikimaru.health == 0 and sniper.health > 0:
- break
- if rikimaru.health > 0 and sniper.health > 0:
- print(" === ")
- rikimaru.attack(sniper)
- if sniper.health == 0 and rikimaru.health > 0:
- break
- elif sniper.armorNumber > rikimaru.armorNumber:
- for y in range(sniper.armorNumber):
- if sniper.health > 0 and rikimaru.health > 0:
- print("\n", y, "second condition")
- rikimaru.attack(sniper)
- if sniper.health == 0 and rikimaru.health > 0:
- break
- if rikimaru.health > 0 and sniper.health > 0:
- print(" === ")
- sniper.attack(rikimaru)
- if rikimaru.health == 0 and sniper.health > 0:
- break
- else:
- print("THE END")
- if sniper.health == 0:
- print("\n", "Rikimaru Win")
- else:
- print("Sniper WIN")
- # SIMPLE GAME IN CLI: ATTACK EACH OTHER
- # 2 OBJECT(HERO): sniper & rikimaru
- # If hero attack each other:
- # 1. display attack to other
- # 2. display attacked by other
- # 3. amount of attack
- # 4. blood/health balance
- # link: https://www.youtube.com/watch?v=6F0T4IEzke4&list=PLZS-MHyEIRo7ab0-EveSvf4CLdyOECMm0&index=5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement