-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
๐ 1๋จ๊ณ - ์ง๋ขฐ ์ฐพ๊ธฐ(๊ทธ๋ฆฌ๊ธฐ) #417
base: giibeom
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ญ๊ฐ ์ด๋ฒ 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readln()
์ ์ฌ์ฉํ ๊น ํ๋ค๊ฐIllegalArgumentException
๋ก ํต์ผํ๋๊ฒ ์ข์ ๊ฒ ๊ฐ์์ ์์ ๊ฐ์ด ์ฝ๋๋ฅผ ์ง๋ณด์์ต๋๋น ๐ค
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์๋
ํ์ธ์ ๊ธฐ๋ฒ๋!
์ฐ๋ง์ด๋ผ ์ ์ ์ด ์์ด์, ๋ฆฌ๋ทฐ๊ฐ ๋ฆ์๋ค์ใ
ใ
!
๋ช๊ฐ์ง ์ฝ๋ฉํธ ๋จ๊ฒผ์ผ๋, ํ์ธํด์ฃผ์ธ์ :)
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"C"๋ผ๋๊ฑด ๋ฌด์์ ์๋ฏธํ ๊น์?
๋ชจ๋ ์์ ๊ฐ๊ณผ ๋ฌธ์์ด์ ํฌ์ฅํ๋ค.
์๊ตฌ์ฌํญ์ ์ง์ผ๋ณด์์!
return board.joinToString("\n") { row -> | ||
row.joinToString(" ") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ํด๋น ๋ก์ง์ View๊ด๋ จ ๋ก์ง์ ์๋๊น์?
View๊ฐ ํ
์คํธ๋ก ์งํ๋์ง ์๋๋ค๋ฉด domain๋ก์ง์๋ ์ํฅ์ด ๊ฐ๋๊ตฌ์กฐ๋ค์!
package game.minesweeper.domain | ||
|
||
object MineGenerator { | ||
fun create(board: Array<Array<String>>, minesNumber: Int) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Array<Array>๋ ๋ฌด์์ ์๋ฏธํ ๊น์?
์ผ๊ธ ์ปฌ๋ ์ ์ ์ด๋ค.
์ ํ์ฉํด๋ณด๋ฉด ์ด๋จ๊น์?
if (board[randomRow][randomCol] != "*") { | ||
board[randomRow][randomCol] = "*" | ||
minesPlaced++ | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ํ ๋ฉ์๋์ ์ค์ง ํ ๋จ๊ณ์ ๋ค์ฌ์ฐ๊ธฐ๋ง ํ๋ค.
์๊ตฌ์ฌํญ์ ์ง์ผ๋ณด์์!
val randomCol = (0 until width).random() | ||
|
||
if (board[randomRow][randomCol] != "*") { | ||
board[randomRow][randomCol] = "*" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"*"์ ๋ฌด์์ ์๋ฏธํ ๊น์? ๋ง์ฐฌ๊ฐ์ง๋ก ๊ฐ์ฒด๋ก ๊ด๋ฆฌํด๋ณด๋ฉด ์ด๋จ๊น์?
val randomCol = (0 until width).random() | ||
|
||
if (board[randomRow][randomCol] != "*") { | ||
board[randomRow][randomCol] = "*" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ํ๋ฆฌ๋ฏธํฐ๋ก ์ ๋ฌ๋ฐ์ 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MineGenerator๋ผ๋ ์ฑ๊ธํด๊ฐ์ฒด์ ์ ๊ทผํ๋ ๊ตฌ์กฐ๋ค์
์ฑ๊ธํดํจํด์ ๊ฐ์ฒด๊ฐ ๊ฒฐํฉ๋๋ฅผ ์ฌ๋ฆฌ๋ ๊ฒฝ์ฐ๋ ๋ง์์ ์ฌ์ฉ์ ์ฃผ์ํ๋๊ฒ ์ข์์!
import io.kotest.data.row | ||
import io.kotest.matchers.shouldBe | ||
|
||
class MineGeneratorTest : StringSpec({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GameBoard ๊ด๋ จ ํ ์คํธ ์ฝ๋๋ ์์ฑํด๋ณด๋ฉด ์ด๋จ๊น์?
์๋ ํ์ธ์ ๋ฆฌ๋ทฐ์ด๋ :)
์์ฃผ๋ฅผ ์ํด ์ด์ฌํ ๋ฌ๋ฆฌ๊ณ ์์ต๋๋ค ใ ใ ๐
์ ๋ถํ๋๋ฆฝ๋๋ค ๐๐