-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBishop.java
54 lines (46 loc) · 1.55 KB
/
Bishop.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
////////////////////////////////////////////////////////////////////////////////
/// @brief Class for the Bishop class
////////////////////////////////////////////////////////////////////////////////
class Bishop extends Piece {
////////////////////////////////////////////////////////////////////////////
/// @brief Constructor for Bishop
/// @param _x X position
/// @param _y Y position
/// @param _color Color of piece
public Bishop(int _x, int _y, char _color) {
super.x = _x;
super.y = _y;
super.color = _color;
}
////////////////////////////////////////////////////////////////////////////
/// @brief Returns if a Bishop can move to a point
/// @param _x Possible new x
/// @param _y Possible new y
public boolean canMove(int _x, int _y) {
int xBaseDifference = x - _x;
int yBaseDifference = y - _y;
int xDifference = xBaseDifference;
int yDifference = yBaseDifference;
if(xDifference <= 0)
xDifference *= -1;
if(yDifference <= 0)
yDifference *= -1;
return xDifference == yDifference;
}
////////////////////////////////////////////////////////////////////////////
/// @brief Moves Bishop to a point
/// @param _x New x
/// @param _y New y
public void move(int _x, int _y) {
x = _x;
y = _y;
}
////////////////////////////////////////////////////////////////////////////
/// @brief Return Bishop type
public int pieceType() { return 4; }
////////////////////////////////////////////////////////////////////////////
/// @brief Returns Bishop board icon
public String draw() {
return color =='W' ? "WB" : "BB";
}
}