我正在为一个项目制作俄罗斯方 block 克隆。我几乎完成了,但我的清晰线条类有一个我无法摆脱的错误。我制作了一个 10*20 的网格,我将 Sprite 绘制到其中。当我在地板上得到一条线时,它工作正常但在它上面它只是删除线并将它下面的所有内容也向下移动。这是我的清晰线类的代码:
public static void ClearLines()
{
for (int CountY = Game1.LandedBlocks.GetLength(1) - 1; CountY >= 0; CountY--)
{
bool clearLine = true;
for (int CountX = 0; CountX < Game1.LandedBlocks.GetLength(0); CountX++)
{
clearLine &= Game1.LandedBlocks[CountX, CountY] != -1;
}
if (clearLine)
{
for (int CountX = 0; CountX < Game1.LandedBlocks.GetLength(0); CountX++)
{
Game1.LandedBlocks[CountX, CountY] = -1;
}
for (int y = Game1.LandedBlocks.GetLength(1) - 1; y > 0; y--)
{
for (int CountX = 0; CountX < Game1.LandedBlocks.GetLength(0); CountX++)
{
Game1.LandedBlocks[CountX, y] = Game1.LandedBlocks[CountX, y - 1];
}
}
CountY++;
Game1.rows++;
Game1.score += 100;
}
}
}
如果有人能阐明该怎么做,我将不胜感激。我已经尝试了很多,但没有任何效果:(
最佳答案
看起来问题出在
for (int y = Game1.LandedBlocks.GetLength(1) - 1; y > 0; y--)
{
for (int CountX = 0; CountX < Game1.LandedBlocks.GetLength(0); CountX++)
{
Game1.LandedBlocks[CountX, y] = Game1.LandedBlocks[CountX, y - 1];
}
}
这(我认为)将所有行向下移动了一行。问题在于循环边界总是指向第 0 行。您应该只将这些行移动到您正在清除的任何行之上。将 y > 0
更改为 y > lineNumber
,其中 lineNumber
是您清除的行。
关于c# - 俄罗斯方 block 清晰的线条问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10144273/