@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; }
/* * 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; }
@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; }