From 2564ce820c5c53c0f234646c8593022a670e233c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=98=8A=E6=97=B8?= Date: Sat, 26 Oct 2024 10:26:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tinytetris-commented.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/tinytetris-commented.cpp b/tinytetris-commented.cpp index f151188..395c3d1 100644 --- a/tinytetris-commented.cpp +++ b/tinytetris-commented.cpp @@ -57,20 +57,23 @@ int update_piece() { // remove line(s) from the board if they're full void remove_line() { - for (int row = y; row <= y + NUM(r, 18); row++) { - c = 1; - for (int i = 0; i < 10; i++) { - c *= board[row][i]; + for (int row = 0; row < 20; row++) { + bool full = true; + for (int i = 0; i < 10; i++) { + if (board[row][i] == 0) { + full = false; + break; + } + } + if (full) { + for (int i = row; i > 0; i--) { + memcpy(board[i], board[i - 1], sizeof(board[0])); + } + memset(board[0], 0, sizeof(board[0])); + score++; + row--; // Stay on the current row to check it again + } } - if (!c) { - continue; - } - for (int i = row - 1; i > 0; i--) { - memcpy(&board[i + 1][0], &board[i][0], 40); - } - memset(&board[0][0], 0, 10); - score++; - } } // check if placing p at (x,y,r) will be a collision