-
Notifications
You must be signed in to change notification settings - Fork 550
[๐ ์ฌ์ดํด2 - ๋ฏธ์ (๋ธ๋์ญ ๋ฒ ํ )] ๋งฅ์ค ๋ฏธ์ ์ ์ถํฉ๋๋ค. #1130
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
base: simhokyung
Are you sure you want to change the base?
Changes from all commits
d32da74
ce21f2c
75962f0
d7a1d18
f70f371
88ff16f
ee164cf
4865776
a9f6fb3
3af8be8
b8311b7
f1fa65a
6b70e46
c7411c4
fc1a151
9ca1e73
9e59c62
442c944
df03b79
fe60635
c26fded
896b284
75c7e6f
26c5b86
71ab035
1cdc20b
9ab3080
f7b44e2
e95ef28
a83d96c
a46f68e
d694cd6
3272e76
52506d2
0786e8f
c1cb694
c399b48
b75dd97
091289a
48e7f1b
9bb0cfd
ea79a35
33c2910
14baaeb
53119fc
0337cad
054b8a8
efcb0f1
adcd3bc
7e15fc9
e0175ca
5c25a3c
6707507
96ec568
1134e84
db4570d
06d9e2a
dca898f
e77d81f
c4d6107
5ccee00
c7d3de8
d127436
b83635b
7875c22
a08777d
e649ed8
5d50dc6
a0f1c13
35c13aa
238769e
a88c4c6
f743aa8
ac97136
6d80700
edae525
ade6ff6
91f0740
545e9ed
85c4481
e34f9d1
34cc79d
7b050bb
dca12aa
0910024
c7fb9c0
fa93618
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,34 +1,69 @@ | ||
| package controller; | ||
|
|
||
| import domain.BlackjackGame; | ||
| import domain.Dealer; | ||
| import domain.GameResultCalculator; | ||
| import domain.Player; | ||
| import domain.Players; | ||
| import domain.TotalFinalResult; | ||
| import dto.DealerFinalResultDto; | ||
| import domain.participant.BettingMoney; | ||
| import domain.participant.Dealer; | ||
| import domain.participant.Name; | ||
| import domain.participant.Player; | ||
| import domain.participant.PlayerCreationInfo; | ||
| import domain.participant.Players; | ||
| import domain.ProfitCalculator; | ||
| import dto.PlayerDto; | ||
| import dto.PlayersDto; | ||
| import dto.ResultDto; | ||
| import dto.TotalFinalResultsDto; | ||
| import view.InputView; | ||
| import view.OutputView; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class GameController { | ||
|
|
||
| public void run() { | ||
| BlackjackGame blackjackGame = BlackjackGame.start(InputView.readParticipants()); | ||
| BlackjackGame blackjackGame = startGame(); | ||
| printInitialStatus(blackjackGame); | ||
| playGame(blackjackGame); | ||
| printGameResult(blackjackGame); | ||
| } | ||
|
|
||
| private BlackjackGame startGame() { | ||
| List<String> names = InputView.readParticipants(); | ||
| List<PlayerCreationInfo> playerCreationInfos = createPlayerCreationInfos(names); | ||
| return BlackjackGame.start(playerCreationInfos); | ||
| } | ||
|
|
||
| private void printInitialStatus(BlackjackGame blackjackGame) { | ||
| Dealer dealer = blackjackGame.getDealer(); | ||
| Players players = blackjackGame.getPlayers(); | ||
|
|
||
| PlayersDto playersDto = PlayersDto.from(players); | ||
|
|
||
| OutputView.printHandOutMessage(playersDto); | ||
| OutputView.printCardStatus(playersDto, ResultDto.fromDealerInitial(dealer)); | ||
| } | ||
|
|
||
| private void playGame(BlackjackGame blackjackGame) { | ||
| Players players = blackjackGame.getPlayers(); | ||
| addPlayersCard(blackjackGame, players); | ||
| addDealerCards(blackjackGame); | ||
| printCardResults(ResultDto.from(dealer), PlayersDto.from(players)); | ||
| printFinalResults(players, dealer); | ||
| } | ||
|
|
||
| private void printGameResult(BlackjackGame blackjackGame) { | ||
| Dealer dealer = blackjackGame.getDealer(); | ||
| Players players = blackjackGame.getPlayers(); | ||
| PlayersDto afterPlayersDto = PlayersDto.from(players); | ||
|
|
||
| printCardResults(ResultDto.from(dealer), afterPlayersDto); | ||
| printProfitResults(players, dealer); | ||
| } | ||
|
|
||
| private List<PlayerCreationInfo> createPlayerCreationInfos(List<String> names) { | ||
| List<PlayerCreationInfo> playerCreationInfos = new ArrayList<>(); | ||
| for (String name : names) { | ||
| Integer money = InputView.readBettingMoney(name); | ||
| System.out.println(); | ||
|
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. System.out.println()์ด ์ปจํธ๋กค๋ฌ์ ์ง์ ์๋ค์. |
||
| playerCreationInfos.add(PlayerCreationInfo.of(Name.from(name), BettingMoney.of(money))); | ||
| } | ||
| return playerCreationInfos; | ||
| } | ||
|
|
||
| private void addPlayersCard(BlackjackGame blackjackGame, Players players) { | ||
|
|
@@ -51,15 +86,23 @@ private void addDealerCards(BlackjackGame blackjackGame) { | |
| } | ||
| } | ||
|
|
||
| private void printCardResults(ResultDto resultDto, PlayersDto playersDto) { | ||
| OutputView.printCardResult(resultDto, playersDto); | ||
| private void printCardResults(ResultDto resultDto, PlayersDto afterPlayersDto) { | ||
| OutputView.printCardResult(resultDto, afterPlayersDto); | ||
| } | ||
|
|
||
| private void printFinalResults(Players players, Dealer dealer) { | ||
| TotalFinalResult totalFinalResult = GameResultCalculator.checkGameResult(players, dealer); | ||
| DealerFinalResultDto dealerFinalResultDto = DealerFinalResultDto.from(totalFinalResult); | ||
| TotalFinalResultsDto totalFinalResultsDto = TotalFinalResultsDto.from(totalFinalResult); | ||
| private void printProfitResults(Players players, Dealer dealer) { | ||
| String dealerProfit = ProfitCalculator.formatProfit( | ||
| ProfitCalculator.calculateDealerProfit(players, dealer) | ||
| ); | ||
|
|
||
| List<String> playerProfitResults = players.getPlayers().stream() | ||
| .map(player -> String.format("%s: %s%n", | ||
| player.getNameValue(), | ||
| ProfitCalculator.formatProfit( | ||
| ProfitCalculator.calculatePlayerProfit(player, dealer) | ||
| ))) | ||
| .toList(); | ||
|
Comment on lines
+98
to
+104
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. ์ปจํธ๋กค๋ฌ์์ String.format์ผ๋ก ์ง์ ํฌ๋งทํ
ํ๊ณ ์์ด์. |
||
|
|
||
| OutputView.printTotalResult(dealerFinalResultDto, totalFinalResultsDto); | ||
| OutputView.printTotalProfit(dealerProfit, playerProfitResults); | ||
| } | ||
| } | ||
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,51 @@ | ||
| package domain; | ||
|
|
||
| import domain.participant.Dealer; | ||
| import domain.participant.Player; | ||
| import domain.participant.Players; | ||
|
|
||
| public class ProfitCalculator { | ||
| private static final double BLACKJACK_PROFIT_RATE = 1.5; | ||
|
|
||
| public static double calculatePlayerProfit(Player player, Dealer dealer) { | ||
|
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.
|
||
| int bettingMoney = player.getBettingMoneyValue(); | ||
|
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. ์์๊ฐ์ ์ง์ ๋
ธ์ถํ๊ณ ์๋ค์. |
||
| int playerScore = player.getScoreValue(); | ||
| int dealerScore = dealer.getScoreValue(); | ||
|
|
||
| if (player.isBlackjack() && dealer.isBlackjack()) { | ||
| return 0; | ||
| } | ||
| if (player.isBlackjack()) { | ||
| return bettingMoney * BLACKJACK_PROFIT_RATE; | ||
| } | ||
| if (dealer.isBlackjack()) { | ||
| return -bettingMoney; | ||
| } | ||
| if (player.isBust()) { | ||
| return -bettingMoney; | ||
| } | ||
| if (dealer.isBust()) { | ||
| return bettingMoney; | ||
| } | ||
| if (playerScore > dealerScore) { | ||
| return bettingMoney; | ||
| } | ||
| if (playerScore < dealerScore) { | ||
| return -bettingMoney; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| public static double calculateDealerProfit(Players players, Dealer dealer) { | ||
| return -players.getPlayers().stream() | ||
| .mapToDouble(player -> calculatePlayerProfit(player, dealer)) | ||
| .sum(); | ||
| } | ||
|
|
||
| public static String formatProfit(double profit) { | ||
| if (profit == (long) profit) { | ||
| return String.valueOf((long) profit); | ||
| } | ||
| return String.valueOf(profit); | ||
| } | ||
| } | ||
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.start() ๊ตฌ์กฐ๋ฅผ ์ ์งํ๊ธฐ ์ํด ์์ฑ ์ ๋ณด ๊ฐ์ฒด๋ฅผ ์ถ๊ฐํ ์ ํ์ด ์ ์ ํ๊ฐ?
์ปจํธ๋กค๋ฌ๊ฐ PlayerCreationInfo๋ฅผ ์ง์ ๋ง๋๋ ๊ฒ ์์ฒด๋ ์์ฑ์ ๊ด์ฌํ๋ ํ์ ์๋๊น์?
์๋ ** ์ฝ๋ฉํธ๋ ํจ๊ป ํ์ธํด๋ณด์ธ์.
Hand์ ์ฑ ์ ๋ถ๋ฆฌ
์ ๋ต์ด ์๋ค๊ธฐ๋ณด๋ค๋ ํธ๋ ์ด๋์คํ์ ๋ฌธ์ ์์.
์ฌ์ฉํ๋ ์ชฝ์์ Hand.getScore()๋ก ์ฐ๋ ๊ฑด ๋์ผํ์ง๋ง,
Score๊ฐ isBust() ๊ฐ์ ํ์๋ฅผ ๊ฐ์ง๋ค๋ฉด ๋๊ฐ ์์ฑ ์ฑ ์์ ๊ฐ๋์ง๊ฐ ์๋ฏธ ์์ด์ ธ์.
ํ์ฌ ๊ตฌ์กฐ์์ Hand๊ฐ new Score(...)๋ฅผ ์ง์ ํธ์ถํ๊ณ ์์ผ๋,
ScoreCalculator์ ์์ํ๋ค๊ณ ํด๋ ์์ฑ ์ฑ ์์ Hand์ ๋จ์์๋ ์ ์ด์์.
๊ฒฐ๊ตญ ๋๊ฐ ์์ฑ ์ฑ ์์ ๊ฐ๋์ง์ ์ฐจ์ด์์.