-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPawn.java
64 lines (53 loc) · 1.8 KB
/
Pawn.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
public class Pawn extends Piece{
private boolean firstMove = true;
public Pawn(int c, int y, int x){
if(c == 1){this.symbol = "♙";}
else{this.symbol = "♟";}
this.color = c;
this.currentX = x;
this.currentY = y;
this.firstMove = true;
}
public Piece[][] move(int y, int x, Piece[][] board, boolean ghost){
board = basicMovement(board,currentX, x, currentY, y, 0,color, ghost);
if(firstMove){
board = basicMovement(board, currentX, x, currentY, y, 0,color*2, ghost);
}
if(!ghost){
firstMove = false;
}
if(currentX+color == x && currentY+color== y && board[y][x].hasPiece()){
if(board[y][x].getColor()!= color){
board[y][x] = board[currentY][currentX];
board[currentY][currentX] = new Piece();
if(!ghost){
currentX = x;
currentY = y;
firstMove = false;
}
}
}
else if(currentX-color == x && currentY+color== y && board[y][x].hasPiece()){
if(board[y][x].getColor()!= color){
board[y][x] = board[currentY][currentX];
board[currentY][currentX] = new Piece();
if(!ghost){
currentX = x;
currentY = y;
firstMove = false;
}
}
}
return board;
}
@Override public Piece[][] promote(int y, int x){
Piece[][] board = Main.board;
if(y == 0 && color == -1){
board[y][x] = new Queen(color, y,x);
}
if(y == 7 && color == 1){
board[y][x] = new Queen(color,y,x);
}
return board;
}
}