Skip to content

queralt - #16

Open
queraltic wants to merge 1 commit into
Ironhack-data-bcn-oct-2022:mainfrom
queraltic:main
Open

queralt#16
queraltic wants to merge 1 commit into
Ironhack-data-bcn-oct-2022:mainfrom
queraltic:main

Conversation

@queraltic

Copy link
Copy Markdown

No description provided.

@ta-data-bcn

Copy link
Copy Markdown

Well done on the lab. I saw your TA comment; here's some help for the war class:

  • start by initializing the class (add armies on both sides)
  • then actually add the armies
  • write functions that will use the attack function you already wrote and apply the damage to your armies and read that, removing dead soldiers from your armies

Review this code just to familiarize yourself, but don't worry about writing it.
`class War:

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

    damage_recieved = random_saxon.receiveDamage(random_viking.attack())

    self.saxonArmy = [saxon for saxon in self.saxonArmy if saxon.health > 0]

    return damage_recieved


def saxonAttack(self):
    random_saxon = random.choice(self.saxonArmy)
    random_viking = random.choice(self.vikingArmy)

    damage_recieved = random_viking.receiveDamage(random_saxon.attack())

    self.vikingArmy = [viking for viking in self.vikingArmy if viking.health > 0]

    return damage_recieved


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..."
    elif self.saxonArmy != [] and self.vikingArmy !=[]: 
        return "Vikings and Saxons are still in the thick of battle."`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants