diff --git a/.gitignore b/.gitignore index ed8ebf5..c34d28b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -__pycache__ \ No newline at end of file +__pycache__ +.DS_Store \ No newline at end of file diff --git a/equiposClases.py b/equiposClases.py new file mode 100644 index 0000000..7182574 --- /dev/null +++ b/equiposClases.py @@ -0,0 +1,78 @@ +import random + +# Soldier + + +class Soldier: + def __init__(self, name, health, strength): + self.health = health + self.strength = strength + self.name = name + + def attack(self): + return self.strength + + def receiveDamage(self, damage): + self.health -= damage + +# Viking + + +class Viking(Soldier): + def receiveDamage(self, damage): + self.health -= damage + if self.health > 0: + return "Viking {} has received {} points of damage" .format(self.name, str(damage)) + else: + return "Viking {} has died in act of combat" .format(self.name) + + def battleCry(self): + return "Odin Owns You All!" +# Saxon + + +class Saxon(Soldier): + def receiveDamage(self, damage): + self.health -= damage + if self.health > 0: + return "Saxon {} has received {} points of damage" .format(self.name, str(damage)) + else: + return "Saxon {} Saxon has died in combat" .format(str(self.name)) + +# War + + +class War: + def __init__(self): + self.vikingArmy = [] + self.saxonArmy = [] + + def addViking(self, viking_1): + self.vikingArmy.append(viking_1) + + def addSaxon(self, saxon_1): + self.saxonArmy.append(saxon_1) + + def vikingAttack(self): + sax = random.choice(self.saxonArmy) + vik = random.choice(self.vikingArmy) + vikatt = sax.receiveDamage(vik.strength) + if sax.health <= 0: + self.saxonArmy.remove(sax) + return vikatt + + def saxonAttack(self): + sax = random.choice(self.saxonArmy) + vik = random.choice(self.vikingArmy) + saxatt = vik.receiveDamage(sax.strength) + if vik.health <= 0: + self.vikingArmy.remove(vik) + return saxatt + + def showStatus(self): + if len(self.saxonArmy) == 0: + return "Vikings have won the war of the century!" + elif len(self.vikingArmy) == 0: + return "Saxons have fought for their lives and survive another day..." + elif len(self.saxonArmy) >= 1 and len(self.vikingArmy) >= 1: + return "Vikings and Saxons are still in the thick of battle." diff --git a/juegoPropio.py b/juegoPropio.py new file mode 100644 index 0000000..401366d --- /dev/null +++ b/juegoPropio.py @@ -0,0 +1,115 @@ +import unittest +import random +from equiposClases import War +from equiposClases import Viking +from equiposClases import Saxon +from inspect import signature +# Lista con todos los nombres +nombres = ["Miguel_Ceinos", "Eduardo_Vill", "Laura", "Patricia", "Xabier", "Cristina", "Santi", "Irene", "Ricardo_Alf", "Fernando", "Guille_Diego", "María", "Jose_Vidal", + "Eduardo_Garo", "Marlena", "Guille_Mart", "Alex_Vidal", "Iván", "Sergio", "Elisa", "Amanda", "Héctor", "Jose_Pérez", "Fabián", "Marc", "Clara", "Blanca", "Fran", "Felipe"] + +vikingTeam = [] +saxonTeam = [] +# Aquí es donde realmente se hacen los equipos +nombres1 = list(random.sample(nombres, int(len(nombres)/2))) +nombres2 = [i for i in nombres if i not in nombres1] +empieza = "" +# Con esta función añado los equipos a los ejércitos convertidos en Vikings y Saxons con fuerza y salud + + +def creandoEquipos(): + for v in nombres1: + vikingTeam.append(Viking(v, 10, random.choice(range(5, 15)))) + for s in nombres2: + saxonTeam.append(Saxon(s, 10, random.choice(range(5, 15)))) + + +def vikAttack(): + sax = random.choice(saxonTeam) + vik = random.choice(vikingTeam) + vikatt = sax.receiveDamage(vik.strength) + print("Turno Vikingo") + print("{} ataca a {} con fuerza {}".format( + vik.name, sax.name, vik.strength)) + if sax.health <= 0: + saxonTeam.remove(sax) + print("{} ha muerto".format(sax.name)) + else: + print("La vida de {} ahora es {}".format(sax.name, sax.health)) + # return vikatt + + +def saxAttack(): + sax = random.choice(saxonTeam) + vik = random.choice(vikingTeam) + saxatt = vik.receiveDamage(sax.strength) + print("Turno Sajón") + print("{} ataca a {} con fuerza {}".format( + sax.name, vik.name, sax.strength)) + if vik.health <= 0: + vikingTeam.remove(vik) + print("{} ha muerto".format(vik.name)) + else: + print("La vida de {} ahora es {}".format(vik.name, vik.health)) + # return saxatt + + +def eligeInicio(): + global empieza + empieza = input("Introduce V o S para empezar el juego ") + return empieza + + +def empiezaVik(): + while True: + vikAttack() + if len(vikingTeam) == 0 or len(saxonTeam) == 0: + break + saxAttack() + print("Quedan {} sajones y {} vikingos".format( + len(saxonTeam), len(vikingTeam))) + if len(vikingTeam) == 0 or len(saxonTeam) == 0: + break + + +def empiezaSax(): + while True: + saxAttack() + if len(vikingTeam) == 0 or len(saxonTeam) == 0: + break + vikAttack() + print("Quedan {} sajones y {} vikingos".format( + len(saxonTeam), len(vikingTeam))) + if len(vikingTeam) == 0 or len(saxonTeam) == 0: + break + + +def muestraGana(): + if len(vikingTeam) > len(saxonTeam): + print("Vikingos ganan") + for i in vikingTeam: + print("Superviviente: ", i.__dict__) + else: + print("Sajones ganan") + for i in saxonTeam: + print("Superviviente: ", i.__dict__) + + +creandoEquipos() + +print("Vikingos") +for i in vikingTeam: + print(i.__dict__) + +print("Sajones") +for i in saxonTeam: + print(i.__dict__) + +eligeInicio() + +if empieza == "v": + empiezaVik() +else: + empiezaSax() + +muestraGana() diff --git a/juegoPropio2.py b/juegoPropio2.py new file mode 100644 index 0000000..1343ce3 --- /dev/null +++ b/juegoPropio2.py @@ -0,0 +1,130 @@ +import unittest +import random +from equiposClases import War +from equiposClases import Viking +from equiposClases import Saxon +from inspect import signature +import sys +# Lista con todos los nombres +nombres = ["Miguel_Ceinos", "Eduardo_Vill", "Laura", "Patricia", "Xabier", "Cristina", "Santi", "Irene", "Ricardo_Alf", "Fernando", "Guille_Diego", "María", "Jose_Vidal", + "Eduardo_Garo", "Marlena", "Guille_Mart", "Alex_Vidal", "Iván", "Sergio", "Elisa", "Amanda", "Héctor", "Jose_Pérez", "Fabián", "Marc", "Clara", "Blanca", "Fran", "Felipe"] + +vikingTeam = [] +saxonTeam = [] +# Aquí es donde realmente se hacen los equipos +nombres1 = list(random.sample(nombres, int(len(nombres)/2))) +nombres2 = [i for i in nombres if i not in nombres1] +empieza = "" +# Con esta función añado los equipos a los ejércitos convertidos en Vikings y Saxons con fuerza y salud + + +def creandoEquipos(): + for v in nombres1: + vikingTeam.append(Viking(v, 10, random.choice(range(5, 15)))) + for s in nombres2: + saxonTeam.append(Saxon(s, 10, random.choice(range(5, 15)))) + + +def vikAttack(): + sax = random.choice(saxonTeam) + vik = random.choice(vikingTeam) + vikatt = sax.receiveDamage(vik.strength) + print("Turno Vikingo") + print("{} ataca a {} con fuerza {}".format( + vik.name, sax.name, vik.strength)) + if sax.health <= 0: + saxonTeam.remove(sax) + print("{} ha muerto".format(sax.name)) + else: + print("La vida de {} ahora es {}".format(sax.name, sax.health)) + # return vikatt + + +def saxAttack(): + sax = random.choice(saxonTeam) + vik = random.choice(vikingTeam) + saxatt = vik.receiveDamage(sax.strength) + print("Turno Sajón") + print("{} ataca a {} con fuerza {}".format( + sax.name, vik.name, sax.strength)) + if vik.health <= 0: + vikingTeam.remove(vik) + print("{} ha muerto".format(vik.name)) + else: + print("La vida de {} ahora es {}".format(vik.name, vik.health)) + # return saxatt + + +def eligeInicio(): + global empieza + empieza = input("Introduce V o S para empezar el juego ") + return empieza + + +def pause(): + pause = input('Presiona ENTER para seguir o z + enter para salir ') + if pause == "z": + sys.exit() + print("----------------------------------------") + + +def empiezaVik(): + while True: + vikAttack() + if len(vikingTeam) == 0 or len(saxonTeam) == 0: + break + saxAttack() + print("Quedan {} sajones y {} vikingos".format( + len(saxonTeam), len(vikingTeam))) + print("----------------------------------------") + if len(vikingTeam) == 0 or len(saxonTeam) == 0: + break + pause() + + +def empiezaSax(): + while True: + saxAttack() + if len(vikingTeam) == 0 or len(saxonTeam) == 0: + break + vikAttack() + print("Quedan {} sajones y {} vikingos".format( + len(saxonTeam), len(vikingTeam))) + print("----------------------------------------") + if len(vikingTeam) == 0 or len(saxonTeam) == 0: + break + pause() + + +def muestraGana(): + if len(vikingTeam) > len(saxonTeam): + print("Vikingos ganan") + for i in vikingTeam: + print("Superviviente: ", i.__dict__) + else: + print("Sajones ganan") + for i in saxonTeam: + print("Superviviente: ", i.__dict__) + + +# Creandoequipos convierte las listas con los equipos (aleatorias) en vikingos y sajones con datos. +creandoEquipos() +# mostramos los equipos por la terminal. +print("He creado aletoriamente dos equipos \n") +print("Vikingos") +for i in vikingTeam: + print(i.__dict__) +print("Sajones") +for i in saxonTeam: + print(i.__dict__) +# el usuario elige quién empieza +eligeInicio() + +if empieza == "v": + print("Ok, empiezan los Vikingos") + empiezaVik() +else: + print("Ok, empiezan los Sajones") + empiezaSax() + +muestraGana() diff --git a/vikingsClases.py b/vikingsClases.py index b51cd5f..32b7e5e 100644 --- a/vikingsClases.py +++ b/vikingsClases.py @@ -1,24 +1,82 @@ +import random # Soldier class Soldier: - pass + def __init__(self, health, strength): + self.health = health + self.strength = strength + + def attack(self): + return self.strength + + def receiveDamage(self, damage): + self.health -= damage # Viking -class Viking: - pass +class Viking(Soldier): + def __init__(self, name, health, strength): + super().__init__(health, strength) + self.name = name + + def receiveDamage(self, damage): + self.health -= damage + if self.health > 0: + return "{} has received {} points of damage" .format(self.name, str(damage)) + else: + return "{} has died in act of combat" .format(self.name) + def battleCry(self): + return "Odin Owns You All!" # Saxon -class Saxon: - pass +class Saxon(Soldier): + def receiveDamage(self, damage): + #self.health -= damage + super().receiveDamage(damage) # como hereda de Soldier... + if self.health > 0: + return "A Saxon has received {} points of damage" .format(str(damage)) + else: + return "A Saxon has died in combat" -# War +# War class War: - pass + def __init__(self): + self.vikingArmy = [] + self.saxonArmy = [] + + def addViking(self, viking_1): + self.vikingArmy.append(viking_1) + + def addSaxon(self, saxon_1): + self.saxonArmy.append(saxon_1) + + def vikingAttack(self): + sax = random.choice(self.saxonArmy) + vik = random.choice(self.vikingArmy) + vikatt = sax.receiveDamage(vik.strength) + if sax.health <= 0: + self.saxonArmy.remove(sax) + return vikatt + + def saxonAttack(self): + sax = random.choice(self.saxonArmy) + vik = random.choice(self.vikingArmy) + saxatt = vik.receiveDamage(sax.strength) + if vik.health <= 0: + self.vikingArmy.remove(vik) + return saxatt + + def showStatus(self): + if len(self.saxonArmy) == 0: + return "Vikings have won the war of the century!" + elif len(self.vikingArmy) == 0: + return "Saxons have fought for their lives and survive another day..." + elif len(self.saxonArmy) >= 1 and len(self.vikingArmy) >= 1: + return "Vikings and Saxons are still in the thick of battle."