-
Notifications
You must be signed in to change notification settings - Fork 75
[황인규] 연료 주입, blackjack (Step1) #41
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
sk11ingyuhwang
wants to merge
82
commits into
next-step:sk11ingyuhwang
Choose a base branch
from
sk11ingyuhwang:step1
base: sk11ingyuhwang
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
82 commits
Select commit
Hold shift + click to select a range
cb6c3ad
docs(rentCar): 연료주입 기능요구사항 정의
hyoenju c0947c3
feat(main): Application 클래스 생성
hyoenju 527c83f
feat(car): Car 추상 클래스 생성
hyoenju 7b498fa
feat(car): Car 상속 클래스 생성
hyoenju 9f5362d
feat: empty.txt 생성
hyoenju 3498e4c
feat(company): RentCompany 클래스 생성
hyoenju ebcb132
test(company): RentCompany 클래스 생성 테스트
hyoenju d8cb870
feat(company): Car 객체 추가
hyoenju 80dd03e
test(company): Car 객체 추가 테스트
hyoenju 8cafc20
feat(car): getter 정의
hyoenju 0687344
feat(company): 레포트 생성 기능 구현
hyoenju 19286f8
test(company): 레포트 생성 기능 테스트
hyoenju d8cc419
docs: Update README.md
hyoenju cf06f9e
feat(main): main method 정의
hyoenju a06b01f
feat: empty.txt 삭제
hyoenju ebcaf92
remove: empty.txt 삭제
hyoenju f4c30c4
feat(view): inputView 클래스 생성
sk11ingyuhwang bfded44
remove: 불필요한 파일 삭제
sk11ingyuhwang e518287
test: 테스트 코드 작성
sk11ingyuhwang 8c65c2f
feat(view): OutputView 클래스 생성, InputView 로직 수정
sk11ingyuhwang 1fa56ff
feat(rentCar): enum으로 rentCar 타입 결정
sk11ingyuhwang e43b483
feat(Application): Application에서 Controller 호출
sk11ingyuhwang 512b778
Merge branch 'step1' of https://github.com/hyoenju/java-blackjack int…
sk11ingyuhwang aeaab59
docs: 연료 주입 기능 구현 완료
sk11ingyuhwang bbfecb5
docs: 블랙잭 기능 명세서 작성
sk11ingyuhwang 9146c02
feat(participant): 부모 클래스(Person) 생성
hyoenju 875efb0
feat(participant): Participant 클래스 생성
hyoenju 165f03c
test(participant): Participant 클래스 생성 테스트
hyoenju f1b626d
feat(card): cardNumber enum 클래스 생성
hyoenju fd92fd7
feat(card): cardPattern enum 클래스 생성
hyoenju 25e555a
feat(card): Card 클래스 생성
hyoenju d45bbcf
feat(card): CardDeck 클래스 생성
hyoenju da370f9
test(card): CardDeck 클래스 생성 테스트
hyoenju 75ab3a5
test(input): InputView 클래스 생성
hyoenju 17c3904
feat(player): Participant -> Player 로 클래스 이름 변경
hyoenju bea5c54
feat(dealer): Dealer 클래스 생성
hyoenju c571bc5
style(player): Participant -> Player 로 클래스 이름 변경
hyoenju e79cfef
feat(card) : Card 생성, 추가를 위한 인터페이스 생성
hyoenju 00f6f1d
feat(view) : InputView, OuputView 클래스 생성, 기능 구현
hyoenju dfa02ad
feat(card) : 게임 진행 위한 카드 객체 생성
hyoenju 0646780
feat(dealer) : Dealer 클래스 생성
hyoenju 13cc902
feat(main) : blackjack 기능 구현
hyoenju 5403ec2
remove(test) : Remove Test
hyoenju 6c4694f
refactor(view): InputView, OutputView 정적 팩토리 메소드로 변경
sk11ingyuhwang 72bb5f9
feat(game): game 클래스 생성
sk11ingyuhwang db82882
refactor(view): OutputView 클래스 수정
sk11ingyuhwang 089ff30
test(player): PlayerTest 코드 작성
sk11ingyuhwang 181a0e4
test(dealer): DealerTest 코드 작성
sk11ingyuhwang d08b32a
test(dealer): Game 테스트 코드 작성
sk11ingyuhwang f86f7d4
refactor(main): Controller new 연산자로 생성
sk11ingyuhwang ec8a9c6
refactor(main): 구현된 기능 분리 작업
sk11ingyuhwang 2e180aa
feat(card) : Card 객체 생성 && test(card)
hyoenju a7bb315
feat(cards) : Card 객체 생성, 계산 && test(card)
hyoenju 57fb0f5
refactor(cardDeck) : 파일 위치 이동
hyoenju 7f6b559
refactor(cardDeck) : 매직넘버 생성, final 정의
hyoenju db9372d
refactor(number) : 파일 위치 이동
hyoenju 4f8dbcd
refactor(number) : final 정의
hyoenju aa60018
refactor(person): 파일 이동, final 정의
hyoenju 1b5e63c
refactor(state): 공통 기능 분리
hyoenju bf9ab2c
delete & remove
hyoenju dccbe46
feat(view): 결과 출력 메소드 구현
hyoenju ce019ba
feat(winner): 게임 결과 메소드 구현 && test(winner)
hyoenju 5558990
feat(control): Controller 기능 구현
hyoenju ffb0e10
refactor(game): game 기능 구현 && test(game)
hyoenju d04be38
refactor: reformat Codes
hyoenju aca0ca1
Update README.md
hyoenju 7057c55
feat(Gameable): 인터페이스로 공통 기능 추가
sk11ingyuhwang 91ba5d6
refactor(Dealer): 인터페이스에 구현된 기능을 추가 구현
sk11ingyuhwang c19ccae
refactor(Controller): 클래스 레이아웃 변경
sk11ingyuhwang 76937c7
refactor(Player): 인터페이스에 추가된 기능 구현
sk11ingyuhwang 4b04243
refactor(Cards): 네이밍 변경
sk11ingyuhwang 15f0789
refactor(Cards): 카드를 가져오는 기능 구현
sk11ingyuhwang 57b88c1
refactor(View): 인터페이스로 구현된 기능으로 체이닝 간소화
sk11ingyuhwang b56f972
refactor(blackjack): 매직넘버, 리터럴
sk11ingyuhwang dfa073e
refactor(blackjack): intellij code style 적용
sk11ingyuhwang c6ca5f2
refactor(CardDeck): 카드를 정적으로 생성
sk11ingyuhwang b6d0f5b
refactor(CardDeck): 테스트 돌릴 때마다 다른 결과가 나오는것을 수정
sk11ingyuhwang 5ddbcbc
refactor(State): 블랙잭 상태를 표현하는 클래스 생성
sk11ingyuhwang b838084
refactor(State): 불필요한 행위의 abstract 클래스 삭제
sk11ingyuhwang 2d4a365
refactor(Test): 테스트 코드 수정
sk11ingyuhwang b7c9f70
refactor(End): 블랙잭 상태를 표현하는 클래스 생성
sk11ingyuhwang f691dd1
fix(Main): 블랙잭 게임 Play 상태 변경으로 인한 cards 접근 수정
sk11ingyuhwang 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,25 @@ | ||
| # java-blackjack | ||
| # 연료 주입 | ||
|
|
||
| ## 기능요구사항 | ||
|
|
||
| - [x] 렌터카는 Sonata 2대, Avante 1대, K5 2대로 총 5대의 차량을 보유하고 있다. | ||
| - [x] 차량 별 연비 정보를 저장하고 있다. | ||
| - Sonata : 10km/리터 | ||
| - Avante : 15km/리터 | ||
| - K5 : 13km/리터) | ||
| - 차량 별 보유 대수를 저장하고 있다. | ||
| - [x] 고객은 여행할 목적지의 대략적인 이동거리를 입력 받는다. | ||
| - [x] 이 이동거리를 활용해 차량 별로 필요한 연료를 주입한다. | ||
| - [x] 차량 별로 주입해야 할 연료량을 확인할 수 있는 보고서를 생성한다. | ||
| - [x] 보고서를 출력한다. | ||
|
|
||
| # java-blackjack | ||
|
|
||
| - [x] 게임에 참여할 사람의 이름을 입력하세요. | ||
| - [x] 게임이 시작하면 참여한 사람과 딜러는 카드 2개씩을 받는다. | ||
| - [x] 카드 숫자를 기본으로 하며, 예외로 Ace는 1 또는 11로 계산할 수 있으며, King, Queen, Jack은 각각 10으로 계산한다. | ||
| - [x] 게임에 참여한 사람 순서대로 카드를 더 받을지 물어보고 카드를 제공한다. 21점을 넘지 않을 경우 원한다면 얼마든지 카드를 계속 뽑을 수 있다. 단, 여기서 카드의 합은 | ||
| 21점을 넘어가지 않는다. | ||
| - [x] 게임에 딜러도 기존에 받았던 카드들의 합이 16점 이하이면 한장의 카드를 더 받아야 한다. 17점 이상이면 추가로 받을 수 없다. | ||
| - [x] 블랙잭 게임은 딜러와 플레이어 중 카드의 합이 21점 또는 21점에 가장 가까운 숫자를 가지는 쪽이 이기는 게임이다. | ||
| - [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,11 @@ | ||
| package blackjack; | ||
|
|
||
| import blackjack.controller.Controller; | ||
|
|
||
| public class Application { | ||
|
|
||
| public static void main(String[] args) { | ||
| Controller controller = new Controller(); | ||
| controller.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,66 @@ | ||
| package blackjack.controller; | ||
|
|
||
| import blackjack.domain.Game; | ||
| import blackjack.domain.Winner; | ||
| import blackjack.domain.card.CardDeck; | ||
| import blackjack.domain.player.Player; | ||
| import blackjack.domain.state.Gameable; | ||
| import blackjack.view.InputView; | ||
| import blackjack.view.OutputView; | ||
|
|
||
| public class Controller { | ||
|
|
||
| private static final String BLANK = ""; | ||
| private static final String YES_MESSAGE = "y"; | ||
| private static final String NO_MESSAGE = "n"; | ||
|
|
||
| private static void initGame(Game game) { | ||
| OutputView.printStartMessage(game); | ||
| OutputView.printDealerCard(game.getDealer()); | ||
| OutputView.printPlayerCard(game.getPlayers()); | ||
| } | ||
|
|
||
| public void run() { | ||
| Game game = new Game(InputView.inputPlayers()); | ||
| initGame(game); | ||
| playGame(game); | ||
| finishGame(game); | ||
| } | ||
|
|
||
| private void playGame(Game game) { | ||
| game.getPlayers().forEach(this::receive); | ||
| if (game.giveCardToDealer()) { | ||
| OutputView.printMessageToGiveCardToDealer(); | ||
| } | ||
| } | ||
|
|
||
| private void receive(Player player) { | ||
| Gameable gameable = player.getCards(); | ||
| String yesOrNo = BLANK; | ||
| while(!gameable.isEnd()){ | ||
| yesOrNo = InputView.inputYesOrNo(player.getName()); | ||
| if (yesOrNo.equals(YES_MESSAGE)) { | ||
| gameable.cards().add(CardDeck.pop()); | ||
| OutputView.printCurrentCardsState(player.getName(), player.getCards()); | ||
| gameable = gameable.draw(); | ||
| } | ||
| if (yesOrNo.equals(NO_MESSAGE)) { | ||
| gameable = gameable.stay(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void finishGame(Game game) { | ||
| Winner winner = new Winner(game); | ||
|
|
||
| OutputView.printGameResults(game.getDealer(), game.getPlayers()); | ||
|
|
||
| OutputView.printGameWinOrLose(game.getDealer(), winner.calculateDealerGameResult()); | ||
| game.getPlayers().forEach( | ||
| player -> OutputView.printGameWinOrLose( | ||
| player, winner.calculatePlayerGameResult(player) | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| } |
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,61 @@ | ||
| package blackjack.domain; | ||
|
|
||
| import blackjack.domain.card.CardDeck; | ||
| import blackjack.domain.player.Dealer; | ||
| import blackjack.domain.player.Player; | ||
| import blackjack.domain.state.Hit; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class Game { | ||
|
|
||
| private static final int PASS_CARD_NUMBER = 2; | ||
| private static final String DEALER_NAME = "딜러"; | ||
| private final static int DEALER_THRESHOLD = 16; | ||
|
|
||
| private final List<Player> players; | ||
| private final Dealer dealer; | ||
|
|
||
| public Game(Dealer dealer, List<Player> players) { | ||
| this.players = players; | ||
| this.dealer = dealer; | ||
| } | ||
|
|
||
| public Game(List<String> playerNames) { | ||
| this(new Dealer(DEALER_NAME, handOutCards()), playerNames.stream() | ||
| .map(Game::createPlayer) | ||
| .collect(Collectors.toList())); | ||
| } | ||
|
|
||
| private static Player createPlayer(String name) { | ||
| return new Player(name, handOutCards()); | ||
| } | ||
|
|
||
| private static Hit handOutCards() { | ||
| CardDeck.makeCardDeck(); | ||
| return new Hit(CardDeck.pop(PASS_CARD_NUMBER)); | ||
| } | ||
|
|
||
| public boolean giveCardToDealer() { | ||
| if (dealer.getCards().cards().sumScore() <= DEALER_THRESHOLD) { | ||
| dealer.getCards().cards().add(CardDeck.pop()); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public List<Integer> getScoresOfPlayers() { | ||
| return players.stream() | ||
| .mapToInt(Player::getTotalScoreOfPlayer) | ||
| .boxed().collect(Collectors.toList()); | ||
| } | ||
|
|
||
| public List<Player> getPlayers() { | ||
| return Collections.unmodifiableList(players); | ||
| } | ||
|
|
||
| public Dealer getDealer() { | ||
| return dealer; | ||
| } | ||
| } |
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,58 @@ | ||
| package blackjack.domain; | ||
|
|
||
| import blackjack.domain.player.Player; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class Winner { | ||
|
|
||
| private final int BLACKJACK = 21; | ||
| private final int NUMBER_ZERO = 0; | ||
| private final Game game; | ||
|
|
||
| public Winner(final Game game) { | ||
| this.game = game; | ||
| } | ||
|
|
||
| public List<Integer> calculateDealerGameResult() { | ||
| int dealerScore = game.getDealer().getCards().cards().sumScore(); | ||
| return calculateGameResult(dealerScore); | ||
| } | ||
|
|
||
| public List<Integer> calculatePlayerGameResult(final Player player) { | ||
| int playerScore = player.getCards().cards().sumScore(); | ||
| return calculateGameResult(playerScore); | ||
| } | ||
|
|
||
| private List<Integer> calculateGameResult(final int sourceScore) { | ||
| List<Integer> targetScores = game.getScoresOfPlayers().stream() | ||
| .map(this::convertZeroScore) | ||
| .collect(Collectors.toList()); | ||
| return Arrays.asList(countWin(sourceScore, targetScores), | ||
| countLose(sourceScore, targetScores)); | ||
| } | ||
|
|
||
| private int convertZeroScore(final int score) { | ||
| if (score > BLACKJACK) { | ||
| return NUMBER_ZERO; | ||
| } | ||
| return score; | ||
| } | ||
|
|
||
| private int countWin(final int sourceScore, final List<Integer> targetScores) { | ||
| if (sourceScore > BLACKJACK) { | ||
| return 0; | ||
| } | ||
| return Long.valueOf(targetScores.stream() | ||
| .filter(targetScore -> sourceScore > targetScore).count()).intValue(); | ||
| } | ||
|
|
||
| private int countLose(final int sourceScore, final List<Integer> targetScores) { | ||
|
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. |
||
| if (sourceScore > BLACKJACK) { | ||
| return targetScores.size(); | ||
| } | ||
| return Long.valueOf(targetScores.stream() | ||
| .filter(targetScore -> sourceScore < targetScore).count()).intValue(); | ||
| } | ||
| } | ||
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,21 @@ | ||
| package blackjack.domain.card; | ||
|
|
||
| public class Card { | ||
|
|
||
| private final CardNumber cardNumber; | ||
| private final CardPattern cardPattern; | ||
|
|
||
| public Card(final CardNumber cardNumber, final CardPattern cardPattern) { | ||
| this.cardNumber = cardNumber; | ||
| this.cardPattern = cardPattern; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return cardNumber.getName() + cardPattern.getName(); | ||
| } | ||
|
|
||
| public CardNumber getCardNumber() { | ||
| return 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,41 @@ | ||
| package blackjack.domain.card; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| public class CardDeck { | ||
|
|
||
| private static final int FIRST_INDEX = 0; | ||
| private static List<Card> cards; | ||
|
|
||
| static { | ||
| cards = new ArrayList<>(); | ||
| } | ||
|
|
||
| public static void makeCardDeck(){ | ||
| List<Card> oldCards = new ArrayList<>(); | ||
| Arrays.stream(CardNumber.values()).forEach( | ||
| cardNumber -> Arrays.stream(CardPattern.values()).forEach( | ||
| cardPattern -> oldCards.add(new Card(cardNumber, cardPattern)) | ||
| ) | ||
| ); | ||
| Collections.shuffle(oldCards); | ||
| cards = new ArrayList<>(oldCards); | ||
| } | ||
|
|
||
| public static Cards pop(final int count) { | ||
| List<Card> newCards = new ArrayList<>(cards.subList(FIRST_INDEX, count)); | ||
| cards = cards.subList(count, cards.size() - count); | ||
| return new Cards(newCards); | ||
| } | ||
|
|
||
| public static Card pop() { | ||
| return cards.remove(FIRST_INDEX); | ||
| } | ||
|
|
||
| public static List<Card> getCards() { | ||
| return Collections.unmodifiableList(cards); | ||
| } | ||
| } |
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,33 @@ | ||
| package blackjack.domain.card; | ||
|
|
||
| public enum CardNumber { | ||
| ACE("A", 11), | ||
| TWO("2", 2), | ||
| THREE("3", 3), | ||
| FOUR("4", 4), | ||
| FIVE("5", 5), | ||
| SIX("6", 6), | ||
| SEVEN("7", 7), | ||
| EIGHT("8", 8), | ||
| NINE("9", 9), | ||
| JACK("J", 10), | ||
| QUEEN("Q", 10), | ||
| KING("K", 10); | ||
|
|
||
| private final String name; | ||
| private final int score; | ||
|
|
||
| CardNumber(final String name, final int score) { | ||
| this.name = name; | ||
| this.score = score; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public int getScore() { | ||
| return 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,18 @@ | ||
| package blackjack.domain.card; | ||
|
|
||
| public enum CardPattern { | ||
| DIAMOND("다이아몬드"), | ||
| CLOVER("클로버"), | ||
| HEART("하트"), | ||
| SPADE("스페이드"); | ||
|
|
||
| private final String name; | ||
|
|
||
| CardPattern(final String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
| } |
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.
질문주신 내용은 카드 점수의 상태를
CardSupport를 수정하시면 자연스럽게 해결 될 문제라고 생각합니다.블랙잭 게임 역할을 하는
Game객체는 크게 다음과 같은 기능을 하면 될 것으로 생각합니다.Winner에게 참가자와 딜러의 카드점수 상태 전달Winner에서 게임 결과 리턴받기승패를 결정하는게
Winner의 역할이라고 생각합니다.