Skip to content

Commit 6f38f2b

Browse files
committed
refactor: 게임테이블 상태에서 참가자 목록 제거
1 parent a95919b commit 6f38f2b

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@
3636

3737
### 기능 구현사항
3838
- [x] 딜러는 처음받는 2장의 합계가 16이하면 반드시 1장의 카드를 추가로 받는다
39-
- [ ] 딜러가 21을 초과하면 남은 플레이어들은 패에 상관없이 승리한다
39+
- [x] 딜러가 21을 초과하면 남은 플레이어들은 패에 상관없이 승리한다
4040
- [ ] 게임 완료 후 각 플레이어별로 승패를 출력한다

src/main/kotlin/blackjack/controller/BlackjackGame.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,11 @@ class BlackjackGame(
1313
private val resultView: ResultView,
1414
) {
1515
fun start() {
16-
val gameTable = GameTable(getParticipants(), Deck.create())
16+
val gameTable = GameTable(Deck.create())
1717
val participants = playGame(gameTable)
1818
printGameResult(participants)
1919
}
2020

21-
private fun getParticipants(): List<Participant> {
22-
return buildList {
23-
add(Dealer.create())
24-
addAll(inputView.inputNames().map { Player.create(name = it) })
25-
}
26-
}
27-
2821
private fun playGame(gameTable: GameTable): List<Participant> {
2922
val participants = setUpInitCard(gameTable)
3023
val (players, dealer) = Participant.separate(participants)
@@ -35,7 +28,7 @@ class BlackjackGame(
3528
}
3629

3730
private fun setUpInitCard(gameTable: GameTable): List<Participant> {
38-
val participants = gameTable.dealInitCard()
31+
val participants = gameTable.dealInitCard(getParticipants())
3932
resultView.linebreak()
4033
resultView.printInitCardReceive(participants)
4134
resultView.printParticipantsCard(participants = participants, printScore = false)
@@ -79,4 +72,11 @@ class BlackjackGame(
7972
resultView.linebreak()
8073
resultView.printParticipantsCard(participants = participants, printScore = true)
8174
}
75+
76+
private fun getParticipants(): List<Participant> {
77+
return buildList {
78+
add(Dealer.create())
79+
addAll(inputView.inputNames().map { Player.create(name = it) })
80+
}
81+
}
8282
}

src/main/kotlin/blackjack/domain/GameTable.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package blackjack.domain
22

33
class GameTable(
4-
private val participants: List<Participant>,
54
private val deck: Deck,
65
) {
7-
fun dealInitCard(): List<Participant> {
6+
fun dealInitCard(participants: List<Participant>): List<Participant> {
87
return participants.map { participant ->
98
(1..INIT_CARD_DRAW_COUNT).fold(participant) { acc, _ ->
109
acc.hit(deck.draw())

src/test/kotlin/blackjack/domain/GameTableTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import io.kotest.matchers.shouldBe
66

77
class GameTableTest : StringSpec({
88
"최초 딜 시 카드를 2장 나누어준다" {
9-
val initCardReceivedUsers = GameTable(createUsers(), Deck.create()).dealInitCard()
9+
val initCardReceivedUsers = GameTable(Deck.create()).dealInitCard(createUsers())
1010

1111
initCardReceivedUsers.forEach {
1212
it.cards.values.size shouldBe 2

0 commit comments

Comments
 (0)