Exemplo n.º 1
0
  public static void main(String[] args) {

    List<Card> cards = new LinkedList<Card>();
    for (Value v : Value.values()) {
      for (Suit s : Suit.values()) {
        cards.add(new Card(v, s));
      }
    }

    Random rand = new Random();
    Card[] cards1 = new Card[7];
    Card[] cards2 = new Card[7];

    for (int i = 0; i < 7; i++) {
      // Card c = cards.remove(rand.nextInt(cards.size())) ;
      Card c1 = cards.remove(2 + i * 3);
      cards1[i] = c1;
      Card c2 = cards.remove(rand.nextInt(cards.size()));
      cards2[i] = c2;
    }

    System.out.println("------ Card 1 ---------");
    for (Card c : cards1) {
      System.out.println(c.getSuit() + " " + c.getValue());
    }
    System.out.println(Round.getRank(cards1));
    System.out.println("------ Card 2 ---------");
    for (Card c : cards2) {
      System.out.println(c.getSuit() + " " + c.getValue());
    }
    System.out.println(Round.getRank(cards2));
  }
Exemplo n.º 2
0
  public static void main(String[] args) {
    Collection<Suit> suits = Arrays.asList(Suit.values());
    Collection<Rank> ranks = Arrays.asList(Rank.values());

    List<Card> deck = new ArrayList<Card>();
    for (Iterator<Suit> i = suits.iterator(); i.hasNext(); )
      for (Iterator<Rank> j = ranks.iterator(); j.hasNext(); )
        deck.add(new Card(i.next(), j.next()));

    // Preferred idiom for nested iteration on collections and arrays
    //        for (Suit suit : suits)
    //            for (Rank rank : ranks)
    //                deck.add(new Card(suit, rank));
  }
Exemplo n.º 3
0
 static {
   for (Suit suit : Suit.values())
     for (Face face : Face.values()) theDeck.add(new Card(face, suit));
 }