Exemple #1
0
  public Knight(Color col, boolean white, int x, int y) {
    this.color = col;
    this.x = x;
    this.y = y;
    this.icon = new ImageIcon(Piece.loadImage("knight", color, 64, 64));
    setIcon(this.icon);
    setBorderPainted(false);
    setOpaque(true);

    int[][] pieceSquareConfigW = {
      {-50, -40, -30, -30, -30, -30, -40, -50},
      {-40, -20, 0, 0, 0, 0, -20, -40},
      {-30, 0, 10, 15, 15, 10, 0, -30},
      {-30, 5, 15, 20, 20, 15, 5, -30},
      {-30, 0, 15, 20, 20, 15, 0, -30},
      {-30, 5, 10, 15, 15, 10, 5, -30},
      {-40, -20, 0, 5, 5, 0, -20, -40},
      {-50, -40, -30, -30, -30, -30, -40, -50}
    };

    super.pieceSquareConfigW = pieceSquareConfigW;

    int[][] pieceSquareConfigB = new int[8][8];

    for (int r = 0, r2 = 7; r < 8; r++, r2--) {
      for (int c = 0; c < 8; c++) {
        pieceSquareConfigB[r][c] = pieceSquareConfigW[r2][c];
      }
    }

    super.pieceSquareConfigB = pieceSquareConfigB;

    if (white) {
      setBackground(new Color(192, 192, 192));
    } else {
      setBackground(new Color(128, 128, 128));
    }
    setPreferredSize(new Dimension(80, 76));
  }