Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
cb6c3ad
docs(rentCar): 연료주입 기능요구사항 정의
hyoenju Feb 11, 2022
c0947c3
feat(main): Application 클래스 생성
hyoenju Feb 11, 2022
527c83f
feat(car): Car 추상 클래스 생성
hyoenju Feb 11, 2022
7b498fa
feat(car): Car 상속 클래스 생성
hyoenju Feb 11, 2022
9f5362d
feat: empty.txt 생성
hyoenju Feb 11, 2022
3498e4c
feat(company): RentCompany 클래스 생성
hyoenju Feb 11, 2022
ebcb132
test(company): RentCompany 클래스 생성 테스트
hyoenju Feb 11, 2022
d8cb870
feat(company): Car 객체 추가
hyoenju Feb 11, 2022
80dd03e
test(company): Car 객체 추가 테스트
hyoenju Feb 11, 2022
8cafc20
feat(car): getter 정의
hyoenju Feb 11, 2022
0687344
feat(company): 레포트 생성 기능 구현
hyoenju Feb 11, 2022
19286f8
test(company): 레포트 생성 기능 테스트
hyoenju Feb 11, 2022
d8cc419
docs: Update README.md
hyoenju Feb 11, 2022
cf06f9e
feat(main): main method 정의
hyoenju Feb 11, 2022
a06b01f
feat: empty.txt 삭제
hyoenju Feb 11, 2022
ebcaf92
remove: empty.txt 삭제
hyoenju Feb 11, 2022
f4c30c4
feat(view): inputView 클래스 생성
sk11ingyuhwang Feb 14, 2022
bfded44
remove: 불필요한 파일 삭제
sk11ingyuhwang Feb 14, 2022
e518287
test: 테스트 코드 작성
sk11ingyuhwang Feb 14, 2022
8c65c2f
feat(view): OutputView 클래스 생성, InputView 로직 수정
sk11ingyuhwang Feb 14, 2022
1fa56ff
feat(rentCar): enum으로 rentCar 타입 결정
sk11ingyuhwang Feb 14, 2022
e43b483
feat(Application): Application에서 Controller 호출
sk11ingyuhwang Feb 14, 2022
512b778
Merge branch 'step1' of https://github.com/hyoenju/java-blackjack int…
sk11ingyuhwang Feb 14, 2022
aeaab59
docs: 연료 주입 기능 구현 완료
sk11ingyuhwang Feb 14, 2022
bbfecb5
docs: 블랙잭 기능 명세서 작성
sk11ingyuhwang Feb 14, 2022
9146c02
feat(participant): 부모 클래스(Person) 생성
hyoenju Feb 15, 2022
875efb0
feat(participant): Participant 클래스 생성
hyoenju Feb 15, 2022
165f03c
test(participant): Participant 클래스 생성 테스트
hyoenju Feb 15, 2022
f1b626d
feat(card): cardNumber enum 클래스 생성
hyoenju Feb 15, 2022
fd92fd7
feat(card): cardPattern enum 클래스 생성
hyoenju Feb 15, 2022
25e555a
feat(card): Card 클래스 생성
hyoenju Feb 15, 2022
d45bbcf
feat(card): CardDeck 클래스 생성
hyoenju Feb 15, 2022
da370f9
test(card): CardDeck 클래스 생성 테스트
hyoenju Feb 15, 2022
75ab3a5
test(input): InputView 클래스 생성
hyoenju Feb 15, 2022
17c3904
feat(player): Participant -> Player 로 클래스 이름 변경
hyoenju Feb 15, 2022
bea5c54
feat(dealer): Dealer 클래스 생성
hyoenju Feb 15, 2022
c571bc5
style(player): Participant -> Player 로 클래스 이름 변경
hyoenju Feb 15, 2022
e79cfef
feat(card) : Card 생성, 추가를 위한 인터페이스 생성
hyoenju Feb 15, 2022
00f6f1d
feat(view) : InputView, OuputView 클래스 생성, 기능 구현
hyoenju Feb 15, 2022
dfa02ad
feat(card) : 게임 진행 위한 카드 객체 생성
hyoenju Feb 15, 2022
0646780
feat(dealer) : Dealer 클래스 생성
hyoenju Feb 15, 2022
13cc902
feat(main) : blackjack 기능 구현
hyoenju Feb 15, 2022
5403ec2
remove(test) : Remove Test
hyoenju Feb 15, 2022
6c4694f
refactor(view): InputView, OutputView 정적 팩토리 메소드로 변경
sk11ingyuhwang Feb 16, 2022
72bb5f9
feat(game): game 클래스 생성
sk11ingyuhwang Feb 16, 2022
db82882
refactor(view): OutputView 클래스 수정
sk11ingyuhwang Feb 16, 2022
089ff30
test(player): PlayerTest 코드 작성
sk11ingyuhwang Feb 16, 2022
181a0e4
test(dealer): DealerTest 코드 작성
sk11ingyuhwang Feb 16, 2022
d08b32a
test(dealer): Game 테스트 코드 작성
sk11ingyuhwang Feb 16, 2022
f86f7d4
refactor(main): Controller new 연산자로 생성
sk11ingyuhwang Feb 16, 2022
ec8a9c6
refactor(main): 구현된 기능 분리 작업
sk11ingyuhwang Feb 17, 2022
2e180aa
feat(card) : Card 객체 생성 && test(card)
hyoenju Feb 17, 2022
a7bb315
feat(cards) : Card 객체 생성, 계산 && test(card)
hyoenju Feb 17, 2022
57fb0f5
refactor(cardDeck) : 파일 위치 이동
hyoenju Feb 17, 2022
7f6b559
refactor(cardDeck) : 매직넘버 생성, final 정의
hyoenju Feb 17, 2022
db9372d
refactor(number) : 파일 위치 이동
hyoenju Feb 17, 2022
4f8dbcd
refactor(number) : final 정의
hyoenju Feb 17, 2022
aa60018
refactor(person): 파일 이동, final 정의
hyoenju Feb 17, 2022
1b5e63c
refactor(state): 공통 기능 분리
hyoenju Feb 17, 2022
bf9ab2c
delete & remove
hyoenju Feb 17, 2022
dccbe46
feat(view): 결과 출력 메소드 구현
hyoenju Feb 17, 2022
ce019ba
feat(winner): 게임 결과 메소드 구현 && test(winner)
hyoenju Feb 17, 2022
5558990
feat(control): Controller 기능 구현
hyoenju Feb 17, 2022
ffb0e10
refactor(game): game 기능 구현 && test(game)
hyoenju Feb 17, 2022
d04be38
refactor: reformat Codes
hyoenju Feb 17, 2022
aca0ca1
Update README.md
hyoenju Feb 17, 2022
7057c55
feat(Gameable): 인터페이스로 공통 기능 추가
sk11ingyuhwang Feb 18, 2022
91ba5d6
refactor(Dealer): 인터페이스에 구현된 기능을 추가 구현
sk11ingyuhwang Feb 18, 2022
c19ccae
refactor(Controller): 클래스 레이아웃 변경
sk11ingyuhwang Feb 18, 2022
76937c7
refactor(Player): 인터페이스에 추가된 기능 구현
sk11ingyuhwang Feb 18, 2022
4b04243
refactor(Cards): 네이밍 변경
sk11ingyuhwang Feb 18, 2022
15f0789
refactor(Cards): 카드를 가져오는 기능 구현
sk11ingyuhwang Feb 18, 2022
57b88c1
refactor(View): 인터페이스로 구현된 기능으로 체이닝 간소화
sk11ingyuhwang Feb 18, 2022
b56f972
refactor(blackjack): 매직넘버, 리터럴
sk11ingyuhwang Feb 18, 2022
dfa073e
refactor(blackjack): intellij code style 적용
sk11ingyuhwang Feb 18, 2022
c6ca5f2
refactor(CardDeck): 카드를 정적으로 생성
sk11ingyuhwang Feb 26, 2022
b6d0f5b
refactor(CardDeck): 테스트 돌릴 때마다 다른 결과가 나오는것을 수정
sk11ingyuhwang Feb 26, 2022
5ddbcbc
refactor(State): 블랙잭 상태를 표현하는 클래스 생성
sk11ingyuhwang Feb 27, 2022
b838084
refactor(State): 불필요한 행위의 abstract 클래스 삭제
sk11ingyuhwang Feb 27, 2022
2d4a365
refactor(Test): 테스트 코드 수정
sk11ingyuhwang Feb 27, 2022
b7c9f70
refactor(End): 블랙잭 상태를 표현하는 클래스 생성
sk11ingyuhwang Feb 27, 2022
f691dd1
fix(Main): 블랙잭 게임 Play 상태 변경으로 인한 cards 접근 수정
sk11ingyuhwang Feb 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion README.md
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] 블랙잭 게임을 완료한 후 각 플레이어별로 승패를 출력한다.
11 changes: 11 additions & 0 deletions src/main/java/blackjack/Application.java
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();
}
}
66 changes: 66 additions & 0 deletions src/main/java/blackjack/controller/Controller.java
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)
)
);
}

}
61 changes: 61 additions & 0 deletions src/main/java/blackjack/domain/Game.java
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;
}
}
58 changes: 58 additions & 0 deletions src/main/java/blackjack/domain/Winner.java
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();
Copy link

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의 역할이라고 생각합니다.

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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

각 플레이어와 딜러의 경기 입니다.
아래의 경우 b는 1패를 기록 해야합니다.
스크린샷 2022-02-21 오후 10 42 19

if (sourceScore > BLACKJACK) {
return targetScores.size();
}
return Long.valueOf(targetScores.stream()
.filter(targetScore -> sourceScore < targetScore).count()).intValue();
}
}
21 changes: 21 additions & 0 deletions src/main/java/blackjack/domain/card/Card.java
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;
}
}
41 changes: 41 additions & 0 deletions src/main/java/blackjack/domain/card/CardDeck.java
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);
}
}
33 changes: 33 additions & 0 deletions src/main/java/blackjack/domain/card/CardNumber.java
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;
}

}
18 changes: 18 additions & 0 deletions src/main/java/blackjack/domain/card/CardPattern.java
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;
}
}
Loading