so Im creating a simple text based game but having trouble with my loop. So my character has 3 battles with the same enemy but the battle is not over until one character dies. With my current code, it only loops through the first battle but leave battle 2 and 3 blank. What am i doing wrong?
for (int i = 1; i <= 3; i++) {
ATK = rand.nextInt((weaponMax - weaponMin) + 1) + weaponMin;
enemyATK = rand.nextInt((enemyWeaponMax - enemyWeaponMin) + 1) + enemyWeaponMin;
int valueOfAttack = (ATK + characterStrength);
int enemyValueOfAttack = (enemyATK + enemyStrength);
System.out.println("\n" + "***" + characterChoice + " vs. Goblin Battle " + i + "***");
while (characterHasntDied) {
System.out.println(characterChoice + " attacks with ATK = " + String.valueOf(ATK) + " + "
+ String.valueOf(characterStrength) + " = " + (valueOfAttack));
System.out.println(enemyChoice + " HP is now " + String.valueOf(enemyHP) + " - "
+ String.valueOf(valueOfAttack) + " = " + (enemyHP - valueOfAttack));
System.out.println("\n");
System.out.println("Goblin attacks with ATK = " + String.valueOf(enemyATK) + " + "
+ String.valueOf(enemyStrength) + " = " + (enemyValueOfAttack));
System.out.println(characterChoice + " HP is now " + String.valueOf(characterHP) + " - "
+ String.valueOf(enemyValueOfAttack) + " = " + (characterHP - enemyValueOfAttack));
enemyHP -= valueOfAttack;
characterHP -= enemyValueOfAttack;
if (enemyHP < 1) {
characterHasntDied = false;
System.out.println(characterChoice + " has defeated Goblin " + i);
break;
} else if (characterHP < 1) {
characterHasntDied = false;
System.out.println(characterChoice + " is defeated in battle!");
break;
}
}
}
Aucun commentaire:
Enregistrer un commentaire