Skip to content

Step2#232

Open
jpoh281 wants to merge 40 commits into
next-step:jpoh281from
jpoh281:step2
Open

Step2#232
jpoh281 wants to merge 40 commits into
next-step:jpoh281from
jpoh281:step2

Conversation

@jpoh281

@jpoh281 jpoh281 commented Jan 2, 2023

Copy link
Copy Markdown

안녕하세요.. 제가 뭔가 커밋을 잘못했는지 꼬였어요.

refactor: ResultView의 매직 리터럴 companion object로 이동

커밋부터 봐주시면 될것같아요.

오늘이 마지막 피드백 날짜라고 해서 진행하던 2단계를 부랴부랴 정리하고 PR 날립니다..

adforus_hjp added 27 commits December 22, 2022 12:28
# Conflicts:
#	src/main/kotlin/minesweeper/README.md
#	src/main/kotlin/minesweeper/controller/GameController.kt
#	src/main/kotlin/minesweeper/domain/Block.kt
#	src/main/kotlin/minesweeper/domain/ExceptionReason.kt
#	src/main/kotlin/minesweeper/domain/MineSweeperBoard.kt
#	src/main/kotlin/minesweeper/domain/Point.kt
#	src/main/kotlin/minesweeper/view/ResultView.kt
#	src/main/kotlin/minesweeper/view/ResultViewImpl.kt
#	src/test/kotlin/minesweeper/domain/PointTest.kt

@ohgillwhan ohgillwhan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

코드 잘 봤습니다. MimeSweeperBoard 테스트 코드도 부탁드려용!

Comment on lines +19 to +25
} catch (e: MineSweeperException) {
resultView.printKnownException(e)
null
} catch (e: Exception) {
resultView.printUnknownException(e)
null
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Exception을 고스란히 터트려주는것도 좋은 방법이에요.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

게임을 종료시킬 수 있는것을 컨트롤러에서 제어가 가능해지죠.

@@ -4,14 +4,29 @@ sealed class Block {
abstract fun open()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

열 수 있는 블록과 없는 블록을 나누는건 어떨까요?
TODO("Not yet implemented") 가 나와서 애매해지는거 같아요.

_state = buildBoard(width, height).toMutableMap()
plantMines(mineCount)
_mineCount = countMine()
buildSafeBlock()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

이 코드는 buildBoard를 할 때 같이 이뤄져야 하지 않나요?

Comment on lines +21 to +24
_state = buildBoard(width, height).toMutableMap()
plantMines(mineCount)
_mineCount = countMine()
buildSafeBlock()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

이 코드가 응집이 되어보는건 어떨까요?

Comment on lines 45 to 46
val width = Random().nextInt(width)
val height = Random().nextInt(height)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

랜덤에 의존적인게 아쉽네요. 전략패턴 등을 이용해보면 어떤가요?

private fun plusOrNull(x: Int, y: Int): Point? {
return try {
Point(this.x + x, this.y + y)
} catch (e: Exception) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

try catch로 로직을 수행하는게 조금 아쉽네요. 현재 객체에서 x, y 만큼 더 할 수 있는지 메서드를 만들어서 처리해보는건 어떨까요?

@jpoh281

jpoh281 commented Jan 10, 2023

Copy link
Copy Markdown
Author

안녕하세요?
처음에 열 수 있는 블록과 열 수 없는 블록으로 구분했다가, 응집도를 높이다보니 열 수 없는 블록이 필요가 없어지는 것 같아서 다시 삭제했습니다.
전략패턴을 통해서 나머지 계산의 방식으로?? 지뢰가 설치 되도록 구현했습니다.
try - catch 안쓰고 주변의 수 받아올 수 있도록 변경했어요! 엄청 어려울 것 같다고 생각했었는데 생각보다 어렵지않았네요.

@ohgillwhan ohgillwhan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

간단한 리뷰 몇개 남겨봤어요! 확인 부탁드립니다.

return gameBoard.state
fun run(): MineSweeperBoard? {
return try {
val gameBoard = setUp()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

타입이 나오면 좋겠네요~


override fun compareTo(other: Point) = compareValuesBy(this, other, { it.y }, { it.x })

private fun plusOrNull(x: Int, y: Int, maxX: Int, maxY: Int): Point? {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

연산자 오버로딩을 해도 괜찮겠네요~

Comment on lines +12 to +14
override fun open() {
TODO("Not yet implemented")
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

구현이 안될 메서드를 만들어야 하는건 조금 아쉽네요. Block을 세분화 해보는건 어떨까요?

Comment on lines +18 to +19


Copy link
Copy Markdown

Choose a reason for hiding this comment

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

린트 돌려주세요~

val userInputMineCount = 1

val controller =
GameController(FakeInputView(userInputHeight, userInputWidth, userInputMineCount), ResultViewImpl())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ResultViewImpl 보다 더 좋은 의미는 없을까요? ConsoleResultView 이런식으로요


@Test
fun `0보다 작은 수는 생성될 수 없다`() {
val exception = org.junit.jupiter.api.assertThrows<MineSweeperException> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

import를 해볼까요?

Comment on lines +53 to +58
val minePoints = strategy.createMines(width, height, plantingMineCount)
minePoints.forEach {
_state[it] = MineBlock()
}
_mineCount = countMine()
updateSafeBlock()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

전략을 바꿀 수 있으니, 여러 장점이 있을것 같아요.
테스트코드에서 전략을 한개 만들어서, 그 전략만큼 지뢰가 잘 심겼는지 등 테스트 할 수 있겠죠? 나중에 게임 실행하면서 원하는 위치에 지뢰를 심고, 터트리는 등 테스트를 더욱 쉽게 가능할거에요.

@jpoh281

jpoh281 commented Jan 17, 2023

Copy link
Copy Markdown
Author

안녕하세요?
공백이나, 임포트 같은 부분 신경 못쓰고 PR 드려서 죄송해요..

  1. 최근에 개발할 때 인터페이스와 구현체가 거의 일방적인 구현체여서 네이밍을 impl 만 사용했었는데, 이렇게 더 명확하게 바꿀 수 있다는걸 다시 생각해볼 수 있어서 너무 좋았어요.

  2. plusOrNull은 오퍼레이터를 오버라이딩하고 싶었는데 이게 제가 계산하는 방식이 null을 사용해야해서 다시 로직을 생각해보는게 좋을까요?

  3. 모든 블록에 isOpen 이라는 값을 두고, MineBlock, SafeBlock 둘 다 open 메소드를 구현해서 사용할까 했었는데 피드백을 반영해서
    아직 열어보지 않은 UnopenedBlock과 열린 상태인 OpenedBlock을 상속받은 MineBlock, SafeBlock으로 나누었습니다.

  4. MineSweeperBoard를 step3에서 어떻게 테스트 해야할지 감이 잡혔습니다. 감사해요!

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.

2 participants