-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPosition.java
More file actions
60 lines (47 loc) · 1.2 KB
/
Copy pathPosition.java
File metadata and controls
60 lines (47 loc) · 1.2 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
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
public class Position {
//Data
private final int x;
private final int y;
private final Set<String> whoWasIn = new HashSet<>();
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Position position = (Position) o;
return x == position.x && y == position.y;
}
@Override
public int hashCode() {
return Objects.hash(x, y);
}
//constructor
public Position(int x, int y) {
this.x = x;
this.y = y;
}
//Functions
public int getWhoWasIn() {
return whoWasIn.size();
}
public void addWhoWasIn (String ID){
this.whoWasIn.add(ID);
}
public boolean isInside() {
return this.x >= 0 && this.x < 11 && this.y >= 0 && this.y < 11;
}
public boolean equals(Position dest) {
return this.x == dest.x && this.y == dest.y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public String toString() {
return "(" + this.x + ", " + this.y + ")";
}
}