public void paint(Graphics graphics) { super.paint(graphics); int size = getFont().getSize(); for (int y = 0; y < Chess.NUM_OF_ROWS; y++) { for (int x = 0; x < Chess.NUM_OF_COLS; x++) { // System.out.println(y + " " + x); int sqi = (m_bottom == Chess.WHITE ? Chess.coorToSqi(x, Chess.NUM_OF_ROWS - y - 1) : Chess.coorToSqi(Chess.NUM_OF_COLS - x - 1, y)); if (Chess.isWhiteSquare(sqi)) { graphics.setColor(m_whiteSquareColor); graphics.fillRect(x * size, y * size, size, size); } else { graphics.setColor(m_blackSquareColor); graphics.fillRect(x * size, y * size, size, size); } int stone = (sqi == m_draggedFrom ? Chess.NO_STONE : m_position.getStone(sqi)); graphics.setColor(Chess.stoneToColor(stone) == Chess.WHITE ? m_whiteColor : m_blackColor); if (m_solidStones) stone = Chess.pieceToStone(Chess.stoneToPiece(stone), Chess.BLACK); // graphics.drawString(getStringForStone(stone, Chess.isWhiteSquare(sqi)), x // * size, (y + 1) * size); graphics.drawString(getStringForStone(stone, true), x * size, (y + 1) * size); } } if (m_draggedStone != Chess.NO_STONE) { graphics.setColor( Chess.stoneToColor(m_draggedStone) == Chess.WHITE ? m_whiteColor : m_blackColor); graphics.drawString( getStringForStone(m_draggedStone, true), m_draggedX - size / 2, m_draggedY + size / 2); } }
private int getSquareForEvent(MouseEvent evt) { int size = getFont().getSize(); return (m_bottom == Chess.WHITE ? Chess.coorToSqi(evt.getX() / size, Chess.NUM_OF_ROWS - evt.getY() / size - 1) : Chess.coorToSqi(Chess.NUM_OF_COLS - evt.getX() / size, evt.getY() / size - 1)); }
/** Flip the sides. */ public void flip() { setBottomPlayer(Chess.otherPlayer(m_bottom)); }