Hello, I would need help. In the console, I get the current amount that the user has after buying a soldier. Do-while () keeps repeating, even if I enter 50.
do {
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
}
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
if(CelkovyPocet > 50) {
System.out.println("Naverboval jsi více jak 50 vojáků");//You recrutied more than 50 soldiers
kontrola = false;
}
if(CelkovyPocet < 50) {
kontrola = true;
}
CelkovyPocet = CelkovyPocet - PocetVojaku;
}while(kontrola == true);
//total amount
}while(kontrola == true);
}while( celkovyPocet != 0 );
System.out.println(armadaHrace2[VyberVojaky]);//second Player's army
Aucun commentaire:
Enregistrer un commentaire