-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEuropeanChess.java
More file actions
53 lines (42 loc) · 1.51 KB
/
EuropeanChess.java
File metadata and controls
53 lines (42 loc) · 1.51 KB
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
// Nathan Hsiao
// Class that implements the rules of chess and to move the pieces
public class EuropeanChess extends ChessGame{
// a field to store which side it is on (North)
private ChessGame.Side Player1 = ChessGame.Side.NORTH;
// a field to store which side it is on(South)
private ChessGame.Side Player2 = ChessGame.Side.SOUTH;
// a field to keep track of which sides it is on
private int switchSides;
// a method to move the chess
@Override
public boolean legalPieceToPlay(ChessPiece piece, int toRow, int toColumn){
// sees if the odd, if one player1
if ( switchSides %2 == 0 && piece.getSide() == Player1){
return true;
}
// see if even, if even player 2
if(switchSides % 2 != 0 && piece.getSide() == Player2){
return true;
}
//increments it by one everytime method is accessed
switchSides++;
return false;
}
// this method takes the turn for the pieces
@Override
public boolean makeMove(ChessPiece piece, int row, int column){
// if statement checks if it is nonlegal capture move
if(piece.isLegalNonCaptureMove(row, column)){
piece.setLocation(row,column);
return true;
}
// if statmenet checks if it is legal capture move
if(piece.isLegalMove(row, column)){
piece.getChessBoard().removePiece(piece.getRow(),piece.getColumn());
piece.setLocation(row,column);
return true;
}
else
return false;
}
}