-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPosition.pde
More file actions
57 lines (50 loc) · 1.47 KB
/
Copy pathPosition.pde
File metadata and controls
57 lines (50 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
class Position{
private final int x;
private final int y;
Position(int x, int y){
this.x = x;
this.y = y;
}
public int getX(){
return this.x;
}
public int getY(){
return y;
}
public boolean equals(Position pos){
return this.x == pos.x && this.y == pos.y;
}
// Renvoie vrai si l'instance et l'objet en paramètre son a une unité d'écart
public boolean isNextTo(Position pos){
return (abs(this.x - pos.x) == 1 && this.y - pos.y == 0)
|| (abs(this.y - pos.y) == 1 && this.x - pos.x == 0);
}
// Vérifie si l'instance peux traverser une ligne constituée des trois positions en paramètres
public final boolean canItCross(Position p1, Position p2, Position p3){
if(p1.x - p2.x == 0 && p1.x - p3.x == 0){
// Allignés sur l'axe des x
boolean res = this.x - p1.x == 0;
return !res;
} else if(p1.y - p2.y == 0 && p1.y - p3.y == 0){
// Allignés sur l'axe des y
boolean res = this.y - p1.y == 0;
return !res;
} else {
return false;
}
}
// Vérifie si l'instance peux traverser une ligne constituée des deux positions en paramètres
public final boolean canItCross(Position p1, Position p2){
if(p1.x - p2.x == 0){
// Allignés sur l'axe des x
boolean res = this.x - p1.x == 0;
return !res;
} else if(p1.y - p2.y == 0){
// Allignés sur l'axe des y
boolean res = this.y - p1.y == 0;
return !res;
} else {
return false;
}
}
}