package util.chess;
import java.util.Objects;
public class PieceP {
private int currentRow;
private int currentColumn;
final static int BOARD_SIZE = 8;
public PieceP(int currentRow, int currentColumn) {
this.currentRow = currentRow;
this.currentColumn = currentColumn;
}
public int getCurrentRow() { return this.currentRow;}
public void setCurrentRow(int currentRow) {
this.currentRow = currentRow;
}
public int getCurrentColumn() { return this.currentColumn;}
public void setCurrentColumn(int currentColumn) {
this.currentColumn = currentColumn;
}
public final boolean move(int toRow, int toColumn) {
System.out.println(“Piecexxx class: move() method”);
if (!isValidMove(toRow, toColumn))
return false;
this.currentRow = toRow;
this.currentColumn = toColumn;
return true;
}
protected boolean isValidMove(int toRow, int toColumn) {
System.out.println(“Piece class: isValidMove() method”);
return toRow >= 0 && toRow < BOARD_SIZE &&
toColumn >= 0 && toColumn < BOARD_SIZE;
}
public String toString() {
return "(" + currentRow + "," + currentColumn + ")";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PieceP pieceP = (PieceP) o;
return currentRow == pieceP.currentRow &&
currentColumn == pieceP.currentColumn;
}
@Override
public int hashCode() {
return Objects.hash(currentRow, currentColumn);
}
}