forked from woowacourse/java-blackjack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlackjackController.java
61 lines (47 loc) · 1.91 KB
/
BlackjackController.java
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
package blackjack.controller;
import blackjack.config.GameConfig;
import blackjack.constant.UserAction;
import blackjack.domain.BlackjackGame;
import blackjack.view.InputView;
import blackjack.view.OutputView;
import java.util.List;
public class BlackjackController {
private final InputView inputView;
private final OutputView outputView;
public BlackjackController(GameConfig gameConfig) {
this.inputView = gameConfig.getInputView();
this.outputView = gameConfig.getOutputView();
}
public void run() {
List<String> playerNames = inputView.readParticipantsNames();
BlackjackGame blackjackGame = new BlackjackGame(playerNames);
for (String playerName : blackjackGame.getPlayerNames()) {
int betAmount = inputView.readParticipantsBetAmount(playerName);
blackjackGame.updateBetAmount(playerName, betAmount);
}
outputView.printInitialGameSettings(blackjackGame);
playGame(blackjackGame);
outputView.printGameSummary(blackjackGame);
outputView.printGameResult(blackjackGame);
}
public void playGame(BlackjackGame blackjackGame) {
while (blackjackGame.isPlaying()) {
playPlayerTurn(blackjackGame);
}
playDealerTurn(blackjackGame);
}
private void playPlayerTurn(BlackjackGame blackjackGame) {
String playerName = blackjackGame.findCurrentTurnPlayerName();
while (inputView.readOneMoreCardResponse(playerName).equals(UserAction.HIT)) {
blackjackGame.addCardTo(playerName);
outputView.printPlayerCards(blackjackGame, playerName);
}
blackjackGame.endPlayerTurn(playerName);
}
private void playDealerTurn(BlackjackGame blackjackGame) {
if (blackjackGame.isDealerShouldDrawCard()) {
outputView.printDealerOneMoreCardMessage();
}
blackjackGame.processDealerTurn();
}
}