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단계 - 지뒰 μ°ΎκΈ°(그리기) #361

Open
wants to merge 3 commits into
base: mins99
Choose a base branch
from

Conversation

mins99
Copy link

@mins99 mins99 commented Nov 23, 2023

μ•ˆλ…•ν•˜μ„Έμš” λ¦¬λ·°μ–΄λ‹˜!
λ“œλ””μ–΄ λ§ˆμ§€λ§‰ λ―Έμ…˜ 지뒰찾기가 μ‹œμž‘λ˜μ—ˆλ„€μš”~! ν•˜μ§€λ§Œ λ§ˆμ§€λ§‰μ΄λΌκ³  μ•ˆμ£Όν•˜μ§€ μ•Šκ³  μ™„μ£Ό ν•΄λ³΄κ² μŠ΅λ‹ˆλ‹€ πŸƒβ€β™€οΈ
이미 μ•Œκ³  μžˆλŠ” κ²Œμž„μ΄λΌ κ·ΈλŸ°μ§€ λΈ”λž™μž­μ— λΉ„ν•΄μ„œλŠ” μˆ˜μ›”ν•˜κ²Œ κ΅¬ν˜„ν–ˆλ˜κ²ƒ κ°™μŠ΅λ‹ˆλ‹€
컀밋을 λ³΄μ‹œλ©΄ μ•„μ‹œκ² μ§€λ§Œ μ—„μ²­λ‚˜κ²Œ λ‹¨μˆœν•˜κ²Œ κ΅¬ν˜„ν–ˆλ‹€κ°€.. 쑰금 더 객체λ₯Ό λ‚˜λˆŒ 수 μžˆμ„κ²ƒ κ°™μ•„μ„œ(+ 객체지ν–₯ μƒν™œ 체쑰 원칙을 μ§€ν‚€κ³ μž) λ‚˜λˆ„μ–΄λ³΄μ•˜μŠ΅λ‹ˆλ‹€!

참고사항

νŒ¨ν‚€μ§€ ꡬ쑰

  • board(지뒰찾기 κ²Œμž„ 판)와 cell(μΉΈ ν•˜λ‚˜)둜 νŒ¨ν‚€μ§€λ₯Ό λ‚˜λˆ„κ³  κ·Έ μ•„λž˜μ— κ΄€λ ¨λœ 객체듀을 λ‘λŠ” ꡬ쑰
  • cell의 경우 κ°€λŠ₯ν•œ μΌ€μ΄μŠ€κ°€ 빈칸 λ˜λŠ” 지뒰 둜 λ˜μ–΄μžˆλ‹€ λ³΄λ‹ˆ μΈν„°νŽ˜μ΄μŠ€(Opening)λ₯Ό μ‚¬μš©ν•˜μ—¬ μœ μ—°ν•˜κ²Œ ꡬ성

고민거리

μΌκΈ‰μ»¬λ ‰μ…˜ μ‚¬μš©μ‹œ view μ˜μ—­μ— 데이터λ₯Ό κ°€μ Έμ˜¬ λ•Œ
fun minefield(): Array<Array<Opening>> = minefield.minefield 와 같이 ν•œ 번 더 κΊΌλ‚΄κ²Œ λ˜λŠ”λ°,
ν˜Ήμ‹œ 객체지ν–₯적으둜 더 쒋은 방법이 μžˆλ‹€λ©΄ μ•Œλ €μ£Όμ‹œλ©΄ κ°μ‚¬ν•˜κ² μŠ΅λ‹ˆλ‹€! πŸ™‡

μ—΄μ‹¬νžˆ ν•΄λ³΄κ² μŠ΅λ‹ˆλ‹€! 잘 λΆ€νƒλ“œλ¦½λ‹ˆλ‹€~!

- 높이, λ„ˆλΉ„, 지뒰 갯수λ₯Ό μž…λ ₯λ°›λŠ”λ‹€
- 지뒰찾기 νŒμ„ λ§Œλ“€μ–΄ κ²Œμž„μ„ μƒμ„±ν•œλ‹€
- μž…λ ₯ κ²°κ³Όλ₯Ό 좜λ ₯ν•œλ‹€
- 객체지ν–₯ μƒν™œ 체쑰 원칙을 지킨닀
- ν™•μž₯성을 κ³ λ €ν•˜μ—¬ κ°œλ°œν•œλ‹€
Copy link

@laco-dev laco-dev left a comment

Choose a reason for hiding this comment

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

μ•ˆλ…•ν•˜μ„Έμš”. 지뒰찾기 λ―Έμ…˜λ™μ•ˆ 잘 λΆ€νƒλ“œλ¦½λ‹ˆλ‹€. πŸ™‡πŸ»

κ·Έλ™μ•ˆ ν•΄μ˜¨ λ―Έμ…˜λ“€μ—μ„œ ν•™μŠ΅ν•œ κ°œλ…λ“€μ΄ μ§€λ’°μ°ΎκΈ°μ—μ„œλ„ μ΄μ–΄μ„œ μ μš©λ˜μ•Ό ν•©λ‹ˆλ‹€.
랜덀 ν…ŒμŠ€νŠΈ, 좔상화 λ“± λ°°μ› λ˜ 것듀을 κΈ°μ–΅ν•˜λ©΄μ„œ λ‹€μ‹œ κ³ λ―Ό ν•΄ 보면 쒋을 λ§Œν•œ λ‚΄μš©λ“€μ„ λ‚¨κ²ΌμŠ΅λ‹ˆλ‹€.

Comment on lines +24 to +33
fun plantingMine(countOfMine: Int) {
var mineCount = 0

while (mineCount < countOfMine) {
val row = rows.getPosition()
val col = cols.getPosition()

mineCount = plantingResult(row, col, mineCount)
}
}

Choose a reason for hiding this comment

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

일반적으둜 μƒκ°ν–ˆμ„ λ•Œ, getPosition() μ΄λΌλŠ” ν•¨μˆ˜κ°€ 무엇을 λ°˜ν™˜ν•  것이라고 μ˜ˆμΈ‘ν• κΉŒμš”?
κ³Όμ—° λ¬΄μž‘μœ„ 값을 λ°˜ν™˜ν•  κ²ƒμœΌλ‘œ κΈ°λŒ€ν•  수 μžˆμ„κΉŒμš”?

μ €λŠ” κ·Έ 이전에 ν–‰, μ—΄ μ΄λΌλŠ” κ°’ 객체가 Position ? μ΄λΌλŠ” μœ„μΉ˜λΌλŠ” 것이 무엇을 μ˜λ―Έν•˜λŠ” 것인지 λΆ€ν„° 이해가 잘 λ˜μ§€ μ•Šμ„ 것 κ°™μ•„μš”.

μ–΄λ– ν•œ x, y μ’Œν‘œμ— 지뒰λ₯Ό μ‹¬λŠ”λ‹€λŠ” μ—­ν• λ‘œ λ§Œλ“€μ–΄ λ³΄λŠ”κ±΄ μ–΄λ–¨κΉŒμš”?

// position μœ„μΉ˜μ— 지뒰λ₯Ό μ‹¬λŠ”λ‹€.
fun mine(position: Position) { ... }

Comment on lines +35 to +41
private fun plantingResult(row: Int, col: Int, mineCount: Int): Int {
if (minefield[row][col] is Island) {
minefield[row][col] = Mine()
return mineCount + 1
}
return mineCount
}

Choose a reason for hiding this comment

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

μ΄μ–΄μ„œ, 지뒰λ₯Ό μ‹¬λŠ”λ‹€λŠ” λ™μž‘μ΄ ν˜„μž¬λŠ” λ¬΄μž‘μœ„ 값에 의쑴이 λ˜μ–΄ μžˆμ–΄μš”.
κ·Έλ™μ•ˆ λ―Έμ…˜μ—μ„œ ν•΄μ™”λ˜ 것 처럼 λ¬΄μž‘μœ„ 값은 ν…ŒμŠ€νŠΈλ₯Ό 맀우 νž˜λ“€κ²Œ ν•˜κ³  객체가 자율적으둜 λ™μž‘μ„ μˆ˜ν–‰ν•˜λŠ” 것을 μ‹ λ’°ν•  수 없도둝 λ§Œλ“­λ‹ˆλ‹€.

μ•žμ„œ μœ„μΉ˜λΌλŠ” κ°œλ…μ„ μ‚¬μš©ν•΄λ³Έλ‹€λ©΄, μ•„λž˜μ™€ 같은 μˆœμ„œλ₯Ό μ°Έκ³  ν•΄ λ³΄μ‹œλ©΄ 도움이 될 것 κ°™μŠ΅λ‹ˆλ‹€.

1. 5 x 5 크기의 λ³΄λ“œλ₯Ό μ€€λΉ„ν•œλ‹€ // Minefield
2. μ§€λ’°μ˜ μœ„μΉ˜λ₯Ό νŒλ‹¨ν•œλ‹€. // MineSweeperGame
3. μ§€λ’°μ˜ μœ„μΉ˜λŠ” 랜덀으둜 받을 μˆ˜λ„ 있고, λͺ…μ‹œμ μœΌλ‘œ 받을 μˆ˜λ„ μžˆλ‹€ (interface)
4. 주어진 μ§€λ’°μ˜ μœ„μΉ˜λ§ŒνΌ 지뒰λ₯Ό μ‹¬λŠ”λ‹€. ( ??? )

Comment on lines +3 to +5
interface Opening {
val value: String
}

Choose a reason for hiding this comment

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

cell의 경우 κ°€λŠ₯ν•œ μΌ€μ΄μŠ€κ°€ 빈칸 λ˜λŠ” 지뒰 둜 λ˜μ–΄μžˆλ‹€ λ³΄λ‹ˆ μΈν„°νŽ˜μ΄μŠ€(Opening)λ₯Ό μ‚¬μš©ν•˜μ—¬ μœ μ—°ν•˜κ²Œ ꡬ성

빈칸, λ˜λŠ” μ§€λ’°λΌλŠ” μ˜λ―Έκ°€ Opening μ΄λΌλŠ” νƒ€μž…μœΌλ‘œ 잘 이루어져 μžˆμ„κΉŒμš”?
Opening μ΄λΌλŠ” 것은 μ–΄λ– ν•œ μƒνƒœ? 처럼 λŠκ»΄μ§€μ§€ μ•Šμ„κΉŒμš”?
isOpening() ...

μ§€λ’°μ°ΎκΈ°μ˜ κΈ°λ³Έ κ²Œμž„ κ΅¬μ„±μœΌλ‘œλŠ” λ³΄λ“œ νŒμ—λŠ” N개의 μ…€(Cell)이 μ‘΄μž¬ν•œλ‹€ 을 ν‘œν˜„ν•˜κ³ λŠ” ν•©λ‹ˆλ‹€.
κ·Έλ ‡λ‹€λ©΄ 이λ₯Ό λŒ€μž…ν•΄ 봀을 λ•Œ λ³΄λ“œ νŒμ—λŠ” N개의 Opening이 μ‘΄μž¬ν•œλ‹€ 둜 비ꡐ ν•΄ 보싀 수 μžˆμŠ΅λ‹ˆλ‹€.

@@ -0,0 +1,3 @@
package minesweeper.model.cell

data class Mine(override val value: String = "*") : Opening

Choose a reason for hiding this comment

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

"*" 을 좜λ ₯ν•˜λŠ” 것은 UI의 관심사 이지 μ•Šμ„κΉŒμš”?
κ°€λ Ή 지뒰λ₯Ό 별이 μ•„λ‹Œ κ·Έλž˜ν”½ λͺ¨μ–‘μ˜ μ§€λ’°λ‘œ 좜λ ₯ν•œλ‹€κ³  ν•˜λ©΄, 도메인 λͺ¨λΈμ˜ valueλŠ” μ•„λ¬΄λŸ° 역할을 ν•˜μ§€ λͺ»ν•˜κ²Œ λ κ±°μ—μš”.

plantingMines()
}

fun minefield(): Array<Array<Opening>> = minefield.minefield

Choose a reason for hiding this comment

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

μΌκΈ‰μ»¬λ ‰μ…˜ μ‚¬μš©μ‹œ view μ˜μ—­μ— 데이터λ₯Ό κ°€μ Έμ˜¬ λ•Œ
fun minefield(): Array<Array> = minefield.minefield 와 같이 ν•œ 번 더 κΊΌλ‚΄κ²Œ λ˜λŠ”λ°,
ν˜Ήμ‹œ 객체지ν–₯적으둜 더 쒋은 방법이 μžˆλ‹€λ©΄ μ•Œλ €μ£Όμ‹œλ©΄ κ°μ‚¬ν•˜κ² μŠ΅λ‹ˆλ‹€! πŸ™‡

κ²°κ³Ό(λͺ¨λ“  셀을 좜λ ₯)μ—λ§Œ μ§‘μ€‘ν•˜λŠ” λŒ€μ‹  ν•„μš”ν•œ κΈ°λŠ₯을 μž‘κ²Œ μ ‘κ·Ό ν•΄ λ³Ό 수둝 μ’‹μŠ΅λ‹ˆλ‹€.
κ°€λ Ή ν–‰κ³Ό μ—΄μ˜ 크기λ₯Ό μ•Œκ³  μžˆμ„ λ•Œ μš°λ¦¬κ°€ μ›ν•˜λŠ” 것은, "ν•΄λ‹Ή μœ„μΉ˜μ— μžˆλŠ” 셀을 μ•Œλ €μ€˜" μž…λ‹ˆλ‹€.

fun getCellByPosition(position: Position): Cell { ... }

val position = Position(x, y)
val cell: Cell = getCellByPosition(position)

class Minefield(
private val rows: Rows,
private val cols: Cols,
val minefield: Array<Array<Opening>>

Choose a reason for hiding this comment

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

Array<Array<Opening>> νƒ€μž…μ΄λΌλ©΄, μ–΄λ– ν•œ μœ„μΉ˜μ˜ 셀에 μ ‘κ·Όν•˜κΈ° μœ„ν•΄ λ‹€μ†Œ λΆˆν•„μš”ν•œ μˆœνšŒκ°€ 많이 ν•„μš”ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

νŠΉμ • μœ„μΉ˜λ₯Ό 보닀 효율적으둜 μ ‘κ·Όν•˜κΈ° μœ„ν•œ 자료ꡬ쑰λ₯Ό κ³ λ € ν•΄ λ³Ό 수 μžˆμ§€ μ•Šμ„κΉŒμš”?

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