summaryrefslogtreecommitdiffstats
path: root/src/Actor.java
blob: ef63217da4077a38b730dd93bac17ba6bb23b7dc (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
public class Actor {
	// TODO: make final
	private String name;
	// TODO: could be replaced with `bool isAlive() { return this.hp > 0; }`
	private boolean alive;
	// TODO: enemy should not be binary (ex clans / groups / factions)	
	private boolean enemy;
	private int hp;
	// TODO: pack abilities / bonus / powers in structures
	private int agility;
	private int strenght;
	private int defense;

	private int x;
	private int y;
	
	private Weapon weapon;
	private int actionsLeft;
	// TODO: make final
	private int actions = 2;
	// TODO: make bonus / power-ups structure

	public Actor(String name, int hp, boolean enemy, int agility) {
		this.name = name;
		this.hp = hp;	
		this.enemy = enemy;
		this.agility = agility;
		// TODO: puch should have infinite durability
		this.weapon = new Weapon("fist", 1, 1, 10000000);

		this.alive = true;
		this.resetActions();
	}

	public void resetActions() {
		this.actionsLeft = this.actions;
	}

	public int getActionsLeft() {
		return this.actionsLeft;
	}

	public boolean hit(Actor actor, Map map) {
		if (this.actionsLeft > 0) {
			if (this.weapon.damage(this, actor, map)) {
				this.actionsLeft--;
				return true;
			}
		}
		return false;
	}

	public Weapon getWeapon() {
		return this.weapon;
	}

	public void equipWeapon(Weapon weapon) {
		this.weapon = weapon;
	}

	// TODO: could be `return this.hp > 0` and remove member
	public boolean isAlive() {
		return this.alive;
	}

	public void setHP(int hp) {
		this.hp = hp;	
		if (this.hp <= 0) {
			this.alive = false;
		}
	}

	public void damage(int dmg) {
		this.hp -= dmg;
		if (this.hp <= 0) {
			this.alive = false;
		}
	}

	public int getAgility() {
		return this.agility;
	}

	public String getName() {
		return this.name;
	}

	public int getHP() {
		return this.hp;
	}

	public int getX() {
		return this.x;
	}

	public int getY() {
		return this.y;
	}

	public boolean isEnemy() {
		return this.enemy;
	}

	public void move(int x, int y) {
		if (this.actionsLeft > 0) {
			this.x = x;
			this.y = y;
			this.actionsLeft--;
		}
	}

	public void place(int x, int y) {
		this.x = x;
		this.y = y;

	}
}