forked from ironhack-labs/mini-project-vikings-en
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vikingsClasses.py
123 lines (91 loc) · 3.72 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import random
# Soldier
class Soldier:
def __init__(self, health, strength):
self.health = health
self.strength = strength
# Method for soldier attach
def attack(self):
return self.strength
# Method for soldier receiving damage:
def receiveDamage(self, damage):
self.health -= damage
# Viking
class Viking(Soldier):
def __init__(self, name, health, strength):
super().__init__(health, strength)
self.name = name
# Method for battle cry
def battleCry(self):
return "Odin Owns You All!"
# Method for viking receiving damage. Prints i) damage if alive ii) dead of viking
def receiveDamage(self, damage):
if damage < self.health:
self.health -= damage
return f"{self.name} has received {damage} points of damage"
else:
self.health -= damage
return f"{self.name} has died in act of combat"
# Method for Viking attack
def attack(self):
# Call the function attack from Mother Class Soldier
return super().attack()
# Saxon
class Saxon(Soldier):
def __init__(self, health, strength):
super().__init__(health, strength)
# Method for Saxon receiving damage. Prints i) damage if alive ii) dead of Saxon
def receiveDamage(self, damage):
if damage < self.health:
self.health -= damage
return f"A Saxon has received {damage} points of damage"
else:
self.health -= damage
return f"A Saxon has died in combat"
# Method for Saxon attack
def attack(self):
# Call the function attack from Mother Class Soldier
return super().attack()
# War
class War():
# Initiates the War with an empty Viking Army and empty Saxon Army
def __init__(self):
self.vikingArmy = []
self.saxonArmy = []
# Method to add 1 Viking to the vikingArmy
def addViking(self, Viking):
self.vikingArmy.append(Viking)
# Method to add 1 Saxon to the saxonArmy
def addSaxon(self, Saxon):
self.saxonArmy.append(Saxon)
def vikingAttack(self):
# Choosing a random Saxon from saxonArmy
random_saxon = random.choice(self.saxonArmy)
# Choosing a random Viking from vikingArmy
random_viking = random.choice(self.vikingArmy)
# Random Saxon receiving damage = random Viking strength
random_saxon_health=random_saxon.receiveDamage(random_viking.strength)
# Remove saxon from list if health=0
if random_saxon.health <= 0:
self.saxonArmy.remove(random_saxon)
# Retorna o resultado de receiveDamage() of a Saxon with the strength of a Viking
return random_saxon_health
def saxonAttack(self):
# Choosing a random Saxon from saxonArmy
random_saxon = random.choice(self.saxonArmy)
# Choosing a random Viking from vikingArmy
random_viking = random.choice(self.vikingArmy)
# Random Viking receiving damage = random Saxon strength
random_viking_health=random_viking.receiveDamage(random_saxon.strength)
# Remove viking from list if health=0
if random_viking.health <= 0:
self.vikingArmy.remove(random_viking)
# Retorna o resultado de receiveDamage() of a Saxon with the strength of a Viking
return random_viking_health
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..."
else:
return "Vikings and Saxons are still in the thick of battle."