2012-04-13 43 views
3

我正在制作项目的俄罗斯方块克隆。我已经完成了很多工作,但我的清晰线条类有一个我无法动摇的bug。我制作了一个10 * 20的网格,我将这些精灵绘制成了。当我在地板上看到一条线时,它可以正常工作,但在此之上,它只会删除线并将其下移。这是我的清线类的代码:俄罗斯方块明确行问题

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

如果任何人都可以阐明怎么做我会很感激它。我试过这么多,没有什么工作:(

+0

关于该类格式遗憾。当我看着被格式化post – user1250838 2012-04-13 16:00:32

+0

我刚刚整理出来,只需要等待批准 – ridecar2 2012-04-13 16:01:34

+0

我刚刚编辑过,所以希望不久就会好起来的。 – 2012-04-13 16:01:37

回答

2

它看起来像问题是与

  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 > 0y > lineNumber其中lineNumber是行,你被清除。

+0

谢谢你现在会告诉你它是如何去 – user1250838 2012-04-13 17:12:31

+0

感谢一个工厂的意见。把我带到了我需要的地方。问题出现在第一个for循环中(y = Game1.LandedBlocks.GetLength(1))。没有阅读要清除的行,但您的建议绝对是什么帮助我找到它 – user1250838 2012-04-13 18:05:58

+0

@ user1250838没问题 – twain249 2012-04-13 18:51:11