-
Notifications
You must be signed in to change notification settings - Fork 1
/
Organism.py
324 lines (227 loc) · 10.5 KB
/
Organism.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
from abc import ABC, abstractmethod
from ManaType import mana_indexes, mana_types, mana_colors
from Drawable import Drawable
class Organism(Drawable, ABC):
def __init__(self, name, ability_description, mana_to_activate_ability, mana_type_index, evolution):
self.name = name
self.ability_description = ability_description
self.mana_to_activate_ability = mana_to_activate_ability
self.mana_type_index = mana_type_index
self.mana_type = mana_types[mana_type_index]
self.num_mana = 0
self.evolution = evolution
self.game = None
def __str__(self):
return self.name
def draw(self):
mana_str = ('+' * self.num_mana) + ('-' * (self.mana_to_activate_ability - self.num_mana))
return f"{mana_colors[self.mana_type_index]}{self.name} ({self.mana_type_index}): {mana_str} \u001b[0m"
def evolve(self):
evolved_organism = self.evolution()
evolved_organism.num_mana = self.num_mana
evolved_organism.game = self.game
return evolved_organism
@abstractmethod
def ability(self):
pass
def change_num_mana(self, delta):
# Clamping mana
prev_mana = self.num_mana
self.num_mana = min(max(0, delta + self.num_mana), self.mana_to_activate_ability)
# Returning the amount change in mana
return abs(self.num_mana - prev_mana)
def add_game_reference_to_objects(self, game):
self.game = game
class Bonzire(Organism):
def __init__(self):
super().__init__("Bonzire", 'Flare+: Attacks for 25 HP and matches 2 random columns.', 8, mana_indexes['fire'], None)
def ability(self):
self.game.next_player.change_HP(-25)
self.game.grid.force_grid_match([-1, 1, 2])
class Bonzumi(Organism):
def __init__(self):
super().__init__("Bonzumi", 'Flare: Attacks for 20 HP and matches 1 random columns.', 8, mana_indexes['fire'], Bonzire)
def ability(self):
self.game.next_player.change_HP(-20)
self.game.grid.force_grid_match([-1, 1, 1])
class Sephanix(Organism):
def __init__(self):
super().__init__("Sephanix", 'Hydro Rush+: Attacks for 20 HP and converts 3 random tiles to Water.', 6, mana_indexes['water'], None)
def ability(self):
self.game.next_player.change_HP(-20)
self.game.grid.convert_tiles(self.mana_type_index, 3)
class Pelijet(Organism):
def __init__(self):
super().__init__("Pelijet", 'Hydro Rush: Attacks for 10 HP and converts 2 random tiles to Water.', 6, mana_indexes['water'], Sephanix)
def ability(self):
self.game.next_player.change_HP(-10)
self.game.grid.convert_tiles(self.mana_type_index, 2)
class Karaggon(Organism):
def __init__(self):
super().__init__("Karaggon", 'Heal Leaf+: Attacks for 15 HP and heals you for 15 HP.', 6, mana_indexes['grass'], None)
def ability(self):
self.game.next_player.change_HP(-15)
self.game.curr_player.change_HP(15)
class Turtleisk(Organism):
def __init__(self):
super().__init__("Turtleisk", 'Heal Leaf: Attacks for 10 HP and heals you for 10 HP.', 6, mana_indexes['grass'], Karaggon)
def ability(self):
self.game.next_player.change_HP(-10)
self.game.curr_player.change_HP(10)
class Axelraze(Organism):
def __init__(self):
super().__init__("Axelraze", 'Electroclaw+: Attacks for 10 HP and matches a random 3x2 grid.', 4, mana_indexes['electric'], None)
def ability(self):
self.game.next_player.change_HP(-10)
self.game.grid.force_grid_match([3, 2, 1])
class Slickitty(Organism):
def __init__(self):
super().__init__("Slickitty", 'Electroclaw: Attacks for 5 HP and matches a random 2x2 grid.', 4, mana_indexes['electric'], Axelraze)
def ability(self):
self.game.next_player.change_HP(-5)
self.game.grid.force_grid_match([2, 2, 1])
class Scoprikon(Organism):
def __init__(self):
super().__init__("Scoprikon", "Psycho Bite+: Attacks for 15 HP and drains 3 Mana from opponent's monsters.", 6, mana_indexes['psychic'], None)
def ability(self):
self.game.next_player.change_HP(-15)
for organism in self.game.next_player.organisms:
organism.change_num_mana(-3)
class Barbenin(Organism):
def __init__(self):
super().__init__("Barbenin", "Psycho Bite: Attacks for 10 HP and drains 2 Mana from opponent's monsters.", 6, mana_indexes['psychic'], Scoprikon)
def ability(self):
self.game.next_player.change_HP(-10)
for organism in self.game.next_player.organisms:
organism.change_num_mana(-2)
class Magnooki(Organism):
def __init__(self):
super().__init__("Magnooki", 'Pyro Blitz+: Attacks for 35 HP and matches a random row.', 10, mana_indexes['fire'], None)
def ability(self):
self.game.next_player.change_HP(-35)
self.game.grid.force_grid_match([1, -1, 1])
class Pyrokun(Organism):
def __init__(self):
super().__init__("Pyrokun", 'Pyro Blitz: Attacks for 25 HP and matches a random row.', 10, mana_indexes['fire'], Magnooki)
def ability(self):
self.game.next_player.change_HP(-25)
self.game.grid.force_grid_match([1, -1, 1])
class Shardivore(Organism):
def __init__(self):
super().__init__("Shardivore", 'Aqua Blast+: Attacks for 25 HP and converts 3 random tiles to Water.', 10, mana_indexes['water'], None)
def ability(self):
self.game.next_player.change_HP(-25)
self.game.grid.convert_tiles(self.mana_type_index, 3)
class Trashark(Organism):
def __init__(self):
super().__init__("Trashark", 'Aqua Blast: Attacks for 20 HP and converts 2 random tiles to Water.', 10, mana_indexes['water'], Shardivore)
def ability(self):
self.game.next_player.change_HP(-20)
self.game.grid.convert_tiles(self.mana_type_index, 2)
class TurnEndEvent(ABC):
def __init__(self, max_num_turns_active, game):
self.curr_num_turns_active = 0
self.max_num_turns_active = max_num_turns_active
self.game = game
# Caching the players, cause current and next player switch around
self.curr_player = self.game.curr_player
self.next_player = self.game.next_player
self.subscribed = True
def act(self):
# Unsubscribing the event
self.curr_num_turns_active += 1
if self.curr_num_turns_active == self.max_num_turns_active:
self.subscribed = False
class FlowerDance(TurnEndEvent):
def __init__(self, max_num_turns_active, game, heal, damage):
super().__init__(max_num_turns_active, game)
self.heal = heal
self.damage = damage
def act(self):
self.next_player.change_HP(self.damage)
self.curr_player.change_HP(self.heal)
super().act()
class Eidelf(Organism):
def __init__(self):
super().__init__("Eidelf", 'Flower Dance+: Attacks for 5 HP and heals 10 HP at the end of the turn for two turns.', 6, mana_indexes['grass'], None)
def ability(self):
self.game.turn_end_events.append(FlowerDance(2, self.game, 5, -10))
class Elfini(Organism):
def __init__(self):
super().__init__("Elfini", 'Flower Dance: Attacks for 5 HP and heals 5 HP at the end of the turn for two turns.', 6, mana_indexes['grass'], Eidelf)
def ability(self):
self.game.turn_end_events.append(FlowerDance(2, self.game, 5, -5))
class Starblitz(TurnEndEvent):
def act(self):
if self.curr_num_turns_active == 1:
self.curr_player.moves += 1
super().act()
class Gleamur(Organism):
def __init__(self):
super().__init__("Gleamur", 'Starblitz+: Attacks for 15 HP and grants 1 extra move in the next turn.', 6, mana_indexes['electric'], None)
def ability(self):
self.game.next_player.change_HP(-15)
self.game.turn_end_events.append(Starblitz(2, self.game))
class Winklit(Organism):
def __init__(self):
super().__init__("Winklit", 'Starblitz: Attacks for 10 HP and grants 1 extra move in the next turn.', 6, mana_indexes['electric'], Gleamur)
def ability(self):
self.game.next_player.change_HP(-10)
self.game.turn_end_events.append(Starblitz(2, self.game))
class Flambagant(Organism):
def __init__(self):
super().__init__("Flambagant", 'Hugs+: Attacks for 15 HP and gives 3 mana to your other monster.', 6, mana_indexes['fire'], None)
def ability(self):
self.game.next_player.change_HP(-15)
index_of_self = self.game.curr_player.organisms.index(self)
self.game.curr_player.organisms[(index_of_self+1) % 2].change_num_mana(3)
class Timingo(Organism):
def __init__(self):
super().__init__("Timingo", 'Hugs: Attacks for 10 HP and gives 2 mana to your other monster.', 6, mana_indexes['fire'], Flambagant)
def ability(self):
self.game.next_player.change_HP(-10)
index_of_self = self.game.curr_player.organisms.index(self)
self.game.curr_player.organisms[(index_of_self+1) % 2].change_num_mana(2)
class Bandicrook(Organism):
def __init__(self):
super().__init__("Bandicrook", 'Pickpocket+: Attacks for 10 HP and steals up to 2 berries and 2 mana.', 6, mana_indexes['psychic'], None)
def ability(self):
self.game.next_player.change_HP(-10)
num_stolen_berries = min(0, self.game.next_player.num_berries - 2) + 2
self.game.curr_player.change_num_berries(num_stolen_berries)
self.game.next_player.change_num_berries(-num_stolen_berries)
organism_to_steal_mana_from = max(self.game.next_player.organisms, key=lambda x: x.num_mana)
num_mana_stolen = min(0, organism_to_steal_mana_from.num_mana - 2) + 2
self.change_num_mana(num_mana_stolen)
organism_to_steal_mana_from.change_num_mana(-num_mana_stolen)
class Criminook(Organism):
def __init__(self):
super().__init__("Criminook", 'Pickpocket: Attacks for 10 HP and steals up to 2 berries and 1 mana.', 6, mana_indexes['psychic'], Bandicrook)
def ability(self):
self.game.next_player.change_HP(-10)
num_stolen_berries = min(0, self.game.next_player.num_berries - 2) + 2
self.game.curr_player.change_num_berries(num_stolen_berries)
self.game.next_player.change_num_berries(-num_stolen_berries)
organism_to_steal_mana_from = max(self.game.next_player.organisms, key=lambda x: x.num_mana)
num_mana_stolen = min(0, organism_to_steal_mana_from.num_mana - 1) + 1
self.change_num_mana(num_mana_stolen)
organism_to_steal_mana_from.change_num_mana(-num_mana_stolen)
class Punish(TurnEndEvent):
def act(self):
if self.curr_num_turns_active >= 1:
if self.game.curr_player == self.curr_player:
self.curr_player.moves -= 1
super().act()
class Wreckore(Organism):
def __init__(self):
super().__init__("Wreckore", 'Punish+: Attacks for 45 HP but loses 1 move for the next 2 turns.', 10, mana_indexes['water'], None)
def ability(self):
self.game.next_player.change_HP(-45)
self.game.turn_end_events.append(Punish(4, self.game))
class Nerverack(Organism):
def __init__(self):
super().__init__("Nerverack", 'Punish: Attacks for 35 HP but loses 1 move for the next 1 turn.', 10, mana_indexes['water'], Wreckore)
def ability(self):
self.game.next_player.change_HP(-35)
self.game.turn_end_events.append(Punish(2, self.game))
stage_1_organisms = [Bonzumi(), Pelijet(), Turtleisk(), Slickitty(), Barbenin(), Pyrokun(), Trashark(), Elfini(), Winklit(), Timingo(), Criminook(), Nerverack()]