-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKnight.java
More file actions
34 lines (29 loc) · 762 Bytes
/
Knight.java
File metadata and controls
34 lines (29 loc) · 762 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
public class Knight extends Piece{
public Knight(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();
if(dx == ox + 2 || dx == ox - 2){
if (dy == oy + 1 || dy == oy - 1 ){
return true;
}
}
if(dx == ox + 1 || dx == ox - 1){
return dy == oy + 2 || dy == oy - 2;
}
return false;
}
@Override
public Type getType() {
return Type.KNIGHT;
}
@Override
public int getValue() {
return 3;
}
}