-
Notifications
You must be signed in to change notification settings - Fork 0
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
Dazzle 블랙잭 2단계 #14
base: woo-chang
Are you sure you want to change the base?
Dazzle 블랙잭 2단계 #14
Changes from all commits
095f92f
72d2d7f
30252f1
b9fc77d
705379f
004c830
fcf4974
1da866c
c4712a7
e3e8f60
0d7034c
9e2ae57
7681194
38dcf8c
fd50b64
be602fd
3b0c9d4
4fd9dea
2ed62c4
1b51f1b
de2820a
69bff94
0fe6fd4
9a5d76b
a2e97f6
bafa2c4
ff230c0
db5dc6e
388fd96
5aea768
3d15375
cbe0e83
e7d6079
f29d7b3
20bf718
34cb8ef
ecc6b2c
ece6266
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,16 @@ | ||
package blackjack; | ||
|
||
import blackjack.controller.BlackJackController; | ||
import blackjack.view.InputView; | ||
import blackjack.view.OutputView; | ||
|
||
public class BlackJackApplication { | ||
|
||
public static void main(String[] args) { | ||
final InputView inputView = new InputView(); | ||
final OutputView outputView = new OutputView(); | ||
|
||
final BlackJackController blackJackController = new BlackJackController(inputView, outputView); | ||
blackJackController.run(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package blackjack.controller; | ||
|
||
import blackjack.controller.dto.DealerStateResponse; | ||
import blackjack.controller.dto.ParticipantResponse; | ||
import blackjack.controller.dto.ParticipantResultResponse; | ||
import blackjack.domain.BlackJackGame; | ||
import blackjack.domain.betting.Betting; | ||
import blackjack.domain.betting.BettingTable; | ||
import blackjack.domain.participant.Dealer; | ||
import blackjack.domain.participant.Participants; | ||
import blackjack.domain.participant.Player; | ||
import blackjack.domain.participant.PlayerName; | ||
import blackjack.view.InputView; | ||
import blackjack.view.OutputView; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class BlackJackController { | ||
|
||
private final InputView inputView; | ||
private final OutputView outputView; | ||
|
||
public BlackJackController(final InputView inputView, final OutputView outputView) { | ||
this.inputView = inputView; | ||
this.outputView = outputView; | ||
} | ||
|
||
public void run() { | ||
final BlackJackGame blackJackGame = createBlackJackGame(); | ||
initialGame(blackJackGame); | ||
|
||
drawCardsForPlayers(blackJackGame); | ||
drawCardForDealer(blackJackGame); | ||
|
||
printResult(blackJackGame); | ||
} | ||
|
||
private BlackJackGame createBlackJackGame() { | ||
final Participants participants = new Participants(new Dealer(), gatherPlayers()); | ||
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. Participants 생성자에 dealer와 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. 근데 제가 못 찾은 것일수도 있는데 Participants안의 validate에서 예외를 던져주는데 해당 예외들에 대한 핸들링이 이루어지지 않고 있는것 같네요..?! 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. 이번 미션에서는 예외가 발생했을 때 올바르지 않은 상황으로 판단하여 예외 처리를 하지 않았습니다 :) |
||
final BettingTable bettingTable = createBettingTable(participants.getPlayerNames()); | ||
return new BlackJackGame(participants, bettingTable); | ||
} | ||
|
||
private List<Player> gatherPlayers() { | ||
return inputView.readPlayerNames() | ||
.stream() | ||
.map(Player::new) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private BettingTable createBettingTable(final List<PlayerName> playerNames) { | ||
final Map<PlayerName, Betting> bettingTable = new HashMap<>(); | ||
playerNames.forEach( | ||
playerName -> bettingTable.put(playerName, new Betting(inputView.readBetting(playerName.getValue())))); | ||
return new BettingTable(bettingTable); | ||
} | ||
|
||
private void initialGame(final BlackJackGame blackJackGame) { | ||
blackJackGame.initialDraw(); | ||
final ParticipantResponse dealer = ParticipantResponse.ofDealerWithHidden(blackJackGame); | ||
final List<ParticipantResponse> players = ParticipantResponse.listOfPlayer(blackJackGame); | ||
outputView.printDealCards(dealer, players, blackJackGame.getInitialDrawCount()); | ||
} | ||
|
||
private void drawCardsForPlayers(final BlackJackGame blackJackGame) { | ||
final List<PlayerName> playerNames = blackJackGame.getPlayerNames(); | ||
playerNames.forEach(playerName -> drawCard(playerName, blackJackGame)); | ||
} | ||
|
||
private void drawCard(final PlayerName playerName, final BlackJackGame blackJackGame) { | ||
while (blackJackGame.isDrawablePlayer(playerName) && inputView.readMoreDraw(playerName.getValue())) { | ||
blackJackGame.dealCardForPlayer(playerName); | ||
outputView.printCardsWithoutScore(ParticipantResponse.ofPlayer(playerName, blackJackGame)); | ||
} | ||
} | ||
|
||
public void drawCardForDealer(final BlackJackGame blackJackGame) { | ||
blackJackGame.dealCardForDealer(); | ||
outputView.printDealerDrawn( | ||
DealerStateResponse.of( | ||
blackJackGame.isDealerAdditionalDrawn(), | ||
blackJackGame.getDealerAdditionalDrawScore() | ||
) | ||
); | ||
} | ||
|
||
private void printResult(final BlackJackGame blackJackGame) { | ||
final ParticipantResponse dealer = ParticipantResponse.ofDealer(blackJackGame); | ||
final List<ParticipantResponse> players = ParticipantResponse.listOfPlayer(blackJackGame); | ||
outputView.printCardsWithScore(dealer, players); | ||
outputView.printFinalResult(ParticipantResultResponse.listOfParticipants(blackJackGame)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package blackjack.controller.dto; | ||
|
||
import blackjack.domain.card.Card; | ||
import blackjack.domain.card.Hand; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class CardsResponse { | ||
|
||
private final int score; | ||
private final List<String> cardInfos; | ||
|
||
private CardsResponse(final int score, final List<String> cardInfos) { | ||
this.score = score; | ||
this.cardInfos = cardInfos; | ||
} | ||
|
||
public static CardsResponse of(final int score, final Hand hand) { | ||
return new CardsResponse(score, createCardInfos(hand.getCards())); | ||
} | ||
|
||
private static List<String> createCardInfos(final List<Card> cards) { | ||
return cards.stream() | ||
.map(card -> card.getNumberName() + card.getSuitName()) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public int getScore() { | ||
return score; | ||
} | ||
|
||
public List<String> createCardInfos() { | ||
return cardInfos; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package blackjack.controller.dto; | ||
|
||
public class DealerStateResponse { | ||
|
||
private final boolean isDrawn; | ||
private final int limit; | ||
|
||
private DealerStateResponse(final boolean isDrawn, final int limit) { | ||
this.isDrawn = isDrawn; | ||
this.limit = limit; | ||
} | ||
|
||
public static DealerStateResponse of(final boolean isDrawn, final int limit) { | ||
return new DealerStateResponse(isDrawn, limit); | ||
} | ||
|
||
public boolean isDrawn() { | ||
return isDrawn; | ||
} | ||
|
||
public int getLimit() { | ||
return limit; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package blackjack.controller.dto; | ||
|
||
import blackjack.domain.BlackJackGame; | ||
import blackjack.domain.card.Hand; | ||
import blackjack.domain.participant.PlayerName; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ParticipantResponse { | ||
|
||
private static final int HIDDEN_SCORE = -1; | ||
|
||
private final String name; | ||
private final CardsResponse cardsResponse; | ||
|
||
private ParticipantResponse(final String name, final CardsResponse cardsResponse) { | ||
this.name = name; | ||
this.cardsResponse = cardsResponse; | ||
} | ||
|
||
public static ParticipantResponse ofPlayer(final PlayerName playerName, final BlackJackGame blackJackGame) { | ||
final int score = blackJackGame.getPlayerScore(playerName); | ||
final Hand hand = blackJackGame.getPlayerHand(playerName); | ||
return new ParticipantResponse(playerName.getValue(), CardsResponse.of(score, hand)); | ||
} | ||
|
||
public static ParticipantResponse ofDealer(final BlackJackGame blackJackGame) { | ||
final int score = blackJackGame.getDealerScore(); | ||
final Hand hand = blackJackGame.getDealerHand(); | ||
return new ParticipantResponse(blackJackGame.getDealerName(), CardsResponse.of(score, hand)); | ||
} | ||
|
||
public static ParticipantResponse ofDealerWithHidden(final BlackJackGame blackJackGame) { | ||
final Hand hand = blackJackGame.getDealerHiddenHand(); | ||
return new ParticipantResponse(blackJackGame.getDealerName(), CardsResponse.of(HIDDEN_SCORE, hand)); | ||
} | ||
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. dto에 정적팩토리메소드 여러개둔거 인상깊네요!! 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 static List<ParticipantResponse> listOfPlayer(final BlackJackGame blackJackGame) { | ||
final List<ParticipantResponse> players = new ArrayList<>(); | ||
final List<PlayerName> playerNames = blackJackGame.getPlayerNames(); | ||
|
||
playerNames.forEach(playerName -> players.add(ParticipantResponse.ofPlayer(playerName, blackJackGame))); | ||
return players; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public CardsResponse getCardsResponse() { | ||
return cardsResponse; | ||
} | ||
} |
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.
추상화 기준이 깔끔해서 구조를 이해하기 쉬웠어 👍
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.
허브 의견에 동의 합니다 굿굿