Ejemplo n.º 1
0
  public void onclick(int row, int column) {
    if (endOfGame) {
      FacesMessage fm =
          new FacesMessage(FacesMessage.SEVERITY_INFO, "", "The game is already over.");
      FacesContext.getCurrentInstance().addMessage(null, fm);
    } else {
      if (!blackIsTop) {
        row = 7 - row;
        column = 7 - column;
      }
      if (isPieceSelected) {
        isPieceSelected = false;
        // chessboard.findLegalMovesIgnoringCheck(); // debug
        if (chessboard.isMovePossible(selectedPieceRow, selectedPieceColumn, row, column)) {
          int piece = chessboard.getChessPiece(selectedPieceRow, selectedPieceColumn);
          int capturedPiece = chessboard.getChessPiece(row, column);

          chessboard =
              chessboard.moveChessPiece(
                  selectedPieceRow, selectedPieceColumn, row, column, ChessConstants.W_QUEEN);
          boolean chess = chessboard.isWhiteKingThreatened || chessboard.isBlackKingThreatened;
          Move m =
              new Move(
                  piece,
                  selectedPieceRow,
                  selectedPieceColumn,
                  row,
                  column,
                  Chessboard.s_MATERIAL_VALUE[1] - Chessboard.s_MATERIAL_VALUE[0],
                  chess,
                  capturedPiece > ChessConstants.W_EMPTY,
                  capturedPiece);
          info = m.toString();
          String move = m.getNotation();
          if (history.size() % 2 == 0) {
            move = String.valueOf((history.size() / 2) + 1) + ". " + move;
          }
          history.add(move);
          selectedPieceRow = 0;
          selectedPieceColumn = 0;
          // opponentsMove();
          startOpponentsMove = true;
        }

      } else {
        int piece = chessboard.getChessPiece(row, column);
        if (piece != ChessConstants.B_EMPTY && piece != ChessConstants.W_EMPTY) {
          if (chessboard.isActivePlayersPiece(piece)) {
            isPieceSelected = true;
            selectedPieceRow = row;
            selectedPieceColumn = column;
          }
        }
      }
    }
    redraw();
  }
Ejemplo n.º 2
0
 public boolean isLegalTarget(int row, int column) {
   if (!blackIsTop) {
     row = 7 - row;
     column = 7 - column;
   }
   if (startOpponentsMove) return false;
   if (!isPieceSelected) return false;
   if (selectedPieceColumn == column && selectedPieceRow == row) return false;
   if (chessboard.isMovePossible(selectedPieceRow, selectedPieceColumn, row, column)) return true;
   return false;
 }
Ejemplo n.º 3
0
 public String getOpacity(int row, int column) {
   if (!blackIsTop) {
     row = 7 - row;
     column = 7 - column;
   }
   if (startOpponentsMove) return "opacity:0.7";
   if (!isPieceSelected) return "opacity:1.0";
   if (selectedPieceColumn == column && selectedPieceRow == row) return "opacity:1.0";
   if (chessboard.isMovePossible(selectedPieceRow, selectedPieceColumn, row, column))
     return "opacity:1.0";
   return "opacity:1.0";
 }
Ejemplo n.º 4
0
 public String getBorder(int row, int column) {
   if (!blackIsTop) {
     row = 7 - row;
     column = 7 - column;
   }
   if (startOpponentsMove) return "border:1px solid black";
   if (!isPieceSelected) return "border:1px solid black";
   if (selectedPieceColumn == column && selectedPieceRow == row) return "border: 2px solid blue;";
   if (chessboard.isMovePossible(selectedPieceRow, selectedPieceColumn, row, column))
     return "border: 2px solid red;";
   return "border: 1px solid black";
 }