コード例 #1
0
 @Override
 public final boolean doesAccept(TEComponentStack stack) {
   boolean accept = false;
   if (stack.getChildStack() == null) {
     PlayingCard card = stack.getPlayingCard();
     TEComponentStack childStack = getChildStack();
     if (childStack == null) {
       accept = (card.getFaceValue() == FaceValue.Ace);
     } else {
       PlayingCard childCard = childStack.getPlayingCard();
       if (card.getSuit() == childCard.getSuit()) {
         while (childStack.getChildStack() != null) {
           childStack = childStack.getChildStack();
         }
         childCard = childStack.getPlayingCard();
         accept = ((childCard.getFaceValue().getValue() + 1) == card.getFaceValue().getValue());
       }
     }
   }
   return accept;
 }
コード例 #2
0
  /*
   * This method takes the card the human played, and the face up card, and
   * strips the cards to their values and their suits. It then compares if any
   * are equivalent, and if yes, passed true back to main. If not, it displays as such,
   * and the data validation is handled in main
   */
  public boolean stripHumanCard(PlayingCard cardPlayed, PlayingCard cardUp) {
    char suit = cardPlayed.getSuit();
    int value = cardPlayed.getValue();

    char otherSuit = cardUp.getSuit();
    int otherValue = cardUp.getValue();

    if (cardPlayed.getValue() == 8) {
      this.discardDeck.push(cardPlayed);
      validCard = true;
    } else if (value == otherValue) {
      this.discardDeck.push(cardPlayed);
      validCard = true;
    } else if (suit == otherSuit) {
      this.discardDeck.push(cardPlayed);
      validCard = true;
    } else {
      System.out.println("Not a legal card!");
      validCard = false;
    }
    return validCard;
  }
コード例 #3
0
ファイル: DynamiteCard.java プロジェクト: nivecher/Bang
  @Override
  public boolean apply(Player p) {
    PlayingCard draw = context.flipCard();

    boolean hit =
        (draw.getSuit() == Suit.Spades
            && EnumSet.range(Face.Two, Face.Nine).contains(draw.getFace()));

    if (hit) {
      p.loseLife();
      p.loseLife();
      p.loseLife();
    }

    return hit;
  }