From 627854bd5896513e7161e12219368e9d0212b136 Mon Sep 17 00:00:00 2001 From: efindus <48939809+efindus@users.noreply.github.com> Date: Tue, 1 Feb 2022 20:25:30 +0100 Subject: [PATCH] Add score system promoting multiple row combos The way it works is quite simple. For every row you clear you get 50 points, but each more row is going to count more times (1st row counts once, 2nd row counts twice and so on). Signed-off-by: efindus <48939809+efindus@users.noreply.github.com> --- tetris.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tetris.c b/tetris.c index 467be1f..4064b1e 100644 --- a/tetris.c +++ b/tetris.c @@ -11,7 +11,6 @@ #include // TODO: add wall kicks -// TODO: add score and award more for multiple rows cleared // Constants #define HEIGHT 22 @@ -87,7 +86,7 @@ int comingUp[COMING_UP_AMOUNT]; TetrominoState currentTetromino; XsetAttributes attributes; -int rowsCleared = 0; +int rowsCleared = 0, score = 0; int mpvSubprocessPID = -1; @@ -217,7 +216,7 @@ void drawFrame() { printf("\x1b[0m\n"); } - printf("\x1b[38;5;2m[SCORE] Rows cleared: %d\x1b[0m\n", rowsCleared); + printf("\x1b[38;5;2m[SCORE: %d] (Rows cleared: %d)\x1b[0m\n", score, rowsCleared); } /* @@ -355,6 +354,8 @@ void createNewTetromino() { * Checks for full rows and clears them */ void cleanupBoard() { + int originalCleared = rowsCleared; + for (int y = 1; y < HEIGHT + 1; y++) { int amount = 0; for (int x = 1; x < WIDTH + 1; x++) { @@ -379,6 +380,11 @@ void cleanupBoard() { rowsCleared++; } } + + while(rowsCleared - originalCleared != 0) { + score += 50 * (rowsCleared - originalCleared); + originalCleared++; + } } void tick() {