Beispiel #1
0
  // Chooses n random cards from haystack
  public static Deck randomCards(Deck haystack, int n) {

    Deck tbr = new Deck();

    while (tbr.length() < n) {

      int random = Randomness.random(0, haystack.length() - 1);
      Card c = haystack.cardAt(random);
      if (tbr.hasCard(c)) continue;
      tbr.add(c);
    }

    return tbr;
  }
Beispiel #2
0
  // Chooses 3 cards to pass.
  public static void handleRequestPass(Message m) {

    Deck toPass = randomCards(hand, 3);

    for (int i = 0; i < toPass.length(); i++) hand.remove(toPass.cardAt(i));

    Message m2 = new Message(Message.PASS, null, toPass);
    server.sendMessage(m2);
  }
Beispiel #3
0
  // Receives passed cards.
  public static void handleSendPassed(Message m) {

    Deck d = m.getDeck();
    for (int i = 0; i < d.length(); i++) hand.add(d.cardAt(i));
    hand.sort();
  }