예제 #1
0
 /**
  * Makes it so all buttons are not clickable except for the spaces with pieces of a particular
  * color
  *
  * @param color Pieces of this color can be clicked on
  */
 public void setCurrentSide(int color) {
   for (char file = 'a'; file < ('a' + board.getXDimension()); file++) {
     for (int rank = 1; rank <= board.getYDimension(); rank++) {
       Piece piece = board.at(file, rank);
       JButton space = gui.getSpaceAt(file, rank);
       // check if the space is empty, or if it matches the color parameter
       if (piece != null && piece.getColor() == color) {
         space.setEnabled(true);
       } else {
         space.setEnabled(false);
       }
     }
   }
 }
예제 #2
0
  /**
   * Method called to handle the situation where a user is moving the currentPiece to a new location
   *
   * @param position New space on the board for a piece to move
   */
  public void handleMove(Pair<Character, Integer> position) {
    // place the current move onto the stack
    Piece captured = board.at(position);
    Pair<Character, Integer> oldPosition = currentPiece.getPosition();
    moveStack.push(new Move(currentPiece, captured, oldPosition, position));

    // make the move
    master.move(currentPiece, position);

    // refresh board after piece is moved
    try {
      gui.refreshBoard();
    } catch (IOException e1) {
      e1.printStackTrace();
    }
    if (!moveStack.empty()) {
      // can undo now that there are moves in the stack
      gui.setUndoEnabled(true);
    }
    // reset backgrounds and change sides
    switchSides();
  }