/
GameManager.py
78 lines (65 loc) · 2.44 KB
/
GameManager.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
import MimicArea, Mimic, AttackController, MusicController
import random
class GameManager(object):
def __init__(self, game_area):
width = 500
height = 500
cols = 3
rows = 3
self.mimic_area = MimicArea.MimicArea(
(game_area[0]/2)-(width/2),
(game_area[1]/2)-(height/2),
width,
height,
rows,
cols
)
self.music_controller = MusicController.MusicController()
self.mimic = Mimic.Mimic(self.mimic_area.cells[0])
self.attack_controller = AttackController.AttackController()
self.is_game_over = False
self.is_paused = False
self.game_active = False
self.points = 0
def get_neighbor_cell(self, direction):
current_cell = self.mimic.cell
return self.mimic_area.find_neighbor_cell(current_cell, direction)
def get_cell_for_attack(self):
# only get cells that are not currently under attack
available_cells = list(filter(
lambda x: x not in self.attack_controller.get_active_cells(),
self.mimic_area.cells
))
# the cell with the mimic should have a higher chance of being the attacked cell
mimic_cell = self.mimic.cell
available_cells.append(mimic_cell)
available_cells.append(mimic_cell)
available_cells.append(mimic_cell)
# choose randomly from the full list
cell_nr = random.randint(0, len(available_cells)-1)
return available_cells[cell_nr]
def check_mimic_collisions(self):
deadly_attacks = list(filter(lambda x: getattr(x, "is_deadly") == True, self.attack_controller.active_attacks))
for attack in deadly_attacks:
if self.mimic.cell.get_rect() == attack.get_rect():
self.is_game_over = True
self.music_controller.stop_music()
else:
self.add_points(10)
def add_points(self, amount):
self.points += amount
def start(self):
self.game_active = True
self.music_controller.start()
def __pause(self):
self.is_paused = True
self.music_controller.pause()
def __resume(self):
self.is_paused = False
self.music_controller.start()
def toggle_pause(self):
if not self.is_game_over:
if self.is_paused:
self.__resume()
else:
self.__pause()