from random import randint class Warrior: def __init__(self, name): self.name = name self.hp = 100 self.type = '' self.damage = 0 self.ultimate = False self.parrying = 0 def info(self): print('___________________') print('Name: {}'.format(self.name)) print('HP: {}'.format(self.hp)) print('Type: {}'.format(self.type)) print('___________________') def attack(self, enemy): self.damage = randint(5, 50) if self.damage >= 50 and not self.ultimate: self.ultimate = True enemy.hp -= self.damage enemy.hp = max(0, enemy.hp) print(f"{self.name} uses an ULTIMATE attack! Hit -{self.damage}. {enemy.name}'s HP: {enemy.hp}") elif self.damage <= 30: if self.damage > enemy.parrying: enemy.hp -= self.damage enemy.hp = max(0, enemy.hp) print(f"{self.name} attacks! Hit -{self.damage}. {enemy.name}'s HP: {enemy.hp}") else: print(f"{enemy.name} is parrying {self.name} attack!") if enemy.hp <= 0: print(f"{enemy.name} is defeated!") swordsman = Warrior('adam',) swordsman.type = 'swordsman' swordsman.parrying = 20 mag = Warrior('eva') mag.type = 'magician' mag.parrying = 15 while mag.hp > 0 and swordsman.hp > 0: # Decide randomly who attacks attacker, defender = (swordsman, mag) if randint(0, 1) == 0 else (mag, swordsman) attacker.attack(defender) # Check if the defender is defeated if defender.hp <= 0: print(f"\n{attacker.name} is the winner!") print(f"{swordsman.info()}\n{mag.info()}") break