如何检查celkovyPocet是否不小于0?接下来是翻译。为什么不扣除这笔钱?
int VyberVojaky; //选择士兵int PocetVojaku; //士兵数量int celkovyPocet = 50; //总金额
do {
System.out.println("Jaké si vybereš?");//What is your choice?
System.out.println("Pešák-0(2)"); //Plebs
System.out.println("Lučištník-1 (5)");//Archer
System.out.println("Jezdectvo-2 (10)");//Cavalry
System.out.println("Težká jednotka-3 (20)");//Special unit
VyberVojaky = Integer.parseInt(sc.nextLine());//ChooseSoldier
System.out.println("A kolik jich chceš?");//How many soldiers do you want?
PocetVojaku = Integer.parseInt(sc.nextLine());//numbofSoldiers
for(int i=0;i < PocetVojaku;i++) {
System.out.println(armadaHrace2[VyberVojaky]); //secondPlayersarmy[chooseSoldiers];
}
//total amount
// limit for recruiting soldiers is 50,so if player will recruit more than 50 soldiers,The game should alert the player and select the soldiers again
if(celkovyPocet > 50 ) {
System.out.println("Naverboval jsi více jak 50 vojáků");//You've recruited more than 50 soldiers
}
celkovyPocet -= PocetVojaku;//total amount -= numbofSoldiers
System.out.println("Ještě můžete naverbovat: " + celkovyPocet + " " + "vojáků");
//How many soldiers player can recruit
Vojaci = armadaHrace2[VyberVojaky];
Penize -= armadaHrace2[VyberVojaky].getCena();
//money
System.out.println("Vybral sis" + armadaHrace2[VyberVojaky]);//Your choice
System.out.println("Zůstalo ti:" + Penize + " " +"peněz");//Your residue
//total amount
}while( celkovyPocet != 0 );
System.out.println(armadaHrace2[VyberVojaky]);//second Player's army
由于celkovyPocet
是整数(int
),如果celkovyPocet < 0
小于0,则true
将返回celkovyPocet
,否则,false