Я могу закончить первым. Я пытаюсь сделать это на нечетных ходах, когда игрок идет, а четные ходы - на процессоре.
public static void main(String[] args) {
Random random = new Random();
Scanner keyboard = new Scanner(System.in);
String mage = "mage";
System.out.println("mage, warrior, assassin, ranger?");
String input = keyboard.nextLine();
int playerAttackDice = random.nextInt(20) + 1;
int cpuAttackDice = random.nextInt(20) + 1;
int playerDefenseDice = random.nextInt(5) + 1;
int cpuDefenseDice = random.nextInt(5) + 1;
int turn = 1;
while(mage.equalsIgnoreCase(input)) {
Mage player = new Mage();
Warrior CPU = new Warrior();
System.out.println("You have selected: mage");
System.out.println("Your Attack Power is: " + player.getMageAttack());
System.out.println("Your Defense is: " + player.getMageDefense());
System.out.println("Your Health is: " + player.getMageHealth());
System.out.println("Your enemy is a: warrior");
System.out.println("Enemy Attack Power is: " + CPU.getMageAttack());
System.out.println("Enemy Defense is: " + CPU.getMageDefense());
System.out.println("Enemy Health is: " + CPU.getMageHealth());
System.out.println();
Вот где начинается ход. Я пытался установить его так, чтобы плеер шел по нечетным числам, когда процессор уходит. Я даже подхожу к этому правильно? Буду очень признателен за любую помощь.
while(player.mageHealth != 0) {
System.out.println("Your health is: " + player.mageHealth);
for(turn = 1; turn % 1 ==0; turn++) {
if(turn % 1==0) {
System.out.println("Your dice roll is:" + playerAttackDice);
int playerDamage = playerAttackDice + player.mageAttack;
int cpuDefense = cpuDefenseDice + CPU.mageDefense;
System.out.println(playerDamage);
System.out.println(cpuDefense);
System.out.println("CPU health is: " + (CPU.mageHealth + cpuDefense - playerDamage ));
return;
}
}
turn++;
for(turn = 2; turn % 2 ==0; turn++) {
while(turn % 2==0) {
System.out.println("CPU dice roll is:" + cpuAttackDice);
System.out.println("Your dice roll is:" + playerDefenseDice);
int cpuDamage = playerDefenseDice + player.mageAttack;
int playerDefense = cpuAttackDice + CPU.mageHealth;
System.out.println(cpuDamage);
System.out.println(playerDefense);
}
}
}
System.out.println("end loop");
break;
}
}