diff --git a/list.md b/list.md index 57269b1..58e2329 100644 --- a/list.md +++ b/list.md @@ -36,7 +36,7 @@ - [x] `14. Fixing` - `src/source/TetrisLogic.cpp` - [x] `17. GameOver` - `src/source/TetrisLogic.cpp` -- [ ] `18. ComputeTarget` - `src/source/TetrisLogic.cpp` +- [x] `18. ComputeTarget` - `src/source/TetrisLogic.cpp` - [ ] `19. Restart` - `src/source/TetrisLogic.cpp` ## 第五阶段:消行与得分逻辑 diff --git a/report/code-snippets/Part4/ComputeTargetAfter.png b/report/code-snippets/Part4/ComputeTargetAfter.png new file mode 100644 index 0000000..effe8de Binary files /dev/null and b/report/code-snippets/Part4/ComputeTargetAfter.png differ diff --git a/report/code-snippets/Part4/ComputeTargetBefore.png b/report/code-snippets/Part4/ComputeTargetBefore.png new file mode 100644 index 0000000..ae9aa4d Binary files /dev/null and b/report/code-snippets/Part4/ComputeTargetBefore.png differ diff --git a/src/source/TetrisLogic.cpp b/src/source/TetrisLogic.cpp index 99c32c9..a3a7dee 100644 --- a/src/source/TetrisLogic.cpp +++ b/src/source/TetrisLogic.cpp @@ -334,9 +334,30 @@ bool GameOver() return false; } +/** + * @brief 计算当前活动方块的预测落点位置。 + * + * 该函数以当前活动方块的位置为起点,使用虚拟下落的方式不断尝试向下移动, + * 直到方块无法继续下落为止。最终得到的最低可达位置会写入 target, + * 供后续界面绘制瞄准器或落点提示时使用。 + * + * 计算过程中不会改变当前方块的真实位置 point。 + */ void ComputeTarget() { - // TODO(作业18): 计算瞄准器的预测落点。 + Point originalPoint = point; + + // 从当前方块位置开始向下试探 + target = point; + + while (CanMoveDown()) + { + point.y++; + target = point; + } + + // 恢复当前方块的真实位置 + point = originalPoint; } void Restart()