created new class for highlighted zones
This commit is contained in:
parent
811d9a28d5
commit
c54e62078f
|
|
@ -9,7 +9,7 @@ public class Board {
|
|||
private Piece chosenPiece=null;
|
||||
private int turnNumber=0;
|
||||
private boolean isTurnWhite=true;
|
||||
// private ArrayList<int[]> highlightedSquares= new ArrayList<>();
|
||||
private ArrayList<int[]> highlightedSquares= new ArrayList<>(); //stores highlighted board positions
|
||||
|
||||
public Board(int colNum, int lineNum) {
|
||||
this.width=colNum;
|
||||
|
|
@ -168,8 +168,13 @@ public class Board {
|
|||
/* The following methods require more work ! */
|
||||
|
||||
public boolean isHighlighted(int x, int y) {
|
||||
//return highlightedSquares.contains(Point(x,y));
|
||||
return true; }
|
||||
for(int i=0; i<highlightedSquares.size();i++) { //loops through list of highlighted squares
|
||||
int[] position= highlightedSquares.get(i); //gets position of highlighted square
|
||||
if(position[0]==x && position[1]==y) { //checks if chosen highlighted square matches with position where piece can go
|
||||
return true; //it is highlighted
|
||||
}
|
||||
}
|
||||
return false; }
|
||||
|
||||
|
||||
public void undoLastMove() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
package backend;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MoveHighlighter {
|
||||
public static ArrayList<int[]> getPossibleMoves(Piece piece, Board board){
|
||||
ArrayList<int[]> validMoves = new ArrayList<int[]>();
|
||||
MovePiece movement = new MovePiece(piece, board);
|
||||
PieceType type= piece.getType();
|
||||
for(int x=0; x<board.getHeight();x++) {
|
||||
for(int y=0; y<board.getHeight();y++) {
|
||||
boolean valid=false;
|
||||
if(type==PieceType.Pawn) {
|
||||
valid=movement.movePawn(x, y);
|
||||
} else if(type==PieceType.Rook) {
|
||||
valid=movement.moveRook(x, y);
|
||||
}else if(type==PieceType.King) {
|
||||
valid=movement.moveKing(x, y);
|
||||
}else if(type==PieceType.Queen) {
|
||||
valid=movement.moveQueen(x, y);
|
||||
}else if(type==PieceType.Bishop) {
|
||||
valid=movement.moveBishop(x, y);
|
||||
}else if(type==PieceType.Knight) {
|
||||
valid=movement.moveKnight(x, y);
|
||||
}
|
||||
if(valid) {
|
||||
validMoves.add(new int[] {x,y});
|
||||
}
|
||||
}
|
||||
}
|
||||
return validMoves;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue