-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoordinates.java
More file actions
84 lines (66 loc) · 1.47 KB
/
Copy pathCoordinates.java
File metadata and controls
84 lines (66 loc) · 1.47 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
public class Coordinates {
private int x;
private int y;
private int size;
public Coordinates(int x, int y, int size) {
this.setX(x);
this.setY(y);
this.setSize(size);
}
public Coordinates(int pos, int size) {
x = pos%size;
y = pos/size;
this.setSize(size);
}
public Coordinates(String str) {
this.x = -1;
this.y = -1;
this.size = 1;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public Coordinates getLeft() {
return new Coordinates(this.x - 1, this.y, this.size);
}
public Coordinates getRight() {
return new Coordinates(this.x + 1, this.y, this.size);
}
public Coordinates getUp() {
return new Coordinates(this.x, this.y - 1, this.size);
}
public Coordinates getDown() {
return new Coordinates(this.x, this.y + 1, this.size);
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public static boolean inRange(int x, int y, int size) {
if(x >= 0 && x < size && y >= 0 && y < size)
return true;
else return false;
}
public boolean inRange() {
if(this.x >= 0 && x < this.size && this.y >= 0 && this.y < this.size)
return true;
else return false;
}
public int toPosition() {
return (getY() * size + getX());
}
public void printCoordinates() throws NullPointerException{
System.out.println("x:" + getX() + " y:" + getY() + " size:" + getSize());
}
}