예제 #1
0
 /**
  * Helper method for actionPerformed. Iterates through the spaces and determines which space was
  * clicked on.
  *
  * @param event the click of a space
  * @return a (file, rank) pair corresponding to the space
  */
 public Pair<Character, Integer> findSource(ActionEvent event) {
   for (int y = board.getYDimension(); y >= 1; y--) {
     for (char x = 'a'; x < ('a' + board.getXDimension()); x++) {
       if (event.getSource() == gui.getSpaceAt(x, y)) {
         return new Pair<Character, Integer>(x, y);
       }
     }
   }
   return null;
 }
예제 #2
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);
       }
     }
   }
 }