gpt4 book ai didi

java - Action 后循环中断

转载 作者:行者123 更新时间:2023-12-02 06:21:21 26 4
gpt4 key购买 nike

完成我设定的选项之一后,do while 循环结束。例如,它说:在我购买并部署了一些部队后,进程已完成,退出代码为 0。

我错过了什么?!我希望它继续下去,直到人们不希望或玩家获胜为止。

do {
refresh();
System.out.println("" +
"Lobby\n\n" +
"==========\n" +
"Balance: "+balance+"\n" +
"Production Per Tick: "+production+"\n"+
"\n----------\n" +
"Options\n" +
"----------\n" +
"1. Show map\n" +
"2. Build troops\n" +
"3. Move troops\n" +
"4. Upgrade Production\n" +
"5. End turn\n");
minimenu = input.nextInt();
if (minimenu==1) {
refresh();
displayMap(map);
System.out.println("" +
"Map Legend:\n" +
"------------\n" +
"0 = not occupied\n" +
"1 = US Territory\n" +
"2 = Terrorist Territory\n");
}
else if (minimenu==2) {
int troop;

refresh();
System.out.println("" +
"Choose the troops you want to build\n" +
"-----------------------------------\n" +
"1. Special Force - 100$\n" +
"2. Tank - 500$ \n" +
"3. F-32 - 1500$ \n" +
"--->");
troop = input.nextInt();

int amount,troopCount;
System.out.print("Number of Special Forces you want: ");
troopCount = input.nextInt();
amount = troopCount*100;
System.out.println("\nTotal: "+amount+"$\n" +
"Type 1 to conform: \n");
if (input.nextInt() ==1)
balance = balance-amount;
int X,Y;
do {
System.out.print("" +
"where do you want to deploy the troops? (Must deploy on own land!)\n" +
"Enter Y coordinate: ");
Y = input.nextInt();
System.out.println("\nEnter X Coordinate");
X = input.nextInt();
System.out.println(map[Y][X]+"This One"); //test code

if (varifyDeployment(map[Y][X])) {
if (troop==1) {
US_SpecialForce[Y][X] += troopCount;
System.out.println("Success!");
}
else if (troop ==2) {
US_Tank[Y][X] += troopCount;
System.out.println("Success!");
}
else if (troop == 3) {
US_Air[Y][X] += troopCount;
System.out.println("Success!");
}
}
else
System.out.println("Incorrect location, Try Again");
}while (!varifyDeployment(map[Y][X]));
displayMap(US_SpecialForce); //test code

}
}while (minimenu==5);

谢谢

最佳答案

看来你的逻辑不正确。您的菜单选项#5

"5. End turn\n"

但是你的 do-while 循环条件是

}while (minimenu==5);

只有当 minimenu 为 5 时,才会继续循环。我认为您希望不等于 5,因此如果不是 5,循环就会继续,并且它会如果是 5 则结束。

}while (minimenu != 5);

关于java - Action 后循环中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20984532/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com