-
Notifications
You must be signed in to change notification settings - Fork 550
[๐ ์ฌ์ดํด2 - ๋ฏธ์ (๋ธ๋์ญ ๊ฒ์ ์คํ)] ์๋ด ๋ฏธ์ ์ ์ถํฉ๋๋ค. #1111
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: realtake
Are you sure you want to change the base?
Changes from all commits
40f9388
7038a8f
9f743a8
b6b2ac6
5445549
51bda21
36cc427
9c4d316
9c90fdd
2d76139
7c456f2
0dffe2e
4232f37
919643b
16dd07a
61e37fa
c4ac74a
f3ecebf
de5db9e
36eda30
966d2a8
08ee405
c1601e1
55f8cda
5bcf8f8
34f1527
2589ab0
e907205
95e3e59
33dbf99
7c155aa
afc7369
8462cd9
68c8912
cd972c9
d6500d3
a72b9f3
881c109
37fc6b8
2ed59cc
ccbf2e7
9fda00a
69f2bc2
f9e30ff
29c2b02
49b176b
62e43c5
445c95e
34c8f47
1a4fcf3
b5f2d3c
9cee12a
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,12 +1,12 @@ | ||
| package team.blackjack; | ||
|
|
||
| import team.blackjack.config.AppConfig; | ||
| import team.blackjack.controler.BlackJackController; | ||
| import team.blackjack.control.BlackJackController; | ||
|
|
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| AppConfig appConfig = AppConfig.getInstance(); | ||
| BlackJackController blackJackController = appConfig.blackJackController(); | ||
| blackJackController.run(); | ||
| BlackJackController controller = appConfig.blackJackController(); | ||
| controller.run(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,20 @@ | ||
| package team.blackjack.config; | ||
|
|
||
| import team.blackjack.controler.BlackJackController; | ||
| import team.blackjack.control.BlackJackController; | ||
| import team.blackjack.service.BlackJackService; | ||
|
|
||
| public class AppConfig { | ||
| private static volatile AppConfig instance; | ||
| private static final AppConfig instance = new AppConfig(); | ||
| private final BlackJackService blackJackService = new BlackJackService(); | ||
| private final BlackJackController blackJackController = new BlackJackController(blackJackService); | ||
|
|
||
| private AppConfig() { | ||
| } | ||
| private AppConfig() {} | ||
|
|
||
| public static AppConfig getInstance() { | ||
| if (instance == null) { | ||
| synchronized (AppConfig.class) { | ||
| if (instance == null) { | ||
| instance = new AppConfig(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return instance; | ||
| } | ||
|
|
||
| public BlackJackService blackJackService() { | ||
| return new BlackJackService(); | ||
| } | ||
|
|
||
| public BlackJackController blackJackController() { | ||
| return new BlackJackController(blackJackService()); | ||
| return blackJackController; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| package team.blackjack.control; | ||
|
|
||
| import java.util.List; | ||
| import team.blackjack.service.dto.DrawResult; | ||
| import team.blackjack.service.dto.RevenueResult; | ||
| import team.blackjack.service.dto.ScoreResult; | ||
| import team.blackjack.service.BlackJackService; | ||
| import team.blackjack.view.InputView; | ||
| import team.blackjack.view.OutputView; | ||
|
|
||
| public class BlackJackController { | ||
| private final BlackJackService blackJackService; | ||
|
|
||
| public BlackJackController(BlackJackService blackJackService) { | ||
| this.blackJackService = blackJackService; | ||
| } | ||
|
|
||
| public void run() { | ||
| List<String> playerNames = readPlayerNames(); | ||
| blackJackService.initGame(playerNames); | ||
| blackJackService.drawInitialCards(); | ||
|
|
||
| readAllPlayerBattingMoneyRetry(blackJackService.getAllPlayerNames()); | ||
|
|
||
| DrawResult drawResult = blackJackService.getDrawResult(); | ||
| OutputView.printDrawResult(drawResult); | ||
|
|
||
| readPlayerHitDecision(blackJackService.getAllPlayerNames()); | ||
|
|
||
| while (blackJackService.shouldDealerHit()) { | ||
| OutputView.printDealerHitMessage(); | ||
| blackJackService.hitDealer(); | ||
| } | ||
|
|
||
| ScoreResult scoreResult = blackJackService.calculateAllParticipantScore(); | ||
| OutputView.printParticipantScoreResult(scoreResult); | ||
|
|
||
| RevenueResult revenueResult = blackJackService.getRevenueResult(); | ||
| OutputView.printRevenueResult(revenueResult); | ||
| } | ||
|
|
||
| public void readAllPlayerBattingMoneyRetry(List<String> playerNames) { | ||
| playerNames.forEach(playerName -> { | ||
| int battingMoney = readPlayerBattingMoneyRetry(playerName); | ||
| blackJackService.batMoney(playerName, battingMoney); | ||
| }); | ||
| } | ||
|
|
||
| private int readPlayerBattingMoneyRetry(String playerName) { | ||
| int battingMoney; | ||
|
|
||
| do { | ||
| battingMoney = readPlayerBattingMoney(playerName); | ||
| } while (battingMoney <= 0); | ||
|
|
||
| return battingMoney; | ||
| } | ||
|
|
||
| private int readPlayerBattingMoney(String playerName) { | ||
| int battingMoney = -1; | ||
| OutputView.printAskBettingMoney(playerName); | ||
| try { | ||
| battingMoney = InputView.readPlayerBattingMoney(); | ||
| } catch (NumberFormatException e) { | ||
| OutputView.printWrongDecisionInputMessage(); | ||
| } | ||
|
|
||
| return battingMoney; | ||
| } | ||
|
|
||
| private List<String> readPlayerNames(){ | ||
| OutputView.printPlayerNameRequest(); | ||
| List<String> playerNames = InputView.readPlayerNames(); | ||
|
|
||
| while (hasDuplicatedName(playerNames)) { | ||
| OutputView.printDuplicatedNameMessage(); | ||
| OutputView.printPlayerNameRequest(); | ||
| playerNames = InputView.readPlayerNames(); | ||
| } | ||
| return playerNames; | ||
| } | ||
|
|
||
| private boolean hasDuplicatedName(List<String> playerNames) { | ||
| return playerNames.size() != playerNames.stream().distinct().count(); | ||
|
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 void readPlayerHitDecision(List<String> playerNames) { | ||
| playerNames.forEach(this::processPlayerHit); | ||
| } | ||
|
|
||
| private void processPlayerHit(String playerName) { | ||
| while (readPlayerHitDecision(playerName)) { | ||
| blackJackService.hitPlayer(playerName); | ||
| OutputView.printPlayerCards(playerName, blackJackService.findPlayerCardNamesByName(playerName)); | ||
| } | ||
| } | ||
|
|
||
| private boolean readPlayerHitDecision(String playerName) { | ||
| final boolean isPlayerBust = blackJackService.isPlayerBust(playerName); | ||
|
|
||
| if (isPlayerBust) { | ||
| OutputView.printBustMessage(); | ||
| return false; | ||
| } | ||
|
|
||
| OutputView.printAskDrawCard(playerName); | ||
| String hitYn = InputView.readHitDecision(); | ||
|
|
||
| while (!"y".equalsIgnoreCase(hitYn) && !"n".equalsIgnoreCase(hitYn)) { | ||
|
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. "y","n"์ด ๋ฐ๋ณต๋๋ ์์๋ก ๊ด๋ฆฌํ๋๊ฑด ์ด๋ ์ค๊น์? |
||
| OutputView.printWrongDecisionInputMessage(); | ||
| hitYn = InputView.readHitDecision(); | ||
| } | ||
|
|
||
| return "y".equalsIgnoreCase(hitYn); | ||
| } | ||
| } | ||
This file was deleted.
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.
์๋ด์ด ์๊ฐํ์๊ธฐ์ blackJackController์ blackJackService์ ๊ฐ๊ฐ ์ญํ ์ด ๋ฌด์์ผ๊น์?
ํ์ฌ๋ ๋ก์ง์ด Controller์ ๋ ๋ง์ ๊ฒ ๊ฐ์๋ฐ ์ด๋ป๊ฒ ์๊ฐํ์ค๊น์?