diff --git a/list.md b/list.md index 58e2329..e6efd6d 100644 --- a/list.md +++ b/list.md @@ -37,7 +37,7 @@ - [x] `14. Fixing` - `src/source/TetrisLogic.cpp` - [x] `17. GameOver` - `src/source/TetrisLogic.cpp` - [x] `18. ComputeTarget` - `src/source/TetrisLogic.cpp` -- [ ] `19. Restart` - `src/source/TetrisLogic.cpp` +- [x] `19. Restart` - `src/source/TetrisLogic.cpp` ## 第五阶段:消行与得分逻辑 diff --git a/report/code-snippets/Part4/RestartAfter.png b/report/code-snippets/Part4/RestartAfter.png new file mode 100644 index 0000000..7a07455 Binary files /dev/null and b/report/code-snippets/Part4/RestartAfter.png differ diff --git a/report/code-snippets/Part4/RestartBefore.png b/report/code-snippets/Part4/RestartBefore.png new file mode 100644 index 0000000..81022a1 Binary files /dev/null and b/report/code-snippets/Part4/RestartBefore.png differ diff --git a/src/source/TetrisLogic.cpp b/src/source/TetrisLogic.cpp index a3a7dee..1962bc4 100644 --- a/src/source/TetrisLogic.cpp +++ b/src/source/TetrisLogic.cpp @@ -360,7 +360,34 @@ void ComputeTarget() point = originalPoint; } +/** + * @brief 重置整个游戏状态,开始新的一局。 + * + * 该函数会清空工作区中的所有固定方块数据,重置分数、结束标记和暂停标记, + * 并重新初始化当前方块、下一方块、旋转状态以及生成位置。 + * 最后会重新计算一次当前方块的预测落点。 + */ void Restart() { - // TODO(作业19): 重置游戏状态。 + for (int i = 0; i < nGameHeight; i++) + { + for (int j = 0; j < nGameWidth; j++) + { + workRegion[i][j] = 0; + } + } + + tScore = 0; + gameOverFlag = false; + suspendFlag = false; + targetFlag = true; + + type = rand() % 7; + nType = rand() % 7; + state = 0; + point.x = 3; + point.y = 0; + target = point; + + ComputeTarget(); }