import java.awt.Dimension; public class Actor { public enum Type { PLAYER, ENEMY } public final String name; public final Type type; private boolean alive; private final int MAXHP; private int hp; private int x, y; private Dimension gridSize; private Weapon weapon; public Actor(String name, int MAXHP, Type type, Dimension gridSize) { this.name = name; this.type = type; this.MAXHP = MAXHP; this.hp = this.MAXHP; this.alive = true; this.gridSize = gridSize; } public void damage(int dmg) { this.hp = this.hp - dmg; if (this.hp <= 0) { this.alive = false; this.hp = 0; } } public void heal(int life) { this.hp = this.hp + life; if (this.hp > this.MAXHP) { this.hp = this.MAXHP; } } public boolean move(int x, int y) { if (x < this.gridSize.width && y < this.gridSize.height && x > 0 && y > 0) { this.x = x; this.y = y; return true; } else { return false; } } public boolean isAlive() { return alive; } public int getHp() { return this.hp; } public int getX() { return this.x; } public int getY() { return this.y; } public void equipWeapon(Weapon weapon) { this.weapon = weapon; } public Weapon dropWeapon() { Weapon tmp = this.weapon; this.weapon = null; return tmp; } public boolean shoot(Actor actor, double probability) { return this.weapon.shoot(actor, probability); } }