-
Notifications
You must be signed in to change notification settings - Fork 206
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
base: jjongwa
Are you sure you want to change the base?
Changes from 1 commit
2e6a43c
d84a3d5
1721d41
8ce06c5
e92bd17
be1c3fb
b9edd3c
10d0733
912d671
49f3806
646f2f3
d956b42
19f1404
b9f4f1b
d9995d5
d7db7a3
2bb8cf2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
} | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spot κ°μ²΄μ isNotOpened() νΉμ isClosed() ν¨μλ₯Ό μΆκ°ν΄μ€λ μ’κ² λ€λ μκ°μ΄ λλ€μ! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. νμ€ν λΆμ λ¬Έμ μ°λ κ²λ³΄λ¨ isClosedλ₯Ό λ§λ€μ΄ μ¬μ©νλ νΈμ΄ ν¨μ¬ λ κ°λ μ±μ΄ μ’μ 보μ΄λ€μ! 2bb8cf2 |
||
} | ||
} | ||
} | ||
|
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.
as? λ‘ nullable μΊμ€ν μ ν λ€, null μ²λ¦¬λ₯Ό νλ ννλ‘ λ‘μ§μ ꡬμ±ν΄λ΄λ μ’κ² μ΄μ!
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.
μ΄λ° μμΌλ‘ letμ ν΅ν΄ nullμ΄ μλ spotμμλ§ λλ¨Έμ§ λ‘μ§μ μ€ννλλ‘ λ°κΎΈμ΄ μ£Όμμ΅λλ€