Esempio n. 1
0
 /** Return one card starting from the given cursor. */
 private static Card oneFromCursor(Cursor cursor) {
   if (cursor.isClosed()) {
     throw new SQLException();
   }
   cursor.moveToFirst();
   Card card = new Card();
   card.id = cursor.getLong(0);
   card.interval = cursor.getDouble(1);
   card.question = cursor.getString(2);
   card.answer = cursor.getString(3);
   return card;
 }
Esempio n. 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;
 }