@@ -2,19 +2,21 @@ package blackjack.controller
22
33import blackjack.domain.Dealer
44import blackjack.domain.Deck
5+ import blackjack.domain.GameResult
56import blackjack.domain.GameTable
67import blackjack.domain.Participant
78import blackjack.domain.Player
89import blackjack.view.InputView
910import blackjack.view.ResultView
1011
11- class BlackjackGame (
12+ data class BlackjackGame (
1213 private val inputView : InputView ,
1314 private val resultView : ResultView ,
1415) {
1516 fun start () {
1617 val gameTable = GameTable (Deck .create())
1718 val participants = playGame(gameTable)
19+ printCard(participants)
1820 printGameResult(participants)
1921 }
2022
@@ -36,6 +38,13 @@ class BlackjackGame(
3638 return participants
3739 }
3840
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+
3948 private fun playersTurn (
4049 participants : List <Participant >,
4150 gameTable : GameTable ,
@@ -51,7 +60,7 @@ class BlackjackGame(
5160 return player
5261 }
5362 val hitPlayer = gameTable.hit(player)
54- resultView.printParticipantCard(participant = player , printScore = false )
63+ resultView.printParticipantCard(participant = hitPlayer , printScore = false )
5564 return playerTurn(hitPlayer, gameTable)
5665 }
5766
@@ -66,15 +75,13 @@ class BlackjackGame(
6675 return dealerTurn(gameTable.hit(dealer), gameTable)
6776 }
6877
69- private fun printGameResult (participants : List <Participant >) {
78+ private fun printCard (participants : List <Participant >) {
7079 resultView.linebreak()
7180 resultView.printParticipantsCard(participants = participants, printScore = true )
7281 }
7382
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))
7986 }
8087}
0 commit comments