๐ 1๋จ๊ณ - ์ง๋ขฐ ์ฐพ๊ธฐ(๊ทธ๋ฆฌ๊ธฐ)#417
Conversation
There was a problem hiding this comment.
๋ญ๊ฐ ์ด๋ฒ step1์์๋ ๋จ์ํ
์คํธ๋ฅผ ์งํํ ๋งํ ๋๋ฉ์ธ ๋ก์ง์ด ๋ณด์ด์ง ์์๋๋ฐ์ ๐ค๐ค
(๊ตณ์ด ํ๋ค๋ฉด... MineGenerator#create ์ ๋..?)
๋ญ๊ฐ TDD ๊ณผ์ ์ด๋ค ๋ณด๋๊น ํ
์คํธ ์ฝ๋ ์์ด PR ๋๋ฆฌ๋๊ฒ ์ข ์ฐ์ฐ...ํด์ ์ฝ๋ฉํธ ๋ฌ์๋ด
๋๋ค ๐
| val height = readlnOrNull()?.toIntOrNull() | ||
| requireNotNull(height) { INVALID_NUMBER_PROMPT } | ||
| require(height > 0) { INVALID_HEIGHT_RANGE_PROMPT } |
There was a problem hiding this comment.
readln()์ ์ฌ์ฉํ ๊น ํ๋ค๊ฐIllegalArgumentException๋ก ํต์ผํ๋๊ฒ ์ข์ ๊ฒ ๊ฐ์์ ์์ ๊ฐ์ด ์ฝ๋๋ฅผ ์ง๋ณด์์ต๋๋น ๐ค
namjackson
left a comment
There was a problem hiding this comment.
์๋
ํ์ธ์ ๊ธฐ๋ฒ๋!
์ฐ๋ง์ด๋ผ ์ ์ ์ด ์์ด์, ๋ฆฌ๋ทฐ๊ฐ ๋ฆ์๋ค์ใ
ใ
!
๋ช๊ฐ์ง ์ฝ๋ฉํธ ๋จ๊ฒผ์ผ๋, ํ์ธํด์ฃผ์ธ์ :)
| package game.minesweeper.domain | ||
|
|
||
| class GameBoard(height: Int, width: Int) { | ||
| private val board = Array(height) { Array(width) { "C" } } |
There was a problem hiding this comment.
"C"๋ผ๋๊ฑด ๋ฌด์์ ์๋ฏธํ ๊น์?
๋ชจ๋ ์์ ๊ฐ๊ณผ ๋ฌธ์์ด์ ํฌ์ฅํ๋ค.
์๊ตฌ์ฌํญ์ ์ง์ผ๋ณด์์!
| return board.joinToString("\n") { row -> | ||
| row.joinToString(" ") | ||
| } |
There was a problem hiding this comment.
ํด๋น ๋ก์ง์ View๊ด๋ จ ๋ก์ง์ ์๋๊น์?
View๊ฐ ํ
์คํธ๋ก ์งํ๋์ง ์๋๋ค๋ฉด domain๋ก์ง์๋ ์ํฅ์ด ๊ฐ๋๊ตฌ์กฐ๋ค์!
| package game.minesweeper.domain | ||
|
|
||
| object MineGenerator { | ||
| fun create(board: Array<Array<String>>, minesNumber: Int) { |
There was a problem hiding this comment.
Array<Array>๋ ๋ฌด์์ ์๋ฏธํ ๊น์?
์ผ๊ธ ์ปฌ๋ ์ ์ ์ด๋ค.
์ ํ์ฉํด๋ณด๋ฉด ์ด๋จ๊น์?
| if (board[randomRow][randomCol] != "*") { | ||
| board[randomRow][randomCol] = "*" | ||
| minesPlaced++ | ||
| } |
There was a problem hiding this comment.
ํ ๋ฉ์๋์ ์ค์ง ํ ๋จ๊ณ์ ๋ค์ฌ์ฐ๊ธฐ๋ง ํ๋ค.
์๊ตฌ์ฌํญ์ ์ง์ผ๋ณด์์!
| val randomCol = (0 until width).random() | ||
|
|
||
| if (board[randomRow][randomCol] != "*") { | ||
| board[randomRow][randomCol] = "*" |
There was a problem hiding this comment.
"*"์ ๋ฌด์์ ์๋ฏธํ ๊น์? ๋ง์ฐฌ๊ฐ์ง๋ก ๊ฐ์ฒด๋ก ๊ด๋ฆฌํด๋ณด๋ฉด ์ด๋จ๊น์?
| val randomCol = (0 until width).random() | ||
|
|
||
| if (board[randomRow][randomCol] != "*") { | ||
| board[randomRow][randomCol] = "*" |
There was a problem hiding this comment.
ํ๋ฆฌ๋ฏธํฐ๋ก ์ ๋ฌ๋ฐ์ board๊ฐ ๋ณ๊ฒฝ๋๋ ๊ตฌ์กฐ๋ค์,
์ธ๋ถ์์ board๊ฐ ๋ณ๊ฒฝ๋์๋ค๋๊ฑธ ์์์์๊น์?
์ถ๊ฐ๋ก ๊ณ ๋ฏผํด๋ณด์์!
| private val board = Array(height) { Array(width) { "C" } } | ||
|
|
||
| fun startGame(minesNumber: Int) { | ||
| MineGenerator.create(board, minesNumber) |
There was a problem hiding this comment.
MineGenerator๋ผ๋ ์ฑ๊ธํด๊ฐ์ฒด์ ์ ๊ทผํ๋ ๊ตฌ์กฐ๋ค์
์ฑ๊ธํดํจํด์ ๊ฐ์ฒด๊ฐ ๊ฒฐํฉ๋๋ฅผ ์ฌ๋ฆฌ๋ ๊ฒฝ์ฐ๋ ๋ง์์ ์ฌ์ฉ์ ์ฃผ์ํ๋๊ฒ ์ข์์!
| import io.kotest.data.row | ||
| import io.kotest.matchers.shouldBe | ||
|
|
||
| class MineGeneratorTest : StringSpec({ |
There was a problem hiding this comment.
GameBoard ๊ด๋ จ ํ ์คํธ ์ฝ๋๋ ์์ฑํด๋ณด๋ฉด ์ด๋จ๊น์?
์๋ ํ์ธ์ ๋ฆฌ๋ทฐ์ด๋ :)
์์ฃผ๋ฅผ ์ํด ์ด์ฌํ ๋ฌ๋ฆฌ๊ณ ์์ต๋๋ค ใ ใ ๐
์ ๋ถํ๋๋ฆฝ๋๋ค ๐๐