-
Notifications
You must be signed in to change notification settings - Fork 0
늦어서 죄송합니다 박스터 입니다 #15
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: main
Are you sure you want to change the base?
Changes from all commits
1258521
3e207f0
7c771a0
3e398eb
47c9b2e
15a6617
6247163
0c8b90e
5c4dcab
52ef885
a1491d3
5d78e14
ee3b48b
d923b0b
d4d08a8
380de2e
ebf4816
4d62340
ae75ab7
039cfc5
6243221
c69b6b3
e1e25c3
7b053be
e3f91e3
5629a10
2224ee6
a277ee8
54c89db
c6e78a8
c02da94
ec5e66a
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 |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package blackjack; | ||
|
|
||
| import blackjack.controller.BlackjackController; | ||
| import blackjack.view.InputView; | ||
| import blackjack.view.OutputView; | ||
|
|
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| BlackjackController blackjackController = new BlackjackController(new InputView(), new OutputView()); | ||
| blackjackController.run(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package blackjack.constants; | ||
|
|
||
| public enum ErrorCode { | ||
| DUPLICATE_NAME, | ||
| RESERVED_NAME, | ||
| NOT_EXIST_MESSAGE, | ||
| BLANK_NAME, | ||
| EMPTY_CARD, | ||
| INVALID_COMMAND, | ||
| INVALID_MONEY_UNIT, | ||
| INVALID_MONEY_BOUND, | ||
| INVALID_SCORE, | ||
| ; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| package blackjack.controller; | ||
|
|
||
| import blackjack.controller.exception.InvalidCommandException; | ||
| import blackjack.domain.card.exception.NoMoreCardException; | ||
| import blackjack.domain.exception.CustomException; | ||
| import blackjack.domain.game.BettingMoney; | ||
| import blackjack.domain.game.BettingResult; | ||
| import blackjack.domain.game.BlackjackGame; | ||
| import blackjack.domain.game.exception.InvalidMoneyValueException; | ||
| import blackjack.domain.user.Dealer; | ||
| import blackjack.domain.user.Participants; | ||
| import blackjack.domain.user.Player; | ||
| import blackjack.view.InputView; | ||
| import blackjack.view.OutputView; | ||
| import java.util.List; | ||
|
|
||
| public class BlackjackController { | ||
| private final InputView inputView; | ||
| private final OutputView outputView; | ||
|
|
||
| public BlackjackController(InputView inputView, OutputView outputView) { | ||
| this.inputView = inputView; | ||
| this.outputView = outputView; | ||
| } | ||
|
|
||
| public void run() { | ||
| BlackjackGame blackjackGame = createBlackjackGame(); | ||
| start(blackjackGame); | ||
| printResult(blackjackGame); | ||
| } | ||
|
|
||
| private BlackjackGame createBlackjackGame() { | ||
| Participants participants = createParticipants(); | ||
| return new BlackjackGame(participants); | ||
| } | ||
|
Comment on lines
+32
to
+35
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(List<String> playerNames) 같은 형태는 어떤가요?
Member
Author
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 start(BlackjackGame blackjackGame) { | ||
| try { | ||
| Participants participants = blackjackGame.getParticipants(); | ||
| bet(participants.getPlayers(), blackjackGame); | ||
| dealOutInitCards(blackjackGame, participants); | ||
| play(participants, blackjackGame); | ||
| outputView.printCardResult(participants); | ||
| } catch (NoMoreCardException e) { | ||
| outputView.printError(e.getErrorCode()); | ||
| } | ||
| } | ||
|
|
||
| private void bet(List<Player> players, BlackjackGame blackjackGame) { | ||
| for (Player player : players) { | ||
| BettingMoney money = createBettingMoney(player); | ||
| blackjackGame.bet(player, money); | ||
| } | ||
| } | ||
|
|
||
| private BettingMoney createBettingMoney(Player player) { | ||
| try { | ||
| int money = inputView.readBettingMoney(player); | ||
| return new BettingMoney(money); | ||
| } catch (InvalidMoneyValueException e) { | ||
| outputView.printError(e.getErrorCode()); | ||
| return createBettingMoney(player); | ||
| } | ||
| } | ||
|
|
||
| private void dealOutInitCards(BlackjackGame blackjackGame, Participants participants) { | ||
| blackjackGame.dealOutCard(); | ||
| outputView.printInitCards(participants); | ||
| } | ||
|
|
||
| private void printResult(BlackjackGame blackjackGame) { | ||
| BettingResult result = blackjackGame.getBettingResult(); | ||
| outputView.printBettingResult(result); | ||
| } | ||
|
|
||
| private Participants createParticipants() { | ||
| try { | ||
| List<String> names = inputView.readNames(); | ||
| return Participants.from(names); | ||
| } catch (CustomException e) { | ||
| outputView.printError(e.getErrorCode()); | ||
| return createParticipants(); | ||
| } | ||
| } | ||
|
Comment on lines
+76
to
+84
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. 재귀보다는 while 어떤가요?
Member
Author
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 play(Participants participants, BlackjackGame blackjackGame) { | ||
| for (Player player : participants.getPlayers()) { | ||
| playPerPlayer(player, blackjackGame); | ||
| } | ||
| Dealer dealer = participants.getDealer(); | ||
| playDealer(dealer, blackjackGame); | ||
| } | ||
|
|
||
| private void playPerPlayer(Player player, BlackjackGame blackjackGame) { | ||
| GameCommand command = GameCommand.PLAY; | ||
| while (player.isDrawable() && command.isPlay()) { | ||
| command = getGameCommand(player); | ||
| giveCard(player, blackjackGame, command); | ||
| outputView.printPlayerCards(player); | ||
| } | ||
| } | ||
|
|
||
| private GameCommand getGameCommand(Player player) { | ||
| try { | ||
| String inputCommand = inputView.readIsContinue(player.getName()); | ||
| return GameCommand.from(inputCommand); | ||
| } catch (InvalidCommandException e) { | ||
| outputView.printError(e.getErrorCode()); | ||
| return getGameCommand(player); | ||
| } | ||
| } | ||
|
|
||
| private void giveCard(Player player, BlackjackGame blackjackGame, GameCommand command) { | ||
| if (command.isPlay()) { | ||
| blackjackGame.drawCard(player); | ||
| } | ||
| } | ||
|
|
||
| private void playDealer(Dealer dealer, BlackjackGame blackjackGame) { | ||
| while (dealer.isDrawable()) { | ||
| outputView.printDealerState(); | ||
| blackjackGame.drawCard(dealer); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package blackjack.controller; | ||
|
|
||
| import blackjack.constants.ErrorCode; | ||
| import blackjack.controller.exception.InvalidCommandException; | ||
|
|
||
| public enum GameCommand { | ||
| PLAY("y"), | ||
| STOP("n"); | ||
|
|
||
| private final String command; | ||
|
|
||
| GameCommand(String command) { | ||
| this.command = command; | ||
| } | ||
|
|
||
| public static GameCommand from(String command) { | ||
| if (PLAY.command.equalsIgnoreCase(command)) { | ||
| return PLAY; | ||
| } | ||
| if (STOP.command.equalsIgnoreCase(command)) { | ||
|
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. equalsIgnoreCase 좋은데요? |
||
| return STOP; | ||
| } | ||
| throw new InvalidCommandException(ErrorCode.INVALID_COMMAND); | ||
| } | ||
|
|
||
| public boolean isPlay() { | ||
| return this == PLAY; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package blackjack.controller.exception; | ||
|
|
||
| import blackjack.constants.ErrorCode; | ||
| import blackjack.domain.exception.CustomException; | ||
|
|
||
| public class InvalidCommandException extends CustomException { | ||
|
|
||
| public InvalidCommandException(ErrorCode errorCode) { | ||
| super(errorCode); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package blackjack.domain.card; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
|
|
||
| public class Card { | ||
|
|
||
| private static final List<Card> CACHE = new ArrayList<>(); | ||
|
|
||
| static { | ||
| for (CardSuit suit : CardSuit.values()) { | ||
| generateCard(suit); | ||
| } | ||
| } | ||
|
|
||
| private final CardSuit cardSuit; | ||
| private final CardNumber cardNumber; | ||
|
|
||
| public Card(CardSuit cardSuit, CardNumber cardNumber) { | ||
| this.cardSuit = cardSuit; | ||
| this.cardNumber = cardNumber; | ||
| } | ||
|
Comment on lines
+20
to
+23
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. new 로 생성할 수 있는데, 캐싱을 하는 의미가 없어보여요
Member
Author
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. 죄송합니다
Collaborator
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. ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ
Collaborator
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. 생성자 막아놓고 정적 팩터리로 이미 만들어놓은거 반환해주면 될라나요? 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. 그죠 그러면 되죠 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 static void generateCard(CardSuit suit) { | ||
| for (CardNumber number : CardNumber.values()) { | ||
| CACHE.add(new Card(suit, number)); | ||
| } | ||
| } | ||
|
|
||
| public static List<Card> values() { | ||
| return List.copyOf(CACHE); | ||
| } | ||
|
|
||
| public boolean isAce() { | ||
| return this.cardNumber.isAce(); | ||
|
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. this를 붙이는 기준이 있을까요? 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. 페어탓 해명하세요 |
||
| } | ||
|
|
||
| public int getValue() { | ||
| return cardNumber.getValue(); | ||
| } | ||
|
|
||
| public CardSuit getSuit() { | ||
| return cardSuit; | ||
| } | ||
|
|
||
| public CardNumber getNumber() { | ||
| return cardNumber; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| Card card = (Card) o; | ||
| return cardSuit == card.cardSuit && cardNumber == card.cardNumber; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(cardSuit, cardNumber); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,35 @@ | ||||||||||||
| package blackjack.domain.card; | ||||||||||||
|
|
||||||||||||
| import blackjack.constants.ErrorCode; | ||||||||||||
| import blackjack.domain.card.exception.NoMoreCardException; | ||||||||||||
| import java.util.ArrayList; | ||||||||||||
| import java.util.Collections; | ||||||||||||
| import java.util.List; | ||||||||||||
|
|
||||||||||||
| public class CardDeck { | ||||||||||||
| private final List<Card> cards; | ||||||||||||
|
Comment on lines
+9
to
+10
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. 전체적으로 한번 통일을 주면 좋을 것 같습니다~ 클래스 선언 다음에 개행을 준다. vs 안준다
Suggested change
|
||||||||||||
|
|
||||||||||||
| public CardDeck() { | ||||||||||||
| this.cards = new ArrayList<>(Card.values()); | ||||||||||||
| shuffleCards(); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| public CardDeck(List<Card> cards) { | ||||||||||||
| this.cards = cards; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| private void shuffleCards() { | ||||||||||||
| Collections.shuffle(this.cards); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| public Card pick() { | ||||||||||||
| if (cards.isEmpty()) { | ||||||||||||
| throw new NoMoreCardException(ErrorCode.EMPTY_CARD); | ||||||||||||
| } | ||||||||||||
| return cards.remove(0); | ||||||||||||
|
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. remove(0)을 수행하면 내부적으로 배열을 앞으로 당기는 행위가 일어납니다. |
||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| public List<Card> getCards() { | ||||||||||||
| return List.copyOf(cards); | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
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.
너무 간결해서 좋은데요?