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

[πŸš€ 3단계 - 지뒰 μ°ΎκΈ°(κ²Œμž„ μ‹€ν–‰)] μ‹ μ’…ν™” λ―Έμ…˜ μ œμΆœν•©λ‹ˆλ‹€. #487

Open
wants to merge 17 commits into
base: jjongwa
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
2e6a43c
refactor: 인접칸 enum으둜 λ³€κ²½ & λŒ€κ°μ„  μœ„μΉ˜ 포함
jjongwa Dec 22, 2024
d84a3d5
refactor: Pair() λŒ€μ‹  μ’Œν‘œλ₯Ό μ˜λ―Έν•˜λŠ” 클래슀 생성
jjongwa Dec 22, 2024
1721d41
refactor: Spot sealed class 적용
jjongwa Dec 22, 2024
8ce06c5
refactor: 지뒰 μœ„μΉ˜ μ„€μ • 및 ν•„λ“œ 생성 둜직 λ³€κ²½
jjongwa Dec 22, 2024
e92bd17
docs(README.md): 3단계 κΈ°λŠ₯ κ΅¬ν˜„ λͺ©λ‘ μž‘μ„±
jjongwa Dec 22, 2024
be1c3fb
feat: Spot에 Open μ—¬λΆ€ μƒνƒœ ν•„λ“œ μΆ”κ°€
jjongwa Dec 22, 2024
b9edd3c
feat: νŠΉμ • μ’Œν‘œ open κΈ°λŠ₯ μΆ”κ°€
jjongwa Dec 22, 2024
10d0733
refactor: μ£Όλ³€ μ’Œν‘œ κ΅¬ν•˜λŠ” λ‘œμ§μ„ Position으둜 이동
jjongwa Dec 24, 2024
912d671
refactor: createField() 둜직 ꡬ쑰 λ³€κ²½
jjongwa Dec 24, 2024
49f3806
refactor: openSpotμ—μ„œ νƒ€μž… μΊμŠ€νŒ… μ—λŸ¬κ°€ λ°œμƒν•˜μ§€ μ•Šλ„λ‘ λ³€κ²½
jjongwa Dec 24, 2024
646f2f3
refactor: 이미 μ—΄λ¦° 칸을 μž…λ ₯ν•  경우 μž¬μ‹œλ„ κ°€λŠ₯ν•˜λ„λ‘ 둜직 λ³€κ²½
jjongwa Dec 24, 2024
d956b42
polish: λ©”μ„œλ“œ 넀이밍 λ³€κ²½
jjongwa Dec 24, 2024
19f1404
refactor: open μ‹œμ μ— μ£Όλ³€ 지뒰 개수 κ³„μ‚°ν•˜λ„λ‘ λ³€κ²½
jjongwa Dec 24, 2024
b9f4f1b
test: 근처 μ’Œν‘œ 확인 ν…ŒμŠ€νŠΈλ₯Ό set끼리 λΉ„κ΅ν•˜λ„λ‘ λ³€κ²½
jjongwa Dec 25, 2024
d9995d5
refactor: nearbyMineCount에 private set μ„€μ •
jjongwa Dec 25, 2024
d7db7a3
refactor: fieldInfo private 제거
jjongwa Dec 25, 2024
2bb8cf2
refactor: Spot에 isClosed() λ©”μ„œλ“œ μΆ”κ°€
jjongwa Dec 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions src/main/kotlin/minesweeper/domain/Field.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,29 @@ class Field(
require(minePositions.size <= totalPossibleSpots) { "지뒰 κ°œμˆ˜λŠ” ν•„λ“œμ˜ 총 μŠ€νŒŸλ³΄λ‹€ λ§Žμ„ 수 μ—†μŠ΅λ‹ˆλ‹€." }
}

fun openSpot(position: Position) {
val targetSpot = spots[position] as SafeSpot
targetSpot.open()
fun openSpot(position: Position): Boolean {
spots[position]?.let {
if (it.isMine()) {
return false
}
openTargetSpot(it as SafeSpot)
Copy link
Member

Choose a reason for hiding this comment

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

as? 둜 nullable μΊμŠ€νŒ…μ„ ν•œ λ’€, null 처리λ₯Ό ν•˜λŠ” ν˜•νƒœλ‘œ λ‘œμ§μ„ ꡬ성해봐도 μ’‹κ² μ–΄μš”!

Copy link
Author

Choose a reason for hiding this comment

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

fun openSpot(position: Position): OpenResult {
        val targetSpot =
            spots[position]?.let {
                if (it.isMine()) {
                    return OpenResult.GameOver
                }
                it
            } as SafeSpot
        val openResult = targetSpot.open()
        targetSpot.calculateNearbyMineCount(minePositions)
        checkAndOpenNearbySpot(targetSpot)
        return openResult
    }

이런 μ‹μœΌλ‘œ let을 톡해 null이 μ•„λ‹Œ spotμ—μ„œλ§Œ λ‚˜λ¨Έμ§€ λ‘œμ§μ„ μ‹€ν–‰ν•˜λ„λ‘ λ°”κΎΈμ–΄ μ£Όμ—ˆμŠ΅λ‹ˆλ‹€

}
return true
}

private fun openTargetSpot(targetSpot: SafeSpot) {
targetSpot.open()
if (targetSpot.nearbyMineCount == 0) {
openNearbySpots(position)
openNearbySpots(targetSpot.position)
}
}

private fun openNearbySpots(position: Position) {
NearbyDirection.entries.forEach { direction ->
val nearbyPosition =
Position(
position.x + direction.dx(),
position.y + direction.dy(),
)
spots[nearbyPosition]?.let {
if (!it.isOpened()) {
openSpot(nearbyPosition)
val nearbyPositions = position.nearbyPositions()
nearbyPositions.forEach {
spots[it]?.let { spot ->
if (!spot.isOpened()) {
openSpot(it)
Copy link
Member

Choose a reason for hiding this comment

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

spot 객체에 isNotOpened() ν˜Ήμ€ isClosed() ν•¨μˆ˜λ₯Ό μΆ”κ°€ν•΄μ€˜λ„ μ’‹κ² λ‹€λŠ” 생각이 λ“œλ„€μš”!

Copy link
Author

Choose a reason for hiding this comment

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

ν™•μ‹€νžˆ 뢀정문을 μ“°λŠ” 것보단 isClosedλ₯Ό λ§Œλ“€μ–΄ μ‚¬μš©ν•˜λŠ” 편이 훨씬 더 가독성이 μ’‹μ•„ λ³΄μ΄λ„€μš”! 2bb8cf2

}
}
}
Expand Down