diff --git a/src/backend/Board.java b/src/backend/Board.java index 8c3aa31..bcf4b01 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -9,7 +9,7 @@ public class Board { private Piece chosenPiece=null; private int turnNumber=0; private boolean isTurnWhite=true; - private ArrayList highlightedSquares= new ArrayList<>(); //stores highlighted board position +// private ArrayList highlightedSquares= new ArrayList<>(); public Board(int colNum, int lineNum) { this.width=colNum; @@ -167,14 +167,9 @@ public class Board { /* The following methods require more work ! */ - public boolean isHighlighted(int x, int y) { //loop through list of highlighted squares - for(int i=0;i= 0 && x < 8 && y >= 0 && y < 8) { + Piece target = board.getPiece(x, y); + if (target == null) { + board.addHighlight(x, y); + return true; + } else if (target.isWhite() != board.getPiece(x, y).isWhite()) { + board.addHighlight(x, y); + return false; + } else { + return false; + } + } + return false; + } + // Queen Moves (Combination of Rook and Bishop) + public void highlightQueenMoves(Piece piece) { + board.clearHighlights(); + highlightRookMoves(piece); // Horizontal and Vertical paths + highlightBishopMoves(piece); // Diagonal paths + + board.refreshHighlights(); + } + + public void highlightKingMoves(Piece piece) { + board.clearHighlights(); + int currentX = piece.getX(); + int currentY = piece.getY(); + int[][] moves = { + {1, 0}, {-1, 0}, {0, 1}, {0, -1}, + {1, 1}, {-1, -1}, {1, -1}, {-1, 1} + }; + + for (int[] move : moves) { + addHighlightIfValid(currentX + move[0], currentY + move[1]); + } + board.refreshHighlights(); + } + + + + + } + + */ + + + + + diff --git a/src/backend/MovePiece.java b/src/backend/MovePiece.java index 42da954..0d23cc0 100644 --- a/src/backend/MovePiece.java +++ b/src/backend/MovePiece.java @@ -4,10 +4,14 @@ public class MovePiece { private Piece piece; private Board board; + // private HighlightManager highlightManager; + + public MovePiece(Piece piece, Board board) { this.piece = piece; this.board = board; + // this.highlightManager = new HighlightManager(board); } //Pawn movement logic @@ -164,7 +168,22 @@ public class MovePiece { return false; } } - + + + /* public void addPossibleMoves() { + switch (piece.getType()) { + case Pawn:highlightManager.highlightPawnMoves(piece); + case Rook:highlightManager.highlightRookMoves(piece); + case Knight:highlightManager.highlightKnightMoves(piece); + case Bishop:highlightManager.highlightBishopMoves(piece); + case Queen:highlightManager.highlightQueenMoves(piece); + case King:highlightManager.highlightKingMoves(piece); + default:System.out.println("Unknown piece type"); + } + } +} + + */ diff --git a/src/backend/initial_Usertouch.java b/src/backend/initial_Usertouch.java index 93dced1..6a28ec6 100644 --- a/src/backend/initial_Usertouch.java +++ b/src/backend/initial_Usertouch.java @@ -24,4 +24,43 @@ public class initial_Usertouch { } } +*/ +//Keshini's user touch +/* +public void userTouch(int x, int y) { + Piece clickedPiece=board[x][y]; + if(chosenPiece==null) { + //when no piece is selected + if(clickedPiece!=null && clickedPiece.isWhite()==isTurnWhite) { + chosenPiece=clickedPiece; + } + } + else { //if a piece is already selected + if(isSelected(x,y)) { + chosenPiece=null; //unselect the chosen piece to revert to normal state + } + else { //move selected piece to new position using MovePiece logics + MovePiece movement= new MovePiece(chosenPiece, this); + boolean movementSuccess=false; + if(chosenPiece.getType()==PieceType.Pawn) { + movementSuccess=movement.movePawn(x,y); + } else if (chosenPiece.getType()==PieceType.Rook) { + movementSuccess=movement.moveRook(x, y); + }else if (chosenPiece.getType()==PieceType.Bishop) { + movementSuccess=movement.moveBishop(x, y); + }else if (chosenPiece.getType()==PieceType.King) { + movementSuccess=movement.moveKing(x, y); + }else if (chosenPiece.getType()==PieceType.Queen) { + movementSuccess=movement.moveQueen(x, y); + } + if(movementSuccess) { + chosenPiece=null; + turnNumber++; + isTurnWhite=! isTurnWhite; + } else { //invalid move + } + } + } + } + */ \ No newline at end of file diff --git a/src/random_file_to_delete.java b/src/random_file_to_delete.java deleted file mode 100644 index e28aeb0..0000000 --- a/src/random_file_to_delete.java +++ /dev/null @@ -1,9 +0,0 @@ - -public class random_file_to_delete { - - public static void main(String[] args) { - // TODO Auto-generated method stub - - } - -}