import random
class Weapon():
def __init__(self, name, damage, scope):
self.name = name
self.damage = int(damage)
if scope == "short" or scope == "long":
self.scope = scope
class Pirate():
boat_life = 200
def __init__(self, name, W):
self.name = name
self.weapon = W
def attack(self, enemigo):
if (self.weapon.scope == "short" and enemigo.position == "near") or (self.weapon.scope == "long" and enemigo.position == "far") or (self.weapon.scope == "long" and enemigo.position == "near"):
print("{} ha atacado a {}".format(self.name, enemigo.name))
return int(self.weapon.damage)
def hit(self, daño):
self.boat_life = self.boat_life-daño
class Enemy():
def __init__(self, name, health, position, min_damage, max_damage):
self.name = name
self.health = health
if position == "near" or position == "far":
self.position = position
self.min_damage = int(min_damage)
self.max_damage = int(max_damage)
def attack(self, Pirate):
daño = random.randint(0, 1)
print("¡Oh no! {} ha atacado a {}".format(self.name, Pirate.name))
if daño == 0:
return self.min_damage
else:
return self.max_damage
def move(self):
movimiento = random.randint(0, 1)
if movimiento == 0:
self.position = "near"
else:
self.position = "far"
def hit(self, daño):
self.health = self.health-daño
Espada = Weapon("Espada", 3, "short")
Hacha = Weapon("Hacha", 5, "short")
Arco = Weapon("Arco", 2, "long")
Torvellino1 = Enemy("Torvellino1", 25, "near", 2, 5)
Torvellino2 = Enemy("Torvellino2", 25, "near", 4, 8)
Torvellino3 = Enemy("Torvellino3", 25, "far", 3, 5)
Torvellino4 = Enemy("Torvellino4", 25, "far", 6, 9)
Pyratilla = Pirate("pyratilla", Espada)
Pym = Pirate("pym", Arco)
Pyerce = Pirate("pyerce", Hacha)
ListaPiratas = [Pyratilla, Pym, Pyerce]
ListaEnemigos = [Torvellino1, Torvellino2, Torvellino3, Torvellino4]
indice = 0
def restart_battle():
"""
Se encarga de regenerar la batalla
"""
global Pyratilla
global Pym
global Pyerce
global Pyerce
global Torvellino1
global Torvellino2
global Torvellino3
global Torvellino4
global ListaPiratas
global ListaEnemigos
Pyratilla.boat_life = 200
Pym.boat_life = 200
Pyerce.boat_life = 200
Torvellino1.health = 25
Torvellino2.health = 25
Torvellino3.health = 25
Torvellino4.health = 25
ListaPiratas = [Pyratilla, Pym, Pyerce]
ListaEnemigos = [Torvellino1, Torvellino2, Torvellino3, Torvellino4]
while len(ListaPiratas) > 0 and len(ListaEnemigos) > 0:
if len(ListaPiratas) < 3:
restart_battle()
else:
indice = 0
for pirata in ListaPiratas:
if ListaEnemigos[indice].health > 0:
valor = pirata.attack(ListaEnemigos[indice])
if valor > 0:
ListaEnemigos[indice].hit(valor)
else:
ListaEnemigos.pop(indice)
indicePiratas = random.randint(0, 2)
for enemigos in ListaEnemigos:
decision = random.randint(0, 1)
if decision == 0:
enemigos.move()
else:
valor = enemigos.attack(ListaPiratas[indicePiratas])
ListaPiratas[indicePiratas].hit(valor)
if ListaPiratas[indicePiratas].boat_life <= 0:
ListaPiratas.pop(indicePiratas)
if len(ListaEnemigos) == 0:
print("¡¡¡La victoria es de los Pyrates")