From 6617cadfa07bbf9443dbe632a745ddd4903299f0 Mon Sep 17 00:00:00 2001 From: danisiaj <123707285+danisiaj@users.noreply.github.com> Date: Fri, 13 Sep 2024 17:22:28 +0200 Subject: [PATCH] Vikings project --- Untitled-1.ipynb | 92 ++++++++ __pycache__/greatWar.cpython-312.pyc | Bin 0 -> 9894 bytes __pycache__/vikingsClasses.cpython-312.pyc | Bin 0 -> 7169 bytes file.py | 25 ++ greatWar.py | 258 +++++++++++++++++++++ vikingsClasses.py | 181 +++++++++++---- wargame.py | 21 +- 7 files changed, 525 insertions(+), 52 deletions(-) create mode 100644 Untitled-1.ipynb create mode 100644 __pycache__/greatWar.cpython-312.pyc create mode 100644 __pycache__/vikingsClasses.cpython-312.pyc create mode 100644 file.py create mode 100644 greatWar.py diff --git a/Untitled-1.ipynb b/Untitled-1.ipynb new file mode 100644 index 0000000..4cf239e --- /dev/null +++ b/Untitled-1.ipynb @@ -0,0 +1,92 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "round: 0 // Viking army: 4 warriors and Saxon army: 4 warriors\n", + "Vikings and Saxons are still in the thick of battle.\n", + "round: 1 // Viking army: 4 warriors and Saxon army: 4 warriors\n", + "Vikings and Saxons are still in the thick of battle.\n", + "round: 2 // Viking army: 4 warriors and Saxon army: 4 warriors\n", + "Vikings and Saxons are still in the thick of battle.\n", + "round: 3 // Viking army: 4 warriors and Saxon army: 4 warriors\n", + "Vikings and Saxons are still in the thick of battle.\n", + "round: 4 // Viking army: 4 warriors and Saxon army: 4 warriors\n", + "Vikings and Saxons are still in the thick of battle.\n", + "round: 5 // Viking army: 3 warriors and Saxon army: 4 warriors\n", + "Vikings and Saxons are still in the thick of battle.\n", + "round: 6 // Viking army: 2 warriors and Saxon army: 4 warriors\n", + "Vikings and Saxons are still in the thick of battle.\n", + "round: 7 // Viking army: 2 warriors and Saxon army: 4 warriors\n", + "Vikings and Saxons are still in the thick of battle.\n", + "round: 8 // Viking army: 1 warriors and Saxon army: 3 warriors\n", + "Vikings and Saxons are still in the thick of battle.\n", + "round: 9 // Viking army: 0 warriors and Saxon army: 2 warriors\n", + "Saxons have fought for their lives and survive another day...\n" + ] + } + ], + "source": [ + "\n", + "from vikingsClasses import Soldier, Viking, Saxon, War\n", + "import random\n", + "\n", + "\n", + "soldier_names = [\"albert\",\"andres\",\"archie\",\"dani\", \"david\",\"gerard\",\"german\",\"graham\",\"imanol\",\"laura\"]\n", + "great_war = War()\n", + "\n", + "#Create 5 Vikings\n", + "for i in range(0,5):\n", + " if i:\n", + " great_war.addViking(Viking(soldier_names[random.randint(0,9)],100,random.randint(0,100)))\n", + "\n", + "#Create 5 Saxons\n", + "for i in range(0,5):\n", + " if i:\n", + " great_war.addSaxon(Saxon(100,random.randint(0,100)))\n", + " \n", + "round = 0\n", + "while great_war.showStatus() == \"Vikings and Saxons are still in the thick of battle.\":\n", + " great_war.vikingAttack()\n", + " great_war.saxonAttack()\n", + " print(f\"round: {round} // Viking army: {len(great_war.vikingArmy)} warriors\",f\"and Saxon army: {len(great_war.saxonArmy)} warriors\")\n", + " print(great_war.showStatus())\n", + " round += 1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "base", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/__pycache__/greatWar.cpython-312.pyc b/__pycache__/greatWar.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7321f43061c3a2af981b95d0a53a8baafc8c9dfb GIT binary patch literal 9894 zcmcIq+fy4?n(x*P0TL2-%tbVgF9;0Aw@d;7E%n zso6Y$%N}4J0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&tDC1ltqwL}GjbMyH*_5Bknpt)CY zd1hjBznuN$s)5+mC;sC0&exDnx$169URZJO%T!Y1l%{^;V#g_EnEHIYO^pbC*oZm#$UJyP{+{4}zyNE2B~ z?ado?cKiN~3OoLaP*IDlQO|z6fAgZa%YIH|27nEM+y5?x@IN)MwDSRaWJL2P`q6ou z|6$@C^&+|ea0HFk_`)iR;(rV7zm+wMzP}2nUY-+Ah>bH>UJAIp?6)+DzM1!43b_33 Rv=|e`bK(Y~Rb1FI{ttgYeH{P* literal 0 HcmV?d00001 diff --git a/__pycache__/vikingsClasses.cpython-312.pyc b/__pycache__/vikingsClasses.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2b9e583b5a0624569a771fd508ea5fd754431274 GIT binary patch literal 7169 zcmds6+fQ7_89!%l-aFvMm^gq3;y5g^@g-@}_>#yqx!|T)4r#0qr1kNh11#PPopTm@ zSL-CI`~X%G?1u`{stQt73CmTQKcR1ZNFTs7@@m^kmYSEoQR6C7p8ES{&K`C*i{rG- zOGo0{GxwQqe&27tZ}>bC2`Whcdg9B8@?(nfcgj?g*Z$bNfR9B*S9CS4j43YVRYiAQ zQ*`%jmuxYniZTz%yoP$)ZI`-4sSl+)YD(Rr)Q{4D)8A82GWwKN@Wu>%qs%YrF?B!X57o6J5sdSo6X|o2?m}yu{ zE}UsuomJQFjH~gPPL}J1saZxp+wSWBXaP0ZSXRM%rYV zylJtE2AkxDW*MAWQ(BfC9*Mgv!MC(@-guew9OncO?t{4Hu6Rr%J+W0{l3t;Pug@os zjsMg%xH+zC*_1hcHfs#=)T}W+WSEz%+|2ke&t+fJl9$F`*Djjl8K~&s49`s)N$cQj z>QX8@X&yAPC`PoV$K}sef7f z<-xzjx>v*9H;$EKL-+QuxuFk!T<+R8H}v68Hqly1I>(9(eG6~^2f$uQnZ|Ep8dc(I zab(DtNM#KZhs89@!d_U$u%>c4vvO?4;1fBXsi~tQO=V`%boLp8=~_mcG^nYOH8Lr~ zjH^E-i*Qd0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Zl%#V`zAqjHg`AHIcNNl}M!15JNVj6#D zF9f1CSHRnKzr*W&>VDLV7v5+Ko+tXEh~!v{_lzogQy);LAXzeG@x&qGKQUaxJYV}y z$YLfo8 literal 0 HcmV?d00001 diff --git a/file.py b/file.py new file mode 100644 index 0000000..1762378 --- /dev/null +++ b/file.py @@ -0,0 +1,25 @@ +from greatWar import Soldier, Viking, Saxon, War +import random + +soldier_names = ["Kerem","Carlos","Tiago","Dani", "Julia","Caroline","Joao","Saul","Dusan", "Jaime"] +great_war = War() + +#Create 5 Vikings +for i in range(0,5): + if i: + great_war.addViking(Viking(soldier_names[random.randint(0,9)],300,random.randint(0,100))) + +#Create 5 Saxons +for i in range(0,5): + if i: + great_war.addSaxon(Saxon(300,random.randint(0,100))) + +round = 0 +while great_war.showStatus() == "Vikings and Saxons are still in the thick of battle.": + great_war.vikingAttack() + + if len(great_war.saxonArmy) != 0: + great_war.saxonAttack() + print(f"round: {round} // Viking army: {len(great_war.vikingArmy)} warriors",f"and Saxon army: {len(great_war.saxonArmy)} warriors") + print(great_war.showStatus()) + round += 1 \ No newline at end of file diff --git a/greatWar.py b/greatWar.py new file mode 100644 index 0000000..460bd5a --- /dev/null +++ b/greatWar.py @@ -0,0 +1,258 @@ +import random + +# Soldier + + +class Soldier: + # Arguments: + def __init__(self, health: int, strength: int): + """ + Class soldier is initialized! Every soldier will have a set health and strength + arg1: Class int. Health + arg2: Class int. Strength + """ + if health <= 0 or strength <= 0: # Make sure the user provides positive values for health and strength + assert ValueError + return "Health & Strength levels must be greater than 0" + else: + self.health = health + self.strength = strength + + + # Methods: + def attack(self): + """Defines an attack method to perform an attack and imply some damage to enemies""" + + return self.strength # this amount will be the damage received by the victim + + def receiveDamage(self, damage): + """ + Defines a method for the soldier to recieve damage and substract it from the health + arg1: int. Damage + """ + + self.health -= damage # substract the amount of damage to the Soldier's health + + + + + + +# Viking + +class Viking(Soldier): + + # Arguments: + def __init__(self, name, health: int, strength: int): + """ + Viking soldier is defined here + arg1: Name + arg2: int. Health + arg3: int. Strength + """ + self.name = name + self.health = health + self.strength = strength + self.shield = 0 + + self.battleCry == True # Special ability for Vikings (health +50) + self.shieldWall == True # Can activate the special ability (shield +50) + + self.berserkerRage == False # special ability for Vikings (strength x2) + + + def receiveDamage(self, damage): + """ + Defines a method for the soldier to recieve damage and substract it from the health + It inherints the method recieve_damage() from the Soldier Class + arg1: int. Damage + """ + self.health -= (damage - self.shield) # substract the amount of the result (damage - shield) + if self.health > 0: + return self.name + f" has received {damage} points of damage" + elif self.health <= 0: + return self.name + " has died in act of combat" + + def battleCry(self): + """ + Effect: When a Viking activates his Battlecry, his health increases 50 points. ONCE + """ + + if self.battleCry == True: + + health_recovery = 50 # Battle Cry restores vikings health +50 points + self.health += health_recovery + self.battleCry = False + return f"For Valhalla! Health +{health_recovery} points. Health: {self.health}" + else: + return f"{self.name} can't use Battlecry" + + def berserkerRage(self): + """ + Effect: when health drops bellow 30 points. Vikings enter a state of rage, + where their strength doubles for one turn. + """ + + self.strength *= 2 # Strength doubles + return f"{self.name} has enter Berserker Rage Mode" + + def shieldWall(self): + """ + Effect: when 50% of vikings have died, Shield Wall is activated + and viking's protective shield increases to 50 points (damage = damage - 50) + """ + self.shield += 50 + + +# Saxon + +class Saxon(Soldier): + + # Arguments: + def __init__(self, health, strength): + """ + Saxon soldier is defined here + arg1: int. Health + arg2: int. Strength + """ + + self.health = health + self.strength = strength + + # Methods: + def receiveDamage(self, damage): + + self.health -= damage # substract the amount of damage to the Saxon's health and check if it's more than 0 + if self.health > 0: + return f"A Saxon has received {damage} points of damage" + elif self.health <= 0: + return "A Saxon has died in combat" + + def arrowBarrage(self): + """ + Effect: Saxons can unleash a rain of arrows hitting multiple enemies at once. activates only once. + """ + barrage_damage = 50 # standard damage to all enemies + return barrage_damage + + + +# Davicente + +class War(): + def __init__(self): + """ + Define the War settings and builds the two armies: + We defined the 2 properties as empty arrays: + arr1: Vikings Army + arr2: Saxons Army + """ + + self.vikingArmy = [] # Define Viking's Army. Empty until addViking() or if all Viking's die + self.saxonArmy = [] + + def addViking(self, viking): + """ + Creates a viking class soldier and add it to the Vikings Army + arg: class. viking + """ + self.vikingArmy.append(viking) # adds Viking to the viking's Army + + def addSaxon(self, saxon): + """ + Creates a Saxon class soldier and add it to the Saxon Army + arg: class. saxon + """ + self.saxonArmy.append(saxon) # adds Saxon to the Saxon's Army + + def vikingAttack(self): + """ + Initializes attack() method from a random Viking to a random Saxon + appying damage equal to the Viking's strength + """ + + viking = random.choice(self.vikingArmy) # select random viking that will attack + damage = viking.strength # store the viking's strength in damage to substract it from the saxon's health + saxon = random.choice(self.saxonArmy) # select random saxon to be attacked + + if viking.berserkerRage == True: # check if viking has entered special ability Berserker Rage Mode (strength x2) + viking.berserkerRage() # Activate special ability + viking.berserkerRage == False # Deactivates special ability + else: + pass + attack_result = saxon.receiveDamage(damage) # Saxon received damaged and health is depleted an amount of "damage" + + if saxon.health <= 0: # Check if the Saxon is still alive (health > 0) + self.saxonArmy.remove(saxon) # Saxon dies and is removed from the army + return attack_result + else: + return attack_result + + + def saxonAttack(self): + """ + Initializes attack() method from a random Saxon to a random Viking + appying damage equal to the Saxon's strength + """ + + saxon = random.choice(self.saxonArmy) # select random Saxon that will attack + + # Chance to activate Arrow Barrage before the atacck + chance_arrowBarrage = random.randint(0,5) + if chance_arrowBarrage == 0: + saxon.arrowBarrage() # return {damage = 50} + for viking in self.vikingArmy: + viking.health -= 50 + + else: + damage = saxon.strength # store the saxon's strength in damage to substract it from the vikings's health + viking = random.choice(self.vikingArmy) # select random viking to be attacked + + # chance to activate Battlecry before the attack + if viking.battleCry == True: # Checks ability to activate special ability Battlecry + chance = random.choice(1,2) # 50% chance to Activate special ability Battlecry + if chance == 1: + return viking.battleCry() # viking's health restored +50 points + else: + pass + else: + pass + + attack_result = viking.receiveDamage(damage) # Viking received damaged and health is depleted an amount of "damage" + + if viking.health <= 0: # Check if the Viking is still alive (health > 0) + self.vikingArmy.remove(viking) # Viking dies and is removed from the army + + else: + if viking.health <= 30: + viking.berserkerRage == True # viking has entered Berserker Rage Mode + return attack_result + else: + return attack_result + + def showStatus(self): + """ + Returns the current status of the `War` based on the size of the armies. + **if the `Saxon` array is empty**, should return _**"Vikings have won the war of the century!"**_ + **if the `Viking` array is empty**, should return _**"Saxons have fought for their lives and survive another day..."**_ + **if there are at least 1 `Viking` and 1 `Saxon`**, should return _**"Vikings and Saxons are still in the thick of battle."**_ + """ + + if len(self.saxonArmy) == 0: # Vikings WIN + return "Vikings have won the war of the century!" + + elif len(self.vikingArmy) == 0: # Saxon WIN + return "Saxons have fought for their lives and survive another day..." + + elif len(self.saxonArmy) > 0 and len(self.vikingArmy) > 0: # BATTLE STILL ON + if len(self.vikingArmy) < 3: + for viking in self.vikingArmy: + if viking.shieldWall == True: + viking.shieldWall() + print(f"{viking.name} has activated shield Wall") + viking.shieldWall == False + else: + pass + else: + pass + return "Vikings and Saxons are still in the thick of battle." \ No newline at end of file diff --git a/vikingsClasses.py b/vikingsClasses.py index c2f31d2..e5a33ec 100644 --- a/vikingsClasses.py +++ b/vikingsClasses.py @@ -4,80 +4,177 @@ class Soldier: - def __init__(self, health, strength): - # your code here - + # Arguments: + def __init__(self, health: int, strength: int): + """ + Class soldier is initialized! Every soldier will have a set health and strength + arg1: Class int. Health + arg2: Class int. Strength + """ + if health <= 0 or strength <= 0: # Make sure the user provides positive values for health and strength + assert ValueError + return "Health & Strength levels must be greater than 0" + else: + self.health = health + self.strength = strength + + + # Methods: def attack(self): - # your code here + """Defines an attack method to perform an attack and imply some damage to enemies""" + return self.strength # this amount will be the damage received by the victim + def receiveDamage(self, damage): - # your code here + """ + Defines a method for the soldier to recieve damage and substract it from the health + arg1: int. Damage + """ + + self.health -= damage # substract the amount of damage to the Soldier's health + + + + # Viking class Viking(Soldier): - def __init__(self, name, health, strength): - # your code here + + # Arguments: + def __init__(self, name, health: int, strength: int): + """ + Viking soldier is defined here + arg1: Name + arg2: int. Health + arg3: int. Strength + """ + self.name = name + self.health = health + self.strength = strength def battleCry(self): - # your code here + """With this method, Vikings call for their battlecry (no effects in this program)""" + + """POSSIBLE EXTRA: + health_recovery = 50 # Battle Cry restores vikings health +50 points + self.health += health_recovery + return (f"For Valhalla! Health +{health_recovery} points. Health: {self.health}") + """ + return "Odin Owns You All!" def receiveDamage(self, damage): - # your code here + """ + Defines a method for the soldier to recieve damage and substract it from the health + It inherints the method recieve_damage() from the Soldier Class + arg1: int. Damage + """ + self.health -= damage # substract the amount of damage to the Viking's health and check if it's more than 0 + if self.health > 0: + return self.name + f" has received {damage} points of damage" + elif self.health <= 0: + return self.name + " has died in act of combat" # Saxon class Saxon(Soldier): + + # Arguments: def __init__(self, health, strength): - # your code here + """ + Saxon soldier is defined here + arg1: int. Health + arg2: int. Strength + """ + + self.health = health + self.strength = strength + # Methods: def receiveDamage(self, damage): - # your code here + + self.health -= damage # substract the amount of damage to the Saxon's health and check if it's more than 0 + if self.health > 0: + return f"A Saxon has received {damage} points of damage" + elif self.health <= 0: + return "A Saxon has died in combat" + # Davicente class War(): def __init__(self): - # your code here + """ + Define the War settings and builds the two armies: + We defined the 2 properties as empty arrays: + arr1: Vikings Army + arr2: Saxons Army + """ + + self.vikingArmy = [] # Define Viking's Army. Empty until addViking() or if all Viking's die + self.saxonArmy = [] def addViking(self, viking): - # your code here + """ + Creates a viking class soldier and add it to the Vikings Army + arg: class. viking + """ + self.vikingArmy.append(viking) # adds Viking to the viking's Army def addSaxon(self, saxon): - # your code here - + """ + Creates a Saxon class soldier and add it to the Saxon Army + arg: class. saxon + """ + self.saxonArmy.append(saxon) # adds Saxon to the Saxon's Army + def vikingAttack(self): - # your code here + """ + Initializes attack() method from a random Viking to a random Saxon + appying damage equal to the Viking's strength + """ + + viking = random.choice(self.vikingArmy) # select random viking that will attack + damage = viking.strength # store the viking's strength in damage to substract it from the saxon's health + saxon = random.choice(self.saxonArmy) # select random saxon to be attacked + attack_result = saxon.receiveDamage(damage) # Saxon received damaged and health is depleted an amount of "damage" + + if saxon.health <= 0: # Check if the Saxon is still alive (health > 0) + self.saxonArmy.remove(saxon) # Saxon dies and is removed from the army + return attack_result + else: + return attack_result def saxonAttack(self): - # your code here + """ + Initializes attack() method from a random Saxon to a random Viking + appying damage equal to the Saxon's strength + """ + saxon = random.choice(self.saxonArmy) # select random Saxon that will attack + damage = saxon.strength # store the saxon's strength in damage to substract it from the vikings's health + viking = random.choice(self.vikingArmy) # select random viking to be attacked + attack_result = viking.receiveDamage(damage) # Viking received damaged and health is depleted an amount of "damage" - def showStatus(self): - # your code here - pass - -#yop -class War2: - - def __init__(self): - # your code here - - def addViking(self, Viking): - # your code here - - def addSaxon(self, Saxon): - # your code here - - def vikingAttack(self): - # your code here + if viking.health <= 0: # Check if the Viking is still alive (health > 0) + self.vikingArmy.remove(viking) # Viking dies and is removed from the army - def saxonAttack(self): - # your code here + else: + return attack_result def showStatus(self): - # your code here - - pass - - + """ + Returns the current status of the `War` based on the size of the armies. + **if the `Saxon` array is empty**, should return _**"Vikings have won the war of the century!"**_ + **if the `Viking` array is empty**, should return _**"Saxons have fought for their lives and survive another day..."**_ + **if there are at least 1 `Viking` and 1 `Saxon`**, should return _**"Vikings and Saxons are still in the thick of battle."**_ + """ + + if len(self.saxonArmy) == 0: # Vikings WIN + return "Vikings have won the war of the century!" + + elif len(self.vikingArmy) == 0: # Saxon WIN + return "Saxons have fought for their lives and survive another day..." + + elif len(self.saxonArmy) > 0 and len(self.vikingArmy) > 0: # BATTLE STILL ON + return "Vikings and Saxons are still in the thick of battle." \ No newline at end of file diff --git a/wargame.py b/wargame.py index 747af67..b897261 100644 --- a/wargame.py +++ b/wargame.py @@ -1,25 +1,26 @@ -from .vikingsClasses import Soldier, Viking, Saxon, War +from vikingsClasses import Soldier, Viking, Saxon, War import random -soldier_names = ["albert","andres","archie","dani", "david","gerard","german","graham","imanol","laura"] - +soldier_names = ["albert","andres","archie","dani","david","gerard","german","graham","imanol","laura"] +great_war = War() #Create 5 Vikings for i in range(0,5): if i: - War.addViking(Viking(soldier_names[random.randint(0,9)],100,random.randint(0,100))) + great_war.addViking(Viking(soldier_names[random.randint(0,9)],100,random.randint(0,100))) #Create 5 Saxons for i in range(0,5): if i: - War.addSaxon(Saxon(100,random.randint(0,100))) + great_war.addSaxon(Saxon(100,random.randint(0,100))) round = 0 -while War.showStatus() == "Vikings and Saxons are still in the thick of battle.": - War.vikingAttack() - War.saxonAttack() - print(f"round: {round} // Viking army: {len(War.vikingArmy)} warriors",f"and Saxon army: {len(War.saxonArmy)} warriors") - print(War.showStatus()) +while great_war.showStatus() == "Vikings and Saxons are still in the thick of battle.": + great_war.vikingAttack() + if len(great_war.saxonArmy) != 0: + great_war.saxonAttack() + print(f"round: {round} // Viking army: {len(great_war.vikingArmy)} warriors",f"and Saxon army: {len(great_war.saxonArmy)} warriors") + print(great_war.showStatus()) round += 1 \ No newline at end of file