Esempio n. 1
0
  public void addFreeSquares(ArrayList<Point> points) { // add all squares
    for (int i = 0; i < GRID_WIDTH; i++) {
      for (int j = 0; j < GRID_HEIGHT; j++) {
        points.add(new Point(i, j));
      }
    }

    // remove all pieces
    for (Piece piece : game.getPieces()) {
      if (!piece.isOut()) {
        points.remove(piece.getLocation());
      }
    }
  }
Esempio n. 2
0
  /**
   * Handles the mouse location click.
   *
   * @param loc the location that was clicked
   * @return true because the click has been handled
   */
  @Override
  public boolean locationClicked(Location loc) {
    if (game.getTurn() instanceof SmartComputerCheckerPlayer) // ignore all clicks on CPU's turn
    {
      return true;
    }

    if (lastMove != null
        && lastMove.isJump()
        && lastMove.getPiece().canJump()) // locks selection onto jump-chaining piece
    {
      Piece lastPiece = lastMove.getPiece();

      if (!loc.equals(lastPiece.getLocation())
          && !lastPiece.getAllowedMoves().contains(loc)) // consumes irrelevant clicks
      {
        return true;
      }
    }
    if (getGrid().get(loc) != null && !(getGrid().get(loc) instanceof PieceTile)) {
      Piece p = getGrid().get(loc);
      if (pieceSelected) {
        game.undisplayMoves(playerPiece);
      }
      game.displayMoves(p); // selection and highlight available moves
      playerPiece = p;
      pieceSelected = true;
    } else if (pieceSelected && !playerPiece.getAllowedMoves().contains(loc)) {
      pieceSelected = false;
      game.undisplayMoves(playerPiece); // undo selection and highlight
      playerPiece = null;
    } else if (pieceSelected && playerPiece.getAllowedMoves().contains(loc)) {
      pieceSelected = false;
      game.undisplayMoves(playerPiece); // undo selection and highlight
      setPlayerLocation(loc);
    }

    return true;
  }