【发布时间】:2021-04-25 22:53:17
【问题描述】:
我研究这个问题已经有一段时间了,一直画一个空白,希望能得到一些帮助。
我正在使用 Python 和 Pygame 制作一个简单的俄罗斯方块克隆。问题是检测完成行的过程有时会在新 GRID 中添加一个克隆行,因此任何影响原始行的东西也会影响克隆行。
这里是删除已完成行的代码:
# create an empty grid
newGRID = []
fullRowsCount = 0
for row in reversed(GRID):
# count number of non-zero blocks in row
rowBlockCount = sum(col > 0 for col in row)
# if number of non-zero blocks is less than the width of grid then copy to newGRID
if rowBlockCount < GRID_SIZE.width:
# insert non-full row into newGRID
newGRID.insert(0, row)
else:
# increment this counter in order to know number of blank rows to add to top of newGRID
fullRowsCount += 1
# if there are any full rows then they're not included in newGRID so blank rows need adding to the top
if fullRowsCount:
newGRID = [[0] * GRID_SIZE.width] * fullRowsCount + newGRID
# update GRID to the newGRID
GRID = newGRID
感谢您的宝贵时间:)
【问题讨论】:
-
基本上有一个名为 GRID 的二维列表,其中包含堆栈数据。通过堆栈,我的意思是一旦形状停止,它的数据就会添加到 GRID 中,因此可以进行基本的碰撞检测。即使使用了 newGRID.insert(0, row[:]) ,即使没有与原始文件纠缠在一起,那是否仍会创建一个克隆?
-
这是完整代码pastebin.com/W1xXjMCU。上面的代码从第 362 行开始