在我完成我提出的其中一个选项后,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);
谢谢
答案 0 :(得分:2)
看起来你的逻辑不正确。您有菜单选项#5
"5. End turn\n"
但你的do-while循环条件是
}while (minimenu==5);
仅当minimenu
为5时,这将继续循环。我认为你不想等于5,所以如果它不是5
,循环将继续,如果它是{{}它将结束1}}。
5