2014-09-06 27 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

相關問題