forked from ironhack-labs/mini-project-vikings-en
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvikingsClasses.py
More file actions
189 lines (170 loc) · 5.86 KB
/
vikingsClasses.py
File metadata and controls
189 lines (170 loc) · 5.86 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import random
# Soldier
class Soldier:
def __init__(self, health, strength):
"""
Initialize Soldier properties.
Args:
healt (int): soldier health
strength (int): soldier strength
"""
self.health = health
self.strength = strength
def attack(self):
"""
Returns the Soldier's Strength.
Args:
no arguments
"""
return self.strength
def receiveDamage(self, damage):
"""
Set Soldier received damage.
Args:
damage (int): receive damage by the soldier
"""
self.health -= damage
# Viking Class - inheritance from Soldier
class Viking(Soldier):
def __init__(self, name, health, strength):
"""
Initialize the viking soldier properties.
Args:
name (str): viking name
healt (int): soldier health
strength (int): soldier strength
"""
super().__init__(health, strength) #taking the things from PARENT class
self.name = name
def battleCry(self):
"""
Return the Viking Yahl Message.
Args:
no arguments
Return:
string
"""
return "Odin Owns You All!"
def receiveDamage(self, damage):
"""
Return the Viking Yahl Message.
Args:
damage (int): damage received by the viking
Return:
string message
"""
super().receiveDamage( 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 Class - inheritance from Soldier
class Saxon(Soldier):
def __init__(self, health, strength):
"""
Initialize the saxon soldier properties.
Args:
healt (int): soldier health
strength (int): soldier strength
"""
super().__init__(health, strength) #taking the things from PARENT class
def receiveDamage(self, damage):
"""
Return the Saxon battle message.
Args:
damage (int): damage received by the viking
Return:
string message
"""
super().receiveDamage( 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):
"""
Initialize the War armies
vikingArmy (Viking): list of Vikings
saxonArmy (Saxon): list of Saxons
Args:
no arguments
"""
self.vikingArmy = []
self.saxonArmy = []
def addViking(self, viking):
"""
Add Vikings to Viking Army List
Args:
viking (object): viking object (name, health, strength)
"""
self.vikingArmy.append(viking)
def addSaxon(self, saxon):
"""
Add Saxon to Saxon Army List
Args:
saxon (object): saxon object (health, strength)
"""
self.saxonArmy.append(saxon)
def vikingAttack(self):
"""
Realize a Viking Attack
Args:
no arguments
Returns:
string (str): Saxon Army status and/or Saxon soldier damage status (Viking or Saxon)
"""
if not self.saxonArmy:
return self.showStatus()
elif not self.vikingArmy:
return "Viking Army not have soldiers!" # Optional: for testing
else:
# Randon selection for the Saxon and the Viking
# saxon = random.randrange(len(self.saxonArmy)) # random.choice(
# viking = random.randrange(len(self.vikingArmy))
saxon = random.choice(self.saxonArmy)
viking = random.choice(self.vikingArmy)
# attack the Saxon
# attack_result_msg = self.saxonArmy[saxon].receiveDamage( self.vikingArmy[viking].attack())
attack_result_msg = saxon.receiveDamage( viking.attack() )
# Remove the Saxon from the Saxon Army if die
if saxon.health <= 0:
self.saxonArmy.remove(saxon)
return attack_result_msg
def saxonAttack(self):
"""
Realize a Saxon Attack
Args:
no arguments
Returns:
string (str): Viking Army status and/or Viking soldier damage status (Viking or Saxon)
"""
if not self.vikingArmy:
return self.showStatus() # No more vikings
elif not self.saxonArmy:
return "Saxon Army not have soldiers!" # Optional: for testing
else:
# Randon selection for the Saxon and the Viking
saxon = random.choice(self.saxonArmy)
viking = random.choice(self.vikingArmy)
# attack the Viking
attack_result_msg = viking.receiveDamage(saxon.attack())
# Remove the Viking from the Viking Army if die
if viking.health <= 0:
self.vikingArmy.remove(viking)
return attack_result_msg
def showStatus(self):
"""
Return the Army Status
Args:
no arguments
Returns:
string (str): Army status (Viking or Saxon)
"""
if not self.saxonArmy:
return "Vikings have won the war of the century!"
elif not self.vikingArmy:
return "Saxons have fought for their lives and survive another day..."
elif self.vikingArmy and self.saxonArmy:
return "Vikings and Saxons are still in the thick of battle."