File tree Expand file tree Collapse file tree 9 files changed +107
-9
lines changed Expand file tree Collapse file tree 9 files changed +107
-9
lines changed Original file line number Diff line number Diff line change 1
1
package blackjack.controller
2
2
3
+ import blackjack.model.Card
4
+ import blackjack.model.CardInfo
5
+ import blackjack.model.CardType
6
+ import blackjack.model.Participant
3
7
import blackjack.ui.InputView
4
8
import blackjack.ui.ResultView
5
9
6
- class BlackJackGame {
10
+ class BlackJackGame (
11
+ val participants : List <Participant >,
12
+ ) {
13
+
14
+ private val cardsPool = mutableSetOf<Card >()
15
+
16
+ init {
17
+ makeCardsPool()
18
+ }
19
+
20
+ private fun makeCardsPool () {
21
+ CardType .values().forEach { type ->
22
+ CardInfo .values().forEach { cardInfo ->
23
+ cardsPool.add(Card (type, cardInfo))
24
+ }
25
+ }
26
+ }
27
+
28
+ fun allocateDefaultCards () {
29
+ participants.forEach {
30
+ it.cards.addAll(pickRandomCards(DEFAULT_CARD_COUNTS ))
31
+ }
32
+ }
33
+
34
+ private fun pickRandomCards (count : Int ): List <Card > {
35
+ val pickedCards = cardsPool.shuffled().take(count)
36
+ pickedCards.forEach { pickedCard ->
37
+ cardsPool.remove(pickedCard)
38
+ }
39
+ return pickedCards
40
+ }
41
+
42
+ companion object {
43
+ const val DEFAULT_CARD_COUNTS = 2
44
+ }
7
45
}
8
46
9
47
fun main () {
10
48
val participants = InputView .registerParticipants()
49
+
50
+ val blackJackGame = BlackJackGame (participants)
51
+
11
52
ResultView .showInitialStatusOfParticipants(participants)
12
- }
53
+ }
Original file line number Diff line number Diff line change 1
1
package blackjack.model
2
2
3
3
data class Card (
4
- val name : String ,
4
+ val type : CardType ,
5
+ val value : CardInfo ,
5
6
)
Original file line number Diff line number Diff line change
1
+ package blackjack.model
2
+
3
+ enum class CardInfo (
4
+ val displayName : String ,
5
+ val value1 : Int ,
6
+ val value2 : Int = value1,
7
+ ) {
8
+ Ace (" ace" , 1 , 10 ),
9
+ One (" 1" , 1 ),
10
+ Two (" 2" , 2 ),
11
+ Three (" 3" , 3 ),
12
+ Four (" 4" , 4 ),
13
+ Five (" 5" , 5 ),
14
+ Six (" 6" , 6 ),
15
+ Seven (" 7" , 7 ),
16
+ Eight (" 8" , 8 ),
17
+ Nine (" 9" , 9 ),
18
+ King (" King" , 10 ),
19
+ Queen (" Queen" , 10 ),
20
+ Jack (" Jack" , 10 ),
21
+ }
Original file line number Diff line number Diff line change
1
+ package blackjack.model
2
+
3
+ enum class CardType {
4
+ Diamond ,
5
+ Spade ,
6
+ Heart ,
7
+ Clover ,
8
+ ;
9
+ }
Original file line number Diff line number Diff line change @@ -2,5 +2,5 @@ package blackjack.model
2
2
3
3
data class Participant (
4
4
val name : String ,
5
- val cards : List <Card >? = null ,
5
+ val cards : MutableList <Card > = mutableListOf() ,
6
6
)
Original file line number Diff line number Diff line change @@ -25,5 +25,4 @@ object InputView {
25
25
}
26
26
} ? : throw IllegalArgumentException (" 카드 받기 여부는 null을 허용하지 않습니다." )
27
27
}
28
-
29
- }
28
+ }
Original file line number Diff line number Diff line change @@ -11,4 +11,4 @@ object ResultView {
11
11
}
12
12
println (" 에게 2장의 카드를 나눠주었습니다." )
13
13
}
14
- }
14
+ }
Original file line number Diff line number Diff line change @@ -34,7 +34,6 @@ class DslTest {
34
34
)
35
35
}
36
36
}
37
-
38
37
}
39
38
40
39
fun introduce (block : PersonBuilder .() -> Unit ): Person {
@@ -100,4 +99,4 @@ data class Person(
100
99
sealed interface Skill {
101
100
data class SoftSkill (val name : String ) : Skill
102
101
data class HardSkill (val name : String ) : Skill
103
- }
102
+ }
Original file line number Diff line number Diff line change
1
+ package blackjack.controller
2
+
3
+ import blackjack.controller.BlackJackGame.Companion.DEFAULT_CARD_COUNTS
4
+ import blackjack.model.Participant
5
+ import io.kotest.matchers.shouldBe
6
+ import org.junit.jupiter.api.Test
7
+
8
+ class BlackJackGameTest {
9
+
10
+ @Test
11
+ fun checkDefaultAllocatedCards () {
12
+ val blackJackGame = BlackJackGame (participants)
13
+ blackJackGame.allocateDefaultCards()
14
+
15
+ blackJackGame.participants.forEach {
16
+ it.cards.size shouldBe DEFAULT_CARD_COUNTS
17
+ }
18
+ }
19
+
20
+ companion object {
21
+ private val participants = listOf (
22
+ Participant (" Liam" ),
23
+ Participant (" Noel" ),
24
+ Participant (" Gem" ),
25
+ Participant (" Andy" ),
26
+ )
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments