From 33b75e5f7b465ef7b193246788a5a70a5837acef Mon Sep 17 00:00:00 2001 From: Ted1_Lee Date: Fri, 8 Dec 2023 09:00:31 +0900 Subject: [PATCH 01/22] =?UTF-8?q?refactor:=20=EB=A6=AC=ED=84=B4=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=20=EB=AA=85=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/mineswipper/domain/map/Field.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/mineswipper/domain/map/Field.kt b/src/main/kotlin/mineswipper/domain/map/Field.kt index 847c627a9..0abc83719 100644 --- a/src/main/kotlin/mineswipper/domain/map/Field.kt +++ b/src/main/kotlin/mineswipper/domain/map/Field.kt @@ -25,7 +25,7 @@ class Field( private fun createPedal( positions: List, position: Position - ) = when (positions.contains(position)) { + ): Pedal = when (positions.contains(position)) { true -> Mine() false -> NormalPedal() } From 4384cfe544dd634df8563df5f42e0efaa36eed5f Mon Sep 17 00:00:00 2001 From: Ted1_Lee Date: Fri, 8 Dec 2023 09:01:50 +0900 Subject: [PATCH 02/22] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=ED=95=A8=EC=88=98=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mineswipper/domain/map/util/PositionFactory.kt | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/main/kotlin/mineswipper/domain/map/util/PositionFactory.kt b/src/main/kotlin/mineswipper/domain/map/util/PositionFactory.kt index ed576c3a9..024cb4cf5 100644 --- a/src/main/kotlin/mineswipper/domain/map/util/PositionFactory.kt +++ b/src/main/kotlin/mineswipper/domain/map/util/PositionFactory.kt @@ -6,15 +6,6 @@ import mineswipper.domain.map.Size class PositionFactory( private val minePositionStrategy: MinePositionStrategy ) { - - fun generateMinePositions(height: Int, width: Int, mineAmount: Int): List { - return (0 until mineAmount).map { - val x = (0 until height).random() - val y = (0 until width).random() - Position(x, y) - } - } - fun generateMinePositions(size: Size, mineAmount: Int): List { require(size.width >= mineAmount && size.height >= mineAmount) { MINE_AMOUNT_VALID_MESSAGE } From 937bfd145e9786e2448e54864a614bbf8c5fc89f Mon Sep 17 00:00:00 2001 From: JunHyun Lee Date: Fri, 8 Dec 2023 23:12:53 +0900 Subject: [PATCH 03/22] =?UTF-8?q?feat:=20=ED=8C=8C=EB=9D=BC=EB=AF=B8?= =?UTF-8?q?=ED=84=B0=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/mineswipper/domain/map/Field.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/mineswipper/domain/map/Field.kt b/src/main/kotlin/mineswipper/domain/map/Field.kt index 0abc83719..847c627a9 100644 --- a/src/main/kotlin/mineswipper/domain/map/Field.kt +++ b/src/main/kotlin/mineswipper/domain/map/Field.kt @@ -25,7 +25,7 @@ class Field( private fun createPedal( positions: List, position: Position - ): Pedal = when (positions.contains(position)) { + ) = when (positions.contains(position)) { true -> Mine() false -> NormalPedal() } From 87e088f23f890729f4944ec0c5d5aae6cee1e520 Mon Sep 17 00:00:00 2001 From: JunHyun Lee Date: Fri, 8 Dec 2023 23:16:11 +0900 Subject: [PATCH 04/22] =?UTF-8?q?feat:=20=ED=8C=8C=EB=9D=BC=EB=AF=B8?= =?UTF-8?q?=ED=84=B0=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/mineswipper/domain/map/Field.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/mineswipper/domain/map/Field.kt b/src/main/kotlin/mineswipper/domain/map/Field.kt index 847c627a9..aa13c60be 100644 --- a/src/main/kotlin/mineswipper/domain/map/Field.kt +++ b/src/main/kotlin/mineswipper/domain/map/Field.kt @@ -2,30 +2,30 @@ package mineswipper.domain.map class Field( private val size: Size, - positions: List + minePositions: List ) { val field: Map init { val initField: MutableMap = mutableMapOf() repeat(size.height) { x -> - initField[x] = pedalSetting(x, positions) + initField[x] = pedalSetting(x, minePositions) } field = initField.toMap() } - private fun pedalSetting(x: Int, positions: List): Pedals { + private fun pedalSetting(x: Int, minePositions: List): Pedals { val pedalList = (0 until size.width).map { y -> val position = Position(x, y) - createPedal(positions, position) + createPedal(minePositions, position) } return Pedals(pedalList) } private fun createPedal( - positions: List, + minePositions: List, position: Position - ) = when (positions.contains(position)) { + ): Pedal = when (minePositions.contains(position)) { true -> Mine() false -> NormalPedal() } From d7f39007ca9218a5ac614554d266310b4156484d Mon Sep 17 00:00:00 2001 From: JunHyun Lee Date: Fri, 8 Dec 2023 23:33:01 +0900 Subject: [PATCH 05/22] =?UTF-8?q?feat:=20=EB=A6=AC=EB=B7=B0=20=EB=B0=98?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/mineswipper/domain/map/Field.kt | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/mineswipper/domain/map/Field.kt b/src/main/kotlin/mineswipper/domain/map/Field.kt index aa13c60be..66fa59e3f 100644 --- a/src/main/kotlin/mineswipper/domain/map/Field.kt +++ b/src/main/kotlin/mineswipper/domain/map/Field.kt @@ -1,8 +1,7 @@ package mineswipper.domain.map class Field( - private val size: Size, - minePositions: List + private val size: Size, minePositions: List ) { val field: Map @@ -23,10 +22,9 @@ class Field( } private fun createPedal( - minePositions: List, - position: Position - ): Pedal = when (minePositions.contains(position)) { - true -> Mine() - false -> NormalPedal() + minePositions: List, position: Position + ): Pedal { + if (minePositions.contains(position)) return Mine() + return NormalPedal() } } From f7c94a6411b600511c579596b54448624273ce16 Mon Sep 17 00:00:00 2001 From: JunHyun Lee Date: Fri, 8 Dec 2023 23:39:20 +0900 Subject: [PATCH 06/22] =?UTF-8?q?feat:=20=ED=95=84=EB=93=9C=EC=9D=98=20row?= =?UTF-8?q?=EB=A5=BC=20=EC=9D=98=EB=AF=B8=ED=95=98=EB=8A=94=20Row=20?= =?UTF-8?q?=EA=B0=9D=EC=B2=B4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/mineswipper/domain/map/Row.kt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/main/kotlin/mineswipper/domain/map/Row.kt diff --git a/src/main/kotlin/mineswipper/domain/map/Row.kt b/src/main/kotlin/mineswipper/domain/map/Row.kt new file mode 100644 index 000000000..cd8298dee --- /dev/null +++ b/src/main/kotlin/mineswipper/domain/map/Row.kt @@ -0,0 +1,3 @@ +package mineswipper.domain.map + +data class Row(val value: Int) From 3f540f90d12025bd1de41ffd513d345fd731ef9e Mon Sep 17 00:00:00 2001 From: Ted1_Lee Date: Mon, 11 Dec 2023 09:59:46 +0900 Subject: [PATCH 07/22] =?UTF-8?q?feat:=20int=EB=A5=BC=20=EA=B0=90=EC=8B=BC?= =?UTF-8?q?=20Row=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/mineswipper/domain/map/Field.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/mineswipper/domain/map/Field.kt b/src/main/kotlin/mineswipper/domain/map/Field.kt index 66fa59e3f..a9d884147 100644 --- a/src/main/kotlin/mineswipper/domain/map/Field.kt +++ b/src/main/kotlin/mineswipper/domain/map/Field.kt @@ -1,14 +1,15 @@ package mineswipper.domain.map class Field( - private val size: Size, minePositions: List + private val size: Size, + minePositions: List ) { - val field: Map + val field: Map init { - val initField: MutableMap = mutableMapOf() + val initField: MutableMap = mutableMapOf() repeat(size.height) { x -> - initField[x] = pedalSetting(x, minePositions) + initField[Row(x)] = pedalSetting(x, minePositions) } field = initField.toMap() } From 8bfbda7d71a0b0c86cf43facd652d9d515d22b80 Mon Sep 17 00:00:00 2001 From: Ted1_Lee Date: Mon, 11 Dec 2023 10:10:49 +0900 Subject: [PATCH 08/22] =?UTF-8?q?feat:=20=EC=A7=80=EB=A2=B0=EB=82=98=20?= =?UTF-8?q?=EC=9D=BC=EB=B0=98=20=EB=B0=9C=ED=8C=90=EC=9D=98=20=EA=B0=92?= =?UTF-8?q?=EC=9D=84=20=EC=9D=98=EB=AF=B8=ED=95=98=EB=8A=94=20Mark=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/mineswipper/domain/map/Mark.kt | 6 ++++++ src/main/kotlin/mineswipper/domain/map/Mine.kt | 8 +++++++- src/main/kotlin/mineswipper/domain/map/Pedal.kt | 3 +-- 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 src/main/kotlin/mineswipper/domain/map/Mark.kt diff --git a/src/main/kotlin/mineswipper/domain/map/Mark.kt b/src/main/kotlin/mineswipper/domain/map/Mark.kt new file mode 100644 index 000000000..ff51d86de --- /dev/null +++ b/src/main/kotlin/mineswipper/domain/map/Mark.kt @@ -0,0 +1,6 @@ +package mineswipper.domain.map + +@JvmInline +value class Mark( + val value: String +) diff --git a/src/main/kotlin/mineswipper/domain/map/Mine.kt b/src/main/kotlin/mineswipper/domain/map/Mine.kt index bfece7366..24fb12ed7 100644 --- a/src/main/kotlin/mineswipper/domain/map/Mine.kt +++ b/src/main/kotlin/mineswipper/domain/map/Mine.kt @@ -1,3 +1,9 @@ package mineswipper.domain.map -class Mine : Pedal +class Mine : Pedal { + val mark: Mark + + init { + mark = Mark("*") + } +} diff --git a/src/main/kotlin/mineswipper/domain/map/Pedal.kt b/src/main/kotlin/mineswipper/domain/map/Pedal.kt index 34bfb6d7a..fc53e138a 100644 --- a/src/main/kotlin/mineswipper/domain/map/Pedal.kt +++ b/src/main/kotlin/mineswipper/domain/map/Pedal.kt @@ -1,4 +1,3 @@ package mineswipper.domain.map -sealed interface Pedal { -} \ No newline at end of file +sealed interface Pedal From e70df0b8f6d637099cf3fc1f5699db30f010e9b2 Mon Sep 17 00:00:00 2001 From: Ted1_Lee Date: Mon, 11 Dec 2023 10:13:07 +0900 Subject: [PATCH 09/22] =?UTF-8?q?feat:=20position=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/mineswipper/MineGame.kt | 2 +- src/main/kotlin/mineswipper/domain/map/Field.kt | 4 ++++ src/main/kotlin/mineswipper/domain/map/Row.kt | 3 --- .../kotlin/mineswipper/domain/map/{ => position}/Position.kt | 2 +- src/main/kotlin/mineswipper/domain/map/position/Row.kt | 3 +++ src/main/kotlin/mineswipper/domain/map/{ => position}/Size.kt | 2 +- .../mineswipper/domain/map/util/MinePositionStrategy.kt | 4 ++-- .../kotlin/mineswipper/domain/map/util/PositionFactory.kt | 4 ++-- .../domain/map/util/RandomMinePositionGenerator.kt | 4 ++-- src/test/kotlin/mineswipper/domain/map/PositionFactoryTest.kt | 2 ++ src/test/kotlin/mineswipper/domain/map/SizeTest.kt | 1 + 11 files changed, 19 insertions(+), 12 deletions(-) delete mode 100644 src/main/kotlin/mineswipper/domain/map/Row.kt rename src/main/kotlin/mineswipper/domain/map/{ => position}/Position.kt (57%) create mode 100644 src/main/kotlin/mineswipper/domain/map/position/Row.kt rename src/main/kotlin/mineswipper/domain/map/{ => position}/Size.kt (60%) diff --git a/src/main/kotlin/mineswipper/MineGame.kt b/src/main/kotlin/mineswipper/MineGame.kt index 9a5dbfb96..daddeaa41 100644 --- a/src/main/kotlin/mineswipper/MineGame.kt +++ b/src/main/kotlin/mineswipper/MineGame.kt @@ -1,7 +1,7 @@ package mineswipper import mineswipper.domain.map.Field -import mineswipper.domain.map.Size +import mineswipper.domain.map.position.Size import mineswipper.domain.map.util.PositionFactory import mineswipper.domain.map.util.RandomMinePositionGenerator import mineswipper.ui.InputManager diff --git a/src/main/kotlin/mineswipper/domain/map/Field.kt b/src/main/kotlin/mineswipper/domain/map/Field.kt index a9d884147..04c297f99 100644 --- a/src/main/kotlin/mineswipper/domain/map/Field.kt +++ b/src/main/kotlin/mineswipper/domain/map/Field.kt @@ -1,5 +1,9 @@ package mineswipper.domain.map +import mineswipper.domain.map.position.Position +import mineswipper.domain.map.position.Row +import mineswipper.domain.map.position.Size + class Field( private val size: Size, minePositions: List diff --git a/src/main/kotlin/mineswipper/domain/map/Row.kt b/src/main/kotlin/mineswipper/domain/map/Row.kt deleted file mode 100644 index cd8298dee..000000000 --- a/src/main/kotlin/mineswipper/domain/map/Row.kt +++ /dev/null @@ -1,3 +0,0 @@ -package mineswipper.domain.map - -data class Row(val value: Int) diff --git a/src/main/kotlin/mineswipper/domain/map/Position.kt b/src/main/kotlin/mineswipper/domain/map/position/Position.kt similarity index 57% rename from src/main/kotlin/mineswipper/domain/map/Position.kt rename to src/main/kotlin/mineswipper/domain/map/position/Position.kt index e1a807f17..4cad8829f 100644 --- a/src/main/kotlin/mineswipper/domain/map/Position.kt +++ b/src/main/kotlin/mineswipper/domain/map/position/Position.kt @@ -1,4 +1,4 @@ -package mineswipper.domain.map +package mineswipper.domain.map.position data class Position( val x: Int, diff --git a/src/main/kotlin/mineswipper/domain/map/position/Row.kt b/src/main/kotlin/mineswipper/domain/map/position/Row.kt new file mode 100644 index 000000000..2f8d772b8 --- /dev/null +++ b/src/main/kotlin/mineswipper/domain/map/position/Row.kt @@ -0,0 +1,3 @@ +package mineswipper.domain.map.position + +data class Row(val value: Int) diff --git a/src/main/kotlin/mineswipper/domain/map/Size.kt b/src/main/kotlin/mineswipper/domain/map/position/Size.kt similarity index 60% rename from src/main/kotlin/mineswipper/domain/map/Size.kt rename to src/main/kotlin/mineswipper/domain/map/position/Size.kt index 8e672b4a7..0e6732099 100644 --- a/src/main/kotlin/mineswipper/domain/map/Size.kt +++ b/src/main/kotlin/mineswipper/domain/map/position/Size.kt @@ -1,4 +1,4 @@ -package mineswipper.domain.map +package mineswipper.domain.map.position data class Size( val width: Int, diff --git a/src/main/kotlin/mineswipper/domain/map/util/MinePositionStrategy.kt b/src/main/kotlin/mineswipper/domain/map/util/MinePositionStrategy.kt index 2cb28092d..33de9400a 100644 --- a/src/main/kotlin/mineswipper/domain/map/util/MinePositionStrategy.kt +++ b/src/main/kotlin/mineswipper/domain/map/util/MinePositionStrategy.kt @@ -1,7 +1,7 @@ package mineswipper.domain.map.util -import mineswipper.domain.map.Position -import mineswipper.domain.map.Size +import mineswipper.domain.map.position.Position +import mineswipper.domain.map.position.Size interface MinePositionStrategy { fun createMinePosition(size: Size, mineAmount: Int): List diff --git a/src/main/kotlin/mineswipper/domain/map/util/PositionFactory.kt b/src/main/kotlin/mineswipper/domain/map/util/PositionFactory.kt index 024cb4cf5..5893ccecf 100644 --- a/src/main/kotlin/mineswipper/domain/map/util/PositionFactory.kt +++ b/src/main/kotlin/mineswipper/domain/map/util/PositionFactory.kt @@ -1,7 +1,7 @@ package mineswipper.domain.map.util -import mineswipper.domain.map.Position -import mineswipper.domain.map.Size +import mineswipper.domain.map.position.Position +import mineswipper.domain.map.position.Size class PositionFactory( private val minePositionStrategy: MinePositionStrategy diff --git a/src/main/kotlin/mineswipper/domain/map/util/RandomMinePositionGenerator.kt b/src/main/kotlin/mineswipper/domain/map/util/RandomMinePositionGenerator.kt index 553283887..6105f38dc 100644 --- a/src/main/kotlin/mineswipper/domain/map/util/RandomMinePositionGenerator.kt +++ b/src/main/kotlin/mineswipper/domain/map/util/RandomMinePositionGenerator.kt @@ -1,7 +1,7 @@ package mineswipper.domain.map.util -import mineswipper.domain.map.Position -import mineswipper.domain.map.Size +import mineswipper.domain.map.position.Position +import mineswipper.domain.map.position.Size class RandomMinePositionGenerator : MinePositionStrategy { override fun createMinePosition(size: Size, mineAmount: Int): List { diff --git a/src/test/kotlin/mineswipper/domain/map/PositionFactoryTest.kt b/src/test/kotlin/mineswipper/domain/map/PositionFactoryTest.kt index 42c28e4b5..7180008df 100644 --- a/src/test/kotlin/mineswipper/domain/map/PositionFactoryTest.kt +++ b/src/test/kotlin/mineswipper/domain/map/PositionFactoryTest.kt @@ -2,6 +2,8 @@ package mineswipper.domain.map import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe +import mineswipper.domain.map.position.Position +import mineswipper.domain.map.position.Size import mineswipper.domain.map.util.MinePositionStrategy import mineswipper.domain.map.util.PositionFactory import org.junit.jupiter.api.Test diff --git a/src/test/kotlin/mineswipper/domain/map/SizeTest.kt b/src/test/kotlin/mineswipper/domain/map/SizeTest.kt index 9acdfb3ff..152550077 100644 --- a/src/test/kotlin/mineswipper/domain/map/SizeTest.kt +++ b/src/test/kotlin/mineswipper/domain/map/SizeTest.kt @@ -1,6 +1,7 @@ package mineswipper.domain.map import io.kotest.matchers.shouldBe +import mineswipper.domain.map.position.Size import org.junit.jupiter.api.Test class SizeTest { From f7eebaf385a765691654912957675c77c2bc040e Mon Sep 17 00:00:00 2001 From: Ted1_Lee Date: Mon, 11 Dec 2023 10:19:17 +0900 Subject: [PATCH 10/22] =?UTF-8?q?feat:=20positions=20=EC=9D=BC=EA=B8=89=20?= =?UTF-8?q?=EC=BB=AC=EB=A0=89=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/mineswipper/domain/map/Field.kt | 7 ++++--- .../domain/map/position/Positions.kt | 9 +++++++++ .../domain/map/util/MinePositionStrategy.kt | 6 +++--- .../domain/map/util/PositionFactory.kt | 3 ++- .../map/util/RandomMinePositionGenerator.kt | 5 +++-- .../domain/map/PositionFactoryTest.kt | 20 +++++++++---------- 6 files changed, 31 insertions(+), 19 deletions(-) create mode 100644 src/main/kotlin/mineswipper/domain/map/position/Positions.kt diff --git a/src/main/kotlin/mineswipper/domain/map/Field.kt b/src/main/kotlin/mineswipper/domain/map/Field.kt index 04c297f99..6d8940d56 100644 --- a/src/main/kotlin/mineswipper/domain/map/Field.kt +++ b/src/main/kotlin/mineswipper/domain/map/Field.kt @@ -1,12 +1,13 @@ package mineswipper.domain.map import mineswipper.domain.map.position.Position +import mineswipper.domain.map.position.Positions import mineswipper.domain.map.position.Row import mineswipper.domain.map.position.Size class Field( private val size: Size, - minePositions: List + minePositions: Positions ) { val field: Map @@ -18,7 +19,7 @@ class Field( field = initField.toMap() } - private fun pedalSetting(x: Int, minePositions: List): Pedals { + private fun pedalSetting(x: Int, minePositions: Positions): Pedals { val pedalList = (0 until size.width).map { y -> val position = Position(x, y) createPedal(minePositions, position) @@ -27,7 +28,7 @@ class Field( } private fun createPedal( - minePositions: List, position: Position + minePositions: Positions, position: Position ): Pedal { if (minePositions.contains(position)) return Mine() return NormalPedal() diff --git a/src/main/kotlin/mineswipper/domain/map/position/Positions.kt b/src/main/kotlin/mineswipper/domain/map/position/Positions.kt new file mode 100644 index 000000000..f15a438c3 --- /dev/null +++ b/src/main/kotlin/mineswipper/domain/map/position/Positions.kt @@ -0,0 +1,9 @@ +package mineswipper.domain.map.position + +class Positions( + val positions: List +) { + fun contains(position: Position): Boolean { + return positions.contains(position) + } +} diff --git a/src/main/kotlin/mineswipper/domain/map/util/MinePositionStrategy.kt b/src/main/kotlin/mineswipper/domain/map/util/MinePositionStrategy.kt index 33de9400a..2b76d9702 100644 --- a/src/main/kotlin/mineswipper/domain/map/util/MinePositionStrategy.kt +++ b/src/main/kotlin/mineswipper/domain/map/util/MinePositionStrategy.kt @@ -1,8 +1,8 @@ package mineswipper.domain.map.util -import mineswipper.domain.map.position.Position +import mineswipper.domain.map.position.Positions import mineswipper.domain.map.position.Size interface MinePositionStrategy { - fun createMinePosition(size: Size, mineAmount: Int): List -} \ No newline at end of file + fun createMinePosition(size: Size, mineAmount: Int): Positions +} diff --git a/src/main/kotlin/mineswipper/domain/map/util/PositionFactory.kt b/src/main/kotlin/mineswipper/domain/map/util/PositionFactory.kt index 5893ccecf..b3b4a7b7e 100644 --- a/src/main/kotlin/mineswipper/domain/map/util/PositionFactory.kt +++ b/src/main/kotlin/mineswipper/domain/map/util/PositionFactory.kt @@ -1,12 +1,13 @@ package mineswipper.domain.map.util import mineswipper.domain.map.position.Position +import mineswipper.domain.map.position.Positions import mineswipper.domain.map.position.Size class PositionFactory( private val minePositionStrategy: MinePositionStrategy ) { - fun generateMinePositions(size: Size, mineAmount: Int): List { + fun generateMinePositions(size: Size, mineAmount: Int): Positions { require(size.width >= mineAmount && size.height >= mineAmount) { MINE_AMOUNT_VALID_MESSAGE } return minePositionStrategy.createMinePosition(size, mineAmount) diff --git a/src/main/kotlin/mineswipper/domain/map/util/RandomMinePositionGenerator.kt b/src/main/kotlin/mineswipper/domain/map/util/RandomMinePositionGenerator.kt index 6105f38dc..7a2e97b41 100644 --- a/src/main/kotlin/mineswipper/domain/map/util/RandomMinePositionGenerator.kt +++ b/src/main/kotlin/mineswipper/domain/map/util/RandomMinePositionGenerator.kt @@ -1,10 +1,11 @@ package mineswipper.domain.map.util import mineswipper.domain.map.position.Position +import mineswipper.domain.map.position.Positions import mineswipper.domain.map.position.Size class RandomMinePositionGenerator : MinePositionStrategy { - override fun createMinePosition(size: Size, mineAmount: Int): List { + override fun createMinePosition(size: Size, mineAmount: Int): Positions { val positions = mutableSetOf() while (positions.size < mineAmount) { @@ -13,6 +14,6 @@ class RandomMinePositionGenerator : MinePositionStrategy { positions.add(Position(x, y)) } - return positions.toList() + return Positions(positions.toList()) } } diff --git a/src/test/kotlin/mineswipper/domain/map/PositionFactoryTest.kt b/src/test/kotlin/mineswipper/domain/map/PositionFactoryTest.kt index 7180008df..0e705cc54 100644 --- a/src/test/kotlin/mineswipper/domain/map/PositionFactoryTest.kt +++ b/src/test/kotlin/mineswipper/domain/map/PositionFactoryTest.kt @@ -3,6 +3,7 @@ package mineswipper.domain.map import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.shouldBe import mineswipper.domain.map.position.Position +import mineswipper.domain.map.position.Positions import mineswipper.domain.map.position.Size import mineswipper.domain.map.util.MinePositionStrategy import mineswipper.domain.map.util.PositionFactory @@ -17,16 +18,13 @@ class PositionFactoryTest { val width = 10 val mineAmount = 10 - val positions: List = positionFactory.generateMinePositions( + val positions: Positions = positionFactory.generateMinePositions( Size(width, height), mineAmount ) - positions.containsAll( - listOf( - Position(1, 1), - Position(2, 2) - ) + positions.contains( + Position(1, 1) ) shouldBe true } @@ -42,10 +40,12 @@ class PositionFactoryTest { } class TestStrategy : MinePositionStrategy { - override fun createMinePosition(size: Size, mineAmount: Int): List { - return listOf( - Position(1, 1), - Position(2, 2) + override fun createMinePosition(size: Size, mineAmount: Int): Positions { + return Positions( + listOf( + Position(1, 1), + Position(2, 2) + ) ) } } From 57ec133f5a6319c4cf220ff88d6a8a6bb1d06444 Mon Sep 17 00:00:00 2001 From: Ted1_Lee Date: Mon, 11 Dec 2023 10:59:22 +0900 Subject: [PATCH 11/22] =?UTF-8?q?feat:=20=EC=A7=80=EB=A2=B0=20=EA=B0=AF?= =?UTF-8?q?=EC=88=98=20=EC=B6=9C=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20=EA=B0=9C?= =?UTF-8?q?=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/mineswipper/domain/map/Field.kt | 27 +++++++++++++++++++ .../kotlin/mineswipper/domain/map/Mine.kt | 9 +++---- .../mineswipper/domain/map/NormalPedal.kt | 6 ++++- .../kotlin/mineswipper/domain/map/Pedal.kt | 4 ++- .../kotlin/mineswipper/domain/map/Pedals.kt | 6 ++++- .../domain/map/position/Position.kt | 20 +++++++++++++- .../domain/map/position/Positions.kt | 2 +- .../mineswipper/domain/map/position/Row.kt | 3 ++- .../kotlin/mineswipper/ui/OutputManager.kt | 3 +-- 9 files changed, 66 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/mineswipper/domain/map/Field.kt b/src/main/kotlin/mineswipper/domain/map/Field.kt index 6d8940d56..a78044121 100644 --- a/src/main/kotlin/mineswipper/domain/map/Field.kt +++ b/src/main/kotlin/mineswipper/domain/map/Field.kt @@ -17,6 +17,8 @@ class Field( initField[Row(x)] = pedalSetting(x, minePositions) } field = initField.toMap() + + markGeneration() } private fun pedalSetting(x: Int, minePositions: Positions): Pedals { @@ -33,4 +35,29 @@ class Field( if (minePositions.contains(position)) return Mine() return NormalPedal() } + + private fun markGeneration(position: Position = Position(0, 0)) { + val pedal = findPedal(position) + if (pedal.mark != null) return + + val aroundPositions = position.getAroundPositions(size) + val count = aroundPositions.positions.count { + val findPedal = findPedal(it) + findPedal is Mine + } + + pedal.mark = Mark(count.toString()) + + aroundPositions.positions.forEach { + markGeneration(it) + } + } + + private fun findPedal(position: Position): Pedal { + val pedals = field[position.toRow()] + require(pedals != null) { } + + val pedal = pedals.get(position.x) + return pedal + } } diff --git a/src/main/kotlin/mineswipper/domain/map/Mine.kt b/src/main/kotlin/mineswipper/domain/map/Mine.kt index 24fb12ed7..87e4eebf5 100644 --- a/src/main/kotlin/mineswipper/domain/map/Mine.kt +++ b/src/main/kotlin/mineswipper/domain/map/Mine.kt @@ -1,9 +1,6 @@ package mineswipper.domain.map -class Mine : Pedal { - val mark: Mark - - init { - mark = Mark("*") - } +class Mine( + override var mark: Mark? = Mark("*") +) : Pedal { } diff --git a/src/main/kotlin/mineswipper/domain/map/NormalPedal.kt b/src/main/kotlin/mineswipper/domain/map/NormalPedal.kt index 399313d20..5577470c5 100644 --- a/src/main/kotlin/mineswipper/domain/map/NormalPedal.kt +++ b/src/main/kotlin/mineswipper/domain/map/NormalPedal.kt @@ -1,3 +1,7 @@ package mineswipper.domain.map -class NormalPedal : Pedal +class NormalPedal( + override var mark: Mark? = null +) : Pedal { + +} \ No newline at end of file diff --git a/src/main/kotlin/mineswipper/domain/map/Pedal.kt b/src/main/kotlin/mineswipper/domain/map/Pedal.kt index fc53e138a..27718d8f8 100644 --- a/src/main/kotlin/mineswipper/domain/map/Pedal.kt +++ b/src/main/kotlin/mineswipper/domain/map/Pedal.kt @@ -1,3 +1,5 @@ package mineswipper.domain.map -sealed interface Pedal +sealed interface Pedal { + var mark: Mark? +} diff --git a/src/main/kotlin/mineswipper/domain/map/Pedals.kt b/src/main/kotlin/mineswipper/domain/map/Pedals.kt index fd73967c1..d60c02e42 100644 --- a/src/main/kotlin/mineswipper/domain/map/Pedals.kt +++ b/src/main/kotlin/mineswipper/domain/map/Pedals.kt @@ -3,4 +3,8 @@ package mineswipper.domain.map @JvmInline value class Pedals( val value: List -) \ No newline at end of file +) { + fun get(index: Int): Pedal { + return value[index] + } +} \ No newline at end of file diff --git a/src/main/kotlin/mineswipper/domain/map/position/Position.kt b/src/main/kotlin/mineswipper/domain/map/position/Position.kt index 4cad8829f..2f191eb9e 100644 --- a/src/main/kotlin/mineswipper/domain/map/position/Position.kt +++ b/src/main/kotlin/mineswipper/domain/map/position/Position.kt @@ -3,4 +3,22 @@ package mineswipper.domain.map.position data class Position( val x: Int, val y: Int -) +) { + fun getAroundPositions(size: Size): Positions { + return (x - 1..x + 1).flatMap { xVal -> + (y - 1..y + 1).map { yVal -> Position(xVal, yVal) } + }.filter { it.isValid(size.width, size.height) && it != this }.toPositions() + } + + fun toRow(): Row { + return Row(y) + } + + private fun isValid(width: Int, height: Int): Boolean { + return x in 0 until width && y in 0 until height + } + + +} + +fun List.toPositions(): Positions = Positions(this) \ No newline at end of file diff --git a/src/main/kotlin/mineswipper/domain/map/position/Positions.kt b/src/main/kotlin/mineswipper/domain/map/position/Positions.kt index f15a438c3..ad99289a4 100644 --- a/src/main/kotlin/mineswipper/domain/map/position/Positions.kt +++ b/src/main/kotlin/mineswipper/domain/map/position/Positions.kt @@ -1,6 +1,6 @@ package mineswipper.domain.map.position -class Positions( +data class Positions( val positions: List ) { fun contains(position: Position): Boolean { diff --git a/src/main/kotlin/mineswipper/domain/map/position/Row.kt b/src/main/kotlin/mineswipper/domain/map/position/Row.kt index 2f8d772b8..d9d2ecbd8 100644 --- a/src/main/kotlin/mineswipper/domain/map/position/Row.kt +++ b/src/main/kotlin/mineswipper/domain/map/position/Row.kt @@ -1,3 +1,4 @@ package mineswipper.domain.map.position -data class Row(val value: Int) +@JvmInline +value class Row(val value: Int) diff --git a/src/main/kotlin/mineswipper/ui/OutputManager.kt b/src/main/kotlin/mineswipper/ui/OutputManager.kt index 96e48cc1b..1498b7b9e 100644 --- a/src/main/kotlin/mineswipper/ui/OutputManager.kt +++ b/src/main/kotlin/mineswipper/ui/OutputManager.kt @@ -16,7 +16,7 @@ class OutputManager { private fun printWidth(pedals: Pedals) { val pedal = pedals.value.joinToString(" ") { when (it) { - is NormalPedal -> NORMAL_PEDAL + is NormalPedal -> it.mark?.value ?: "0" is Mine -> MINE_PEDAL } } @@ -29,7 +29,6 @@ class OutputManager { } companion object { - private const val NORMAL_PEDAL: String = "c" private const val MINE_PEDAL: String = "*" private const val START_GAME: String = "지뢰찾기 게임 시작" } From 12754bef26e0870ef78bd4bd7e603b7fccadb65d Mon Sep 17 00:00:00 2001 From: Ted1_Lee Date: Mon, 11 Dec 2023 11:06:54 +0900 Subject: [PATCH 12/22] =?UTF-8?q?feat:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/mineswipper/domain/map/Field.kt | 2 +- .../mineswipper/domain/map/FieldTest.kt | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/test/kotlin/mineswipper/domain/map/FieldTest.kt diff --git a/src/main/kotlin/mineswipper/domain/map/Field.kt b/src/main/kotlin/mineswipper/domain/map/Field.kt index a78044121..4c677f750 100644 --- a/src/main/kotlin/mineswipper/domain/map/Field.kt +++ b/src/main/kotlin/mineswipper/domain/map/Field.kt @@ -53,7 +53,7 @@ class Field( } } - private fun findPedal(position: Position): Pedal { + fun findPedal(position: Position): Pedal { val pedals = field[position.toRow()] require(pedals != null) { } diff --git a/src/test/kotlin/mineswipper/domain/map/FieldTest.kt b/src/test/kotlin/mineswipper/domain/map/FieldTest.kt new file mode 100644 index 000000000..a97d689c3 --- /dev/null +++ b/src/test/kotlin/mineswipper/domain/map/FieldTest.kt @@ -0,0 +1,36 @@ +package mineswipper.domain.map + +import io.kotest.matchers.shouldBe +import mineswipper.domain.map.position.Position +import mineswipper.domain.map.position.Positions +import mineswipper.domain.map.position.Size +import mineswipper.domain.map.util.MinePositionStrategy +import org.junit.jupiter.api.Test + +class FieldTest { + + @Test + fun `일반 발판은 주변에 지뢰 갯수를 표시한다`() { + val size = Size(2, 2) + val mine = 2 + val field = Field( + size, + MineMarkTestStrategy().createMinePosition(size, mine) + ) + + val pedal = field.findPedal(Position(0, 0)) + + pedal.mark?.value shouldBe "2" + } +} + +class MineMarkTestStrategy : MinePositionStrategy { + override fun createMinePosition(size: Size, mineAmount: Int): Positions { + return Positions( + listOf( + Position(1, 0), + Position(0, 1) + ) + ) + } +} From 875d734391839a357a87fc91324b938d109bd7ec Mon Sep 17 00:00:00 2001 From: Ted1_Lee Date: Mon, 11 Dec 2023 11:33:18 +0900 Subject: [PATCH 13/22] =?UTF-8?q?feat:=20=EC=A7=80=EB=A2=B0=20=EA=B0=AF?= =?UTF-8?q?=EC=88=98=20=EC=84=A4=EC=A0=95=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/mineswipper/MineGame.kt | 3 ++ .../kotlin/mineswipper/domain/map/Field.kt | 24 ++-------------- .../domain/map/util/MarkGenerator.kt | 28 +++++++++++++++++++ .../mineswipper/domain/map/FieldTest.kt | 8 ++---- .../domain/map/util/MarkGeneratorTest.kt | 25 +++++++++++++++++ 5 files changed, 62 insertions(+), 26 deletions(-) create mode 100644 src/main/kotlin/mineswipper/domain/map/util/MarkGenerator.kt create mode 100644 src/test/kotlin/mineswipper/domain/map/util/MarkGeneratorTest.kt diff --git a/src/main/kotlin/mineswipper/MineGame.kt b/src/main/kotlin/mineswipper/MineGame.kt index daddeaa41..d95404e1d 100644 --- a/src/main/kotlin/mineswipper/MineGame.kt +++ b/src/main/kotlin/mineswipper/MineGame.kt @@ -2,6 +2,7 @@ package mineswipper import mineswipper.domain.map.Field import mineswipper.domain.map.position.Size +import mineswipper.domain.map.util.MarkGenerator import mineswipper.domain.map.util.PositionFactory import mineswipper.domain.map.util.RandomMinePositionGenerator import mineswipper.ui.InputManager @@ -22,6 +23,8 @@ class MineGame( positionFactory.generateMinePositions(size, mine) ) + MarkGenerator.markGeneration(field) + outputManager.printStartGame() outputManager.printField(field) } diff --git a/src/main/kotlin/mineswipper/domain/map/Field.kt b/src/main/kotlin/mineswipper/domain/map/Field.kt index 4c677f750..bb7bd7ba3 100644 --- a/src/main/kotlin/mineswipper/domain/map/Field.kt +++ b/src/main/kotlin/mineswipper/domain/map/Field.kt @@ -6,7 +6,7 @@ import mineswipper.domain.map.position.Row import mineswipper.domain.map.position.Size class Field( - private val size: Size, + val size: Size, minePositions: Positions ) { val field: Map @@ -17,8 +17,6 @@ class Field( initField[Row(x)] = pedalSetting(x, minePositions) } field = initField.toMap() - - markGeneration() } private fun pedalSetting(x: Int, minePositions: Positions): Pedals { @@ -30,29 +28,13 @@ class Field( } private fun createPedal( - minePositions: Positions, position: Position + minePositions: Positions, + position: Position ): Pedal { if (minePositions.contains(position)) return Mine() return NormalPedal() } - private fun markGeneration(position: Position = Position(0, 0)) { - val pedal = findPedal(position) - if (pedal.mark != null) return - - val aroundPositions = position.getAroundPositions(size) - val count = aroundPositions.positions.count { - val findPedal = findPedal(it) - findPedal is Mine - } - - pedal.mark = Mark(count.toString()) - - aroundPositions.positions.forEach { - markGeneration(it) - } - } - fun findPedal(position: Position): Pedal { val pedals = field[position.toRow()] require(pedals != null) { } diff --git a/src/main/kotlin/mineswipper/domain/map/util/MarkGenerator.kt b/src/main/kotlin/mineswipper/domain/map/util/MarkGenerator.kt new file mode 100644 index 000000000..538313af9 --- /dev/null +++ b/src/main/kotlin/mineswipper/domain/map/util/MarkGenerator.kt @@ -0,0 +1,28 @@ +package mineswipper.domain.map.util + +import mineswipper.domain.map.Field +import mineswipper.domain.map.Mark +import mineswipper.domain.map.Mine +import mineswipper.domain.map.position.Position + +object MarkGenerator { + fun markGeneration(field: Field, position: Position = Position(0, 0)): Mark { + val pedal = field.findPedal(position) + if (pedal.mark != null) return pedal.mark!! + + val aroundPositions = position.getAroundPositions(field.size) + val count = aroundPositions.positions.count { + val findPedal = field.findPedal(it) + findPedal is Mine + } + + val mark = Mark(count.toString()) + pedal.mark = mark + + aroundPositions.positions.forEach { + markGeneration(field, it) + } + + return mark + } +} diff --git a/src/test/kotlin/mineswipper/domain/map/FieldTest.kt b/src/test/kotlin/mineswipper/domain/map/FieldTest.kt index a97d689c3..276c63d5c 100644 --- a/src/test/kotlin/mineswipper/domain/map/FieldTest.kt +++ b/src/test/kotlin/mineswipper/domain/map/FieldTest.kt @@ -1,6 +1,6 @@ package mineswipper.domain.map -import io.kotest.matchers.shouldBe +import io.kotest.matchers.types.shouldBeInstanceOf import mineswipper.domain.map.position.Position import mineswipper.domain.map.position.Positions import mineswipper.domain.map.position.Size @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test class FieldTest { @Test - fun `일반 발판은 주변에 지뢰 갯수를 표시한다`() { + fun `필드에는 지뢰 발판이 있다`() { val size = Size(2, 2) val mine = 2 val field = Field( @@ -18,9 +18,7 @@ class FieldTest { MineMarkTestStrategy().createMinePosition(size, mine) ) - val pedal = field.findPedal(Position(0, 0)) - - pedal.mark?.value shouldBe "2" + field.findPedal(Position(1, 0)).shouldBeInstanceOf() } } diff --git a/src/test/kotlin/mineswipper/domain/map/util/MarkGeneratorTest.kt b/src/test/kotlin/mineswipper/domain/map/util/MarkGeneratorTest.kt new file mode 100644 index 000000000..e1bab19fb --- /dev/null +++ b/src/test/kotlin/mineswipper/domain/map/util/MarkGeneratorTest.kt @@ -0,0 +1,25 @@ +package mineswipper.domain.map.util + +import io.kotest.matchers.shouldBe +import mineswipper.domain.map.Field +import mineswipper.domain.map.MineMarkTestStrategy +import mineswipper.domain.map.position.Position +import mineswipper.domain.map.position.Size +import org.junit.jupiter.api.Test + +class MarkGeneratorTest { + @Test + fun `일반 발판은 주변에 지뢰 갯수를 표시한다`() { + val size = Size(2, 2) + val mine = 2 + val field = Field( + size, + MineMarkTestStrategy().createMinePosition(size, mine) + ) + + MarkGenerator.markGeneration(field) + + val pedal = field.findPedal(Position(0, 0)) + pedal.mark?.value shouldBe "2" + } +} From 140ec038d626eaa0ed135c280a7dc49124511115 Mon Sep 17 00:00:00 2001 From: Ted1_Lee Date: Mon, 11 Dec 2023 11:36:52 +0900 Subject: [PATCH 14/22] =?UTF-8?q?feat:=20=EC=97=90=EB=9F=AC=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/mineswipper/domain/map/Field.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/mineswipper/domain/map/Field.kt b/src/main/kotlin/mineswipper/domain/map/Field.kt index bb7bd7ba3..6723c0aa9 100644 --- a/src/main/kotlin/mineswipper/domain/map/Field.kt +++ b/src/main/kotlin/mineswipper/domain/map/Field.kt @@ -37,9 +37,13 @@ class Field( fun findPedal(position: Position): Pedal { val pedals = field[position.toRow()] - require(pedals != null) { } + require(pedals != null) { VALID_MESSAGE } val pedal = pedals.get(position.x) return pedal } + + companion object { + private const val VALID_MESSAGE: String = "오류가 발생했습니다." + } } From 31e02a4a91b505624274bac7c3c81b2a3678c824 Mon Sep 17 00:00:00 2001 From: Ted1_Lee Date: Thu, 14 Dec 2023 09:00:42 +0900 Subject: [PATCH 15/22] =?UTF-8?q?feat:=20=ED=95=A8=EC=88=98=EB=A5=BC=20?= =?UTF-8?q?=EB=8D=94=20=EA=B0=84=EB=8B=A8=ED=95=98=EA=B2=8C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/mineswipper/domain/map/Field.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/kotlin/mineswipper/domain/map/Field.kt b/src/main/kotlin/mineswipper/domain/map/Field.kt index 6723c0aa9..bedccf42e 100644 --- a/src/main/kotlin/mineswipper/domain/map/Field.kt +++ b/src/main/kotlin/mineswipper/domain/map/Field.kt @@ -31,8 +31,7 @@ class Field( minePositions: Positions, position: Position ): Pedal { - if (minePositions.contains(position)) return Mine() - return NormalPedal() + return if (minePositions.contains(position)) Mine() else NormalPedal() } fun findPedal(position: Position): Pedal { From fdbda580565567c077789fb247995697c0d6feb9 Mon Sep 17 00:00:00 2001 From: Ted1_Lee Date: Thu, 14 Dec 2023 09:01:44 +0900 Subject: [PATCH 16/22] =?UTF-8?q?feat:=20=EC=97=90=EB=9F=AC=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/mineswipper/domain/map/Field.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/mineswipper/domain/map/Field.kt b/src/main/kotlin/mineswipper/domain/map/Field.kt index bedccf42e..8f103f9d1 100644 --- a/src/main/kotlin/mineswipper/domain/map/Field.kt +++ b/src/main/kotlin/mineswipper/domain/map/Field.kt @@ -43,6 +43,6 @@ class Field( } companion object { - private const val VALID_MESSAGE: String = "오류가 발생했습니다." + private const val VALID_MESSAGE: String = "해당 위치에 값이 존재하지 않습니다." } } From cfdce4badec88d6b4319cd21b816ecf1b71e8e8d Mon Sep 17 00:00:00 2001 From: Ted1_Lee Date: Thu, 14 Dec 2023 09:13:02 +0900 Subject: [PATCH 17/22] =?UTF-8?q?feat:=20editor=20=EC=84=A4=EC=A0=95=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/mineswipper/domain/map/position/Position.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/mineswipper/domain/map/position/Position.kt b/src/main/kotlin/mineswipper/domain/map/position/Position.kt index 2f191eb9e..19f5a101b 100644 --- a/src/main/kotlin/mineswipper/domain/map/position/Position.kt +++ b/src/main/kotlin/mineswipper/domain/map/position/Position.kt @@ -21,4 +21,4 @@ data class Position( } -fun List.toPositions(): Positions = Positions(this) \ No newline at end of file +fun List.toPositions(): Positions = Positions(this) From 0a4a2ae1b86aa5d636c8311ea89c477cfbe8ec59 Mon Sep 17 00:00:00 2001 From: JunHyun Lee Date: Fri, 15 Dec 2023 23:13:43 +0900 Subject: [PATCH 18/22] =?UTF-8?q?feat:=20=EC=97=90=EB=9F=AC=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/mineswipper/domain/map/Field.kt | 3 +-- src/main/kotlin/mineswipper/domain/map/Pedals.kt | 8 +++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/mineswipper/domain/map/Field.kt b/src/main/kotlin/mineswipper/domain/map/Field.kt index 8f103f9d1..c287765ef 100644 --- a/src/main/kotlin/mineswipper/domain/map/Field.kt +++ b/src/main/kotlin/mineswipper/domain/map/Field.kt @@ -38,8 +38,7 @@ class Field( val pedals = field[position.toRow()] require(pedals != null) { VALID_MESSAGE } - val pedal = pedals.get(position.x) - return pedal + return pedals.get(position.x) } companion object { diff --git a/src/main/kotlin/mineswipper/domain/map/Pedals.kt b/src/main/kotlin/mineswipper/domain/map/Pedals.kt index d60c02e42..49da9e7ea 100644 --- a/src/main/kotlin/mineswipper/domain/map/Pedals.kt +++ b/src/main/kotlin/mineswipper/domain/map/Pedals.kt @@ -5,6 +5,12 @@ value class Pedals( val value: List ) { fun get(index: Int): Pedal { + val result = value.getOrNull(index) + require(result != null) { ERROR_MESSAGE } return value[index] } -} \ No newline at end of file + + companion object { + private const val ERROR_MESSAGE: String = "값이 존재하지 않습니다." + } +} From 632971ff826ed07fa7b8735fecf8764ce8f508c6 Mon Sep 17 00:00:00 2001 From: JunHyun Lee Date: Fri, 15 Dec 2023 23:15:57 +0900 Subject: [PATCH 19/22] =?UTF-8?q?feat:=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=EB=A1=9C=EC=A7=81=20=EC=A4=84=EC=9D=B4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/mineswipper/MineGame.kt | 2 -- src/main/kotlin/mineswipper/domain/map/Field.kt | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/mineswipper/MineGame.kt b/src/main/kotlin/mineswipper/MineGame.kt index d95404e1d..caa23ad0a 100644 --- a/src/main/kotlin/mineswipper/MineGame.kt +++ b/src/main/kotlin/mineswipper/MineGame.kt @@ -23,8 +23,6 @@ class MineGame( positionFactory.generateMinePositions(size, mine) ) - MarkGenerator.markGeneration(field) - outputManager.printStartGame() outputManager.printField(field) } diff --git a/src/main/kotlin/mineswipper/domain/map/Field.kt b/src/main/kotlin/mineswipper/domain/map/Field.kt index c287765ef..de767b1ee 100644 --- a/src/main/kotlin/mineswipper/domain/map/Field.kt +++ b/src/main/kotlin/mineswipper/domain/map/Field.kt @@ -4,6 +4,7 @@ import mineswipper.domain.map.position.Position import mineswipper.domain.map.position.Positions import mineswipper.domain.map.position.Row import mineswipper.domain.map.position.Size +import mineswipper.domain.map.util.MarkGenerator class Field( val size: Size, @@ -17,6 +18,8 @@ class Field( initField[Row(x)] = pedalSetting(x, minePositions) } field = initField.toMap() + + MarkGenerator.markGeneration(this) } private fun pedalSetting(x: Int, minePositions: Positions): Pedals { From 227cf4c65411a067931be1efd81d86beb7d51018 Mon Sep 17 00:00:00 2001 From: JunHyun Lee Date: Fri, 15 Dec 2023 23:16:51 +0900 Subject: [PATCH 20/22] feat: ktlint --- src/main/kotlin/mineswipper/domain/map/Mine.kt | 3 +-- src/main/kotlin/mineswipper/domain/map/NormalPedal.kt | 4 +--- src/main/kotlin/mineswipper/domain/map/position/Position.kt | 2 -- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/mineswipper/domain/map/Mine.kt b/src/main/kotlin/mineswipper/domain/map/Mine.kt index 87e4eebf5..a5bf1b745 100644 --- a/src/main/kotlin/mineswipper/domain/map/Mine.kt +++ b/src/main/kotlin/mineswipper/domain/map/Mine.kt @@ -2,5 +2,4 @@ package mineswipper.domain.map class Mine( override var mark: Mark? = Mark("*") -) : Pedal { -} +) : Pedal diff --git a/src/main/kotlin/mineswipper/domain/map/NormalPedal.kt b/src/main/kotlin/mineswipper/domain/map/NormalPedal.kt index 5577470c5..290cc4d4e 100644 --- a/src/main/kotlin/mineswipper/domain/map/NormalPedal.kt +++ b/src/main/kotlin/mineswipper/domain/map/NormalPedal.kt @@ -2,6 +2,4 @@ package mineswipper.domain.map class NormalPedal( override var mark: Mark? = null -) : Pedal { - -} \ No newline at end of file +) : Pedal diff --git a/src/main/kotlin/mineswipper/domain/map/position/Position.kt b/src/main/kotlin/mineswipper/domain/map/position/Position.kt index 19f5a101b..04b79e349 100644 --- a/src/main/kotlin/mineswipper/domain/map/position/Position.kt +++ b/src/main/kotlin/mineswipper/domain/map/position/Position.kt @@ -17,8 +17,6 @@ data class Position( private fun isValid(width: Int, height: Int): Boolean { return x in 0 until width && y in 0 until height } - - } fun List.toPositions(): Positions = Positions(this) From 90a2b659e528c83c40363cd971c1d024383a83f8 Mon Sep 17 00:00:00 2001 From: JunHyun Lee Date: Fri, 15 Dec 2023 23:39:34 +0900 Subject: [PATCH 21/22] =?UTF-8?q?feat:=20FieldFactory=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/mineswipper/MineGame.kt | 8 +--- .../kotlin/mineswipper/domain/map/Field.kt | 40 ++++------------- .../domain/map/util/FieldFactory.kt | 45 +++++++++++++++++++ .../domain/map/util/MarkGenerator.kt | 2 +- .../mineswipper/domain/map/FieldTest.kt | 4 +- .../domain/map/util/MarkGeneratorTest.kt | 4 +- 6 files changed, 60 insertions(+), 43 deletions(-) create mode 100644 src/main/kotlin/mineswipper/domain/map/util/FieldFactory.kt diff --git a/src/main/kotlin/mineswipper/MineGame.kt b/src/main/kotlin/mineswipper/MineGame.kt index caa23ad0a..d4b793fdf 100644 --- a/src/main/kotlin/mineswipper/MineGame.kt +++ b/src/main/kotlin/mineswipper/MineGame.kt @@ -1,8 +1,7 @@ package mineswipper -import mineswipper.domain.map.Field import mineswipper.domain.map.position.Size -import mineswipper.domain.map.util.MarkGenerator +import mineswipper.domain.map.util.FieldFactory import mineswipper.domain.map.util.PositionFactory import mineswipper.domain.map.util.RandomMinePositionGenerator import mineswipper.ui.InputManager @@ -18,10 +17,7 @@ class MineGame( val width = inputManager.inputWidth() val size = Size(width, height) val mine = inputManager.inputMine() - val field = Field( - size, - positionFactory.generateMinePositions(size, mine) - ) + val field = FieldFactory(size).createField(positionFactory.generateMinePositions(size, mine)) outputManager.printStartGame() outputManager.printField(field) diff --git a/src/main/kotlin/mineswipper/domain/map/Field.kt b/src/main/kotlin/mineswipper/domain/map/Field.kt index de767b1ee..4af208e93 100644 --- a/src/main/kotlin/mineswipper/domain/map/Field.kt +++ b/src/main/kotlin/mineswipper/domain/map/Field.kt @@ -1,42 +1,12 @@ package mineswipper.domain.map import mineswipper.domain.map.position.Position -import mineswipper.domain.map.position.Positions import mineswipper.domain.map.position.Row import mineswipper.domain.map.position.Size -import mineswipper.domain.map.util.MarkGenerator class Field( - val size: Size, - minePositions: Positions -) { val field: Map - - init { - val initField: MutableMap = mutableMapOf() - repeat(size.height) { x -> - initField[Row(x)] = pedalSetting(x, minePositions) - } - field = initField.toMap() - - MarkGenerator.markGeneration(this) - } - - private fun pedalSetting(x: Int, minePositions: Positions): Pedals { - val pedalList = (0 until size.width).map { y -> - val position = Position(x, y) - createPedal(minePositions, position) - } - return Pedals(pedalList) - } - - private fun createPedal( - minePositions: Positions, - position: Position - ): Pedal { - return if (minePositions.contains(position)) Mine() else NormalPedal() - } - +) { fun findPedal(position: Position): Pedal { val pedals = field[position.toRow()] require(pedals != null) { VALID_MESSAGE } @@ -44,7 +14,15 @@ class Field( return pedals.get(position.x) } + fun getSize(): Size { + val pedals = field[Row(FIRST_ROW_FOR_SIZE)] + require(pedals != null) { VALID_MESSAGE } + + return Size(field.size, pedals.value.size) + } + companion object { private const val VALID_MESSAGE: String = "해당 위치에 값이 존재하지 않습니다." + private const val FIRST_ROW_FOR_SIZE: Int = 0 } } diff --git a/src/main/kotlin/mineswipper/domain/map/util/FieldFactory.kt b/src/main/kotlin/mineswipper/domain/map/util/FieldFactory.kt new file mode 100644 index 000000000..86319b2d0 --- /dev/null +++ b/src/main/kotlin/mineswipper/domain/map/util/FieldFactory.kt @@ -0,0 +1,45 @@ +package mineswipper.domain.map.util + +import mineswipper.domain.map.Field +import mineswipper.domain.map.Mine +import mineswipper.domain.map.NormalPedal +import mineswipper.domain.map.Pedal +import mineswipper.domain.map.Pedals +import mineswipper.domain.map.position.Position +import mineswipper.domain.map.position.Positions +import mineswipper.domain.map.position.Row +import mineswipper.domain.map.position.Size + +class FieldFactory( + private val size: Size +) { + fun createField( +// size: Size, + minePositions: Positions + ): Field { + val initField: MutableMap = mutableMapOf() + repeat(size.height) { x -> + initField[Row(x)] = pedalSetting(x, minePositions) + } + + val fakeField = Field(initField.toMap()) + + MarkGenerator.markGeneration(fakeField) + + return fakeField + } + private fun createPedal( + minePositions: Positions, + position: Position + ): Pedal { + return if (minePositions.contains(position)) Mine() else NormalPedal() + } + + private fun pedalSetting(x: Int, minePositions: Positions): Pedals { + val pedalList = (0 until size.width).map { y -> + val position = Position(x, y) + createPedal(minePositions, position) + } + return Pedals(pedalList) + } +} diff --git a/src/main/kotlin/mineswipper/domain/map/util/MarkGenerator.kt b/src/main/kotlin/mineswipper/domain/map/util/MarkGenerator.kt index 538313af9..bee60999d 100644 --- a/src/main/kotlin/mineswipper/domain/map/util/MarkGenerator.kt +++ b/src/main/kotlin/mineswipper/domain/map/util/MarkGenerator.kt @@ -10,7 +10,7 @@ object MarkGenerator { val pedal = field.findPedal(position) if (pedal.mark != null) return pedal.mark!! - val aroundPositions = position.getAroundPositions(field.size) + val aroundPositions = position.getAroundPositions(field.getSize()) val count = aroundPositions.positions.count { val findPedal = field.findPedal(it) findPedal is Mine diff --git a/src/test/kotlin/mineswipper/domain/map/FieldTest.kt b/src/test/kotlin/mineswipper/domain/map/FieldTest.kt index 276c63d5c..f7b6fa308 100644 --- a/src/test/kotlin/mineswipper/domain/map/FieldTest.kt +++ b/src/test/kotlin/mineswipper/domain/map/FieldTest.kt @@ -4,6 +4,7 @@ import io.kotest.matchers.types.shouldBeInstanceOf import mineswipper.domain.map.position.Position import mineswipper.domain.map.position.Positions import mineswipper.domain.map.position.Size +import mineswipper.domain.map.util.FieldFactory import mineswipper.domain.map.util.MinePositionStrategy import org.junit.jupiter.api.Test @@ -13,8 +14,7 @@ class FieldTest { fun `필드에는 지뢰 발판이 있다`() { val size = Size(2, 2) val mine = 2 - val field = Field( - size, + val field = FieldFactory(size).createField( MineMarkTestStrategy().createMinePosition(size, mine) ) diff --git a/src/test/kotlin/mineswipper/domain/map/util/MarkGeneratorTest.kt b/src/test/kotlin/mineswipper/domain/map/util/MarkGeneratorTest.kt index e1bab19fb..cc8952e62 100644 --- a/src/test/kotlin/mineswipper/domain/map/util/MarkGeneratorTest.kt +++ b/src/test/kotlin/mineswipper/domain/map/util/MarkGeneratorTest.kt @@ -1,7 +1,6 @@ package mineswipper.domain.map.util import io.kotest.matchers.shouldBe -import mineswipper.domain.map.Field import mineswipper.domain.map.MineMarkTestStrategy import mineswipper.domain.map.position.Position import mineswipper.domain.map.position.Size @@ -12,8 +11,7 @@ class MarkGeneratorTest { fun `일반 발판은 주변에 지뢰 갯수를 표시한다`() { val size = Size(2, 2) val mine = 2 - val field = Field( - size, + val field = FieldFactory(size).createField( MineMarkTestStrategy().createMinePosition(size, mine) ) From 7e628070aca5dcc5081e88cd06ef41d8fd63f33f Mon Sep 17 00:00:00 2001 From: Ted1_Lee Date: Thu, 14 Dec 2023 09:41:52 +0900 Subject: [PATCH 22/22] =?UTF-8?q?feat:=20=EA=B0=92=EC=9D=B4=20=EC=97=86?= =?UTF-8?q?=EC=9D=84=20=EB=95=8C=20=EC=B2=98=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/mineswipper/domain/map/Pedals.kt | 5 +++-- .../kotlin/mineswipper/domain/map/util/PositionFactory.kt | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/mineswipper/domain/map/Pedals.kt b/src/main/kotlin/mineswipper/domain/map/Pedals.kt index 49da9e7ea..8d992644c 100644 --- a/src/main/kotlin/mineswipper/domain/map/Pedals.kt +++ b/src/main/kotlin/mineswipper/domain/map/Pedals.kt @@ -7,10 +7,11 @@ value class Pedals( fun get(index: Int): Pedal { val result = value.getOrNull(index) require(result != null) { ERROR_MESSAGE } - return value[index] + return result } companion object { - private const val ERROR_MESSAGE: String = "값이 존재하지 않습니다." + private const val ERROR_MESSAGE: String = "해당 인덱스에 값이 존재하지 않습니다." } } + diff --git a/src/main/kotlin/mineswipper/domain/map/util/PositionFactory.kt b/src/main/kotlin/mineswipper/domain/map/util/PositionFactory.kt index b3b4a7b7e..a37fb4232 100644 --- a/src/main/kotlin/mineswipper/domain/map/util/PositionFactory.kt +++ b/src/main/kotlin/mineswipper/domain/map/util/PositionFactory.kt @@ -1,6 +1,5 @@ package mineswipper.domain.map.util -import mineswipper.domain.map.position.Position import mineswipper.domain.map.position.Positions import mineswipper.domain.map.position.Size