-
Notifications
You must be signed in to change notification settings - Fork 0
/
WaypointList.java
74 lines (60 loc) · 1.23 KB
/
WaypointList.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
63
64
65
66
67
68
69
70
71
72
73
74
/**
* Class to save taken path
* @author Saroj Tripathi
*
*/
public class WaypointList {
private int xcord;
private int ycord;
private WaypointList next;
// Constructor function
WaypointList(int x, int y, WaypointList next) {
this.setXcord(x);
this.setYcord(y);
this.setNext(next);
}
WaypointList(int x, int y) {
this(x, y, null);
}
WaypointList() {
this(0,0,null);
}
// Getter and Setter Function start here
public void setXcord(int x) {
this.xcord = x;
}
public int getXcord() {
return this.xcord;
}
public void setYcord(int y) {
this.ycord = y;
}
public int getYcord() {
return this.ycord;
}
public void setNext(WaypointList next) {
this.next = next;
}
public WaypointList getNext() {
return this.next;
}
// Getter and setter ends here
/**
* Check if the position if already in the linked list (path)
* @param X-coordinate to search
* @param Y-coordinate to search
* @return 1 if found else 0
*/
public int contains(int x, int y) {
if(this.getXcord() == x && this.getYcord() == y) {
return 1;
} else {
for (WaypointList list = this.next; list != null; list = list.getNext()) {
if(list.getXcord() == x && list.getYcord() == y) {
return 1;
}
}
}
return 0;
}
}