Repository navigation
Expand file tree
/
Copy pathPerson.java
More file actions
94 lines (82 loc) · 1.91 KB
/
Copy pathPerson.java
File metadata and controls
94 lines (82 loc) · 1.91 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
import java.io.PrintStream;
public abstract class Person extends Thing {
protected Direction facing;
protected Status status;
/**
* @param loc a Coordinate
* @param repr a String representation
* @param map a Map
* @param log a PrintStream
*/
public Person(Coord loc, String repr, Map map, PrintStream log) {
super(loc, repr, map, log);
//super.log = log;
facing = Direction.N;
status = Status.Escaping;
// map.addThing(this);
}
public abstract Coord chooseMove();
/**
*calls on child classes implementation of chooseMove()
*/
@Override
public void doAction() {
if (this.status == Status.Escaping) { //only persons still escaping should me called on
Coord nextLocation = this.chooseMove();
this.setLoc(nextLocation);
if(this.getLoc() == this.getPrevLoc()) {
map.log.println(this.toString() + " staying here");
}
else {
map.log.println(this.toString() + " moving " + this.facing);
}
}
}
/**
* @return true if safe
*/
public boolean isSafe() {
if (status == Status.Safe) {
return true;
} else {
return false;
}
}
/**
* sets status to Status.Dead
*/
public void die() {
this.status = Status.Dead;
}
/**
* calls on parent class setLoc, than updates the Status of person if they landed on an exit
*/
@Override
public void setLoc(Coord newLoc) {
super.setLoc(newLoc);
if (this.map.onMap(newLoc)) {
if (map.floorplan[newLoc.r][newLoc.c] == Spot.Exit) {
status = Status.Safe;
map.log.println(this.toString() + " safe");
}
}
/*
*
*/
}
/**
*@return true
*/
@Override
public boolean canLookThrough() {
return true;
}
/**
*@return true
*/
@Override
public boolean canPassThrough() {
return true;
}
abstract boolean isSpotOpen(Coord spot); //check the spot for availability depending on the persons constrains
}