-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_troops.py
223 lines (182 loc) · 6.05 KB
/
test_troops.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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
from troop import Troop, Archer, Assassin, Magician, Turret, Engineer, Shield
from hexagon import Hexagone, Sand
from game import Game
import pygame
def test___init__():
hex = Hexagone("None", 10, 15)
troop = Troop("None", hex)
assert troop.troop_type == "None"
assert troop.hex == hex
assert troop.hex.occupied
assert troop.health == 0
assert troop.attack_capacity == 0
assert troop.attack_power == 0
assert troop.status == "none"
assert troop.default_speed == 0
assert troop.speed == 0
assert troop.attack_range == 0
assert troop.rect == pygame.Rect(troop.hex.x - 10, troop.hex.y - 10, 20, 20)
assert not troop.selected
def test___init__Archer():
hex = Hexagone("None", 10, 15)
troop = Archer(hex)
assert troop.troop_type == "archer"
assert troop.hex == hex
assert troop.health == 100
assert troop.attack_capacity == 1
assert troop.attack_power == 20
assert troop.status == "none"
assert troop.default_speed == 5
assert troop.speed == 5
assert troop.attack_range == 2
assert troop.rect == pygame.Rect(troop.hex.x - 10, troop.hex.y - 10, 20, 20)
assert not troop.selected
assert troop.player == "defender"
def test___init__Assassin():
hex = Hexagone("None", 10, 15)
troop = Assassin(hex)
assert troop.troop_type == "assassin"
assert troop.hex == hex
assert troop.health == 100
assert troop.attack_capacity == 1
assert troop.attack_power == 20
assert troop.status == "none"
assert troop.default_speed == 5
assert troop.speed == 5
assert troop.attack_range == 1
assert troop.rect == pygame.Rect(troop.hex.x - 10, troop.hex.y - 10, 20, 20)
assert not troop.selected
assert troop.player == "attacker"
def test___init__Magician():
hex = Hexagone("None", 10, 15)
troop = Magician(hex)
assert troop.troop_type == "magician"
assert troop.hex == hex
assert troop.health == 200
assert troop.attack_capacity == 1
assert troop.attack_power == 50
assert troop.status == "none"
assert troop.default_speed == 3
assert troop.speed == 3
assert troop.attack_range == 2
assert troop.rect == pygame.Rect(troop.hex.x - 10, troop.hex.y - 10, 20, 20)
assert not troop.selected
assert troop.player == "attacker"
def test___init__Turret():
hex = Hexagone("None", 10, 15)
troop = Turret(hex)
assert troop.troop_type == "turret"
assert troop.hex == hex
assert troop.health == 500
assert troop.attack_capacity == 1
assert troop.attack_power == 100
assert troop.status == "none"
assert troop.default_speed == 1
assert troop.speed == 1
assert troop.attack_range == 3
assert troop.rect == pygame.Rect(troop.hex.x - 10, troop.hex.y - 10, 20, 20)
assert not troop.selected
assert troop.player == "attacker"
def test___init__Engineer():
hex = Hexagone("None", 10, 15)
troop = Engineer(hex)
assert troop.troop_type == "engineer"
assert troop.hex == hex
assert troop.health == 200
assert troop.attack_capacity == 1
assert troop.attack_power == 50
assert troop.status == "none"
assert troop.default_speed == 3
assert troop.speed == 3
assert troop.attack_range == 1
assert troop.rect == pygame.Rect(troop.hex.x - 10, troop.hex.y - 10, 20, 20)
assert not troop.selected
assert troop.player == "defender"
def test___init__Shield():
hex = Hexagone("None", 10, 15)
troop = Shield(hex)
assert troop.troop_type == "shield"
assert troop.hex == hex
assert troop.health == 500
assert troop.attack_capacity == 1
assert troop.attack_power == 100
assert troop.status == "none"
assert troop.default_speed == 1
assert troop.speed == 1
assert troop.attack_range == 1
assert troop.rect == pygame.Rect(troop.hex.x - 10, troop.hex.y - 10, 20, 20)
assert not troop.selected
assert troop.player == "defender"
def test_move():
game = Game(2, 2)
game.generate()
game.board.list[0].accessible = True
game.board.list[1].accessible = True
hex1 = game.board.list[0]
hex2 = game.board.list[1]
troop = Troop("None", hex1)
troop.speed = 5
troop.action(hex2, game)
assert troop.hex == hex2
assert troop.speed < 5
assert troop.hex.occupied
assert not hex1.occupied
hex1.occupied = True
speed_aux = troop.speed
troop.action(hex1, game)
assert troop.hex == hex2
assert troop.speed == speed_aux
assert troop.hex.occupied
hex1.occupied = False
troop.speed = 0
troop.action(hex1, game)
assert troop.hex == hex2
assert troop.speed == 0
assert troop.hex.occupied
assert not hex1.occupied
troop.speed = 5
hex2.toSand()
troop.action(hex1, game)
assert troop.hex == hex1
assert troop.speed == 3
assert troop.hex.occupied
assert not hex2.occupied
troop.speed = 1
hex1.toSand()
troop.action(hex2, game)
assert troop.hex == hex1
assert troop.speed == 1
assert troop.hex.occupied
assert not hex2.occupied
def test_attack():
game = Game(2, 2)
game.generate()
hex1 = game.board.list[0]
hex2 = game.board.list[1]
game.board.list[0].accessible = True
game.board.list[1].accessible = True
troop1 = Archer(hex1)
troop2 = Assassin(hex2)
troop1.attack(troop2, 1, game)
assert troop2.health == 80
assert troop1.attack_capacity == 0
troop1.attack(troop2, 4, game)
assert troop2.status == "dead"
def test_is_troop_allowed_to_strike():
game = Game(3, 3)
game.generate()
for hex in game.board.list:
hex.toBasic()
troop2 = Archer(game.board.list[0])
troop1 = Assassin(game.board.list[1])
troop3 = Magician(game.board.list[8])
assert troop1.is_troop_allowed_to_strike(troop2, game)
assert not troop1.is_troop_allowed_to_strike(troop3, game)
troop1.attack_capacity = 0
assert not troop1.is_troop_allowed_to_strike(troop2, game)
def test_eliminated():
troop = Assassin(Sand(10, 15))
troop.eliminated()
assert troop.hex is None
assert troop.rect is None
assert troop.status == "dead"