Example #1
0
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    String rankOfCard = scanner.nextLine();
    String suitOfCard = scanner.nextLine();

    CardRank cardRank = Enum.valueOf(CardRank.class, rankOfCard);
    CardSuit cardSuit = Enum.valueOf(CardSuit.class, suitOfCard);

    Card card = new Card(cardRank, cardSuit);
    System.out.printf(
        "Card name: %s of %s; Card power: %d",
        card.getCardRank().name(), card.getCardSuit().name(), card.getCardPower());
  }
Example #2
0
 /**
  * gets player with highest card played in hand returns by value then suit
  *
  * @return Player winner
  * @throws IllegalStateException if asked for top player but no cards played
  */
 public Player topPlayer() {
   Card cardLed = hand.get(0).c;
   if (cardLed.id() == -1) { // no cards played
     System.out.println("NO CARDS PLAYED YET. IMPOSSIBLE TO GET TOP CARD");
     throw new IllegalStateException();
   }
   Player p = hand.get(0).playedBy; // place holder for comparison
   Card top = hand.get(0).c; // place holder for comparison
   if (cardLed.isTrump()) { // trump led
     for (CardHistory ch : hand) {
       if ((ch.c).greaterThan(top)) { // Value > Suit
         top = ch.c;
         p = ch.playedBy;
       }
     }
   } else { // fail led
     Suit suitLed = cardLed.getCardSuit();
     Suit suitPlayed = null;
     for (CardHistory ch : hand) {
       if (top.isTrump() || ch.c.isTrump()) { // comparing trump Value > Suit
         if ((ch.c).greaterThan(top)) {
           top = ch.c;
           p = ch.playedBy;
         }
       } else { // comparing fail with fail. Defaults to Suit > Value
         suitPlayed = ch.c.getCardSuit();
         if (suitLed == suitPlayed) { // only compare between suit led
           if ((ch.c).greaterThan(top)) {
             top = ch.c;
             p = ch.playedBy;
           }
         }
       }
     }
   }
   return p;
 }
Example #3
0
 public boolean isSuited() {
   return (card1.getCardSuit().equals(card2.getCardSuit()));
 }