Ejemplo n.º 1
0
 /**
  * Accessor method for accessing list of Plays.
  *
  * @return clonedList
  */
 public List<Play> getTrick() {
   List<Play> clonedList = new ArrayList<Play>(fPlays.size());
   for (Play play : fPlays) {
     clonedList.add(new Play(play.getPlayer(), play.getCard()));
   }
   return clonedList;
 }
Ejemplo n.º 2
0
  /**
   * @return The player who wins the trick to date.
   * @throws ModelException is the trick is empty.
   */
  public String getWinner() throws ModelException {
    String winner;
    Card maxCard;
    Card compareCard;

    if (fPlays.size() == 0) // Check if trick is empty, and return exception.
    {
      throw new ModelException("The trick is empty.");
    }

    Suit led = getSuitLed();
    maxCard = (fPlays.get(0)).getCard();
    winner = new String(fPlays.get(0).getPlayer());

    for (Play play : fPlays) {
      compareCard = play.getCard();
      if (compareCard.getSuit().equals(led)) {
        if (compareCard.compareTo(maxCard) > 0) {
          maxCard = compareCard;
          winner = new String(play.getPlayer());
        }
      }
    }
    return winner;
  }