-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKnight.java
More file actions
38 lines (29 loc) · 740 Bytes
/
Copy pathKnight.java
File metadata and controls
38 lines (29 loc) · 740 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
/**
* Amey Khatri
* Knight.java
* Date Last Modified:
* Class Description:
**/
import java.util.Scanner;
public class Knight extends Piece {
public Knight (Colour colour, String ID, int firstX, int firstY) {
super(colour, ID, firstX, firstY);
}
public String toString() {
if (this.getColour() == Colour.BLACK) {
return "♘";
}
return "♞";
}
public boolean possibleMove (int x, int y) {
int xDiff = Math.abs(x- this.getX());
int yDiff = Math.abs(y - this.getY());
if (xDiff == 1 && yDiff == 2) {
return true;
}
if (xDiff == 2 && yDiff == 1) {
return true;
}
return false;
}
}