-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNonPlayerCharacter.java
More file actions
57 lines (46 loc) · 1.33 KB
/
NonPlayerCharacter.java
File metadata and controls
57 lines (46 loc) · 1.33 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
package APCSA.APCSA_Code_Your_Own;
import java.io.Serializable;
public class NonPlayerCharacter implements Serializable{
private int maxHealth;
private int currentHealth;
private int attackDamage;
private String name;
private boolean isDead = false;
public NonPlayerCharacter(int maxHealth, int attackDamage, String name) {
this.maxHealth = maxHealth;
this.currentHealth = maxHealth;
this.attackDamage = attackDamage;
this.name = name;
}
public int getCurrentHealth() {
return currentHealth;
}
public int getAttackDamage() {
return attackDamage;
}
public boolean takeDamage(int damage) {
currentHealth -= damage;
if (currentHealth > 0){
isDead = true;
}
return isDead;
}
public void attackPlayer(Player targetPlayer, int damage) {
targetPlayer.takeDamage(damage);
}
public void renewHealth() {
currentHealth = maxHealth;
}
public void renewHealth(int health) {
currentHealth += health;
if (currentHealth > maxHealth) {
currentHealth = maxHealth;
}
}
public boolean isDead(){
return isDead;
}
public String toString() {
return name + " with health " + currentHealth + "/" + maxHealth + ".";
}
}