-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCreature.java
114 lines (97 loc) · 2.79 KB
/
Creature.java
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
/**
* This class extends the Entity class and is designed to hold the methods for
* movable entities, "creatures" i the map world.
* Where these creatures are also capable of fighting with each other, hence the
* implementation of the Fightable interface.
*
* @author Ross Petridis | [email protected] | 1080249
*/
public abstract class Creature extends Entity implements Fightable {
// all creatures (player+monster) have these
private String name = null;
private int health;
private int maxHealth;
private int damage;
/**
* Creature constructor for when reading from the world file
*
* @param pos Position of this creature
* @param name Name of this creature
* @param health Initial health of this creature
* @param maxHealth Max health of this creature
* @param damage Damage this creature can deal to others
*/
public Creature(
Position pos,
String name,
int health,
int maxHealth,
int damage) {
super(pos);
this.name = name;
this.health = health;
this.maxHealth = maxHealth;
this.damage = damage;
}
/**
* Constructor used to create creature for default world gameplay
*
* @param x
* @param y
*/
public Creature(int x, int y) {
super(x, y);
}
// Default creature constructur
public Creature() {
// Call another constructor in this class with following default values.
this(new Position(), null, 1, 1, 1);
}
// Implement Fightable
/**
* Heal creature to max health
*/
public void heal() {
health = maxHealth;
}
/**
* Decrease the health of this monster by "damage" amount
*
* @param damage The amount to reduce the health by
* @return Returns True if the monster is dead
*/
public boolean hurt(int damage) {
health -= damage;
if (health <= 0) {
return true;// monster is dead
}
return false; // not dead
}
/**
* Returns the damage this monster can deal
*/
public int getDamage() {
return damage;
}
public int getMaxHealth() {
return maxHealth;
}
public int getHealth() {
return health;
}
public String getName() {
return name;
}
public void setDamage(int damage) {
this.damage = damage;
}
public void setName(String name) {
this.name = name;
}
public void setMaxHealth(int maxHealth) {
this.maxHealth = maxHealth;
}
public void setHealth(int health) {
this.health = health;
}
}