-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPosition.java
110 lines (97 loc) · 2 KB
/
Position.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package com.sokoban;
/**
*
*/
public class Position {
private int x;
private int y;
//GETTER AND SETTER//
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;
}
/**
* @param x
* @param y
*/
public Position(int x, int y) {
this.x = x;
this.y = y;
}
/**
* @param Position
*/
public Position(Position pos) {
this.x = pos.x;
this.y = pos.y;
}
/**
* @param Direction
* @return
*/
public Position add(Direction dir) {
if (dir != null) {
int newX = this.x + dir.getDx();
int newY = this.y + dir.getDy();
Position res = new Position(newX,newY);
return res;
} else {
return this;
}
}
/**
* @param Direction
* @return
*/
public Position sub(Direction dir) {
Position res = new Position(this.x - dir.getDx(), this.y - dir.getDy());
return res;
}
/**
* @param Object
* @return
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Position other = (Position) obj;
if (x != other.x)
return false;
if (y != other.y)
return false;
return true;
}
//TOSTRING//
@Override
public String toString() {
return "Position [x=" + x + ", y=" + y + "]";
}
public Direction directionVers(Position pos) {
// on regarde si il faut ce deplacer à droite
if (this.x-pos.getX() == 1) {
return Direction.HAUT;
//on regarde si il faut ce deplacer à gauche
} else if (this.x-pos.getX() == -1) {
return Direction.BAS;
//on regarde si il faut ce deplacer en bas
} else if (this.y-pos.getY() == 1) {
return Direction.GAUCHE;
//il faut donc ce deplacer en haut
} else {
return Direction.DROITE;
}
}
}