-
Notifications
You must be signed in to change notification settings - Fork 313
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
Step3 블랙잭(딜러) #785
base: duhanmo
Are you sure you want to change the base?
Step3 블랙잭(딜러) #785
Changes from all commits
f301a6c
6658a35
fd73ec1
dee9976
97d81cd
ed857a0
2c50b72
37b72e7
f6331c9
a95919b
6f38f2b
7cff569
823396e
c041297
bca0a30
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 |
---|---|---|
@@ -1,10 +1,7 @@ | ||
package blackjack | ||
|
||
import blackjack.controller.BlackJackGame | ||
import blackjack.domain.GameTable | ||
import blackjack.view.InputView | ||
import blackjack.view.ResultView | ||
import blackjack.controller.BlackjackGame | ||
|
||
fun main() { | ||
BlackJackGame(GameTable, InputView, ResultView).start() | ||
BlackjackGame.start() | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package blackjack.controller | ||
|
||
import blackjack.domain.card.Deck | ||
import blackjack.domain.player.Dealer | ||
import blackjack.domain.player.Player | ||
import blackjack.view.InputView | ||
import blackjack.view.ResultView | ||
|
||
object BlackjackGame { | ||
fun start() { | ||
val gameTable = setUp() | ||
initDeal(gameTable) | ||
turnStart(gameTable) | ||
ResultView.printAfterTurn(gameTable) | ||
} | ||
|
||
private fun setUp(): GameTable { | ||
val gameTable = GameTable(Deck(), Dealer(), getPlayers()) | ||
ResultView.linebreak() | ||
return gameTable | ||
} | ||
|
||
private fun getPlayers(): List<Player> = InputView.inputNames().map { Player(it) } | ||
|
||
private fun initDeal(gameTable: GameTable) { | ||
gameTable.dealInitCard() | ||
ResultView.printDealInitCard(gameTable) | ||
} | ||
|
||
private fun turnStart(gameTable: GameTable) { | ||
gameTable.playersTurn() | ||
ResultView.linebreak() | ||
gameTable.dealerTurn() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package blackjack.controller | ||
|
||
import blackjack.domain.card.Deck | ||
import blackjack.domain.game.GameResult | ||
import blackjack.domain.player.Dealer | ||
import blackjack.domain.player.Player | ||
import blackjack.view.InputView | ||
import blackjack.view.ResultView | ||
Comment on lines
+7
to
+8
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. BlackjackGame , GameTable은 어떤 책임이 있을까요? 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. GameTable에서 게임을 진행하며 (turn) 카드상태를 출력해줘야 하는 요구사항을 만족시키느라 View에 대한 의존성이 들어가게되었는데요, 혹시 생각나시는 방법이 있으시다면 조언 부탁드려도 될까요 남재님!?🙇♂️ |
||
|
||
class GameTable( | ||
val deck: Deck, | ||
val dealer: Dealer, | ||
val players: List<Player>, | ||
) { | ||
fun dealInitCard() = | ||
repeat(INIT_CARD_DRAW_COUNT) { | ||
dealer.hit(deck.draw()) | ||
players.forEach { it.hit(deck.draw()) } | ||
} | ||
|
||
fun playersTurn() = players.forEach { playerTurn(it) } | ||
|
||
fun dealerTurn() { | ||
if (!dealer.canHit()) { | ||
return | ||
} | ||
ResultView.printDealerHit() | ||
dealer.hit(deck.draw()) | ||
dealerTurn() | ||
} | ||
|
||
fun getGameResult(): GameResult = GameResult.from(dealer, players) | ||
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. get으로 접근하기보다 함수의 결과값으로 전달해보면 어떨까요? 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. 넵! 해당방법으로 수정하도록 할게요 🙂 |
||
|
||
private fun playerTurn(player: Player) { | ||
if (!player.canHit() || !InputView.inputHit(player)) { | ||
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. InputView에 대한 의존성을 어떻게 끊을수 있을까요? 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. 제가 제일 어렵게 느껴지는 부분인데🥲 |
||
return | ||
} | ||
player.hit(deck.draw()) | ||
ResultView.printPlayerCard(player) | ||
playerTurn(player) | ||
} | ||
|
||
companion object { | ||
const val INIT_CARD_DRAW_COUNT = 2 | ||
} | ||
} |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package blackjack.domain.card | ||
|
||
import blackjack.domain.card.Rank.ACE | ||
|
||
data class Card( | ||
val rank: Rank, | ||
val suit: Suit, | ||
) { | ||
val score: Int | ||
get() = rank.score | ||
|
||
val isAce: Boolean | ||
get() = rank == ACE | ||
|
||
companion object { | ||
val ALL: List<Card> = | ||
Suit.entries.flatMap { suit -> Rank.entries.map { rank -> Card(rank, suit) } } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package blackjack.domain.card | ||
|
||
class Deck(private val cards: MutableList<Card> = Card.ALL.shuffled().toMutableList()) { | ||
fun draw(): Card { | ||
check(cards.isNotEmpty()) { "카드가 모두 소진되었습니다" } | ||
return cards.removeFirst() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package blackjack.domain.card | ||
|
||
enum class Rank(val value: String, val score: Int) { | ||
ACE("A", 11), | ||
TWO("2", 2), | ||
THREE("3", 3), | ||
FOUR("4", 4), | ||
FIVE("5", 5), | ||
SIX("6", 6), | ||
SEVEN("7", 7), | ||
EIGHT("8", 8), | ||
NINE("9", 9), | ||
TEN("10", 10), | ||
JACK("J", 10), | ||
QUEEN("Q", 10), | ||
KING("K", 10), | ||
; | ||
|
||
companion object { | ||
fun from(value: String): Rank = | ||
entries.firstOrNull { it.value == value } | ||
?: throw IllegalArgumentException("유효하지 않은 랭크 값입니다: $value") | ||
} | ||
} |
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.
BlackjackGame은 Controller역할을 하고 있어요,
하지만 BlackjackGame이 너무 비대하진 않을까요?
너무 많은 로직이 있는거 같아요
책임을 분리해보아요!
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.
네! 말씀대로 GameTable을 service로직처럼 상위패키지(controller)로 추출하여 로직을 분담하도록했어요🙂