Skip to content
Open
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
92 changes: 85 additions & 7 deletions vikingsClases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,100 @@


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):
self.name = name
super().__init__(health, strength)

def attack(self):
return super().attack()

def receiveDamage(self, damage):
self.health -= damage

if self.health > 0:
return self.name + " has received " + str(damage) + " points of damage"
else:
return self.name + " has died in act of combat"

def battleCry(self):
return "Odin Owns You All!"

# Saxon


class Saxon:
pass
class Saxon(Soldier):

def __init__(self, health, strength):
super().__init__(health, strength)

# War
def attack(self):
return super().attack()

def receiveDamage(self, damage):
self.health -= damage

if self.health > 0:
return "A Saxon has received " + str(damage) + " points of damage"
else:
return "A Saxon has died in combat"


# War

import random
class War:
pass

def __init__(self):
self.vikingArmy = []
self.saxonArmy = []

def addViking(self, viking):
self.vikingArmy.append(viking)


def addSaxon(self, saxon):
self.saxonArmy.append(saxon)

def vikingAttack(self):
viking = random.choice(self.vikingArmy)
saxon = random.choice(self.saxonArmy)
result_v = saxon.receiveDamage(viking.attack())
if saxon.health <= 0:
self.saxonArmy.remove(saxon)
return result_v


def saxonAttack(self):
viking = random.choice(self.vikingArmy)
saxon = random.choice(self.saxonArmy)
result_s = viking.receiveDamage(saxon.attack())
if viking.health <= 0:
self.vikingArmy.remove(viking)
return result_s

def showStatus(self):
if len(self.vikingArmy) == 0:
return "Saxons have fought for their lives and survive another day..."
elif len(self.saxonArmy) == 0:
return "Vikings have won the war of the century!"
else:
return "Vikings and Saxons are still in the thick of battle."