2014-01-08 120 views
0

完成我已經設定的選項之一後,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); 

謝謝

+4

使用調試器並逐步執行代碼。 –

+0

'do {...} while(b)'循環一次,然後繼續這樣做,而'b'爲'true'。如果'b'爲'false',則停止運行循環。你可能不清楚這是如何工作的? – ajb

回答

2

它看起來像你的邏輯是不正確。你作爲你的菜單選項#5

"5. End turn\n" 

但您do-while循環的條件是

}while (minimenu==5); 

這將繼續循環只有當5.我想你想不等於5 minimenu,所以如果它不是5,則循環將繼續,如果它是5,它將結束。

}while (minimenu != 5); 
+0

究竟是什麼問題。謝謝! – user3170899