实现 Restart 游戏状态重置逻辑 完成函数19

This commit is contained in:
2026-04-24 09:18:54 +08:00
parent f943bd7c76
commit b604ce9d47
4 changed files with 29 additions and 2 deletions
+1 -1
View File
@@ -37,7 +37,7 @@
- [x] `14. Fixing` - `src/source/TetrisLogic.cpp` - [x] `14. Fixing` - `src/source/TetrisLogic.cpp`
- [x] `17. GameOver` - `src/source/TetrisLogic.cpp` - [x] `17. GameOver` - `src/source/TetrisLogic.cpp`
- [x] `18. ComputeTarget` - `src/source/TetrisLogic.cpp` - [x] `18. ComputeTarget` - `src/source/TetrisLogic.cpp`
- [ ] `19. Restart` - `src/source/TetrisLogic.cpp` - [x] `19. Restart` - `src/source/TetrisLogic.cpp`
## 第五阶段:消行与得分逻辑 ## 第五阶段:消行与得分逻辑
Binary file not shown.

After

Width:  |  Height:  |  Size: 131 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

+28 -1
View File
@@ -360,7 +360,34 @@ void ComputeTarget()
point = originalPoint; point = originalPoint;
} }
/**
* @brief 重置整个游戏状态,开始新的一局。
*
* 该函数会清空工作区中的所有固定方块数据,重置分数、结束标记和暂停标记,
* 并重新初始化当前方块、下一方块、旋转状态以及生成位置。
* 最后会重新计算一次当前方块的预测落点。
*/
void Restart() 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();
} }