-
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
[Step4] 4단계 - 블랙잭(베팅) #697
base: bong6981
Are you sure you want to change the base?
Changes from all commits
ed22ad5
ea2d901
d095226
b1ebc8a
158af44
c8eca31
3d30c05
5181cef
fc1d9ae
a4db3db
780067a
d95162a
00f52f0
8bbefe0
f96543d
ebae7ee
c66f8bf
02e8ce0
25c8735
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,11 +1,14 @@ | ||
package blackjack.controller | ||
|
||
import blackjack.domain.Action | ||
import blackjack.domain.batting.BetAmount | ||
import blackjack.domain.player.Player | ||
import blackjack.domain.player.PlayerNames | ||
|
||
interface InputProcessor { | ||
fun playerNames(): PlayerNames | ||
|
||
fun playerBet(player: Player): BetAmount | ||
|
||
fun playerAction(player: Player): Action | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
package blackjack.controller | ||
|
||
import blackjack.domain.result.Result | ||
import blackjack.domain.result.distribution.DealEndResult | ||
import blackjack.domain.result.distribution.DealInitialCardResult | ||
import blackjack.domain.result.distribution.DealToDealerResult | ||
import blackjack.domain.result.distribution.DealToPlayerResult | ||
import blackjack.domain.result.game.GameResult | ||
import blackjack.domain.result.game.GameEndResult | ||
|
||
class ResultProcessor { | ||
fun handle(result: Result) { | ||
when (result) { | ||
is DealInitialCardResult -> ViewResultProcessor.drawInitialDistribution(result) | ||
is DealToPlayerResult -> { | ||
if (result.isSystemStand) return | ||
ViewResultProcessor.drawPlayerState(result) | ||
} | ||
is DealToPlayerResult -> ViewResultProcessor.drawPlayerState(result) | ||
is DealEndResult -> {} | ||
is DealToDealerResult -> ViewResultProcessor.drawDealerState(result) | ||
is GameResult -> ViewResultProcessor.drawGameResult(result) | ||
is GameEndResult -> ViewResultProcessor.drawGameResult(result) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package blackjack.domain | ||
|
||
import blackjack.domain.player.CardPlayer | ||
import blackjack.domain.player.Player | ||
import blackjack.domain.result.game.VictoryStatus | ||
|
||
object BlackJackJudge { | ||
private const val BLACK_JACK_CARD_COUNT = 2 | ||
private const val BLACK_JACK_SCORE = 21 | ||
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. 21이라는 비즈니스 상수값이 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. 제가 도메인에 대한 지식이 부족해서 발생한 코드 같습니다
|
||
|
||
fun judgeVictory(player: Player, dealer: Dealer): VictoryStatus = | ||
when { | ||
player.isBust() -> VictoryStatus.LOSS | ||
dealer.isBust() || player.score > dealer.score -> VictoryStatus.WIN | ||
player.score == dealer.score -> VictoryStatus.PUSH | ||
else -> VictoryStatus.LOSS | ||
} | ||
|
||
fun isBlackJack(player: Player): Boolean = | ||
(player isSameCardCount BLACK_JACK_CARD_COUNT) && (player isSameScore BLACK_JACK_SCORE) | ||
|
||
private fun CardPlayer.isBust() = score.value > BLACK_JACK_SCORE | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package blackjack.domain.batting | ||
|
||
import java.math.BigDecimal | ||
|
||
data class Amount( | ||
val value: BigDecimal, | ||
) { | ||
|
||
init { | ||
require(value >= BigDecimal.ZERO) { "금액은 0이상이어야 합니다" } | ||
} | ||
|
||
operator fun plus(other: Amount): Amount = Amount(value.plus(other.value)) | ||
operator fun times(count: Int): Amount = Amount(value.times(count.toBigDecimal())) | ||
|
||
operator fun times(count: BigDecimal): Amount = | ||
Amount(value * count) | ||
operator fun compareTo(other: Amount): Int = | ||
this.value.compareTo(other.value) | ||
|
||
companion object { | ||
val ZERO = Amount(BigDecimal.ZERO) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package blackjack.domain.batting | ||
|
||
import java.math.BigDecimal | ||
|
||
@JvmInline | ||
value class BetAmount( | ||
val value: Amount, | ||
) { | ||
init { | ||
require(value > Amount.ZERO) { "베팅 금액은 0보다 커야 합니다" } | ||
} | ||
|
||
constructor(amount: BigDecimal) : this(Amount(amount)) | ||
} |
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.
문서화 👍