-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpace.java
More file actions
93 lines (72 loc) · 1.94 KB
/
Space.java
File metadata and controls
93 lines (72 loc) · 1.94 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
import java.awt.*;
//By: Brandon Beckwith
public class Space implements Comparable<Space> {
private SpaceType type;
private int distTo, distFrom;
private final Point POINT;
private Space previous;
public Space(SpaceType type, int x, int y) {
this.type = type;
this.POINT = new Point(x,y);
}
public SpaceType getType() {
return type;
}
public void setType(SpaceType type) {
this.type = type;
}
public int getDistTo() {
return distTo;
}
public void setDistTo(int distTo) {
this.distTo = distTo;
}
private int getDistFrom() {
return distFrom;
}
public void setDistFrom(int distFrom) {
this.distFrom = distFrom;
}
public Point getPoint() {
return POINT;
}
public int getX(){
return this.POINT.x;
}
public int getY(){
return this.POINT.y;
}
private int getDist(){
return this.getDistFrom() + this.getDistTo();
}
public Space getPrevious() {
return previous;
}
public void setPrevious(Space previous) {
this.previous = previous;
}
public void swapType(){
switch (this.type){
case BLOCK -> this.type = SpaceType.EMPTY;
case EMPTY -> this.type = SpaceType.BLOCK;
}
}
public void reset(){
this.setDistTo(0);
this.setDistFrom(0);
this.setPrevious(null);
if (!(this.getType() == SpaceType.BLOCK || this.getType() == SpaceType.INVALID))
this.setType(SpaceType.EMPTY);
}
public String getPointString(){
return "[" + Integer.toString((int) POINT.getX() + 1) + "," + Integer.toString((int) POINT.getY() + 1) + "]";
}
@Override
public int compareTo(Space space) {
return Integer.compare(this.getDist(), space.getDist());
}
@Override
public String toString() {
return this.getType().toString();
}
}