-
Notifications
You must be signed in to change notification settings - Fork 1
/
NonPlayer.java
62 lines (60 loc) · 1.79 KB
/
NonPlayer.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
import java.util.Iterator;
import java.util.Random;
/**
* Class for NonPlayer Characters. Has check in case placed in invalid spot,
* boolean for whether it has the wincondition, and specific die() method
*
* @author Ari
* @version 2019-12-19
*/
public class NonPlayer extends Character implements CharactersDo
{
private Random rand;
private boolean alive;
private boolean hasWin;
/**
* Constructor for objects of class NonPlayer
*/
public NonPlayer(String character, int attack, int location,
int maxHealth, boolean hasWin)
{
super(character, attack, maxHealth);
boolean valid = false;
int newLocation = location;
rand = new Random();
while(!valid) {
if(Main.map.getCharacter(newLocation).equals(".")) {
setLocation(newLocation);
Main.map.setCharacter(getCharacter(), getLocation());
valid = true;
} else {
newLocation = rand.nextInt(2046);
}
}
this.hasWin = hasWin;
alive = true;
}
/**
* Print dying text, remove from Main.characters,
* trigger main.win() if hasWin
*/
@Override
public void die()
{
System.out.println("You hear a scream as another one bites the dust");
Main.map.setCharacter(".", getLocation());
Main.killed.add(getCharacter());
Iterator it = Main.characters.iterator();
boolean found = false;
while(!found && it.hasNext()) {
Character character = (Character)it.next();
if(character.getLocation() == getLocation()) {
found = true;
Main.characters.remove(character);
}
}
if(hasWin) {
Main.win();
}
}
}