I'm trying to set up the first fight, but at line 24, BlueJ tells me that variable firsthitpoints
is not visible to carry out.
I'd be grateful if someone could tell me what's wrong with this code
if (characterquality == "Slayer"){
int HP = 150;
int Attack = 75;
int Defense = 50;
int MP = 20;
int EXP = 0;
int Gold = 50;
boolean firstbattle = true;
while (firstbattle){
int firstbattlehealth = HP;
int firstbattleattack = Attack;
int firstbattledefense = Defense;
int firstbattleMP = MP;
int firstbattleEXP = EXP;
int firstbattlegold = Gold;
int firstattack = (int) Math.ceil(Math.random() * 6);
int firstdefense = (int) Math.ceil(Math.random() * 6);
int firstenemyattack = (int) Math.ceil(Math.random() * 6);
int firstenemydefense = (int) Math.ceil(Math.random() * 6);
int firstenemyhealth = (int) Math.ceil(Math.random() * 50);
int firstenemyhitpoints = (int) Math.ceil(Math.random() * 25);
boolean firstkill = true;
while (firstkill) {
if (firstattack > firstenemydefense){
int firsthitpoints = (int) Math.ceil(Math.random() * firstbattleattack);
}
int firstenemynewhealth = firstenemyhealth - firsthitpoints;
if (firstenemynewhealth <= 0){
firstkill = false;
}
if (firstattack <= firstenemydefense){
System.out.println("Attack failed!");
}
if (firstenemyattack > firstdefense){
int firstenemyhitpointattack = (int) Math.ceil(Math.random() * firstenemyhitpoints);
System.out.println("The enemy did " + firstenemyhitpointattack + " damage to you. You have " + firstbattlehealth + " health remaining.");
}
if (firstenemyattack <= firstdefense){
System.out.println("Enemy attack missed!");
}
}
int firstenemynewhealth = firstenemynewhealth;
if (firstenemynewhealth <= 0){
firstbattle = false;
}
}
}