forked from Infantdebil/mini-project-vikings-en
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvikingsClasses.py
99 lines (75 loc) · 2.78 KB
/
vikingsClasses.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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 = self.health - damage
return None
# Viking
class Viking(Soldier):
def __init__(self, name, health, strength):
self.name = name
self.health = health
self.strength = strength
def battleCry(self):
return "Odin Owns You All!" # maybe print?
def receiveDamage(self, damage):
self.health = self.health - damage
if self.health <= 0:
return f"{self.name} has died in act of combat"
elif self.health > 0:
return f"{self.name} has received {damage} points of damage"
# Saxon
class Saxon(Soldier):
def __init__(self, health, strength):
self.health = health
self.strength = strength
def receiveDamage(self, damage):
self.health = self.health - damage
if self.health <= 0:
return "A Saxon has died in combat"
elif self.health > 0:
return f"A Saxon has received {damage} points of damage"
# Davicente
class War():
def __init__(self):
self.vikingArmy = []
self.saxonArmy = []
def addViking(self, viking):
self.vikingArmy.append(viking)
return None
def addSaxon(self, saxon):
self.saxonArmy.append(saxon)
return None
def vikingAttack(self):
saxon = random.choice(self.saxonArmy)
viking = random.choice(self.vikingArmy)
damage = saxon.receiveDamage(viking.strength)
if saxon.health <= 0:
self.saxonArmy.remove(saxon)
return damage
def saxonAttack(self):
saxon = random.choice(self.saxonArmy)
viking = random.choice(self.vikingArmy)
damage = viking.receiveDamage(saxon.strength)
if viking.health <= 0:
self.vikingArmy.remove(viking)
return damage
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."
Returns the current status of the War based on the size of the armies.
should be a function
should receive 0 arguments
if the Saxon array is empty, should return "Vikings have won the war of the century!"
if the Viking array is empty, should return "Saxons have fought for their lives and survive another day..."
if there are at least 1 Viking and 1 Saxon, should return "Vikings and Saxons are still in the thick of battle."
"""