-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPawn.java
More file actions
39 lines (33 loc) · 865 Bytes
/
Pawn.java
File metadata and controls
39 lines (33 loc) · 865 Bytes
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
import java.awt.*;
public class Pawn extends Piece{
public Pawn(int x, int y, Player owner) {
super(x, y, owner);
}
@Override
public boolean isMoveAuthorized(Board board, Coordinates destination) {
int dx = destination.getX();
int dy = destination.getY();
int ox = this.getX();
int oy = this.getY();
int deltaX = ox - dx;
int deltaY = oy - dy;
if (Math.abs(deltaY)==1 && Math.abs(deltaX)==1){
return true;
}
if (Math.abs(deltaY)==1 && Math.abs(deltaX) == 0){
return true;
}
if (Math.abs(deltaY) == 2 && deltaX == 0) {
return true;
}
return false;
}
@Override
public Type getType() {
return Type.PAWN;
}
@Override
public int getValue() {
return 1;
}
}