Example #1
0
 private void playCard(@NotNull SevensPlayer inputter, Card card, Card adjacentExtremeCard) {
   if (adjacentExtremeCard.getRank() != SEVEN) {
     extremeCards.remove(adjacentExtremeCard);
   }
   extremeCards.add(card);
   playedCards.get(card.getSuit()).add(card);
   inputter.playCard(card);
 }
Example #2
0
 @Nullable
 private Card getAdjacentExtremeCard(@NotNull Card card) {
   if (card.getRank() == SEVEN) {
     if (extremeCards.isEmpty()) {
       // You can only start the game with the seven of diamonds.
       return card == SEVEN_OF_DIAMONDS ? SEVEN_OF_DIAMONDS : null;
     } else {
       return card;
     }
   }
   return extremeCards
       .stream()
       .filter(extreme -> isAdjacent(card, extreme))
       .findAny()
       .orElse(null);
 }
Example #3
0
 private boolean isAdjacent(Card card, Card extreme) {
   return card.getSuit() == extreme.getSuit()
       && (card.getRank().getValue() == extreme.getRank().getValue() - 1
           || card.getRank().getValue() == extreme.getRank().getValue() + 1);
 }