2014-09-06 24 views
-3

当生成地形时,我的程序在启动程序时并没有响应。我如何解决我的程序没有响应?

这是代码。我相信这是for循环。

Random Random = new Random(); 
     int numberHeight = Random.nextInt(5); 
     GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); 
     GL11.glColor3f(0.5f,0.5f,1.0f); 
     int Bottom = Height - 100; 
     for(int xOffset = 0; xOffset < Width; xOffset = xOffset + 100){ 
      for(int currentHeight = 0; currentHeight < numberHeight; currentHeight = currentHeight++){ 
       GL11.glBegin(GL11.GL_QUADS); 
       { 
        GL11.glVertex2f(xOffset,Bottom - currentHeight * 100); 
        GL11.glVertex2f(xOffset + 100,Bottom - currentHeight * 100); 
        GL11.glVertex2f(xOffset + 100,Bottom - currentHeight * 100 - 100); 
        GL11.glVertex2f(xOffset,Bottom - currentHeight * 100 - 100); 
       } 
       GL11.glEnd(); 
       if(currentHeight >= numberHeight)break; 
      } 
     } 
+3

你会得到什么样的例外?并在哪一行? – honk 2014-09-06 19:13:14

+0

寻求调试帮助的问题(“**为什么不是这个代码工作?”)必须包含所需的行为,特定的问题或错误以及在问题本身**中重现**所需的最短代码。没有**明确问题陈述**的问题对其他读者没有用处。请参见[如何创建最小,完整和可验证示例](http://stackoverflow.com/help/mcve)。 – DavidPostill 2014-09-06 20:02:25

+0

我认为问题必须是可能使立方体超出边界的for循环。 – ZaneGlitch 2014-09-07 06:56:43

回答

0

的问题是,for循环不正确写入:

我试过这段代码:

public static void main(String []args){ 
    for(int i = 0;i < 10;i = i++) 
    { 
     System.out.println(i); 
    } 
} 

它infinitly循环,并打印出0所有的时间。

你的循环是:

for(int currentHeight = 0; currentHeight < numberHeight; currentHeight = currentHeight++) 

,并应

for(int currentHeight = 0; currentHeight < numberHeight; currentHeight++) 

或:

for(int currentHeight = 0; currentHeight < numberHeight; currentHeight += 1) 

如何递增/递减运算工作作为前缀或后缀:

Java: Prefix/postfix of increment/decrement operators?

+0

我把它改成了CurrentHeight ++并且它能够工作,但它最终在每个块中都以相同的大小创建了块,直到它可能是因为这两个循环已经成为它导致它执行的一部分。但无论如何感谢这个问题。 – ZaneGlitch 2014-09-13 16:10:15

相关问题