public void setPiece(Piece piece, Point p) { final Square sq = squares[p.getX()][p.getY()]; sq.setPiece(piece); // Keep track of the kings if (piece == WHITE_KING && whiteKing != sq) { whiteKing.setPiece(null); whiteKing = sq; } else if (piece == BLACK_KING && blackKing != sq) { blackKing.setPiece(null); blackKing = sq; } }
/** * Constructor Initialize instance variables. * * @param name The name of this Piece * @param lightIcon The Icon representing the white version of Piece in the GUI * @param darkIcon The Icon representing the black version of Piece in the GUI * @param isBlack The color of this Piece * @param curSquare The Square this Piece occupies * @param board The Board this Piece occupies * @param movements Map of legal movements for this Piece */ public Piece( String name, boolean isBlack, Square curSquare, Board board, Map<Character, Integer> movements) { m_name = name; m_lightIcon = ImageUtility.getLightImage(name); m_darkIcon = ImageUtility.getDarkImage(name); setBlack(isBlack); m_curSquare = curSquare; setOriginalSquare(curSquare); // Tell the Square what Piece is on it. curSquare.setPiece(this); m_board = board; m_movements = movements; List<Square> legalDests = Lists.newArrayList(); setLegalDests(legalDests); List<Square> guardSquares = Lists.newArrayList(); setGuardSquares(guardSquares); setMoveCount(0); }