@@ -2,19 +2,21 @@ package blackjack.controller
2
2
3
3
import blackjack.domain.Dealer
4
4
import blackjack.domain.Deck
5
+ import blackjack.domain.GameResult
5
6
import blackjack.domain.GameTable
6
7
import blackjack.domain.Participant
7
8
import blackjack.domain.Player
8
9
import blackjack.view.InputView
9
10
import blackjack.view.ResultView
10
11
11
- class BlackjackGame (
12
+ data class BlackjackGame (
12
13
private val inputView : InputView ,
13
14
private val resultView : ResultView ,
14
15
) {
15
16
fun start () {
16
17
val gameTable = GameTable (Deck .create())
17
18
val participants = playGame(gameTable)
19
+ printCard(participants)
18
20
printGameResult(participants)
19
21
}
20
22
@@ -36,6 +38,13 @@ class BlackjackGame(
36
38
return participants
37
39
}
38
40
41
+ private fun getParticipants (): List <Participant > {
42
+ return buildList {
43
+ add(Dealer .create())
44
+ addAll(inputView.inputNames().map { Player .create(name = it) })
45
+ }
46
+ }
47
+
39
48
private fun playersTurn (
40
49
participants : List <Participant >,
41
50
gameTable : GameTable ,
@@ -51,7 +60,7 @@ class BlackjackGame(
51
60
return player
52
61
}
53
62
val hitPlayer = gameTable.hit(player)
54
- resultView.printParticipantCard(participant = player , printScore = false )
63
+ resultView.printParticipantCard(participant = hitPlayer , printScore = false )
55
64
return playerTurn(hitPlayer, gameTable)
56
65
}
57
66
@@ -66,15 +75,13 @@ class BlackjackGame(
66
75
return dealerTurn(gameTable.hit(dealer), gameTable)
67
76
}
68
77
69
- private fun printGameResult (participants : List <Participant >) {
78
+ private fun printCard (participants : List <Participant >) {
70
79
resultView.linebreak()
71
80
resultView.printParticipantsCard(participants = participants, printScore = true )
72
81
}
73
82
74
- private fun getParticipants (): List <Participant > {
75
- return buildList {
76
- add(Dealer .create())
77
- addAll(inputView.inputNames().map { Player .create(name = it) })
78
- }
83
+ private fun printGameResult (participants : List <Participant >) {
84
+ resultView.linebreak()
85
+ resultView.printGameResult(GameResult .from(participants))
79
86
}
80
87
}
0 commit comments