diff --git a/list.md b/list.md index f0d928e..b2fed32 100644 --- a/list.md +++ b/list.md @@ -34,7 +34,7 @@ 简要说明:完成方块落地后的固定、游戏结束判断、预测落点与重新开始等状态控制逻辑。 -- [ ] `14. Fixing` - `src/source/TetrisLogic.cpp` +- [x] `14. Fixing` - `src/source/TetrisLogic.cpp` - [ ] `17. GameOver` - `src/source/TetrisLogic.cpp` - [ ] `18. ComputeTarget` - `src/source/TetrisLogic.cpp` - [ ] `19. Restart` - `src/source/TetrisLogic.cpp` diff --git a/report/code-snippets/Part4/FixingAfter.png b/report/code-snippets/Part4/FixingAfter.png new file mode 100644 index 0000000..95afa4c Binary files /dev/null and b/report/code-snippets/Part4/FixingAfter.png differ diff --git a/report/code-snippets/Part4/FixingBefore.png b/report/code-snippets/Part4/FixingBefore.png new file mode 100644 index 0000000..7bf4ac9 Binary files /dev/null and b/report/code-snippets/Part4/FixingBefore.png differ diff --git a/src/source/TetrisLogic.cpp b/src/source/TetrisLogic.cpp index f5cf3d0..1d38469 100644 --- a/src/source/TetrisLogic.cpp +++ b/src/source/TetrisLogic.cpp @@ -252,9 +252,40 @@ void DropDown() } } +/** + * @brief 将当前活动方块固定到工作区,并生成下一个活动方块。 + * + * 遍历当前方块 4x4 形状矩阵,把其中所有非空单元写入工作区数组, + * 表示该方块已经落地并转为固定状态。 + * 随后将“下一方块”切换为新的当前方块,重置旋转状态, + * 并把新方块生成到工作区上方的初始位置。 + */ void Fixing() { - // TODO(作业14): 将当前方块固定到工作区,并生成下一个方块。 + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++) + { + if (bricks[type][state][i][j] != 0) + { + int fixY = point.y + i; + int fixX = point.x + j; + + // 将当前方块的非空单元写入工作区 + if (fixY >= 0 && fixY < nGameHeight && fixX >= 0 && fixX < nGameWidth) + { + workRegion[fixY][fixX] = bricks[type][state][i][j]; + } + } + } + } + + // 生成下一个活动方块 + type = nType; + nType = rand() % 7; + state = 0; + point.x = 3; + point.y = 0; } void DeleteOneLine(int number)