-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntity.java
More file actions
33 lines (26 loc) · 781 Bytes
/
Copy pathEntity.java
File metadata and controls
33 lines (26 loc) · 781 Bytes
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
import java.util.Random;
public abstract class Entity {
protected Random myRandom = new Random();
protected boolean isWinner = true;
protected String myName;
protected int myHp;
public Entity(int hp) {
this.myHp = hp;
}
public void Heal(int hp) {
myHp += hp;
}
public void TakeDamage(int dmg) {
myHp -= dmg;
if (myHp <= 0) {
System.out.println(myName + " has died");
isWinner = false;
}
else {
System.out.println(myName + " has " + myHp + " health left");
}
}
public void Attack(Entity e, int dmg) {e.TakeDamage(dmg);}
public String getName() {return myName;}
public int getHp() {return myHp;}
}