实现 Fixing 方块固定与生成下一个方块逻辑 完成函数14
This commit is contained in:
@@ -34,7 +34,7 @@
|
|||||||
|
|
||||||
简要说明:完成方块落地后的固定、游戏结束判断、预测落点与重新开始等状态控制逻辑。
|
简要说明:完成方块落地后的固定、游戏结束判断、预测落点与重新开始等状态控制逻辑。
|
||||||
|
|
||||||
- [ ] `14. Fixing` - `src/source/TetrisLogic.cpp`
|
- [x] `14. Fixing` - `src/source/TetrisLogic.cpp`
|
||||||
- [ ] `17. GameOver` - `src/source/TetrisLogic.cpp`
|
- [ ] `17. GameOver` - `src/source/TetrisLogic.cpp`
|
||||||
- [ ] `18. ComputeTarget` - `src/source/TetrisLogic.cpp`
|
- [ ] `18. ComputeTarget` - `src/source/TetrisLogic.cpp`
|
||||||
- [ ] `19. Restart` - `src/source/TetrisLogic.cpp`
|
- [ ] `19. Restart` - `src/source/TetrisLogic.cpp`
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 159 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
@@ -252,9 +252,40 @@ void DropDown()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 将当前活动方块固定到工作区,并生成下一个活动方块。
|
||||||
|
*
|
||||||
|
* 遍历当前方块 4x4 形状矩阵,把其中所有非空单元写入工作区数组,
|
||||||
|
* 表示该方块已经落地并转为固定状态。
|
||||||
|
* 随后将“下一方块”切换为新的当前方块,重置旋转状态,
|
||||||
|
* 并把新方块生成到工作区上方的初始位置。
|
||||||
|
*/
|
||||||
void Fixing()
|
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)
|
void DeleteOneLine(int number)
|
||||||
|
|||||||
Reference in New Issue
Block a user