-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacterEntity.java
More file actions
81 lines (62 loc) · 1.68 KB
/
Copy pathCharacterEntity.java
File metadata and controls
81 lines (62 loc) · 1.68 KB
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
/*
Abstract class for a Character object, which will be extended by concrete character
types (Heroes and Enemies). Implements the Entity and Unit interfaces.
*/
abstract class CharacterEntity implements Entity, Unit{
// the attributes are protected, so the child classes can access them
protected String name;
protected int level, health;
protected String indicator;
protected int r, c;
public CharacterEntity(String name, int level, String indicator){
this.name = name;
this.level = level;
this.health = 100*level;
this.indicator = indicator;
this.r = 0;
this.c = 0;
}
// getter methods
public String getName() {
return name;
}
public int getLevel() {
return level;
}
public int getHealth() {
return health;
}
public String getIndicator() {
return indicator;
}
public int[] getLocation() {
int[] location = new int[2];
location[0] = r;
location[1] = c;
return location;
}
// setter methods
public void setName(String newName) {
name = newName;
}
public void setLevel(int k) {
level = k;
}
public void setIndicator(String newIndicator) {
indicator = newIndicator;
}
public void setLocation(int r, int c) {
this.r = r;
this.c = c;
}
// returns true if the character has died in the attack
public boolean isFainted() {
return health <= 0;
}
public abstract void takeDamage(int amountOfDamage, String type);
public String toString() {
String s = name + " (";
s += Colors.ANSI_CYAN + Integer.toString(level) + Colors.ANSI_RESET + ")";
return s;
}
}