Skip to content

Commit a667cef

Browse files
authored
Merge pull request #14 from Fenigor/score_system
Score system
2 parents fe77f1a + 2337467 commit a667cef

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

game.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ def setup_game(self, next_colors):
7272
SCREEN.fill(BLACK)
7373
self.draw_future_grid(next_colors)
7474
self.draw_grid(True)
75-
# self.load_score()
75+
self.load_score()
7676
# self.colored_grid()
77+
# self.load_space()
7778

7879
def main(self):
7980
next_colors = [rand_color() for _ in range(3)]
@@ -94,6 +95,7 @@ def main(self):
9495
self.handle_mouse_click()
9596
self.handle_selected_square()
9697
self.score()
98+
self.movesmade()
9799
pygame.display.update()
98100

99101
def handle_mouse_click(self):
@@ -198,6 +200,13 @@ def score(self):
198200
SCREEN.fill(BLACK, (470, 10, 130, 30))
199201
SCREEN.blit(img, (470, 10))
200202

203+
def movesmade(self):
204+
img = self.text_font.render(
205+
f'Moves made: {self.moves_made}', True, WHITE,
206+
)
207+
SCREEN.fill(BLACK, (200, 10, 230, 30))
208+
SCREEN.blit(img, (200, 10))
209+
201210
def draw_predicted(self, next_colors):
202211
placed = 0
203212
future_square_cord_color = []
@@ -261,9 +270,9 @@ def find_adjacent_color(self, x_y, color):
261270
x += dir_x
262271
y += dir_y
263272
try:
264-
color_org = self.sqr_grid[org_x][org_y].color
273+
color = self.sqr_grid[org_x][org_y].color
265274
color_adj = self.sqr_grid[x][y].color
266-
is_same_color = color_org == color_adj
275+
is_same_color = color == color_adj
267276
is_taken = self.space[x][y] == 1
268277
if is_taken and is_same_color:
269278
if x < 0 or y < 0:
@@ -323,19 +332,24 @@ def save_score(self):
323332
file.write(str(self.sqr_grid) + '\n')
324333
file.write(f'{str(self.future_square_cord_color),} \n')
325334

326-
# def load_score(self):
335+
def load_score(self):
336+
with open('score.txt') as file:
337+
lines = file.readlines()
338+
data = lines[-4:]
339+
self.score_vr = int(data[0])
340+
self.scoreall = int(data[0])
341+
342+
# def load_space(self):
327343
# with open('score.txt') as file:
328344
# lines = file.readlines()
329345
# data = lines[-4:]
330-
# self.score_vr = int(data[0])
331-
# self.scoreall = int(data[0])
332-
# print(data[0])
346+
# self.space.append(str(data[1]))
347+
# print(data[1])
333348

334349
# def colored_grid(self):
335-
# with open('score.txt') as file:
350+
# with open('score.txt' "r") as file:
336351
# lines = file.readlines()
337352
# data = lines[-4:]
338-
339353
# print(data[2])
340354

341355

0 commit comments

Comments
 (0)