-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint.java
More file actions
69 lines (55 loc) · 1.45 KB
/
Point.java
File metadata and controls
69 lines (55 loc) · 1.45 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
// a very small unit of discrete linear distance
public class Point {
private int myX;
private int myY;
private boolean[] data;
private static final int NUM_DATA = 2;
private static final int PATHABLE = 0;
private static final int OCCUPIED = 1;
public Point(String _data, int _x, int _y) {
myX = _x;
myY = _y;
data = new boolean[NUM_DATA];
if (_data.equals("e")) { //empty space
data[PATHABLE] = true;
} else if (_data.equals("w")) { //wall
data[PATHABLE] = false;
} else { //default case
data[PATHABLE] = false;
}
data[OCCUPIED] = false;
} //constructor
public Point(int _x, int _y) {
myX = _x;
myY = _y;
data = new boolean[NUM_DATA];
data[PATHABLE] = false;
data[OCCUPIED] = false;
} //constructor for "null" points
//*********************util methods*******************//
//@method: call only after isOccupied returns false
public void occupy() {
data[OCCUPIED] = true;
} //occupy
public void vacate() {
data[OCCUPIED] = false;
} //vacate
public String parseToString() {
if (data[PATHABLE])
return "p";
else return "b";
} //parseToString
//*******************accessor methods*****************//
public int getX() {
return myX;
} //getX
public int getY() {
return myY;
} //getY
public boolean isPathable() {
return data[PATHABLE];
} //isPathable
public boolean isOccupied() {
return data[OCCUPIED];
} //isOccupied
}