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

Step2- 블랙잭 #491

Open
wants to merge 19 commits into
base: oliveunji
Choose a base branch
from
Open

Step2- 블랙잭 #491

wants to merge 19 commits into from

Conversation

oliveunji
Copy link

안녕하세요 리뷰어님! 블랙잭 코드 업데이트 합니다.
Application.kt 파일의 크키가 큰데 어떻게 리팩토링 해야할 지 몰라서 조언부탁드립니다.
(BlackJack.kt파일에 Application의 일부 로직을 추가하려고 했으나, 그럴경우 InputViewResultView의 의존성 때문에 고민이 됩니다.)
감사합니다!

Copy link

@sah3122 sah3122 left a comment

Choose a reason for hiding this comment

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

블랙잭 미션 구현 잘해주셨네요 👍
몇가지 고민거리를 남겨두었는데 확인 부탁드리며 질문이 있다면 편하게 DM 주세요 🙏

import blackjack.view.InputView
import blackjack.view.ResultView

fun main() {
Copy link

Choose a reason for hiding this comment

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

main 함수의 크기가 커진것에 대해 코멘트 남겨주셨네요 😄
개인적으론 BlackJack 클래스를 더 활용하는것을 권장드립니다.
BlackJack 클래스가 블랙잭 게임을 진행할수 있도록 역할을 정의하고, Input / Output View 와의 결합을 제거 하는 방법으론 입 / 출력을 위한 값객체를 정의하여 전달하는것을 도전해보세요 😄

Comment on lines +14 to +17
var players = mutableListOf<Player>()
for (name in names) {
players.add(Player(name))
}
Copy link

Choose a reason for hiding this comment

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

플레이어를 모아두는 클래스를 정의해보는건 어떨까요 ?

Comment on lines +20 to +23
players.forEach {
it.addCards(cards.takeCards(2))
ResultView.printUserCardList(it)
}
Copy link

Choose a reason for hiding this comment

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

플레이어가 카드를 뽑는다.라는 모델링을 만족 시켜보세요 😄
이번 과정을 통해 자연스러운 모델링이 될수 있도록 노력해보세요 !

ResultView.printUserCardList(it)
}

players.forEach { player ->
Copy link

Choose a reason for hiding this comment

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

마찬가지로 해당 로직도 플레이어를 모아둔 클래스로 옮겨보세요 👍
이번 미션을 진행하며 forEach 와 같이 클래스 내부 상태값을 꺼내어 비즈니스로직을 실행하는 코드는 모두 상태값을 가진 클래스 내부로 옮겨보세요 !

Comment on lines +27 to +29
if (checkBurst(player)) {
break
}
Copy link

Choose a reason for hiding this comment

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

Burst 라는 상태는 플레이어가 가진 카드의 합이 21을 초과한 상태 입니다.
외부에서 검사하기 보단 카드를 들고있는 플레이어 클래스가 제공하는건 어떨까요 ?

package blackjack.domain

enum class CardSymbol(val cardNumber: Int, val score: Int) {
ACE(1, 11),
Copy link

Choose a reason for hiding this comment

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

ACE 카드는 1 또는 11의 점수를 나타낼수 있습니다 !
해당 요구사항을 만족해보세요 😄

Comment on lines +4 to +5
private val cards: MutableList<Card> = mutableListOf()

Copy link

Choose a reason for hiding this comment

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

kotlin의 backing property에 대해 학습해보는것도 좋을것 같습니다 😄
https://kotlinlang.org/docs/coding-conventions.html#names-for-backing-properties

Comment on lines +20 to +23
cards.shuffle()
val takenCards = cards.take(count)
cards.removeAll(takenCards)
return takenCards
Copy link

Choose a reason for hiding this comment

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

카드를 매번 섞지않고 생성하는 시점에 섞는건 어떨까요 ?

package blackjack.domain

class Player(private val name: String, cards: List<Card> = emptyList()) {
private val _cards: MutableList<Card> = cards.toMutableList()
Copy link

Choose a reason for hiding this comment

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

플레이어가 뽑은 카드는 블랙잭 게임에서 중요한 도메인이 될수 있다고 생각합니다.
새로운 클래스로 정의해보는건 어떨까요 ?

players.add(Player(name))
}

ResultView.printDistributionPlan(players, 2)
Copy link

Choose a reason for hiding this comment

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

매직넘버는 의미를 가지는 상수로 정의하여 가독성을 높여보세요 😄
https://www.slipp.net/questions/356

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