diff --git a/list.md b/list.md index e6efd6d..2121330 100644 --- a/list.md +++ b/list.md @@ -43,8 +43,8 @@ 简要说明:完成删除单行、批量消行以及相关分数更新逻辑。 -- [ ] `15. DeleteOneLine` - `src/source/TetrisLogic.cpp` -- [ ] `16. DeleteLines` - `src/source/TetrisLogic.cpp` +- [x] `15. DeleteOneLine` - `src/source/TetrisLogic.cpp` +- [x] `16. DeleteLines` - `src/source/TetrisLogic.cpp` ## 第六阶段:界面绘制与整体完善 diff --git a/report/code-snippets/Part5/Part5CodeAfter.png b/report/code-snippets/Part5/Part5CodeAfter.png new file mode 100644 index 0000000..9a0ea33 Binary files /dev/null and b/report/code-snippets/Part5/Part5CodeAfter.png differ diff --git a/report/code-snippets/Part5/Part5CodeBefore.png b/report/code-snippets/Part5/Part5CodeBefore.png new file mode 100644 index 0000000..66c2054 Binary files /dev/null and b/report/code-snippets/Part5/Part5CodeBefore.png differ diff --git a/src/source/TetrisLogic.cpp b/src/source/TetrisLogic.cpp index 1962bc4..1783e75 100644 --- a/src/source/TetrisLogic.cpp +++ b/src/source/TetrisLogic.cpp @@ -288,15 +288,61 @@ void Fixing() point.y = 0; } +/** + * @brief 删除指定行,并让其上方所有行整体下移一格。 + * + * 该函数会先将目标行上方的所有数据逐行向下复制, + * 再把最顶端一行清空,从而完成一次标准的消行下移操作。 + * + * @param number 需要被删除的目标行号。 + */ void DeleteOneLine(int number) { - // TODO(作业15): 删除指定行,并让其上方所有行整体下移。 - UNREFERENCED_PARAMETER(number); + for (int i = number; i > 0; i--) + { + for (int j = 0; j < nGameWidth; j++) + { + workRegion[i][j] = workRegion[i - 1][j]; + } + } + + // 清空最顶端一行 + for (int j = 0; j < nGameWidth; j++) + { + workRegion[0][j] = 0; + } } +/** + * @brief 检查并删除所有已满的行,同时更新当前得分。 + * + * 该函数会从底部向上遍历工作区,判断每一行是否被完全填满。 + * 如果某一行全部非 0,则调用 DeleteOneLine 删除该行, + * 并将该行上方的内容整体下移。为了避免连续满行被漏检, + * 删除后会继续检查当前行号。每成功消除 1 行,当前得分增加 100 分。 + */ void DeleteLines() { - // TODO(作业16): 完成消行与计分逻辑。 + for (int i = nGameHeight - 1; i >= 0; i--) + { + bool fullLine = true; + + for (int j = 0; j < nGameWidth; j++) + { + if (workRegion[i][j] == 0) + { + fullLine = false; + break; + } + } + + if (fullLine) + { + DeleteOneLine(i); + tScore += 100; + i++; + } + } } /**