-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathCardDeck.java
More file actions
37 lines (29 loc) · 838 Bytes
/
CardDeck.java
File metadata and controls
37 lines (29 loc) · 838 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
33
34
35
36
37
package blackjack.domain;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class CardDeck {
private final List<Card> cardDeck;
public CardDeck() {
cardDeck = initDeck();
}
public List<Card> initDeck() {
List<Card> deck = new ArrayList<>();
for (Suit suit : Suit.values()) {
for (Denomination denomination : Denomination.values()) {
deck.add(new Card(suit, denomination));
}
}
Collections.shuffle(deck);
return deck;
}
public Card popCard() {
int target = cardDeck.size() - 1;
Card card = cardDeck.get(target);
cardDeck.remove(target);
return card;
}
public boolean contains(Card target) {
return cardDeck.contains(target);
}
}