-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeck.java
More file actions
32 lines (26 loc) · 841 Bytes
/
Deck.java
File metadata and controls
32 lines (26 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
public class Deck implements Serializable {
private ArrayList<Card> cards;
public Deck() {
cards = new ArrayList<>();
String[] suits = { "Hearts", "Diamonds", "Clubs", "Spades" };
String[] ranks = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace" };
for (String suit : suits) {
for (String rank : ranks) {
cards.add(new Card(suit, rank));
}
}
Collections.shuffle(cards);
}
public Card drawCard() {
return cards.isEmpty() ? null : cards.remove(cards.size() - 1);
}
public void addCard(Card card) {
cards.add(card);
}
public boolean isEmpty() {
return cards.isEmpty();
}
}