-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntity.java
More file actions
108 lines (86 loc) · 1.74 KB
/
Entity.java
File metadata and controls
108 lines (86 loc) · 1.74 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
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
/*
* Entity.java
* @version 1.0
* @since April 24, 2019
* Base class for all other entities in simulation
*/
abstract class Entity {
// Health points
private int health;
// X Position on map
private int xPos;
// Y Position on Map
private int yPos;
// Moved condition
private boolean moved;
Entity(int health, int y, int x) {
this.moved = true;
this.health = health;
this.yPos = y;
this.xPos = x;
}
/**
* getHealth
* Retrieves entity's health
* @return int, true if the operation was a success, false otherwise.
*/
int getHealth() {
return health;
}
/**
* takeDamage
* Decreases entity's health
* @param points, Amount of health taken off
*/
void takeDamage(int points) {
this.health -= points;
}
/**
* gainHealth
* Increases entity's health
* @param points, Amount of health added
*/
void gainHealth(int points) {
this.health += points;
}
/**
* getX
* Retrieves the X position
* @return int, X position of entity
*/
int getX() {
return xPos;
}
/**
* getY
* Retrieves the Y position
* @return int, Y position of entity
*/
int getY() {
return yPos;
}
/**
* setX
* Updates X position of entity
* @param newX, new X position
*/
void setX(int newX) {
this.xPos = newX;
}
/**
* setY
* Updates Y position of entity
* @param newY, new Y position
*/
void setY(int newY) {
this.yPos = newY;
}
/**
* getHealthString
* Retrieves the health of the entity as a string to be used on the display
* @return String, Health points of the entity
*/
String getHealthString() {
return Integer.toString(health);
}
}