c# - 俄罗斯方 block 清晰的线条问题

标签 c# tetris

我正在为一个项目制作俄罗斯方 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/

相关文章:

c# - 简单 C# 程序的惊人不同性能

c# - 从 ASP MVC 中的区域 Controller 链接到根 Controller

c# - 我可以通过 ClosedXML 将 EXCEL 工作表保存为 CSV 格式吗?

python - 运算符 "<>"在 Python 中是什么意思?

javascript - TETRIS html5 GAME代码检查

c++ - 我的方形 tetrimonos 一直奇怪地旋转,但我的其他 tetrimonos 旋转正常?

c# - DropShadowPanel 和边框圆角半径

c# - Swagger(.Net Core)中的 XML 支持?

javascript - 为什么俄罗斯方 block 会同时掉落而不是一次掉落一个?

java - Java中的俄罗斯方 block 形状生成算法