-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathGame.java
More file actions
64 lines (51 loc) · 1.74 KB
/
Game.java
File metadata and controls
64 lines (51 loc) · 1.74 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package blackjack.domain;
import blackjack.domain.card.CardDeck;
import blackjack.domain.player.Dealer;
import blackjack.domain.player.Player;
import blackjack.domain.state.State;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class Game {
private static final int PASS_CARD_NUMBER = 2;
private static final String DEALER_NAME = "딜러";
private final static int DEALER_THRESHOLD = 16;
private final List<Player> players;
private final Dealer dealer;
public Game(Dealer dealer, List<Player> players) {
this.players = players;
this.dealer = dealer;
}
public Game(List<String> playerNames) {
this(new Dealer(DEALER_NAME, handOutCards()), playerNames.stream()
.map(Game::createPlayer)
.collect(Collectors.toList()));
}
private static Player createPlayer(String name) {
return new Player(name, handOutCards());
}
private static State handOutCards() {
return new State(CardDeck.pop(PASS_CARD_NUMBER), true);
}
public boolean giveCardToDealer() {
if (dealer.getCards().cards().sumScore() <= DEALER_THRESHOLD) {
dealer.getCards().addCard(CardDeck.pop());
return true;
}
return false;
}
public int getTotalScoreOfPlayer(Player player) {
return player.getCards().cards().sumScore();
}
public List<Integer> getScoresOfPlayers() {
return players.stream()
.mapToInt(this::getTotalScoreOfPlayer)
.boxed().collect(Collectors.toList());
}
public List<Player> getPlayers() {
return Collections.unmodifiableList(players);
}
public Dealer getDealer() {
return dealer;
}
}