34 lines
715 B
Java
34 lines
715 B
Java
![]() |
public abstract class Character {
|
||
|
protected String name;
|
||
|
protected int health;
|
||
|
protected int attackPower;
|
||
|
|
||
|
public Character(String name, int health, int attackPower) {
|
||
|
this.name = name;
|
||
|
this.health = health;
|
||
|
this.attackPower = attackPower;
|
||
|
}
|
||
|
|
||
|
public void takeDamage(int damage) {
|
||
|
this.health -= damage;
|
||
|
}
|
||
|
|
||
|
public boolean isAlive() {
|
||
|
return this.health > 0;
|
||
|
}
|
||
|
|
||
|
public String getName() {
|
||
|
return name;
|
||
|
}
|
||
|
|
||
|
public int getHealth() {
|
||
|
return health;
|
||
|
}
|
||
|
|
||
|
public int getAttackPower() {
|
||
|
return attackPower;
|
||
|
}
|
||
|
|
||
|
public abstract void displayInfo(); // Abstract method to be implemented by subclasses
|
||
|
}
|