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

finish Vikings mini Porject #17

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
2 changes: 1 addition & 1 deletion 1-testsSoldier.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def testHealth(self):
self.assertEqual(self.soldier.health, self.health)

def testStrength(self):
self.assertEqual(self.soldier.strength, self.strength)
self.assertEqual(self.soldier.strenght, self.strength)

def testAttackShouldBeFunction(self):
self.assertEqual(callable(self.soldier.attack), True)
Expand Down
Empty file modified 2-testsVikings.py
100644 → 100755
Empty file.
Empty file modified 3-testsSaxons.py
100644 → 100755
Empty file.
Empty file modified 4-testsWar.py
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ So, let's say you have already created the class for Soldiers.
3. In your terminal, run the test file for that class

```bash
$ python3 1-testSoldier.py --v
$ python3 1-testsSoldier.py --v
```

### Correct Test
Expand Down
Binary file added __pycache__/vikingsClasses.cpython-312.pyc
Binary file not shown.
168 changes: 85 additions & 83 deletions vikingsClasses.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,83 +1,85 @@
import random

# Soldier


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

def attack(self):
# your code here

def receiveDamage(self, damage):
# your code here


# Viking

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

def battleCry(self):
# your code here

def receiveDamage(self, damage):
# your code here

# Saxon

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

def receiveDamage(self, damage):
# your code here

# Davicente

class War():
def __init__(self):
# your code here

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

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

def vikingAttack(self):
# your code here

def saxonAttack(self):
# your code here

def showStatus(self):
# your code here
pass

#yop
class War2:

def __init__(self):
# your code here

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

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

def vikingAttack(self):
# your code here

def saxonAttack(self):
# your code here

def showStatus(self):
# your code here

pass


import random

# Soldier


class Soldier:
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 - this inherits from the soldier and has a name parameter,. Also has a battleCry() method and receiveDamage() method that provies custom input

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

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

def receiveDamage(self, damage):
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 - inherits from the soldier , has no name parameter nut also a receiveDamage() methood that outpouts a custom message

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

def receiveDamage(self, damage):
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):
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 = saxon.receiveDamage(viking.strength)
if saxon.health <= 0:
self.saxonArmy.remove(saxon)
return result

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

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."


Empty file modified wargame.py
100644 → 100755
Empty file.