Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add solution #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added __pycache__/vikingsClasses.cpython-311.pyc
Binary file not shown.
11 changes: 11 additions & 0 deletions file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import vikingsClasses


V = vikingsClasses.Viking('Olaf',100,30)
S = vikingsClasses.Saxon(100,30)

print(S.strength)
print(V.battleCry())

def generate_army(number, army_type):
pass
68 changes: 54 additions & 14 deletions vikingsClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,81 +3,121 @@
# Soldier


class Soldier:
class Soldier():
def __init__(self, health, strength):
# your code here
self.health = health
self.strength = strength

def attack(self):
# your code here

return self.strength

def receiveDamage(self, damage):
# your code here
self.health = self.health - damage


# Viking

class Viking(Soldier):
def __init__(self, name, health, strength):
# your code here
super().__init__(health, strength)
self.name = name

def battleCry(self):
# your code here
return "Odin Owns You All!"

def receiveDamage(self, damage):
# your code here
self.health = self.health - damage
if self.health > 0:
return f"{self.name} has received {damage} points of damage"
else:
return f"{self.name} has died in act of combat"

# Saxon

class Saxon(Soldier):
def __init__(self, health, strength):
# your code here
super().__init__(health, strength)

def receiveDamage(self, damage):
# your code here
self.health = self.health - damage
if self.health > 0:
return f"a Saxon has received {damage} points of damage"
else:
return f"A Saxon has died in combat"

# Davicente

class War():
def __init__(self):
# your code here
self.vikingArmy = list()
self.saxonArmy = list()

def addViking(self, viking):
# your code here
self.vikingArmy.append(viking)

def addSaxon(self, saxon):
# your code here
self.saxonArmy.append(saxon)

def vikingAttack(self):
# your code here
Saxon_f = random.choice(self.saxonArmy)
Viking_f = random.choice(self.vikingArmy)
result = Saxon_f.receiveDamage(Viking_f.strength)
if Saxon_f.health <=0:
self.saxonArmy.remove(Saxon_f)
return result

def saxonAttack(self):
# your code here

Saxon_f = random.choice(self.saxonArmy)
Viking_f = random.choice(self.vikingArmy)
result = Viking_f.receiveDamage(Saxon_f.strength)
if Viking_f.health <=0:
self.vikingArmy.remove(Viking_f)
return result

def showStatus(self):
# your code here
pass
if len(self.saxonArmy) >= 1 and len(self.vikingArmy) >= 1:
return "Vikings and Saxons are still in the thick of battle."
elif 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..."




#yop

class War2:

def __init__(self):
# your code here
pass

def addViking(self, Viking):
# your code here
pass

def addSaxon(self, Saxon):
# your code here

pass
def vikingAttack(self):
# your code here

pass
def saxonAttack(self):
# your code here

pass
def showStatus(self):
# your code here

pass


pass
pass
17 changes: 9 additions & 8 deletions wargame.py
Original file line number Diff line number Diff line change
@@ -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"]

war_instance = 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)))
war_instance.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)))
war_instance.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 war_instance.showStatus() == "Vikings and Saxons are still in the thick of battle.":
war_instance.vikingAttack()
war_instance.saxonAttack()
print(f"round: {round} // Viking army: {len(war_instance.vikingArmy)} warriors",f"and Saxon army: {len(war_instance.saxonArmy)} warriors")
print(war_instance.showStatus())
round += 1