Skip to content
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

Open
wants to merge 4 commits into
base: giibeom
Choose a base branch
from

Conversation

giibeom
Copy link

@giibeom giibeom commented Dec 14, 2023

์•ˆ๋…•ํ•˜์„ธ์š” ๋ฆฌ๋ทฐ์–ด๋‹˜ :)

์™„์ฃผ๋ฅผ ์œ„ํ•ด ์—ด์‹ฌํžˆ ๋‹ฌ๋ฆฌ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค ใ…Žใ…Ž ๐Ÿš€
์ž˜ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค ๐Ÿ™๐Ÿ™

Copy link
Author

@giibeom giibeom left a 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 ๋“œ๋ฆฌ๋Š”๊ฒŒ ์ข€ ์ฐœ์ฐœ...ํ•ด์„œ ์ฝ”๋ฉ˜ํŠธ ๋‹ฌ์•„๋ด…๋‹ˆ๋‹ค ๐Ÿ˜‚

Comment on lines +18 to +20
val height = readlnOrNull()?.toIntOrNull()
requireNotNull(height) { INVALID_NUMBER_PROMPT }
require(height > 0) { INVALID_HEIGHT_RANGE_PROMPT }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readln()์„ ์‚ฌ์šฉํ• ๊นŒ ํ•˜๋‹ค๊ฐ€IllegalArgumentException๋กœ ํ†ต์ผํ•˜๋Š”๊ฒŒ ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์„œ ์œ„์™€ ๊ฐ™์ด ์ฝ”๋“œ๋ฅผ ์งœ๋ณด์•˜์Šต๋‹ˆ๋‹น ๐Ÿค”

Copy link

@namjackson namjackson left a 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" } }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"C"๋ผ๋Š”๊ฑด ๋ฌด์—‡์„ ์˜๋ฏธํ• ๊นŒ์š”?

๋ชจ๋“  ์›์‹œ ๊ฐ’๊ณผ ๋ฌธ์ž์—ด์„ ํฌ์žฅํ•œ๋‹ค.

์š”๊ตฌ์‚ฌํ•ญ์„ ์ง€์ผœ๋ณด์•„์š”!

Comment on lines +11 to +13
return board.joinToString("\n") { row ->
row.joinToString(" ")
}

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) {

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++
}

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] = "*"

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] = "*"

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)

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({

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GameBoard ๊ด€๋ จ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋„ ์ž‘์„ฑํ•ด๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants