-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathDeck.java
More file actions
45 lines (34 loc) · 1.07 KB
/
Deck.java
File metadata and controls
45 lines (34 loc) · 1.07 KB
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
38
39
40
41
42
43
44
45
package blackjack.domain;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class Deck {
private final int TOP_OF_CARDS = 0;
private final String INVALID_DRAW = "남아있는 카드가 없습니다";
private final List<Card> cards;
private Deck(List<Card> cards) {
this.cards = cards;
}
public static Deck createDeck() {
List<Card> blackJack = makeBlackJackCards();
Collections.shuffle(blackJack);
return new Deck(blackJack);
}
private static List<Card> makeBlackJackCards() {
return Arrays.stream(CardNumber.values())
.flatMap(number ->
Arrays.stream(CardType.values())
.map(type -> new Card(number, type)))
.collect(Collectors.toList());
}
public Card cardDraw() {
if (cards.isEmpty()) {
throw new RuntimeException(INVALID_DRAW);
}
return cards.remove(TOP_OF_CARDS);
}
public List<Card> getCards() {
return cards;
}
}