Ejemplo n.º 1
0
  /**
   * ****************************************************************** determines if a card at row
   * and position is covered
   *
   * @exception: IllegalArgumentException if row or position is invalid
   * @exception: IllegalStateException if there is no card there
   */
  public boolean isCovered(PositionCard pc) {
    if (pc == null) {
      throw new IllegalArgumentException("Pyramid::isCovered() received null argument.");
    }

    return isCovered(pc.getRow(), pc.getPosition());
  }
Ejemplo n.º 2
0
  /**
   * **************************************************************** Adds a PositionCard to the
   * pyramid returns false if there is already a card there
   *
   * @exception: IllegalArgumentException if the positioncard is null
   */
  public boolean addCard(PositionCard pc) {
    if (pc == null) {
      throw new IllegalArgumentException("Cannot add null card to pyramid");
    }

    int r = pc.getRow();
    int p = pc.getPosition();
    if (pyrArray[r][p] != null) {
      return false;
    }

    pyrArray[r][p] = pc;
    hasChanged();
    return true;
  }
Ejemplo n.º 3
0
  /**
   * ********************************************************************* Selects a card by row and
   * position Returns true if card is selected, false if not
   *
   * @exception: IllegalArgumentException if row or position is invalid
   * @exception: IllegalStateException if another card is already selected
   */
  public boolean select(int row, int position) {
    if ((row > numRows) || (row <= 0)) {
      throw new IllegalArgumentException("\"" + row + "\" is an invalid row number");
    }
    if ((position > numRows) || (position <= 0)) {
      throw new IllegalArgumentException("\"" + position + "\" is an invalid position number");
    }
    if (isSelected()) {
      throw new IllegalStateException("Cannot select more than one card");
    }

    if (!isCovered(row, position)) {

      PositionCard pc = pyrArray[row][position];
      pc.setSelected(true);
      hasChanged();
      selectedRow = row;
      selectedPos = position;
      return true;
    }
    return false;
  }