aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/Actor.java
blob: 55fcc3a2f69fd7e83c01240021c8ffe9eb5bd317 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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);
    }
}