-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNPC.java
More file actions
48 lines (42 loc) · 1.06 KB
/
NPC.java
File metadata and controls
48 lines (42 loc) · 1.06 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
import java.util.Random;
/**
* A class to represent an NPC.
*
* @author Thomas Vakili
* @version 2013.12.14
*/
public class NPC extends Character {
private String phrase;
private boolean hasSpoken;
public NPC(String phrase, String name, Room room) {
super(name, room);
this.phrase = phrase;
this.hasSpoken = false;
}
/**
* Choose an action to perform in a fight.
* Right now the AI is pretty stupid.
*
* @param enemy the enemy the NPC faces
* @return the action chosen
*/
@Override
public Action getAction(Character enemy) {
Action.ActionVal action;
int random = (new Random()).nextInt(101) - getHP();
if (random > 70) {
action = Action.ActionVal.BLOCK;
} else {
action = Action.ActionVal.ATTACK;
}
return new Action(action, this, enemy);
}
public String getPhrase() {
if (hasSpoken) {
return null;
} else {
hasSpoken = true;
return phrase;
}
}
}