I'm trying to develop a text-based game. Here is the concept-demo version.
class Arena {
public static void battle(Hero h1, Hero h2){
h1.setHp(h1.getHp()-h2.getPhysical_attack());
h1.info();
}
public static void main(String[] args) {
System.out.println("Entering Arena ...");
Hero mike = new Hero();
mike.setUname("mike");
mike.info();
Hero tom = new Hero();
tom.setUname("tom");
tom.info();
battle(mike, tom);
}
}
class Hero{
private String uname;
private int hp;
private int physical_attack;
Hero(){
hp = 620;
physical_attack = 66;
}
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public int getHp() {
return hp;
}
public void setHp(int hp) {
this.hp = hp;
}
public int getPhysical_attack() {
return physical_attack;
}
public void setPhysical_attack(int physical_attack) {
this.physical_attack = physical_attack;
}
void info() {
System.out.println("HP of "+uname+"'s hero = "+hp);
}
}
Is it common to use static void method to handle objects that way?
static
can be ok, however there's questions I'd consider... are you going to support multiple Arena, with different Hero's fighting? How come Mike never hits Tom back? Does it make sense to have a Hero that doesn't have a name, or should this be a constructor parameter? Are you going to support equipment (to reduce damage / inflict more damage)? Get/Set pairings setup a race condition does that matter? Should Hero have a take damage method instead? etc... \$\endgroup\$