我的程序在生成地形时启动程序时没有响应。
这是代码。我相信它是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;
}
}
答案 0 :(得分:0)
问题是for循环写得不正确:
我试过这段代码:
public static void main(String []args){
for(int i = 0;i < 10;i = i++)
{
System.out.println(i);
}
}
它无限循环并一直打印出来。
你的循环是:
for(int currentHeight = 0; currentHeight < numberHeight; currentHeight = currentHeight++)
应该是
for(int currentHeight = 0; currentHeight < numberHeight; currentHeight++)
或:
for(int currentHeight = 0; currentHeight < numberHeight; currentHeight += 1)
递增/递减运算符如何作为前缀或后缀: