user7210750 user7210750 - 15 days ago 8
Java Question

Program skipping over Setter in

I am making a very simple text based game in Java to try and familiarize myself with the language. When "fight choice" is 1, I want to subtract the attacks of the User and the enemy from the other's HP. When the program runs, It shows that the UserHP decreases, but the enemy HP always stays constant. Below are relative bits of code.

I have tried printing userATT just before printing enemyHP, and userATT always has a value ranging from 1-3, so I know the variable containing 0 or something isn't the issue.

public void setEnemyHP(int hp){
enemyHP = hp;
}

public void setUserBattleHP(int uhp){
userHP = uhp;
}

if(fightChoice.equals("1")){
setEnemyHP(this.enemyHP - this.userATT); //appears to be skipping this line
setUserBattleHP(this.userHP - enemyATT);


if I sysout all four variables, a value will always print. My only issue is for some reason enemyHP never changes from its original value.

Answer

I could not find any mistake in your code but post all the logic and sysout you get after every logical operation you do.. it may help finding the bug