Exemplo n.º 1
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);
  }
Exemplo n.º 2
0
  // Plays a card.
  public static void handleRequestPlay(Message m) {

    boolean heartsBroken = false;
    if (m.info.equals("true")) heartsBroken = true;

    Deck legal = Rules.extractLegalCards(hand, trick, heartsBroken);

    Card c = randomCards(legal, 1).cardAt(0);
    hand.remove(c);

    Message m2 = new Message(Message.PLAY, null, c);
    server.sendMessage(m2);
  }
Exemplo n.º 3
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;
  }
Exemplo n.º 4
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();
  }