forked from woowacourse/java-blackjack
-
Notifications
You must be signed in to change notification settings - Fork 0
[1단계 - 블랙잭 게임 실행] 망쵸(김주환) 미션 제출합니다. #2
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
Open
3Juhwan
wants to merge
56
commits into
woowacourse-6th-code-review-study:main
Choose a base branch
from
3Juhwan:step1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
6a4844d
docs: 기능 요구 사항 작성
3Juhwan 34f668e
feat: 플레이어에게 카드를 분배하는 기능 구현
3Juhwan 8163280
feat: 각 플레이어에게 2장씩 카드를 분배하는 기능 구현
3Juhwan 4d55c54
feat: 가진 패의 합계를 구하는 기능 구현
3Juhwan b180f62
feat: 플레이어가 죽었는지 여부를 반환하는 기능 구현
3Juhwan 5135ec3
feat: 카드 덱에서 무작위 카드를 뽑는 기능 구현
3Juhwan 49b5168
feat: 딜러와 단일 플레이어의 승패를 판단하는 기능 구현
3Juhwan 280ef53
feat: 딜러와 여러 플레이어의 승패를 판단하는 기능 구현
3Juhwan 14abcca
refactor: 플레이어에 픽스처 적용
3Juhwan 987e856
refactor: Dealer 클래스 분리 및 픽스쳐 수정
3Juhwan 12bbf04
refactor: 픽스쳐 내 중복 제거
3Juhwan 240e408
docs: 게임 승패 결정 로직 작성
3Juhwan 933b422
feat: 승패 판단 기능 구현
3Juhwan b42c767
chore: 불필요한 클래스 삭제
3Juhwan dc3387f
docs: 뷰에 대한 기능 요구사항 추가
3Juhwan 043a26f
feat: 딜러의 승패 횟수 계산 기능 구현
3Juhwan 2ad912d
feat: InputView 구현
3Juhwan f252caa
feat: Player 이름 길이를 검증하는 기능 구현
3Juhwan cdb2713
feat: 딜러와 플레이어 전원에게 초기에 분배한 카드 출력하는 기능 구현
3Juhwan 710ec42
feat: 플레이어가 보유한 모든 카드를 출력하는 기능 구현
3Juhwan 972dee8
feat: 딜러가 추가 카드를 발급 받았는지 여부 출력하는 기능 구현
3Juhwan 4371415
feat: 보유한 모든 카드의 합을 출력하는 기능 구현
3Juhwan 8bb8fd2
feat: 최종 승패를 출력하는 기능 구현
3Juhwan 35de854
feat: controller에서 사용자에게 처음 카드 2장씩 부여하는 기능 구현
3Juhwan 2b06dd1
fix: 플레이어 카드를 출력하는 구문 수정
3Juhwan 0f5681d
feat: Controller 전체 기능 구현
3Juhwan 5d02370
refactor: 딜러, 플레이어 생성자에 매개변수 최소화
3Juhwan 6e32df2
refactor: 딜러 클래스의 메서드명 수정
3Juhwan 4940a10
refactor: 도메인 용어로 변경 (draw -> hit)
3Juhwan cbe46ac
refactor: 패키지 분리
3Juhwan 0972560
refactor: view, controller 리팩터링
3Juhwan ac428c6
refactor: 도메인 로직 리팩터링
3Juhwan 8ba77c3
feat: 에이스 관련 처리 기능 추가
3Juhwan c29212d
docs: 구현한 사항 체크
3Juhwan c5555e5
chore: 잘못된 변수명 수정
3Juhwan a0e2241
fix: 카드 계산 로직 변경으로 테스트 결과 수정
3Juhwan c62821a
refactor: Deck 리팩터링
3Juhwan 78e94fd
test: Deck에 52장의 카드가 있는지 검증하는 테스트
3Juhwan d1907c8
refactor: Hand 클래스 수정
3Juhwan e23c9f5
test: Hand 클래스 테스트
3Juhwan 944578d
refactor: 접근 제어자 수정
3Juhwan c30e9e4
test: DealerTest 추가
3Juhwan 6de9287
refactor: 메서드 분리
3Juhwan a4df5f4
refactor: Judge의 역할을 Dealer로 옮김
3Juhwan 1b1d5a0
refactor: 게임 로직 설정 정보 이동
3Juhwan c205252
refactor: 출력 메시지를 Outview로 위임
3Juhwan 731dea0
refactor: CardGameResult를 record로 변경
3Juhwan adb40af
refactor: OutputView에서 메시지를 생성하는 로직을 MessageResolver로 분리
3Juhwan 1b67385
style: 불필요한 공백 제거
3Juhwan 6770804
refactor: 덱 생성 로직에 스트림 적용
3Juhwan f682149
refactor: 불필요한 위임 메서드 삭제
3Juhwan 0279a2e
test: 게임 결과에서 플레이어가 순서대로 반환되는지 테스트
3Juhwan e983f17
refactor: CardGame의 역할을 Deck으로 이동
3Juhwan c2aafef
refactor: 승패 결과에 대한 결과 문자열을 뷰로 이동
3Juhwan 07d47c6
refactor: BUST 조건에 대한 다른 클래스의 의존성 제거
3Juhwan 3670388
refactor: 게임 결과를 생성하는 로직을 CardGameResult로 이동
3Juhwan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,67 @@ | ||
| # java-blackjack | ||
| # 블랙잭 | ||
|
|
||
| 블랙잭 미션 저장소 | ||
|
|
||
| ## 우아한테크코스 코드리뷰 | ||
| ## 기능 요구 사항 | ||
|
|
||
| - [온라인 코드 리뷰 과정](https://github.com/woowacourse/woowacourse-docs/blob/master/maincourse/README.md) | ||
| ### 플레이어 이름 | ||
|
|
||
| ### 플레이어 | ||
|
|
||
| - [X] 플레이어는 이름을 갖는다 | ||
| - [X] 플레이어는 카드들을 갖는다 | ||
| - [X] 플레이어는 카드를 저장한다 | ||
| - [X] 죽었는지 안 죽었는지 여부를 반환한다 (21을 초과하는지) | ||
|
|
||
|
|
||
| ### 카드 | ||
|
|
||
| - [X] 문자와 모양을 상태로 갖는다 | ||
|
|
||
|
|
||
| ### Hand(카드들) | ||
|
|
||
| - [X] 여러개의 카드를 갖는다 | ||
| - [X] 카드의 총합 계산한다 | ||
| - [X] 카드 추가한다 | ||
|
|
||
|
|
||
| ### 카드 게임 | ||
|
|
||
| - [X] 각 플레이어에게 카드를 2장씩 지급한다 | ||
| - [X] 플레이어마다 추가 지급한다 | ||
|
|
||
|
|
||
| ### 덱 | ||
|
|
||
| - [X] 모든 카드를 1장씩 갖고 있다. | ||
| - [X] 랜덤으로 카드를 뽑는다. | ||
|
|
||
|
|
||
| ### 게임 승패 결정 | ||
|
|
||
| - [X] 딜러와 모든 플레이어의 승패 여부를 결정한다. | ||
| - [X] 딜러와 플레이어 둘다 21을 초과할 경우, 플레이어가 패배한다. | ||
| - [X] 카드 합계가 딜러는 21 이하, 플레이어는 21 초과인 경우, 플레이어가 패배한다. | ||
| - [X] 카드 합계가 딜러는 21 초과, 플레이어는 21 이하인 경우, 플레이어가 승리한다. | ||
| - [X] 카드 합계가 딜러와 플레이어 모두 21 이하인 경우, 숫자가 큰 사람이 승리한다. | ||
| - [X] 카드 합계가 딜러와 플레이어 모두 21 이하이고 동일한 경우, 무승부다. | ||
|
|
||
|
|
||
| ### 인풋 뷰 | ||
|
|
||
| - [X] 참가자의 이름을 입력받는다. | ||
| - [X] 이름은 쉼표 기준으로 분리한다. | ||
| - [X] 카드 추가 여부를 입력받는다. | ||
| - [X] y 또는 n이 아닌 경우, 예외를 발생한다. | ||
| - [X] 사용자 카드 합이 21을 초과하면, 카드 추가 여부를 묻지 않는다. | ||
| - [X] 플레이어가 n을 입력할 때까지 카드 추가 여부를 묻는다. | ||
|
|
||
|
|
||
| ### 아웃풋 뷰 | ||
|
|
||
| - [X] 딜러와 플레이어 전원에게 초기에 분배한 카드 출력한다. | ||
| - [X] 딜러의 카드는 1장만 공개한다. | ||
| - [X] 플레이어가 보유한 모든 카드를 출력한다. | ||
| - [X] 딜러가 추가 카드를 발급 받았는지 여부 출력한다. | ||
| - [X] 보유한 모든 카드의 합을 출력한다. | ||
| - [X] 최종 승패를 출력한다. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package blackjack; | ||
|
|
||
| import blackjack.view.InputView; | ||
| import blackjack.view.MessageResolver; | ||
| import blackjack.view.OutputView; | ||
|
|
||
| public class BlackjackApplication { | ||
| public static void main(String[] args) { | ||
| final InputView inputView = new InputView(); | ||
| final OutputView outputView = new OutputView(new MessageResolver()); | ||
|
|
||
| final BlackjackController blackjackController = new BlackjackController(inputView, outputView); | ||
| blackjackController.run(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| package blackjack; | ||
|
|
||
| import blackjack.domain.cardgame.CardDeck; | ||
| import blackjack.domain.cardgame.CardGameResult; | ||
| import blackjack.domain.player.Dealer; | ||
| import blackjack.domain.player.Player; | ||
| import blackjack.view.InputView; | ||
| import blackjack.view.OutputView; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class BlackjackController { | ||
| private final InputView inputView; | ||
| private final OutputView outputView; | ||
|
|
||
| BlackjackController(final InputView inputView, final OutputView outputView) { | ||
| this.inputView = inputView; | ||
| this.outputView = outputView; | ||
| } | ||
|
|
||
| public void run() { | ||
| final List<String> names = inputView.askPlayerNames(); | ||
| final Dealer dealer = new Dealer(); | ||
| final List<Player> players = names.stream().map(Player::new).toList(); | ||
| final CardDeck deck = CardDeck.createShuffledDeck(); | ||
|
|
||
| initializeHand(deck, dealer, players); | ||
| outputView.printInitialHandOfEachPlayer(dealer, players); | ||
|
|
||
| for (final Player player : players) { | ||
| givePlayerMoreCardsIfWanted(deck, player); | ||
| } | ||
| giveDealerMoreCardsIfNeeded(deck, dealer); | ||
|
|
||
| printHandStatusOfEachPlayer(dealer, players); | ||
| printCardGameResult(dealer, players); | ||
| } | ||
|
|
||
| private void initializeHand(final CardDeck deck, final Dealer dealer, final List<Player> players) { | ||
| deck.giveInitialCards(dealer); | ||
| for (final Player player : players) { | ||
| deck.giveInitialCards(player); | ||
| } | ||
| } | ||
|
|
||
| private void givePlayerMoreCardsIfWanted(final CardDeck deck, final Player player) { | ||
| final String playerName = player.getName(); | ||
| while (player.isAlive() && inputView.askForMoreCard(playerName)) { | ||
| deck.giveCard(player); | ||
| outputView.printPlayerCard(player); | ||
| } | ||
| } | ||
|
|
||
| private void giveDealerMoreCardsIfNeeded(final CardDeck deck, final Dealer dealer) { | ||
| while (dealer.isMoreCardNeeded()) { | ||
| deck.giveCard(dealer); | ||
| outputView.printDealerHitMessage(dealer); | ||
| } | ||
| } | ||
|
|
||
| private void printHandStatusOfEachPlayer(final Dealer dealer, final List<Player> players) { | ||
| outputView.printPlayerCardWithScore(dealer); | ||
| for (final Player player : players) { | ||
| outputView.printPlayerCardWithScore(player); | ||
| } | ||
| } | ||
|
|
||
| private void printCardGameResult(final Dealer dealer, final List<Player> players) { | ||
| outputView.printResult(CardGameResult.of(dealer, players)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package blackjack.domain.card; | ||
|
|
||
| public class Card { | ||
| private final CardNumber cardNumber; | ||
| private final CardShape cardShape; | ||
|
|
||
| public Card(final CardNumber cardNumber, final CardShape cardShape) { | ||
| this.cardNumber = cardNumber; | ||
| this.cardShape = cardShape; | ||
| } | ||
|
|
||
| public boolean isAceCard() { | ||
| return cardNumber == CardNumber.ACE; | ||
| } | ||
|
|
||
| public int getScore() { | ||
| return cardNumber.getValue(); | ||
| } | ||
|
|
||
| public CardNumber getNumber() { | ||
| return cardNumber; | ||
| } | ||
|
|
||
| public CardShape getShape() { | ||
| return cardShape; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package blackjack.domain.card; | ||
|
|
||
| public enum CardNumber { | ||
| ACE(1), | ||
| TWO(2), | ||
| THREE(3), | ||
| FOUR(4), | ||
| FIVE(5), | ||
| SIX(6), | ||
| SEVEN(7), | ||
| EIGHT(8), | ||
| NINE(9), | ||
| TEN(10), | ||
| JACK(10), | ||
| QUEEN(10), | ||
| KING(10); | ||
|
|
||
| private final int value; | ||
|
|
||
| CardNumber(final int value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| int getValue() { | ||
| return value; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package blackjack.domain.card; | ||
|
|
||
| public enum CardShape { | ||
| SPADE, | ||
| HEART, | ||
| DIAMOND, | ||
| CLOVER | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package blackjack.domain.cardgame; | ||
|
|
||
| import blackjack.domain.card.Card; | ||
| import blackjack.domain.card.CardNumber; | ||
| import blackjack.domain.card.CardShape; | ||
| import blackjack.domain.player.Player; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.Deque; | ||
| import java.util.LinkedList; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
|
|
||
| public class CardDeck { | ||
| private static final int INITIAL_CARD_NUMBER = 2; | ||
|
|
||
| private final Deque<Card> deck; | ||
|
|
||
| private CardDeck(Deque<Card> deck) { | ||
| this.deck = deck; | ||
| } | ||
|
|
||
| public static CardDeck createShuffledDeck() { | ||
| final List<Card> allKindOfCards = Arrays.stream(CardShape.values()) | ||
| .flatMap(CardDeck::createEachNumber) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| Collections.shuffle(allKindOfCards); | ||
|
|
||
| return new CardDeck(new LinkedList<>(allKindOfCards)); | ||
| } | ||
|
|
||
| private static Stream<Card> createEachNumber(final CardShape cardShape) { | ||
| return Arrays.stream(CardNumber.values()) | ||
| .map(cardNumber -> new Card(cardNumber, cardShape)); | ||
| } | ||
|
|
||
| public void giveInitialCards(Player player) { | ||
| for (int i = 0; i < INITIAL_CARD_NUMBER; i++) { | ||
| giveCard(player); | ||
| } | ||
| } | ||
|
|
||
| public void giveCard(final Player player) { | ||
| player.addCard(this.draw()); | ||
| } | ||
|
|
||
| private Card draw() { | ||
| if (deck.size() == 0) { | ||
| throw new IllegalStateException("카드가 존재하지 않습니다."); | ||
| } | ||
|
|
||
| return deck.pop(); | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
src/main/java/blackjack/domain/cardgame/CardGameResult.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package blackjack.domain.cardgame; | ||
|
|
||
| import blackjack.domain.player.Dealer; | ||
| import blackjack.domain.player.Player; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static blackjack.domain.cardgame.WinningStatus.LOSE; | ||
| import static blackjack.domain.cardgame.WinningStatus.WIN; | ||
|
|
||
| public record CardGameResult(Map<Player, WinningStatus> totalResult) { | ||
| public static CardGameResult of(final Dealer dealer, final List<Player> players) { | ||
| return new CardGameResult( | ||
| players.stream() | ||
| .collect(Collectors.toMap( | ||
| player -> player, | ||
| player -> WinningStatus.doesPlayerWin(dealer, player), | ||
| (key, value) -> key, | ||
| LinkedHashMap::new | ||
| ))); | ||
| } | ||
|
|
||
| public Map<Player, WinningStatus> totalResult() { | ||
| return Collections.unmodifiableMap(totalResult); | ||
| } | ||
|
|
||
| public int getDealerWinCount() { | ||
| return (int) totalResult.values() | ||
| .stream() | ||
| .filter(playerWinningStatus -> playerWinningStatus.equals(LOSE)) | ||
| .count(); | ||
| } | ||
|
|
||
| public int getDealerLoseCount() { | ||
| return (int) totalResult.values() | ||
| .stream() | ||
| .filter(status -> status.equals(WIN)) | ||
| .count(); | ||
| } | ||
| } | ||
26 changes: 26 additions & 0 deletions
26
src/main/java/blackjack/domain/cardgame/WinningStatus.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package blackjack.domain.cardgame; | ||
|
|
||
| import blackjack.domain.player.Dealer; | ||
| import blackjack.domain.player.Player; | ||
|
|
||
| public enum WinningStatus { | ||
| WIN, | ||
| PUSH, | ||
| LOSE; | ||
|
|
||
| public static WinningStatus doesPlayerWin(final Dealer dealer, final Player player) { | ||
| if (!player.isAlive()) { | ||
| return WinningStatus.LOSE; | ||
| } | ||
| if (!dealer.isAlive()) { | ||
| return WinningStatus.WIN; | ||
| } | ||
| if (dealer.getScore() == player.getScore()) { | ||
| return WinningStatus.PUSH; | ||
| } | ||
| if (dealer.getScore() < player.getScore()) { | ||
| return WinningStatus.WIN; | ||
| } | ||
| return WinningStatus.LOSE; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package blackjack.domain.player; | ||
|
|
||
| import blackjack.domain.card.Card; | ||
|
|
||
| public class Dealer extends Player { | ||
| private static final int HIT_CONDITION = 16; | ||
|
|
||
| public Dealer() { | ||
| super("딜러"); | ||
| } | ||
|
|
||
| public boolean isMoreCardNeeded() { | ||
| return this.getScore() <= HIT_CONDITION; | ||
| } | ||
|
|
||
| public Card getFirstCard() { | ||
| try { | ||
| return hand.getAllCards().get(0); | ||
| } catch (IndexOutOfBoundsException e) { | ||
| throw new RuntimeException("[ERROR] 딜러가 카드를 갖고 있지 않습니다."); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
위에
playerWinningStatus너무 좋은데! 여기도 수정하면 좋겠어요!+딜러의 무승부 결과는 출력하지 않나요?