-
Notifications
You must be signed in to change notification settings - Fork 0
/
Move.java
54 lines (43 loc) · 1.25 KB
/
Move.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
public class Move {
private Square startSquare;
private Square endSquare;
private char specialMove;
/** Constructor that gets a string */
public Move(String moveString) {
if ( moveString.length() < 4 ) {
this.startSquare = null;
this.endSquare = null;
this.specialMove = 0;
}
else {
this.startSquare = Board.getFromString(moveString.substring(0,2));
this.endSquare = Board.getFromString(moveString.substring(2,4));
if ( moveString.length() == 5 ) this.specialMove = moveString.charAt(4);
else this.specialMove = 0;
}
}
/** Constructor that gets start and end square */
public Move(Square startSquare, Square endSquare) {
this.startSquare = startSquare;
this.endSquare = endSquare;
}
public Move reverse() {
return new Move(this.endSquare, this.startSquare);
}
public Square getStartSquare() {
return this.startSquare;
}
public Square getEndSquare() {
return this.endSquare;
}
@Override
public String toString() {
return ("move " + startSquare.getCoords() + endSquare.getCoords()).toLowerCase() + '\n';
}
public char getSpecialMove() {
return specialMove;
}
public void setSpecialMove(char specialMove) {
this.specialMove = specialMove;
}
}