我试图做一个控制台游戏(如俄勒冈步道),我有一个问题with the loop但后来解决了。Java循环在第二次尝试后停止工作
**这只是整个游戏代码的一部分。
现在的问题是,第二次尝试后循环不起作用;这里是代码:
int o1, o2, o3, o4, o5, o6, o7, o8, o9;
boolean thugloop = false;
System.out.println("Woah, you beat the thug; but now the thug is angry and he won't rest until he beats you.");
Thread.sleep(1000);
thugloop = true;
System.out.println("Pick your numbers again");
while(thugloop = true){
o4=reader.nextInt();
o5=reader.nextInt();
o6=reader.nextInt();
o7=reader.nextInt();
o8=reader.nextInt();
int sumhop2 = o4+o5+o6+o7+o8;
int angrythug= 3 + (int)(Math.random()*85);
if(sumhop2>angrythug){
Thread.sleep(1000);
System.out.println("Woah, you are really good at this!");
System.out.println("But the thug is getting angrier. Put in 5 more numbers:");
o4=reader.nextInt();
o5=reader.nextInt();
o6=reader.nextInt();
o7=reader.nextInt();
o8=reader.nextInt();
**sumhop2 = o5 + o5 + o7 + o8;
angrythug= 3 + (int)(Math.random()*85);**
}else if(sumhop2<angrythug){
//other code goes here.
break;
}
}
所以它的工作原理是第一次,但是当它说:“暴徒越来越愤怒将在5个...”我把在5个号码,什么也没有发生,它只是那里闪烁的光标。
我该如何解决这个错误?
谢谢!
请正确地格式化您的代码将退出。我试图弄清楚块在哪里结束,我很头痛。 – Keppil
'while(thugloop = true)'应该是'while(thugloop)'(或者,不太推荐,'while(thugloop == true)') – Maroun
@Keppil,我是一个noob,我不能正确格式化;抱歉。 – Aakarsh