public void movePiceTo(int x, int y, Piece pieceToMove) {
if(pieceToMove.canMove(board, pieceToMove.getX(), pieceToMove.getY(), x, y)){ //Check if the piece canMove to the location
if(board[x][y] == null) { //Check if the location is empty
removePiece(pieceToMove.getX(), pieceToMove.getY());
board[x][y] = pieceToMove;
if(pieceToMove instanceof Pawn) {
pieceToMove = (Pawn)pieceToMove;
pieceToMove.isFirstMove = false;
}
This code snippet controls the move of a chess Piece. At the bottom 3 lines, it tries to change the isFirstMove variable of a Pawn class to false since it is not Pawn's first move any more. But I am having hard time changing the variable because the pieceToMove object is basically a Piece class (superclass of Pawn), not a Pawn class. How can I do this smoothly?