private void battleButtonActionPerformed(java.awt.event.ActionEvent evt) {
if(!gamer.isFighting())
{
gamer.fighting();
}
if(gamer.isFighting())
{
monster = spawner.getMob(rand.nextInt(3));
eName.setText(monster.getName());
eLvl.setText("Lvl " + monster.getLevel());
eHP.setText("HP: " + monster.getHealth());
eMana.setText("Mana: " + monster.getMana());
eAttack.setText("Attack: " + monster.getAttack());
eArmor.setText("Armor: " + monster.getArmor());
bLog1.setText("You've encountered a " + monster.getName());
System.out.println(monster.getHealth());
}
}
The problem is once the player clicks the battle button again after beating a monster, the data shown on the GUI shows zero health and zero armor. I think whats happening is the attack method:
public void attack(Enemy badGuy)
{
badDude = badGuy;
if(badDude.getHealth() > 0)
{
if(badDude.getArmor() > 0)
{
if(this.getAttack() > badDude.getArmor())
{
badDude.setHealth(badDude.getHealth() -(this.getAttack() - badDude.getArmor()));
badDude.setArmor(0);
}else{
badDude.setArmor(badDude.getArmor() - this.getAttack());
}
}else{
badDude.setHealth(badDude.getHealth() - this.getAttack());
}
}
if(badDude.getHealth() < 0)
{
badDude.setHealth(0);
}
}
is actually changing the value of the enemy in the arraylist. Thanks for your time and I hope you guys can help me out!
So I have an object of type Database. This object has an ArrayList variable in it that holds all the Enemy objects for the game. The problem is that I want the ArrayList to act as a reference for Enemy information. This means I don't want the data changing. The thing is though, when players of this game hit the battle button and defeat an Enemy the actual variables of the Enemy in the ArrayList in the Database class change. As seen above in the first code segment I create another Enemy object that takes the information from the Database object so that the information in the ArrayList doesnt change. I've tried almost everything from reloading the database object when the enemy is defeated to making a reset method in the Enemy class that resets its stats but all of those didnt work. Hopefully you guys can help me. Oh also, here is the getMob() method depicted in the battle button method:
public Enemy getMob(int inx)
{
return creatures.get(inx);
}
Thanks for your time and hopefully you guys can help me since no one else has seemed to be able to thus far.

New Topic/Question
Reply



MultiQuote





|