I have 3 classes, Main, Enemy and UserCharacter. Enemy contains the enemy's attributes and possible actions. UserCharacter contains the user's attributes and possible actions. Main manages the logic and creates the objects from Enemy and UserCharacter classes.
I'm trying to use a setter method contained in class Enemy from a method in class UserCharacter
public class UserCharacter {
private String userName = "Adventurer";
private int userAttack = 5;
private int userLife = 100;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public int getUserLife() {
return userLife;
}
public void setUserLife(int userLife) {
this.userLife = userLife;
}
public void Attack() {
Enemy.setEnemyLife(10);
}
}
Is there a way to do so without setting the method as static? (other than creating an object of the class which is not an option since it's done in Main) Is using a static setter method advisable? (and I guess I'll have to create a dummy static variable for the setter)
Thanks