forked from woowacourse/java-blackjack
-
Notifications
You must be signed in to change notification settings - Fork 0
[블랙잭 - 1단계] 아토(이혜린) 미션 제출합니다. #3
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
hyxrxn
wants to merge
68
commits into
woowacourse-6th-code-review-study:main
Choose a base branch
from
hyxrxn: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
68 commits
Select commit
Hold shift + click to select a range
143ebe7
docs: 컨벤션 및 기능 요구사항 작성
hyxrxn 21dae3a
chore: remove gitkeep
hyxrxn 1786e9f
feat(Card): 카드 점수 계산
hyxrxn 76ef94b
feat(Deck): 덱에서 카드 한 장 드로우
hyxrxn 3cd8593
feat(Deck): 비어있는 덱에서 드로우할 때 예외 처리
hyxrxn f61ae03
feat(Player): 플레이어 점수 계산
hyxrxn be2c348
feat(Dealer): 딜러의 점수에 따른 카드 드로우
hyxrxn cc38fcc
feat(Dealer): 주어진 점수에 따른 승패 판단
hyxrxn 959c905
feat(Hand): Ace 점수를 유리한 방향으로 계산
hyxrxn 4b04093
refactor(Player): 드로우 가능 여부 판단 메서드 위치 변경
hyxrxn a10af0c
feat(Name): 이름 생성 및 검증
hyxrxn 48dc12d
feat(Players): 플레이어들 생성 및 검증
hyxrxn c305c41
feat(View): 콘솔 입출력
hyxrxn 7ceb8ba
feat(CardDisplay): 카드의 모양과 수의 표현 방식 설정
hyxrxn 9608caf
refactor(Player): 게임 상수 추출 및 드로우 조건 수정
hyxrxn 4ec8b0e
feat(MatchResult): 게임 결과 판단
hyxrxn 25353e0
feat(MatchResults): 게임 결과 저장
hyxrxn 9e6d1f3
feat(Deck): Shape와 Number의 조합으로 한 세트 생성
hyxrxn 9c16047
feat(Command): 사용자의 명령어 변환
hyxrxn 25088ec
refactor(OutputView): 매개변수로 `Card`를 받도록 수정
hyxrxn de8d257
feat(Display): 플레이어의 결과 표현 방식 설정
hyxrxn a1666f1
feat(BlackJackGame): 게임 흐름 제어
hyxrxn fc78bad
feat(BlackJackMain): 의존성 설정 및 실행
hyxrxn a86d395
refactor(BlackJackGame): 메서드 분리
hyxrxn e836cbe
refactor(Players): 불필요한 래핑 제거
hyxrxn 3cbf5c0
style(Shape): 불필요한 세미콜론 제거
hyxrxn efad4ef
refactor: 상수 추출
hyxrxn 6e0a373
refactor(OutputView): 메서드 분리
hyxrxn 86c80ac
refactor: 패키지 이동
hyxrxn 3e0e9ee
test(Player): 드로우 가능 여부 판단
hyxrxn 46cc05c
fix(Dealer): 카드를 가지고 있지 않은 경우 예외 처리
hyxrxn 4f27bbd
refactor(Deck): 덱 생성 정적 메서드 추가
hyxrxn c245b03
refactor(Hand): 접근 제한자 변경
hyxrxn 70db6d4
refactor(Deck): 메서드 분리
hyxrxn cace848
refactor(Display): 패키지 분리
hyxrxn a957752
style(Number): 파일 끝 공백 추가
hyxrxn d4da751
refactor: 메서드 순서 변경
hyxrxn d888faa
refactor: 패키지 이동
hyxrxn 5729a1d
style: 불필요한 개행 삭제
hyxrxn 1ca43df
style(Hand): 가독성을 위한 변수 위치 및 줄바꿈 수정
hyxrxn ce53b0d
refactor(MatchResult): 승리 조건 별 메서드 분리
hyxrxn 8969a9a
test(MatchResult): 승리 조건 테스트 데이터 보강
hyxrxn 1a0d96e
style: 테스트 클래스 접근제한자 삭제
hyxrxn 4d35231
refactor(OutputView): 중복 코드 제거 및 메서드명 번경
hyxrxn 23b3015
style: 개행 및 오타 수정
hyxrxn 0155159
docs: 기능 구현 사항 추가
hyxrxn 1800705
refactor(Card): this 사용 일관성 고려해 수정
hyxrxn 76bed3c
refactor(InputView): 상수명 수정
hyxrxn 33d8237
refactor(Display): 메서드명 수정
hyxrxn 1f5d1ff
test(Card): 에이스 여부 확인
hyxrxn eb15bf0
refactor(Hand): 점수 계산 로직 수정
hyxrxn cf27355
refactor: 드로우 관련 메서드명 변경
hyxrxn 543e4a1
refactor(Command): 클래스 내부 메서드로 No 여부 확인
hyxrxn 8c510c9
refactor(Rank): 클래스명 변경
hyxrxn 429555c
refactor(MatchResult): 메서드명 변경
hyxrxn 7622c5f
refactor(Players): 메서드 간소화
hyxrxn 560a034
refactor: 예외 메시지에서 상수 사용
hyxrxn 948d569
refactor: 상호 참조 제외
hyxrxn b3cc95c
refactor: 예외 발생시 메시지 출력 후 종료
hyxrxn b9c0665
refactor(Display): 메서드 리턴 타입 변경
hyxrxn 5c8c80d
refactor(OutputView): 상수 추출
hyxrxn 61950f8
feat(Score): 점수 덧셈
hyxrxn a1b1c15
feat(Score): 버스트 여부 판단
hyxrxn 3e1c8f8
feat(Score): 점수 대소 비교
hyxrxn c99ed8e
feat(Score): 에이스 보정 점수 계산
hyxrxn c551c57
refactor: Score 이용
hyxrxn 28dd3a1
test(Deck): 덱 생성
hyxrxn dc16898
refactor(Score): 메서드명 번경
hyxrxn 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
Empty file.
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,19 @@ | ||
| package blackjack; | ||
|
|
||
| import blackjack.game.BlackJackGame; | ||
| import blackjack.view.InputView; | ||
| import blackjack.view.OutputView; | ||
|
|
||
| public class BlackJackMain { | ||
|
|
||
| public static void main(String[] args) { | ||
| InputView inputView = new InputView(); | ||
| OutputView outputView = new OutputView(); | ||
| BlackJackGame blackJackGame = new BlackJackGame(inputView, outputView); | ||
| try { | ||
| blackJackGame.play(); | ||
| } catch (Exception e) { | ||
| outputView.printExceptionMessage(e); | ||
| } | ||
| } | ||
| } |
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,48 @@ | ||
| package blackjack.card; | ||
|
|
||
| import blackjack.player.Score; | ||
| import java.util.Objects; | ||
|
|
||
| public class Card { | ||
|
|
||
| private final Shape shape; | ||
| private final Rank rank; | ||
|
|
||
| public Card(Shape shape, Rank rank) { | ||
| this.shape = shape; | ||
| this.rank = rank; | ||
| } | ||
|
|
||
| public boolean isAce() { | ||
| return rank == Rank.ACE; | ||
| } | ||
|
|
||
| public Score getScore() { | ||
| return rank.getScore(); | ||
| } | ||
|
|
||
| public Shape getShape() { | ||
| return shape; | ||
| } | ||
|
|
||
| public Rank getRank() { | ||
| return rank; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| Card card = (Card) o; | ||
| return shape == card.shape && rank == card.rank; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(shape, rank); | ||
| } | ||
| } |
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.card; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.LinkedList; | ||
| import java.util.List; | ||
| import java.util.Queue; | ||
|
|
||
| public class Deck { | ||
|
|
||
| private final Queue<Card> cards; | ||
|
|
||
| Deck(List<Card> cards) { | ||
| this.cards = new LinkedList<>(cards); | ||
| } | ||
|
|
||
| public static Deck createShuffledFullDeck() { | ||
| List<Card> cards = new LinkedList<>(); | ||
| for (Shape shape : Shape.values()) { | ||
| cards.addAll(createNumberCardsOf(shape)); | ||
| } | ||
| Collections.shuffle(cards); | ||
| return new Deck(cards); | ||
| } | ||
|
|
||
| static List<Card> createNumberCardsOf(Shape shape) { | ||
| List<Card> cards = new ArrayList<>(); | ||
| for (Rank rank : Rank.values()) { | ||
| cards.add(new Card(shape, rank)); | ||
| } | ||
| return cards; | ||
| } | ||
|
|
||
| public Card draw() { | ||
| if (cards.isEmpty()) { | ||
| throw new IllegalStateException("[ERROR] 덱이 비어있습니다."); | ||
| } | ||
| return cards.poll(); | ||
| } | ||
|
|
||
| int size() { | ||
| return cards.size(); | ||
| } | ||
| } |
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,30 @@ | ||
| package blackjack.card; | ||
|
|
||
| import blackjack.player.Score; | ||
|
|
||
| public enum Rank { | ||
|
|
||
| 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 Score score; | ||
|
|
||
| Rank(int score) { | ||
| this.score = new Score(score); | ||
| } | ||
|
|
||
| Score getScore() { | ||
| return this.score; | ||
| } | ||
| } |
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,9 @@ | ||
| package blackjack.card; | ||
|
|
||
| public enum Shape { | ||
|
|
||
| HEART, | ||
| SPADE, | ||
| CLOVER, | ||
| DIAMOND | ||
| } |
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,130 @@ | ||
| package blackjack.game; | ||
|
|
||
| import blackjack.card.Deck; | ||
| import blackjack.player.Dealer; | ||
| import blackjack.player.Player; | ||
| import blackjack.player.Players; | ||
| import blackjack.view.InputView; | ||
| import blackjack.view.OutputView; | ||
| import java.util.List; | ||
|
|
||
| public class BlackJackGame { | ||
|
|
||
| private final InputView inputView; | ||
| private final OutputView outputView; | ||
|
|
||
| public BlackJackGame(InputView inputView, OutputView outputView) { | ||
| this.inputView = inputView; | ||
| this.outputView = outputView; | ||
| } | ||
|
|
||
| public void play() { | ||
| Deck deck = Deck.createShuffledFullDeck(); | ||
| Dealer dealer = new Dealer(); | ||
|
|
||
| Players players = createPlayers(); | ||
| initializeGame(deck, dealer, players); | ||
| proceedPlayersTurn(deck, players); | ||
| proceedDealerTurn(deck, dealer); | ||
|
|
||
| showCardsWithScore(dealer, players); | ||
| showMatchResult(dealer, players); | ||
| } | ||
|
|
||
| private Players createPlayers() { | ||
| outputView.printNamesRequest(); | ||
| List<String> names = inputView.readNames(); | ||
| Players players = new Players(names); | ||
| outputView.printNewLine(); | ||
| return players; | ||
| } | ||
|
|
||
| private void initializeGame(Deck deck, Dealer dealer, Players players) { | ||
| players.doInitialDraw(deck); | ||
| dealer.doInitialDraw(deck); | ||
| outputView.printInitializeBlackJack(players.getNames()); | ||
| showInitialCard(dealer, players); | ||
| } | ||
|
|
||
| private void showInitialCard(Dealer dealer, Players players) { | ||
| outputView.printDealerFirstCard(dealer.getFirstCard()); | ||
|
|
||
| for (Player player : players.getPlayers()) { | ||
| outputView.printPlayerCards(player.getName(), player.getCards()); | ||
| } | ||
| outputView.printNewLine(); | ||
| } | ||
|
|
||
| private void proceedPlayersTurn(Deck deck, Players players) { | ||
| for (Player player : players.getPlayers()) { | ||
| proceedPlayerTurn(deck, player); | ||
| } | ||
| outputView.printNewLine(); | ||
| } | ||
|
|
||
| private void proceedPlayerTurn(Deck deck, Player player) { | ||
| Command command = askPlayerToDrawMore(player); | ||
| if (command.isNo()) { | ||
| return; | ||
| } | ||
| player.drawCard(deck); | ||
| outputView.printPlayerCards(player.getName(), player.getCards()); | ||
|
|
||
| if (player.hasDrawableScore()) { | ||
| proceedPlayerTurn(deck, player); | ||
| } | ||
| } | ||
|
|
||
| private Command askPlayerToDrawMore(Player player) { | ||
| outputView.printDrawMoreCardRequest(player.getName()); | ||
| String input = inputView.readCommand(); | ||
| return Command.from(input); | ||
| } | ||
|
|
||
| private void proceedDealerTurn(Deck deck, Dealer dealer) { | ||
| while (dealer.hasDrawableScore()) { | ||
| dealer.drawCard(deck); | ||
| outputView.printDealerDrawCard(); | ||
| outputView.printNewLine(); | ||
| } | ||
| } | ||
|
|
||
| private void showCardsWithScore(Dealer dealer, Players players) { | ||
| outputView.printDealerCardsWithScore(dealer.getCards(), dealer.getScore()); | ||
| for (Player player : players.getPlayers()) { | ||
| outputView.printPlayerCardsWithScore(player.getName(), player.getCards(), player.getScore()); | ||
| } | ||
| outputView.printNewLine(); | ||
| } | ||
|
|
||
| private void showMatchResult(Dealer dealer, Players players) { | ||
| MatchResults matchResults = calculateMatchResults(dealer, players); | ||
| outputView.printResultStart(); | ||
| showDealerResult(matchResults); | ||
| showPlayersResult(players, matchResults); | ||
| } | ||
|
|
||
| private MatchResults calculateMatchResults(Dealer dealer, Players players) { | ||
| MatchResults matchResults = new MatchResults(); | ||
| for (Player player : players.getPlayers()) { | ||
| matchResults.addResult(player.getName(), player.getScore(), dealer.getScore()); | ||
| } | ||
| return matchResults; | ||
| } | ||
|
|
||
| private void showDealerResult(MatchResults matchResults) { | ||
| outputView.printDealerResult( | ||
| matchResults.getResultCount(MatchResult.DEALER_WIN), | ||
| matchResults.getResultCount(MatchResult.TIE), | ||
| matchResults.getResultCount(MatchResult.PLAYER_WIN) | ||
| ); | ||
| } | ||
|
|
||
| private void showPlayersResult(Players players, MatchResults matchResults) { | ||
| for (Player player : players.getPlayers()) { | ||
| String playerName = player.getName(); | ||
| MatchResult result = matchResults.getResultByName(playerName); | ||
| outputView.printPlayerResult(playerName, result); | ||
| } | ||
| } | ||
| } |
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.game; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Objects; | ||
|
|
||
| public enum Command { | ||
| YES("y"), | ||
| NO("n"); | ||
|
|
||
| private final String value; | ||
|
|
||
| Command(String value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| public static Command from(String value) { | ||
| return Arrays.stream(values()) | ||
| .filter(command -> command.value.equals(value)) | ||
| .findFirst() | ||
| .orElseThrow(() -> new IllegalArgumentException("[ERROR] 존재하지 않는 명령어입니다.")); | ||
| } | ||
|
|
||
| public boolean isNo() { | ||
| return Objects.equals(value, Command.NO.value); | ||
| } | ||
| } |
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.
옹 이렇게 페어와 지킬 컨벤션을 작성해두는것도 좋은 거 같네요!!