Skip to content

Commit

Permalink
feat : Player 생성 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
goodbyeyo committed Dec 16, 2024
1 parent bd1e7be commit 768e53d
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/test/kotlin/blackjack/BlackJackTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ class BlackJackTest {
it.message shouldBe "카드를 받을 수 없습니다"
}
}

@Test
fun `게임에 참여할 사람들의 이름을 입력 받을 수 있다`() {
val players = Players.create("kim,lee,hong")
players.size shouldBe 3
}
}

object UserInput {
fun enterParticipatingPlayers(): Players {
println("게임에 참여할 사람의 이름을 입력하세요.(쉼표 기준으로 분리)")
val playerNames = readln()
return Players.create(playerNames)
}
}

data class Card(val rank: Ranks, val suits: Suits)
Expand Down Expand Up @@ -140,9 +154,8 @@ class GameCards private constructor(private val deck: Queue<Card>) {
}
}

class Player(val name: String) {
class Player(val name: String, private var isDrawContinue: Boolean = true) {
private var userCards = UserCards(mutableListOf())
private var isDrawContinue: Boolean = true

fun receiveCard(card: Card) {
require(isDrawContinue) { "카드를 받을 수 없습니다" }
Expand All @@ -162,4 +175,15 @@ class Player(val name: String) {
}
}

data class Players(private val players: List<Player>) : Collection<Player> by players {
companion object {
private const val DELIMITER = ","

fun create(playerNames: String): Players {
val players = playerNames.split(DELIMITER).map { playerName -> Player(playerName, true) }
return Players(players)
}
}
}


0 comments on commit 768e53d

Please sign in to comment.