init
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
from random import randint
|
||||
|
||||
|
||||
class Warrior:
|
||||
def __init__(self):
|
||||
self.name = None
|
||||
self.hp = 100
|
||||
self.damage = 10
|
||||
self.defense = 10
|
||||
self.ultimate = False
|
||||
|
||||
def info(self):
|
||||
print('___________________')
|
||||
print('Name: {}'.format(self.name))
|
||||
print('HP: {}'.format(self.hp))
|
||||
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.defense:
|
||||
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}'s attack!")
|
||||
if enemy.hp <= 0:
|
||||
print(f"\n{enemy.name} is defeated!")
|
||||
|
||||
|
||||
class Swordsman(Warrior):
|
||||
def __init__(self, name):
|
||||
super().__init__()
|
||||
self.name = name
|
||||
self.hp = 100
|
||||
self.damage = 0
|
||||
self.defense = 20
|
||||
self.ultimate = False
|
||||
|
||||
|
||||
class Dragon(Warrior):
|
||||
def __init__(self, name):
|
||||
super().__init__()
|
||||
self.name = name
|
||||
self.hp = 200
|
||||
self.damage = 0
|
||||
self.defense = 0
|
||||
self.ultimate = False
|
||||
|
||||
|
||||
hero = Swordsman('Hero')
|
||||
dragon = Dragon('Dragon')
|
||||
|
||||
while hero.hp > 0 and dragon.hp > 0:
|
||||
|
||||
attacker, defender = (hero, dragon) if randint(0, 1) == 1 else (dragon, hero)
|
||||
attacker.attack(defender)
|
||||
|
||||
if defender.hp <= 0:
|
||||
print(f"\n{attacker.name} is the winner!")
|
||||
hero.info()
|
||||
dragon.info()
|
||||
break
|
||||
Reference in New Issue
Block a user