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
99 changes: 92 additions & 7 deletions vikingsClasses.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,109 @@

import random
# Soldier


class Soldier:
pass
def __init__(self, health, strength):
self.strength = strength
self.health = health

def attack(self):
return self.strength

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

# Viking


class Viking:
pass
class Viking(Soldier):
def __init__ (self, name, health, strength):
self.name = name
self.health = health
self.strength = strength

def attack(self):
return self.strength

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

if self.health > 0:
return f"{self.name} has received {self.thedamage} points of damage"
else:
return f"{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):
self.health = health
self.strength = strength

def attack(self):
return self.strength

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

if self.health > 0:
return f"A Saxon has received {self.thedamage} points of damage"
else:
return "A Saxon has died in combat"


# War


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):
randomsaxon = random.choice(self.saxonArmy)
randomviking = random.choice(self.vikingArmy)

damage_viking = randomsaxon.receiveDamage(randomviking.strength)

if randomsaxon.health <= 0:
self.saxonArmy.remove(randomsaxon)

return damage_viking


def saxonAttack(self):
randomsaxon = random.choice(self.saxonArmy)
randomviking = random.choice(self.vikingArmy)

damage_saxon = randomviking.receiveDamage(randomsaxon.strength)

if randomviking.health <= 0:
self.vikingArmy.remove(randomviking)

return damage_saxon

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..."
else:
return "Vikings and Saxons are still in the thick of battle."