【问题标题】:Tetris clear lines issue俄罗斯方块清除线问题
【发布时间】:2012-04-14 00:20:12
【问题描述】:

我正在为一个项目制作俄罗斯方块克隆。我几乎完成了,但我的清晰线条课程有一个我无法摆脱的错误。我制作了一个 10*20 的网格,将精灵绘制到其中。当我在地板上找到一条线时,它可以正常工作,但在此之上它只会删除该线并将其下方的所有内容也向下移动。这是我的 clear line 类的代码:

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;
        }
    }
}

如果有人能说明该怎么做,我将不胜感激。我已经尝试了很多,但没有任何效果:(

【问题讨论】:

  • 对该类的格式感到抱歉。当我查看帖子时被格式化
  • 我刚刚整理出来,只需要等待批准
  • 我刚刚编辑了它,希望很快就会好起来。
  • 请标记您使用的语言。 (真的有一个 [俄罗斯方块] 标签?boggles
  • @Wooble:你可以输入任何你喜欢的标签。

标签: c# tetris


【解决方案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];
                }
            }

这(我认为)将所有行向下移动一行。问题在于循环边界总是指向第 0 行。您应该只将这些行移到您要清除的行之上。将y &gt; 0 更改为y &gt; lineNumber,其中lineNumber 是您清除的行。

【讨论】:

  • 感谢工厂的建议。把我带到了我需要去的地方。问题在于第一个 for 循环中的 (y = Game1.LandedBlocks.GetLength(1))。没有阅读要清除的行,但您的建议绝对是帮助我找到它的原因
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-17
相关资源
最近更新 更多