-
Notifications
You must be signed in to change notification settings - Fork 75
[정다훈] 연료 주입, 블랙잭 리뷰 요청드립니다. #33
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
base: pandahun
Are you sure you want to change the base?
Changes from all commits
2923419
a84e84b
8149941
14c46a7
aab7ec1
2fbfb59
e019f85
60cf0c1
743bf38
9adf74f
632c050
e8eec27
f1c0a6d
4e1ac2b
a4d432c
e90bbd8
19803f2
0779b13
1c020de
13e6a9d
3b6ecd3
c6d79eb
04a4bae
8773ed7
d8f6255
b11b8aa
a3a3858
e0aeab7
3b8a006
ea267e2
2794e2c
ec1ad3f
6e1f474
6bd8569
850bb0b
bc224bd
ca15d8b
f99d99e
9ed5b64
f733537
57f4cab
557cacd
fa28493
63a9ede
6660f48
8eeb941
6cead3f
8a0a431
0c72f30
103f96b
32e0ef4
d81132c
fef941b
1f4d8c7
8b2010f
a9326d5
59c320b
55bd181
ee44ffc
ed02a3a
c1a136a
8627517
b28d592
33558cd
7e56239
3200388
10f6ca9
1f86c26
aec9de9
a9917ed
7575590
d9ea429
4054963
a4f3a20
ae38381
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,88 @@ | ||
# java-blackjack | ||
# Black-Jack | ||
|
||
## 기능 목록 | ||
|
||
- [X] 참여할 사람의 이름 입력받기 | ||
|
||
- [X] 카드 나눠주기 | ||
|
||
- [X] 카드 수령 여부 | ||
|
||
- [X] 딜러의 카드 합이 16 이하이면 무조건 1장을 받아야한다. | ||
|
||
- [X] 결과 판정하기 | ||
|
||
## 기능 요구 사항 | ||
블랙잭 게임을 변형한 프로그램을 구현한다. | ||
|
||
블랙잭 게임은 딜러와 플레이어 중 카드의 합이 21 또는 21에 가장 가까운 숫자를 가지는 쪽이 이기는 게임이다. | ||
|
||
카드의 숫자 계산은 카드 숫자를 기본으로 하며, 예외로 Ace는 1 또는 11로 계산할 수 있으며, King, Queen, Jack은 각각 10으로 계산한다. | ||
|
||
게임을 시작하면 플레이어는 두 장의 카드를 지급 받으며, 두 장의 카드 숫자를 합쳐 21을 초과하지 않으면서 21에 가깝게 만들면 이긴다. 21을 넘지 않을 경우 원한다면 얼마든지 카드를 계속 뽑을 수 있다. | ||
|
||
딜러는 처음에 받은 2장의 합계가 16이하이면 반드시 1장의 카드를 추가로 받아야 하고, 17점 이상이면 추가로 받을 수 없다. | ||
|
||
게임을 완료한 후 각 플레이어별로 승패를 출력한다. | ||
|
||
## 프로그래밍 요구 사항 | ||
|
||
* 자바 코드 컨벤션을 지키면서 프로그래밍한다. | ||
* 기본적으로 Google Java Style Guide을 원칙으로 한다. | ||
* 단, 들여쓰기는 '2 spaces'가 아닌 '4 spaces'로 한다. | ||
* indent(인덴트, 들여쓰기) depth를 2를 넘지 않도록 구현한다. 1까지만 허용한다. | ||
* 예를 들어 while문 안에 if문이 있복으면 들여쓰기는 2이다. | ||
* 힌트: indent(인덴트, 들여쓰기) depth를 줄이는 좋은 방법은 함수(또는 메서드)를 분리하면 된다. | ||
* 3항 연산자를 쓰지 않는다. | ||
* else 예약어를 쓰지 않는다. | ||
* else 예약어를 쓰지 말라고 하니 switch/case로 구현하는 경우가 있는데 switch/case도 허용하지 않는다. | ||
* 힌트: if문에서 값을 반환하는 방식으로 구현하면 else 예약어를 사용하지 않아도 된다. | ||
* 모든 기능을 TDD로 구현해 단위 테스트가 존재해야 한다. 단, UI(System.out, System.in) 로직은 제외 | ||
* 핵심 로직을 구현하는 코드와 UI를 담당하는 로직을 구분한다. | ||
* UI 로직을 InputView, ResultView와 같은 클래스를 추가해 분리한다. | ||
* 함수(또는 메서드)의 길이가 10라인을 넘어가지 않도록 구현한다. | ||
* 함수(또는 메소드)가 한 가지 일만 하도록 최대한 작게 만들어라. | ||
* 배열 대신 컬렉션을 사용한다. | ||
* 모든 원시 값과 문자열을 포장한다 | ||
* 줄여 쓰지 않는다(축약 금지). | ||
* 일급 컬렉션을 쓴다. | ||
## 추가된 요구 사항 | ||
* 모든 엔티티를 작게 유지한다. | ||
* 3개 이상의 인스턴스 변수를 가진 클래스를 쓰지 않는다. | ||
* 딜러와 플레이어에서 발생하는 중복 코드를 제거해야 한다. | ||
|
||
# 연료 주입 | ||
|
||
## 기능 목록 | ||
|
||
- [X] 차량 별 주입 연료 필요량 구하기 | ||
|
||
- [X] 보고서 생성 | ||
|
||
## 기능 요구 사항 | ||
|
||
우리 회사는 렌터카를 운영하고 있다. | ||
|
||
현재 보유하고 있는 차량은 Sonata 2대, Avante 1대, K5 2대로 총 5대의 차량을 보유하고 있다. | ||
|
||
고객이 인터넷으로부터 예약할 때 여행할 목적지의 대략적인 이동거리를 입력 받는다. | ||
|
||
이 이동거리를 활용해 차량 별로 필요한 연료를 주입한다. | ||
|
||
차량 별로 주입해야 할 연료량을 확인할 수 있는 보고서를 생성해야 한다. | ||
|
||
각 차량별 연비는 다음과 같다. | ||
|
||
* Sonata : 10km/리터 | ||
|
||
* Avante : 15km/리터 | ||
|
||
* K5 : 13km/리터 | ||
|
||
## 프로그래밍 요구 사항 | ||
|
||
* 상속과 추상 메서드를 활용한다. | ||
|
||
* 위 요구사항을 if/else 절을 쓰지 않고 구현해야 한다. | ||
|
||
* 인터페이스를 적용해 구현한다. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package blackjack; | ||
|
||
import blackjack.controller.BlackJack; | ||
import blackjack.domain.request.UserNamesRequest; | ||
import blackjack.view.InputView; | ||
|
||
public class BlackjackApplication { | ||
|
||
public static void main(String[] args) { | ||
String playerNames = InputView.getPlayerNames(); | ||
BlackJack blackJack = BlackJack.init(UserNamesRequest.from(playerNames)); | ||
blackJack.runGame(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package blackjack.controller; | ||
|
||
import blackjack.domain.card.CardFactory; | ||
import blackjack.domain.card.Deck; | ||
import blackjack.domain.report.GameReports; | ||
import blackjack.domain.request.DrawRequest; | ||
import blackjack.domain.request.UserNamesRequest; | ||
import blackjack.domain.user.Dealer; | ||
import blackjack.domain.user.Player; | ||
import blackjack.domain.user.Players; | ||
import blackjack.view.InputView; | ||
import blackjack.view.OutputView; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class BlackJack { | ||
|
||
private final Players players; | ||
private final Deck deck; | ||
|
||
private BlackJack(Players players, Deck deck) { | ||
this.players = players; | ||
this.deck = deck; | ||
} | ||
|
||
public static BlackJack init(UserNamesRequest playerNames) { | ||
Dealer dealer = new Dealer(); | ||
Players candidates = playerNames.userNames() | ||
.stream() | ||
.map(Player::new) | ||
.collect(Collectors.collectingAndThen(Collectors.toList(), | ||
PandaHun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
players -> new Players(dealer, players))); | ||
CardFactory cardFactory = CardFactory.getInstance(); | ||
Deck deck = new Deck(cardFactory.createCards()); | ||
return new BlackJack(candidates, deck); | ||
} | ||
|
||
public void runGame() { | ||
spreadStartCards(); | ||
if (!players.hasBlackJack()) { | ||
drawPlayers(); | ||
drawDealer(); | ||
} | ||
GameReports reports = getResult(); | ||
showResult(reports); | ||
} | ||
|
||
private void spreadStartCards() { | ||
players.drawStartCards(deck); | ||
OutputView.printAllPlayersCard(players); | ||
} | ||
|
||
private void drawPlayers() { | ||
for (Player player : players.findOnlyPlayers()) { | ||
drawEachPlayer(player); | ||
} | ||
} | ||
|
||
private void drawEachPlayer(Player player) { | ||
while (player.isDrawable() && getPlayerRequest(player)) { | ||
player.drawCard(deck.spreadCard()); | ||
OutputView.printEachCardInfo(player); | ||
} | ||
} | ||
|
||
private boolean getPlayerRequest(Player player) { | ||
String drawRequest = InputView.getDrawRequest(player); | ||
return DrawRequest.valueOf(drawRequest) | ||
.isDrawable(); | ||
} | ||
|
||
private void drawDealer() { | ||
Dealer dealer = players.findDealer(); | ||
while (dealer.isDrawable()) { | ||
dealer.drawCard(deck.spreadCard()); | ||
OutputView.printDealerGetCard(); | ||
} | ||
} | ||
|
||
private GameReports getResult() { | ||
Dealer dealer = players.findDealer(); | ||
List<Player> candidates = players.findOnlyPlayers(); | ||
return candidates.stream() | ||
.map(dealer::createReport) | ||
.collect(Collectors.collectingAndThen(Collectors.toList(), GameReports::new)); | ||
} | ||
|
||
private void showResult(GameReports reports) { | ||
OutputView.printResultStatus(players.all()); | ||
OutputView.printReports(reports); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package blackjack.domain.card; | ||
|
||
import java.util.Objects; | ||
|
||
public class Card { | ||
|
||
private final Suit suit; | ||
private final Number number; | ||
|
||
public Card(Suit suit, Number number) { | ||
this.suit = suit; | ||
this.number = number; | ||
} | ||
|
||
public boolean isAce() { | ||
return number == Number.ACE; | ||
} | ||
|
||
public String message() { | ||
return number.message(); | ||
} | ||
|
||
public String suit() { | ||
return suit.suit(); | ||
} | ||
|
||
public int value() { | ||
return number.score(); | ||
} | ||
|
||
@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 && number == card.number; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(suit, number); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package blackjack.domain.card; | ||
|
||
import blackjack.domain.score.ScoreCalculator; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class CardBundle { | ||
|
||
private static final int BLACK_JACK_SCORE = 21; | ||
|
||
private final List<Card> cards; | ||
|
||
private CardBundle() { | ||
this.cards = new ArrayList<>(); | ||
} | ||
|
||
public static CardBundle emptyBundle() { | ||
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. CardBundle. 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.
|
||
return new CardBundle(); | ||
} | ||
|
||
public void addCard(Card card) { | ||
cards.add(card); | ||
} | ||
|
||
public int calculateScore() { | ||
return ScoreCalculator.findByCards(cards) | ||
.calculateScore(cards); | ||
Comment on lines
+27
to
+28
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.
지금의 코드에서 또한 |
||
} | ||
|
||
public List<Card> getCards() { | ||
return Collections.unmodifiableList(cards); | ||
} | ||
|
||
public boolean isBurst() { | ||
return calculateScore() > BLACK_JACK_SCORE; | ||
} | ||
|
||
public boolean isBlackJack() { | ||
return calculateScore() == BLACK_JACK_SCORE; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package blackjack.domain.card; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class CardFactory { | ||
|
||
public static CardFactory INSTANCE; | ||
|
||
private CardFactory() { | ||
} | ||
|
||
public static CardFactory getInstance() { | ||
if (INSTANCE == null) { | ||
INSTANCE = new CardFactory(); | ||
} | ||
return INSTANCE; | ||
} | ||
|
||
public List<Card> createCards() { | ||
List<Card> cards = new ArrayList<>(); | ||
for (Suit suit : Suit.values()) { | ||
createBySuit(cards, suit); | ||
} | ||
PandaHun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Collections.shuffle(cards); | ||
return cards; | ||
} | ||
|
||
private void createBySuit(List<Card> cards, Suit suit) { | ||
for (Number number : Number.values()) { | ||
cards.add(new Card(suit, number)); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package blackjack.domain.card; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Queue; | ||
|
||
public class Deck { | ||
|
||
private final Queue<Card> deck; | ||
|
||
public Deck(List<Card> cards) { | ||
this.deck = new LinkedList<>(cards); | ||
} | ||
|
||
public Card spreadCard() { | ||
return deck.poll(); | ||
} | ||
PandaHun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public int remainCardSize() { | ||
return deck.size(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package blackjack.domain.card; | ||
|
||
public enum Number { | ||
PandaHun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
ACE(1, "A"), | ||
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(10, "J"), | ||
QUEEN(10, "Q"), | ||
KING(10, "K"); | ||
|
||
private final int score; | ||
private final String message; | ||
|
||
Number(int score, String message) { | ||
this.score = score; | ||
this.message = message; | ||
} | ||
|
||
public int score() { | ||
return score; | ||
} | ||
|
||
public String message() { | ||
return message; | ||
} | ||
Comment on lines
+27
to
+33
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. 객체의 상태 값을 외부로 호출하는 메서드는 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. 저는 해당에 대해서도 |
||
} |
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.
BlackJack
클래스는 Controller의 용도로 사용하려는 것 같으나 비즈니스 로직이 상당수 존재하는 것 같아요. 🤔Controller는 상태 값을 가지지 않아야해요. 👀
BlackJackController
클래스와 비즈니스 모델인BlackJack
클래스로 분리해볼 수 있을 것 같아요. 🤗