Skip to content
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Lab | Vikings (lab-data-vikings)


## Introduction

The Vikings and the Saxons are at War. Both are Soldiers but they have their own methods to fight. Vikings are ported to Python. YAY!!
Expand Down
1 change: 1 addition & 0 deletions battle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Hacer una batalla entre vikingos: un projecto bonito.
86 changes: 81 additions & 5 deletions vikingsClases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,98 @@


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 attack(self):
# super().attack()

def receiveDamage(self, damage):
super().receiveDamage(damage)
if self.health > 0:
return "".join([self.name," has received ",str(damage)," points of damage"])
else:
return "".join([self.name," has died in act of combat"])

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


# Saxon


class Saxon:
class Saxon(Soldier):
def __init__(self, health, strength):
super().__init__(health, strength)

def receiveDamage(self, damage):
super().receiveDamage(damage)
if self.health > 0:
return "".join(["A Saxon has received ",str(damage)," points of damage"])
else:
return "A Saxon has died in combat"

pass

# 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):
vikingAttacker = random.choice(self.vikingArmy)
dmg = vikingAttacker.attack()
saxonVictim = random.choice(self.saxonArmy)
result = saxonVictim.receiveDamage(dmg)
if saxonVictim.health <= 0:
self.saxonArmy.remove(saxonVictim)
return result

#victimIndex = random.randint(0,sum(len(self.vikingArmy),-1))
#result = self.saxonArmy[victimIndex].receiveDamage(dmg)
#if result == "A Saxon has died in combat":
#saxonArmy.remove(saxonArmy[victimIndex])
#return result
pass
def saxonAttack(self):
saxonAttacker = random.choice(self.saxonArmy)
dmg = saxonAttacker.attack()
vikingVictim = random.choice(self.vikingArmy)
result = vikingVictim.receiveDamage(dmg)
if vikingVictim.health <= 0:
self.vikingArmy.remove(vikingVictim)
return result

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