From fd3513d0b15aac2c5a7990facfffdca33de95bf1 Mon Sep 17 00:00:00 2001 From: baek0318 Date: Mon, 20 Nov 2023 21:52:02 +0900 Subject: [PATCH 01/12] step1 : ktlintCheck --- src/main/kotlin/dsl/Resume.kt | 7 ------- src/test/kotlin/dsl/ResumeTest.kt | 4 ++-- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/dsl/Resume.kt b/src/main/kotlin/dsl/Resume.kt index e46b870dee..0b6aa50d74 100644 --- a/src/main/kotlin/dsl/Resume.kt +++ b/src/main/kotlin/dsl/Resume.kt @@ -44,8 +44,6 @@ class Resume( result = 31 * result + languages.hashCode() return result } - - } class Skill( @@ -78,8 +76,6 @@ class Skill( result = 31 * result + hardSkills.hashCode() return result } - - } class Language( @@ -102,11 +98,8 @@ class Language( override fun hashCode(): Int { return languages.hashCode() } - - } - fun introduce(block: Resume.() -> Unit): Resume { val resume = Resume() resume.block() diff --git a/src/test/kotlin/dsl/ResumeTest.kt b/src/test/kotlin/dsl/ResumeTest.kt index fdc26060c9..54d9122507 100644 --- a/src/test/kotlin/dsl/ResumeTest.kt +++ b/src/test/kotlin/dsl/ResumeTest.kt @@ -3,7 +3,7 @@ package dsl import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe -class ResumeTest:StringSpec({ +class ResumeTest : StringSpec({ "이력서 dsl 생성 테스트" { val result = introduce { @@ -34,4 +34,4 @@ class ResumeTest:StringSpec({ ) ) } -}) \ No newline at end of file +}) From 7c30e8f3d5fa5433e9ff2b0963ad16ed48d8c68f Mon Sep 17 00:00:00 2001 From: baek0318 Date: Mon, 20 Nov 2023 23:16:24 +0900 Subject: [PATCH 02/12] =?UTF-8?q?step1=20:=20Resume=EA=B0=80=20=EB=B6=88?= =?UTF-8?q?=EB=B3=80=EC=9D=B4=20=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/dsl/Resume.kt | 155 +++++++++++++----------------- src/test/kotlin/dsl/ResumeTest.kt | 6 +- 2 files changed, 68 insertions(+), 93 deletions(-) diff --git a/src/main/kotlin/dsl/Resume.kt b/src/main/kotlin/dsl/Resume.kt index 0b6aa50d74..995a9d4ba5 100644 --- a/src/main/kotlin/dsl/Resume.kt +++ b/src/main/kotlin/dsl/Resume.kt @@ -1,107 +1,82 @@ package dsl -class Resume( - var name: String = "", - var company: String = "", - var skills: Skill = Skill(), - var languages: Language = Language() +data class Resume( + val name: String, + val company: String, + val skills: Skill, + val languages: Language ) { - - fun name(name: String) { - this.name = name - } - - fun company(companyName: String) { - this.company = companyName - } - - fun skills(block: Skill.() -> Unit) { - skills.block() - } - - fun languages(block: Language.() -> Unit) { - languages.block() - } - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as Resume - - if (name != other.name) return false - if (company != other.company) return false - if (skills != other.skills) return false - if (languages != other.languages) return false - - return true - } - - override fun hashCode(): Int { - var result = name.hashCode() - result = 31 * result + company.hashCode() - result = 31 * result + skills.hashCode() - result = 31 * result + languages.hashCode() - return result + class Builder( + private var name: String = "", + private var company: String = "", + private var skills: Skill.Builder = Skill.Builder(), + private var languages: Language.Builder = Language.Builder() + ) { + + fun name(name: String) { + this.name = name + } + + fun company(companyName: String) { + this.company = companyName + } + + fun skills(block: Skill.Builder.() -> Unit) { + skills.block() + } + + fun languages(block: Language.Builder.() -> Unit) { + languages.block() + } + + internal fun build(): Resume { + return Resume(name, company, skills.build(), languages.build()) + } } } -class Skill( - val softSkills: MutableList = mutableListOf(), - val hardSkills: MutableList = mutableListOf() +data class Skill( + val softSkills: List, + val hardSkills: List ) { - - fun soft(skill: String) { - softSkills.add(skill) - } - - fun hard(skill: String) { - hardSkills.add(skill) - } - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as Skill - - if (softSkills != other.softSkills) return false - if (hardSkills != other.hardSkills) return false - - return true - } - - override fun hashCode(): Int { - var result = softSkills.hashCode() - result = 31 * result + hardSkills.hashCode() - return result + class Builder( + private val softSkills: MutableList = mutableListOf(), + private val hardSkills: MutableList = mutableListOf() + ) { + + fun soft(skill: String) { + softSkills.add(skill) + } + + fun hard(skill: String) { + hardSkills.add(skill) + } + + internal fun build(): Skill { + return Skill(softSkills, hardSkills) + } } } -class Language( - val languages: MutableMap = mutableMapOf() +data class Language( + val languages: Map ) { + class Builder( + private val languages: MutableMap = mutableMapOf() + ) { - infix fun String.level(level: Int) { - languages[this] = level - } - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as Language - - return languages == other.languages - } + infix fun String.level(level: Int) { + languages[this] = level + } - override fun hashCode(): Int { - return languages.hashCode() + internal fun build(): Language { + return Language(languages) + } } } -fun introduce(block: Resume.() -> Unit): Resume { - val resume = Resume() - resume.block() - return resume +fun introduce(block: Resume.Builder.() -> Unit): Resume { + val builder = Resume.Builder() + builder.block() + return builder.build() } diff --git a/src/test/kotlin/dsl/ResumeTest.kt b/src/test/kotlin/dsl/ResumeTest.kt index 54d9122507..a70727cbfc 100644 --- a/src/test/kotlin/dsl/ResumeTest.kt +++ b/src/test/kotlin/dsl/ResumeTest.kt @@ -23,11 +23,11 @@ class ResumeTest : StringSpec({ name = "박재성", company = "우아한형제들", skills = Skill( - softSkills = mutableListOf("A passion for problem solving", "Good communication skills"), - hardSkills = mutableListOf("Kotlin") + softSkills = listOf("A passion for problem solving", "Good communication skills"), + hardSkills = listOf("Kotlin") ), languages = Language( - languages = mutableMapOf( + languages = mapOf( "Korean" to 5, "English" to 3 ) From 96a8a5a8482bd0b1ddd03921ab2d7f13aa13114b Mon Sep 17 00:00:00 2001 From: baek0318 Date: Mon, 20 Nov 2023 23:22:33 +0900 Subject: [PATCH 03/12] =?UTF-8?q?step1=20:=20@DslMarker=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/dsl/Dsl.kt | 5 +++++ src/main/kotlin/dsl/Resume.kt | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 src/main/kotlin/dsl/Dsl.kt diff --git a/src/main/kotlin/dsl/Dsl.kt b/src/main/kotlin/dsl/Dsl.kt new file mode 100644 index 0000000000..cf9109251b --- /dev/null +++ b/src/main/kotlin/dsl/Dsl.kt @@ -0,0 +1,5 @@ +package dsl + +@DslMarker +@Target(AnnotationTarget.CLASS, AnnotationTarget.TYPE) +annotation class Dsl() diff --git a/src/main/kotlin/dsl/Resume.kt b/src/main/kotlin/dsl/Resume.kt index 995a9d4ba5..947c5ad752 100644 --- a/src/main/kotlin/dsl/Resume.kt +++ b/src/main/kotlin/dsl/Resume.kt @@ -21,11 +21,11 @@ data class Resume( this.company = companyName } - fun skills(block: Skill.Builder.() -> Unit) { + fun skills(block: (@Dsl Skill.Builder).() -> Unit) { skills.block() } - fun languages(block: Language.Builder.() -> Unit) { + fun languages(block: (@Dsl Language.Builder).() -> Unit) { languages.block() } @@ -75,7 +75,7 @@ data class Language( } } -fun introduce(block: Resume.Builder.() -> Unit): Resume { +fun introduce(block: (@Dsl Resume.Builder).() -> Unit): Resume { val builder = Resume.Builder() builder.block() return builder.build() From 548b22399fc73060b58cb0116a94317bcb10ccb4 Mon Sep 17 00:00:00 2001 From: baek0318 Date: Mon, 20 Nov 2023 23:26:12 +0900 Subject: [PATCH 04/12] =?UTF-8?q?step1=20:=20skill,=20language=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EB=B3=B5=EC=88=98=ED=98=95=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/dsl/Resume.kt | 24 ++++++++++++------------ src/test/kotlin/dsl/ResumeTest.kt | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/dsl/Resume.kt b/src/main/kotlin/dsl/Resume.kt index 947c5ad752..40b966bd03 100644 --- a/src/main/kotlin/dsl/Resume.kt +++ b/src/main/kotlin/dsl/Resume.kt @@ -3,14 +3,14 @@ package dsl data class Resume( val name: String, val company: String, - val skills: Skill, - val languages: Language + val skills: Skills, + val languages: Languages ) { class Builder( private var name: String = "", private var company: String = "", - private var skills: Skill.Builder = Skill.Builder(), - private var languages: Language.Builder = Language.Builder() + private var skills: Skills.Builder = Skills.Builder(), + private var languages: Languages.Builder = Languages.Builder() ) { fun name(name: String) { @@ -21,11 +21,11 @@ data class Resume( this.company = companyName } - fun skills(block: (@Dsl Skill.Builder).() -> Unit) { + fun skills(block: (@Dsl Skills.Builder).() -> Unit) { skills.block() } - fun languages(block: (@Dsl Language.Builder).() -> Unit) { + fun languages(block: (@Dsl Languages.Builder).() -> Unit) { languages.block() } @@ -35,7 +35,7 @@ data class Resume( } } -data class Skill( +data class Skills( val softSkills: List, val hardSkills: List ) { @@ -52,13 +52,13 @@ data class Skill( hardSkills.add(skill) } - internal fun build(): Skill { - return Skill(softSkills, hardSkills) + internal fun build(): Skills { + return Skills(softSkills, hardSkills) } } } -data class Language( +data class Languages( val languages: Map ) { class Builder( @@ -69,8 +69,8 @@ data class Language( languages[this] = level } - internal fun build(): Language { - return Language(languages) + internal fun build(): Languages { + return Languages(languages) } } } diff --git a/src/test/kotlin/dsl/ResumeTest.kt b/src/test/kotlin/dsl/ResumeTest.kt index a70727cbfc..e0b5496019 100644 --- a/src/test/kotlin/dsl/ResumeTest.kt +++ b/src/test/kotlin/dsl/ResumeTest.kt @@ -22,11 +22,11 @@ class ResumeTest : StringSpec({ result shouldBe Resume( name = "박재성", company = "우아한형제들", - skills = Skill( + skills = Skills( softSkills = listOf("A passion for problem solving", "Good communication skills"), hardSkills = listOf("Kotlin") ), - languages = Language( + languages = Languages( languages = mapOf( "Korean" to 5, "English" to 3 From 0530d68b6bf660083e102c00a2a45355cbf6ccd8 Mon Sep 17 00:00:00 2001 From: baek0318 Date: Mon, 27 Nov 2023 00:39:31 +0900 Subject: [PATCH 05/12] =?UTF-8?q?step2=20:=20CardDeck=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/CardDeck.kt | 6 ++++++ src/main/kotlin/blackjack/ListCardDeck.kt | 18 ++++++++++++++++++ src/main/kotlin/blackjack/RandomCardDeck.kt | 7 +++++++ src/test/kotlin/blackjack/CardDeckTest.kt | 16 ++++++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 src/main/kotlin/blackjack/CardDeck.kt create mode 100644 src/main/kotlin/blackjack/ListCardDeck.kt create mode 100644 src/main/kotlin/blackjack/RandomCardDeck.kt create mode 100644 src/test/kotlin/blackjack/CardDeckTest.kt diff --git a/src/main/kotlin/blackjack/CardDeck.kt b/src/main/kotlin/blackjack/CardDeck.kt new file mode 100644 index 0000000000..6d791a7b3c --- /dev/null +++ b/src/main/kotlin/blackjack/CardDeck.kt @@ -0,0 +1,6 @@ +package blackjack + +interface CardDeck { + fun drawCard(): Card + +} \ No newline at end of file diff --git a/src/main/kotlin/blackjack/ListCardDeck.kt b/src/main/kotlin/blackjack/ListCardDeck.kt new file mode 100644 index 0000000000..42abafa144 --- /dev/null +++ b/src/main/kotlin/blackjack/ListCardDeck.kt @@ -0,0 +1,18 @@ +package blackjack + +class ListCardDeck( + private val cards: MutableList +): CardDeck { + + override fun drawCard(): Card { + checkCardCount() + return cards.removeAt(cards.size - 1) + } + + private fun checkCardCount() { + if (cards.size == 0) { + throw IllegalStateException("카드가 없습니다.") + } + } + +} \ No newline at end of file diff --git a/src/main/kotlin/blackjack/RandomCardDeck.kt b/src/main/kotlin/blackjack/RandomCardDeck.kt new file mode 100644 index 0000000000..8778bf9689 --- /dev/null +++ b/src/main/kotlin/blackjack/RandomCardDeck.kt @@ -0,0 +1,7 @@ +package blackjack + +class RandomCardDeck: CardDeck { + override fun drawCard(): Card { + return Card.values().random() + } +} \ No newline at end of file diff --git a/src/test/kotlin/blackjack/CardDeckTest.kt b/src/test/kotlin/blackjack/CardDeckTest.kt new file mode 100644 index 0000000000..09234659f7 --- /dev/null +++ b/src/test/kotlin/blackjack/CardDeckTest.kt @@ -0,0 +1,16 @@ +package blackjack + +import io.kotest.core.spec.style.StringSpec +import io.kotest.matchers.shouldBe +import java.util.* +import kotlin.collections.ArrayList + +class CardDeckTest: StringSpec({ + + "카드를 뽑을 수 있다" { + val cardDeck = ListCardDeck(mutableListOf(Card.TWO, Card.THREE)) + val card = cardDeck.drawCard() + card shouldBe Card.THREE + } + +}) \ No newline at end of file From d776058352a635186ca18f84b113e27f40cefc0f Mon Sep 17 00:00:00 2001 From: baek0318 Date: Mon, 27 Nov 2023 00:39:55 +0900 Subject: [PATCH 06/12] =?UTF-8?q?step2=20:=20Player=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/Player.kt | 19 +++++++++++++++++ src/test/kotlin/blackjack/PlayerTest.kt | 28 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/main/kotlin/blackjack/Player.kt create mode 100644 src/test/kotlin/blackjack/PlayerTest.kt diff --git a/src/main/kotlin/blackjack/Player.kt b/src/main/kotlin/blackjack/Player.kt new file mode 100644 index 0000000000..60f0ad4477 --- /dev/null +++ b/src/main/kotlin/blackjack/Player.kt @@ -0,0 +1,19 @@ +package blackjack + +class Player( + val name: String, +) { + private val _cards: MutableList = mutableListOf() + + val cards: List + get() = _cards.toList() + + fun go(card: Card) { + _cards.add(card) + } + + fun stop(): Int { + return ScoreCalculator.calc(cards) + } + +} \ No newline at end of file diff --git a/src/test/kotlin/blackjack/PlayerTest.kt b/src/test/kotlin/blackjack/PlayerTest.kt new file mode 100644 index 0000000000..2bd728e6fe --- /dev/null +++ b/src/test/kotlin/blackjack/PlayerTest.kt @@ -0,0 +1,28 @@ +package blackjack + +import io.kotest.core.spec.style.StringSpec +import io.kotest.matchers.shouldBe + +class PlayerTest: StringSpec({ + + "player는 go를 한다면 카드를 받을 수 있어야 한다" { + val player = Player("test") + player.go(Card.TWO) + player.go(Card.THREE) + + player.cards shouldBe listOf(Card.TWO, Card.THREE) + } + + "player는 stop을 한다면 자신의 점수를 계산해서 줘야한다" { + val player = Player("test") + player.go(Card.TWO) + player.go(Card.THREE) + + player.stop() shouldBe 5 + } + + "player는 이름을 가질 수 있다" { + val player = Player("edward") + player.name shouldBe "edward" + } +}) From 18cd2e0b4ab8aef01c62b7a9c6f6c0e637cc86d7 Mon Sep 17 00:00:00 2001 From: baek0318 Date: Mon, 27 Nov 2023 00:40:06 +0900 Subject: [PATCH 07/12] =?UTF-8?q?step2=20:=20=EC=A0=90=EC=88=98=20?= =?UTF-8?q?=EA=B3=84=EC=82=B0=EA=B8=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/ScoreCalculator.kt | 8 ++++++++ src/test/kotlin/blackjack/ScoreCalculatorTest.kt | 12 ++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/main/kotlin/blackjack/ScoreCalculator.kt create mode 100644 src/test/kotlin/blackjack/ScoreCalculatorTest.kt diff --git a/src/main/kotlin/blackjack/ScoreCalculator.kt b/src/main/kotlin/blackjack/ScoreCalculator.kt new file mode 100644 index 0000000000..f672fed0a1 --- /dev/null +++ b/src/main/kotlin/blackjack/ScoreCalculator.kt @@ -0,0 +1,8 @@ +package blackjack + +object ScoreCalculator { + + fun calc(cards: List): Int { + return cards.map { it.score }.reduce { acc, i -> acc + i } + } +} \ No newline at end of file diff --git a/src/test/kotlin/blackjack/ScoreCalculatorTest.kt b/src/test/kotlin/blackjack/ScoreCalculatorTest.kt new file mode 100644 index 0000000000..ac28de8188 --- /dev/null +++ b/src/test/kotlin/blackjack/ScoreCalculatorTest.kt @@ -0,0 +1,12 @@ +package blackjack + +import io.kotest.core.spec.style.StringSpec +import io.kotest.matchers.shouldBe + +class ScoreCalculatorTest: StringSpec({ + + "카드 점수에 맞게 최종 점수가 계산 되어야 한다" { + ScoreCalculator.calc(listOf(Card.TWO, Card.THREE)) shouldBe 5 + } + +}) \ No newline at end of file From d2d6a5c3940ce659aaa89082b1d3efe2e51f0842 Mon Sep 17 00:00:00 2001 From: baek0318 Date: Mon, 27 Nov 2023 00:40:17 +0900 Subject: [PATCH 08/12] =?UTF-8?q?step2=20:=20Card=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/Card.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/main/kotlin/blackjack/Card.kt diff --git a/src/main/kotlin/blackjack/Card.kt b/src/main/kotlin/blackjack/Card.kt new file mode 100644 index 0000000000..c14ea567f8 --- /dev/null +++ b/src/main/kotlin/blackjack/Card.kt @@ -0,0 +1,19 @@ +package blackjack + +enum class Card( + val score: Int +) { + ACE(1), + TWO(2), + THREE(3), + FOUR(4), + FIVE(5), + SIX(6), + SEVEN(7), + EIGHT(8), + NINE(9), + TEN(10), + JACK(10), + QUEEN(10), + KING(10); +} \ No newline at end of file From 3dcf33191b44dfad9cc551aab1b621fa8172bb11 Mon Sep 17 00:00:00 2001 From: baek0318 Date: Mon, 27 Nov 2023 00:40:31 +0900 Subject: [PATCH 09/12] =?UTF-8?q?step2=20:=20InputView=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/InputView.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/main/kotlin/blackjack/InputView.kt diff --git a/src/main/kotlin/blackjack/InputView.kt b/src/main/kotlin/blackjack/InputView.kt new file mode 100644 index 0000000000..c6d5964ed4 --- /dev/null +++ b/src/main/kotlin/blackjack/InputView.kt @@ -0,0 +1,14 @@ +package blackjack + +fun oneMoreCardInput(): Boolean { + val input = readlnOrNull() ?: throw IllegalArgumentException("올바른 입력을 해주세요") + return when (input) { + "y" -> true + "n" -> false + else -> throw IllegalArgumentException("올바른 입력을 해주세요") + } +} + +fun namesInput(): List { + return readlnOrNull()?.split(",") ?: throw IllegalArgumentException("이름을 입력해주세요.") +} \ No newline at end of file From d76b68666a9b577e7a9b9b8ca4090f6fb5717af6 Mon Sep 17 00:00:00 2001 From: baek0318 Date: Mon, 27 Nov 2023 00:40:45 +0900 Subject: [PATCH 10/12] =?UTF-8?q?step2=20:=20OutputView=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/OutputView.kt | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/kotlin/blackjack/OutputView.kt diff --git a/src/main/kotlin/blackjack/OutputView.kt b/src/main/kotlin/blackjack/OutputView.kt new file mode 100644 index 0000000000..6cd867266d --- /dev/null +++ b/src/main/kotlin/blackjack/OutputView.kt @@ -0,0 +1,27 @@ +package blackjack + +fun startOutput() { + println("게임에 참여할 사람의 이름을 입력하세요.(쉼표 기준으로 분리)") +} + +fun giveCardsOutput(name: String) { + println("${name}에게 카드를 2장 나누었습니다.") +} + +fun whatCardsOutput(name: String, cardsName: String) { + println("${name}카드: $cardsName") +} + +fun drawResultOutput(name: String, cardsName: String) { + println("${name}카드: $cardsName") +} + +fun resultOutput(players: List) { + players.forEach { + println("${it.name}카드: ${it.cards.joinToString(separator = ",") { card -> card.name }}-결과: ${it.stop()}") + } +} + +fun oneMoreCardOutput(name: String) { + println("${name}는 한장의 카드를 더 받겠습니까?(예는 y, 아니오는 n)") +} \ No newline at end of file From f583371ef625de5ff2edf579c0022aa2115894f3 Mon Sep 17 00:00:00 2001 From: baek0318 Date: Mon, 27 Nov 2023 00:40:58 +0900 Subject: [PATCH 11/12] =?UTF-8?q?step2=20:=20Main=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/blackjack/Main.kt | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/main/kotlin/blackjack/Main.kt diff --git a/src/main/kotlin/blackjack/Main.kt b/src/main/kotlin/blackjack/Main.kt new file mode 100644 index 0000000000..a63e57753f --- /dev/null +++ b/src/main/kotlin/blackjack/Main.kt @@ -0,0 +1,47 @@ +package blackjack + +fun main() { + startOutput() + val names = namesInput() + val players = names.map { Player(it) } + val deck = RandomCardDeck() + + giveCardsOutput(players.joinToString(separator = ",") { it.name }) + initPlayer(players, deck) + + playGame(players, deck) + + resultOutput(players) +} + +fun initPlayer(players: List, deck: CardDeck) { + players.forEach { + it.go(deck.drawCard()) + it.go(deck.drawCard()) + whatCardsOutput(it.name, it.cards.joinToString(separator = ",") { card -> card.name }) + } +} + +fun playGame(players: List, deck: CardDeck) { + players.forEach { + playerGoOrStop(it, deck) + } +} + +private fun playerGoOrStop(player: Player, deck: CardDeck) { + while (true) { + if (isGo(player, deck)) break + } +} + +private fun isGo(player: Player, deck: CardDeck): Boolean { + oneMoreCardOutput(player.name) + val isGo = oneMoreCardInput() + if (isGo) { + player.go(deck.drawCard()) + drawResultOutput(player.name, player.cards.joinToString(separator = ",") { card -> card.name }) + } else { + return true + } + return false +} \ No newline at end of file From c1451716a87a7db5565e7f85db248ff6b2072e3d Mon Sep 17 00:00:00 2001 From: baek0318 Date: Mon, 27 Nov 2023 00:41:07 +0900 Subject: [PATCH 12/12] =?UTF-8?q?step2=20:=20Readme=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e1c7c927d8..db1c54f214 100644 --- a/README.md +++ b/README.md @@ -1 +1,9 @@ -# kotlin-blackjack \ No newline at end of file +# kotlin-blackjack + +## 요구사항 +- 카드의 숫자 계산은 카드 숫자를 기본으로 하며 + - Ace는 1 또는 11로 계산할 수 있으며 + - King, Queen, Jack은 각각 10으로 계산한다. +- 게임을 시작하면 플레이어는 두 장의 카드를 지급 받으며 + - 두 장의 카드 숫자를 합쳐 21을 초과하지 않으면서 21에 가깝게 만들면 이긴다. + - 21을 넘지 않을 경우 원한다면 얼마든지 카드를 계속 뽑을 수 있다. \ No newline at end of file