From bc4759d90701263450a023881de28edb048fc073 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Tue, 22 Dec 2020 20:08:15 +0100 Subject: Show the score in the terminal Signed-off-by: Olivier Gayot --- cameltris.py | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/cameltris.py b/cameltris.py index ca4ffed..d3973be 100755 --- a/cameltris.py +++ b/cameltris.py @@ -255,9 +255,11 @@ def burn_rows(): grid.insert(0, [None for _ in range(10)]) grid.remove(row) + return len(rows_to_burn) + def stick_piece(): - global current_piece, current_piece_position, next_piece, next_piece_position + global current_piece, current_piece_position, next_piece, next_piece_position, lines_burnt, level, score for row_id, row in enumerate(current_piece.elements): for col_id, element in enumerate(row): @@ -265,7 +267,32 @@ def stick_piece(): continue grid[row_id + current_piece_position[0]][col_id + current_piece_position[1]] = element - burn_rows() + count = burn_rows() + + if count == 1: + print("Single") + rate = 1 + elif count == 2: + print("Double") + rate = 2.5 + elif count == 3: + print("Triple") + rate = 7.5 + elif count == 4: + print("Tetris!") + rate = 30 + else: + rate = 0 + + lines_burnt += count + + score += int(level * 40 * rate) + + print("Score is ", score) + + if lines_burnt >= level * 10: + level += 1 + print("Level up to ", level) current_piece, current_piece_position = next_piece, next_piece_position next_piece, next_piece_position = generate_piece() refresh_piece_preview_canvas() @@ -302,12 +329,16 @@ refresh_piece_preview_canvas() frames_per_gridcell = [48, 43, 38, 33, 28, 23, 18, 13, 8, 6, 5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1] piece_drop_frames = 0 -level = 16 +level = 1 +score = 0 pygame.key.set_repeat(200, 50) clock = pygame.time.Clock() +print("Level is ", level) +lines_burnt = 0 + while True: piece_drop_frames += 1 -- cgit v1.2.3