-
Notifications
You must be signed in to change notification settings - Fork 75
[손민철] 연료주입, 블랙잭 - 1단계 #45
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
MinChul-Son
wants to merge
64
commits into
next-step:minchul-son
Choose a base branch
from
MinChul-Son:step1
base: minchul-son
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
64 commits
Select commit
Hold shift + click to select a range
7be777d
docs: 연료 주입 요구 사항 작성
kworkbee f1985fb
refactor: Remove Unnecessary Files empty.txt's
kworkbee 9ce23cd
test: RentCompanyTest 작성
kworkbee 6d4d637
feat: Car / PassengerCar 작성
kworkbee 1f44c48
feat: PassengerCar 상속받은 자동차 정의
kworkbee 4b1ce8b
feat: RentCompany 정의
kworkbee 41bbc18
refactor: Add final modifier into K5 / Avante for making distance imm…
kworkbee 5a02cc7
docs: 연료 주입 요구사항 반영
kworkbee c8d9181
docs: update README.md
judy5050 18629ed
test: CardNumberTest 작성
judy5050 b1486aa
feat: Player 정의
judy5050 e8d2d78
feat: Score 정의
judy5050 151b0d4
feat: Suit 정의
judy5050 36af6d5
test: Deck 테스트코드 작성
MinChul-Son 16699df
feat: Deck 클래스 구현
MinChul-Son a55c743
feat: Card 클래스 equals & hashCode 오버라이드
MinChul-Son fa5905d
refactor: CardNumber에서 사용하지 않는 Getter 제거
MinChul-Son 3dd4f68
feat: Person의 추상 메서드 변경
MinChul-Son 754087e
feat: 추상 메서드 오버라이드
MinChul-Son 5c6ebe8
refactor: 불필요한 공백 및 public 키워드 제거
MinChul-Son 9b05903
feat: Cards의 isNearTwentyOne 메서드 구현
MinChul-Son 7c3352a
test: 도메인 테스트 구현
kworkbee c0e7999
test: 도메인 테스트 구현
kworkbee 1d6d1ef
feat: 도메인 기능 구현
kworkbee 0d26b30
feat: 도메인 기능 구현
kworkbee dfeecf4
feat: View / Controller
kworkbee fccc5fc
refactor: domain 패키지 이동
kworkbee eb50a57
feat: ResultView 뷰 로직 구현
judy5050 32ec9fe
feat: Players 이름 반환 및 카드 오픈 기능 구현
judy5050 b7e9073
feat: Player 카드 오픈 기능 구현
judy5050 d45db41
feat: Person 카드 오픈 및 NameDto 변환 기능 구현
judy5050 76af023
feat: GameController 구현
judy5050 316a510
feat: Dealer CardInfo 반환 기능 구현
judy5050 acb4123
feat: 카드 이름 반환 메서드 구현
judy5050 4da5a3a
style: 매직 넘버 변경
judy5050 2065276
feat: main 기능 구현
judy5050 15404c0
feat: CardInfo 구현
judy5050 d85d6e7
feat: NameInfo 구현
judy5050 e774da4
feat: PeopleController 구현
judy5050 66d3ef6
style: 코드라인 정렬
judy5050 502a5bd
refactor: Controller
kworkbee ec398cc
feat: Dto
kworkbee 1193866
feat: View
kworkbee a09581c
feat: Cards
kworkbee 14b4ec5
feat: Person (Player / Dealer)
kworkbee e7d4691
feat: Score / ScoreBoard
kworkbee ccb5359
test: 기능 요구 사항에 따른 테스트 구현
MinChul-Son 05ce88d
feat: 컨트롤러 구현
MinChul-Son cd1e181
feat: 도메인 구현
MinChul-Son 5e3663f
feat: DTO 구현
MinChul-Son e3f49f6
feat: View 구현
MinChul-Son a5158db
refactor: 누락된 커밋 반영
MinChul-Son 007cf1c
refactor: 누락된 커밋 반영
MinChul-Son 10c15b2
docs: 완료된 요구사항 리드미 반영
MinChul-Son 714705b
refactor(rentCar): 공통 필드 부모 클래스로 이동
MinChul-Son 1c3978f
refactor(blackJack): 가독성을 위해 코드 분리
MinChul-Son 88ab17c
refactor(blackJack): Collections.foreack()로 변경
MinChul-Son f06bc8c
refactor(blackJack): Player 객체 생성시 생성자를 적잘한 것으로 변경
MinChul-Son 346e27a
refactor(blackJack): 구글 코드 스타일 적용
MinChul-Son 279e281
refactor(blackJack): 활성화된 플레이어를 찾을 때 validation 추가
MinChul-Son 0f3d189
refactor(blackJack): 변수 네이밍 변경
MinChul-Son eb02039
test(blackJack): Card 클래스 테스트코드 작성
MinChul-Son e84849e
test(blackJack): Cards 클래스 테스트코드 작성
MinChul-Son 3c711f6
refactor(blackJack): 사용하지 않는 import문 삭제
MinChul-Son 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 +1,33 @@ | ||
| # java-blackjack | ||
| # java-blackjack | ||
|
|
||
| ## 연료 주입 | ||
|
|
||
| ### 기능 요구사항 | ||
|
|
||
| - [X] 각 보유 차량 (5대) 렌트할 때 대략적인 이동거리를 입력 | ||
| - [X] 자동차 객체 생성 시 생성자에 이동거리 주입 | ||
| - [X] 연료량 계산 | ||
| - [X] 연료 주입에 필요한 연료량 보고서 생성 | ||
|
|
||
| ### 프로그래밍 요구사항 | ||
|
|
||
| - [X] 상속 / 추상 메서드 활용 | ||
| - [X] 조건문 X | ||
|
|
||
| ### 블랙잭 | ||
|
|
||
| - [x] 카드계산 | ||
| - [x] 카드의 숫자 계산은 카드 숫자를 기본으로 하며, 예외로 Ace는 1 또는 11로 계산할 수 있으며, King, Queen, Jack은 각각 10으로 계산 | ||
| - [x] 카드지급 기준 | ||
| - [x] 게임을 시작하면 플레이어는 두 장의 카드를 지급 받음 | ||
| - [x] 21을 넘지 않을 경우 원한다면 얼마든지 카드를 계속 뽑을 수 있음 | ||
| -[x] 딜러는 처음에 받은 2장의 합계가 16이하이면 반드시 1장의 카드를 추가로 받아야 하고, 17점 이상이면 추가로 받을 수 없음 | ||
| - [x] 승자 결정 기준 | ||
| - [x] 두 장의 카드 숫자를 합쳐 21을 초과하지 않으면서 21에 가깝게 만들면 이김 | ||
| - [x] 게임을 완료한 후 각 플레이어별로 승패를 출력 | ||
|
|
||
| ### 프로그래밍 요구사항 | ||
|
|
||
| - [x] 모든 엔티티를 작게 유지 | ||
| - [x] 3개 이상의 인스턴스 변수를 가진 클래스를 쓰지 않음 | ||
| - [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,14 @@ | ||
| package blackjack; | ||
|
|
||
| import blackjack.controller.GameController; | ||
|
|
||
| public class Application { | ||
|
|
||
|
|
||
| public static void main(String[] args) { | ||
|
|
||
| final GameController gameController = new GameController(); | ||
| gameController.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,82 @@ | ||
| package blackjack.controller; | ||
|
|
||
| import static blackjack.domain.Dealer.DEALER_DRAW_LIMIT; | ||
|
|
||
| import blackjack.domain.Dealer; | ||
| import blackjack.domain.Deck; | ||
| import blackjack.domain.Players; | ||
| import blackjack.domain.ScoreBoard; | ||
| import blackjack.view.InputView; | ||
| import blackjack.view.ResultView; | ||
|
|
||
| public class GameController { | ||
|
|
||
| private final Players players; | ||
| private final Dealer dealer; | ||
|
|
||
| public GameController() { | ||
| this.players = Players.create(InputView.getNames()); | ||
| this.dealer = new Dealer(); | ||
| } | ||
|
|
||
| public void run() { | ||
| final Deck deck = Deck.create(); | ||
|
|
||
| setUpPerson(deck); | ||
| play(deck); | ||
| showGameResult(); | ||
| } | ||
|
|
||
| private void setUpPerson(final Deck deck) { | ||
| ResultView.margin(); | ||
|
|
||
| players.initializeDeck(deck); | ||
| dealer.initializeDeck(deck); | ||
|
|
||
| ResultView.shareCards(dealer.nameInfo().getPersonName(), players.nameInfos()); | ||
| ResultView.openCardInfo(dealer.openCards(), players.openCards()); | ||
| } | ||
|
|
||
| private void play(final Deck deck) { | ||
| ResultView.margin(); | ||
|
|
||
| playersJudgment(deck); | ||
| dealerJudgment(deck); | ||
|
|
||
| ResultView.scoreboard(dealer.scoreInfo()); | ||
| ResultView.scoreboard(players.scoreInfos()); | ||
| } | ||
|
|
||
| private void showGameResult() { | ||
| ScoreBoard scoreBoard = players.match(dealer); | ||
| ResultView.matchResult(scoreBoard.dealerMatches(dealer), | ||
| scoreBoard.playerMatches()); | ||
| } | ||
|
|
||
| private void playersJudgment(final Deck deck) { | ||
| while (players.hasActivePlayer()) { | ||
| activePlayerJudgement(deck); | ||
| } | ||
| } | ||
|
|
||
| private void activePlayerJudgement(final Deck deck) { | ||
| while (players.checkActivePlayerCanDrawCard() && InputView.drawChoice( | ||
| players.getActivePlayerNameInfo())) { | ||
| players.drawCardToActivePlayer(deck); | ||
| ResultView.playerCardsInfo(players.getActivePlayerCardInfo()); | ||
| } | ||
| players.nextActivePlayer(); | ||
| } | ||
|
|
||
| private void dealerJudgment(final Deck deck) { | ||
| ResultView.margin(); | ||
|
|
||
| while (dealer.canDrawCard()) { | ||
| dealer.drawCard(deck); | ||
| ResultView.dealerDrawDecision(dealer.nameInfo(), DEALER_DRAW_LIMIT); | ||
| } | ||
|
|
||
| ResultView.margin(); | ||
| } | ||
|
|
||
| } |
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,45 @@ | ||
| package blackjack.domain; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| public class Card { | ||
MinChul-Son marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private static final String CARD_NAME_FORMAT = "%s%s"; | ||
|
|
||
| private final CardNumber cardNumber; | ||
| private final Suit suit; | ||
|
|
||
| public Card(final CardNumber cardNumber, final Suit suit) { | ||
| this.cardNumber = cardNumber; | ||
| this.suit = suit; | ||
| } | ||
|
|
||
| public boolean isAce() { | ||
| return cardNumber.isAce(); | ||
| } | ||
|
|
||
| public String getCardName() { | ||
|
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. 해당 역할은 View의 역할인 것 같은데요! View에서 |
||
| return String.format(CARD_NAME_FORMAT, cardNumber.getInitial(), suit.getName()); | ||
| } | ||
|
|
||
| public int getCardScore() { | ||
| return cardNumber.getScore(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| Card card = (Card) o; | ||
| return suit == card.suit && cardNumber == card.cardNumber; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(suit, cardNumber); | ||
| } | ||
| } | ||
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,39 @@ | ||
| package blackjack.domain; | ||
|
|
||
| public enum CardNumber { | ||
|
|
||
| ACE("A", 1), | ||
| TWO("2", 2), | ||
| THREE("3", 3), | ||
| FOUR("4", 4), | ||
| FIVE("5", 5), | ||
| SIX("6", 6), | ||
| SEVEN("7", 7), | ||
| EIGHT("8", 8), | ||
| NINE("9", 9), | ||
| TEN("10", 10), | ||
| JACK("J", 10), | ||
| QUEEN("Q", 10), | ||
| KING("K", 10); | ||
|
|
||
| private final String initial; | ||
| private final int score; | ||
|
|
||
| CardNumber(final String initial, final int score) { | ||
| this.initial = initial; | ||
| this.score = score; | ||
| } | ||
|
|
||
| public boolean isAce() { | ||
| return this == ACE; | ||
| } | ||
|
|
||
| public int getScore() { | ||
| return this.score; | ||
| } | ||
|
|
||
| public String getInitial() { | ||
| return this.initial; | ||
| } | ||
|
|
||
| } |
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,64 @@ | ||
| package blackjack.domain; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class Cards { | ||
MinChul-Son marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private static final int ADDITION_ACE_SCORE = 10; | ||
| private static final int LIMITED_ACE_SCORE = 11; | ||
| private static final int REFERENCE_POINT = 21; | ||
| private static final String CARD_SIZE_ZERO_ERROR = "카드가 존재하지 않습니다."; | ||
| private static final int FRONT = 0; | ||
|
|
||
| private final List<Card> cards; | ||
|
|
||
| public Cards(final List<Card> cards) { | ||
| this.cards = cards; | ||
| } | ||
|
|
||
| public int size() { | ||
| return cards.size(); | ||
| } | ||
|
|
||
| public int totalScore() { | ||
| final int score = cards.stream() | ||
| .mapToInt(Card::getCardScore) | ||
| .sum(); | ||
|
|
||
| if (hasAce() && score <= LIMITED_ACE_SCORE) { | ||
| return score + ADDITION_ACE_SCORE; | ||
| } | ||
| return score; | ||
| } | ||
|
|
||
| public void add(final Card drawCard) { | ||
| cards.add(drawCard); | ||
| } | ||
|
|
||
| private boolean hasAce() { | ||
| return cards.stream().anyMatch(Card::isAce); | ||
| } | ||
|
|
||
| public List<String> openCardOne() { | ||
| if (cards.isEmpty()) { | ||
| throw new RuntimeException(CARD_SIZE_ZERO_ERROR); | ||
| } | ||
| return Arrays.asList(cards.get(FRONT).getCardName()); | ||
| } | ||
|
|
||
| public List<String> openCardAll() { | ||
| return cards.stream() | ||
| .map(Card::getCardName) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| public boolean isBust() { | ||
| return totalScore() > REFERENCE_POINT; | ||
| } | ||
|
|
||
| public boolean blackjack() { | ||
| return totalScore() == REFERENCE_POINT; | ||
| } | ||
| } | ||
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.domain; | ||
|
|
||
| import blackjack.dto.CardInfo; | ||
| import blackjack.dto.MatchInfo; | ||
| import java.util.ArrayList; | ||
|
|
||
| public class Dealer extends Person { | ||
|
|
||
| public static final int DEALER_DRAW_LIMIT = 16; | ||
| private static final String DEALER_NAME = "딜러"; | ||
|
|
||
| public Dealer(final String userName, final Cards cards) { | ||
| super(userName, cards); | ||
| } | ||
|
|
||
| public Dealer() { | ||
| this(DEALER_NAME, new Cards(new ArrayList<>())); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean canDrawCard() { | ||
| return cards.totalScore() <= DEALER_DRAW_LIMIT; | ||
| } | ||
|
|
||
| @Override | ||
| public CardInfo openCards() { | ||
| return new CardInfo(userName, cards.openCardOne()); | ||
| } | ||
|
|
||
| } |
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,46 @@ | ||
| package blackjack.domain; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.LinkedList; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
|
|
||
| public class Deck { | ||
|
|
||
| private static final int REMOVE_INDEX = 0; | ||
| private final List<Card> cards; | ||
|
|
||
| public Deck(final List<Card> cards) { | ||
| this.cards = cards; | ||
| } | ||
|
|
||
| public static Deck create() { | ||
| final List<Card> cards = createEntireCards(); | ||
| Collections.shuffle(cards); | ||
| return new Deck(cards); | ||
| } | ||
|
|
||
| public Card drawCard() { | ||
| if (cards.isEmpty()) { | ||
| throw new RuntimeException("더 이상 카드를 뽑을 수 없습니다."); | ||
| } | ||
| return cards.remove(REMOVE_INDEX); | ||
| } | ||
|
|
||
| public int deckSize() { | ||
| return cards.size(); | ||
| } | ||
|
|
||
| private static List<Card> createEntireCards() { | ||
| return Arrays.stream(CardNumber.values()) | ||
| .flatMap(Deck::createEntireSuitCards) | ||
| .collect(Collectors.toCollection(LinkedList::new)); | ||
| } | ||
|
|
||
| private static Stream<Card> createEntireSuitCards(final CardNumber cardNumber) { | ||
| return Arrays.stream(Suit.values()) | ||
| .map(suit -> new Card(cardNumber, suit)); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.