我觉得这有点奇怪。我的循环不循环,我不知道为什么。没有错误信息。该程序只运行一次。这是我正在创建的游戏,它让你掷 1-9 骰子,你可以选择从数字 1-9 列表中删除该数字,或删除该数字本身。这应该会发生,直到棋盘中没有数字为止。但是......循环不循环!
public class gudmundur_skilaverkefni9 {
public static void main (String[] args) {
System.out.println("Godan dag. Thu ert ad spila Larus.");
System.out.println("1 2 3 4 5 6 7 8 9");
int N = 9;
boolean[] Spilafylki = new boolean[10];
for (int i = 1; i <= N; i++) {
System.out.println("Sladu inn slembitolu til ad kasta teningunum.");
int teningakast = StdIn.readInt();
int teningatala = (int) (Math.random() * 10);
System.out.println("Thu fekkst " + teningatala + ".");
if (teningatala != 2) {
System.out.println("Viltu taka ut " + teningatala
+ " eda velja tvaer tolur sem mynda summu af "
+ teningatala + "? (1/2)");
int tala2 = StdIn.readInt();
if (tala2 == 2) {
System.out.println("Slaid inn fyrri tolu:");
int fyrritala = StdIn.readInt();
System.out.println("Slaid inn seinni tolu:");
int seinnitala = StdIn.readInt();
while (fyrritala+seinnitala != teningatala
|| fyrritala == seinnitala){
System.out.println("Thetta gengur ekki! Valdirdu nokkud somu toluna tvisvar? Reyndu aftur:");
System.out.println("Slaid inn fyrri tolu:");
fyrritala = StdIn.readInt();
System.out.println("Slaid inn seinni tolu:");
seinnitala = StdIn.readInt();
}
System.out.println("Nu litur spilid svona ut:");
Spilafylki[fyrritala] = true;
Spilafylki[seinnitala] = true;
for (i = 1; i <= N; i++) {
if (Spilafylki[i] == false)
System.out.print(i + " ");
else
System.out.print(" ");
}
System.out.println();
}
if (tala2 == 1) {
Spilafylki[teningatala] = true;
System.out.println("Nu litur spilid svona ut:");
for (i = 1; i <= N; i++) {
if (Spilafylki[i] == false)
System.out.print(i + " ");
else
System.out.print(" ");
}
System.out.println();
}
}
else {
System.out.println("Thu fekkst tvo. Ekki er hægt ad velja tvaer olikar natturulegar tolur sem mynda 2.");
System.out.println("Nu litur spilid svona ut:");
Spilafylki[teningatala] = true;
for (i = 1; i <= N; i++) {
if (Spilafylki[i] == false)
System.out.print(i + " ");
else
System.out.print(" ");
}
System.out.println();
int count = 0;
for (i = 1; i <= N; i++)
if (Spilafylki[i] == true)
count++;
if (count == 9) {
System.out.println("Allar tolurnar eru farnar. Takk fyrir ad spila Larus.");
break;
}
}
}
}