-
Notifications
You must be signed in to change notification settings - Fork 75
[어해림] 연료주입, 블랙잭 Step1 #43
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: hae-riri
Are you sure you want to change the base?
Changes from all commits
6e7164a
dc3370c
02f2075
d0b0ed4
fe0aeaf
58d95c4
737b38b
0072001
d254e79
57ab33e
13f2df3
723a695
0c6149e
43e7536
99375ef
24d421f
4863c10
f3a00b4
ca9bc9b
a847574
cdc3af1
a1079a0
61e8084
9427d25
08557de
856da6c
60bae55
b9d844c
f37cbca
063732b
5e6fad3
380dc86
9abddc6
9c52e6a
f45209c
f5c4c7d
edecc81
610f916
45d6ee9
97461b0
17816e4
b7359f2
4d55fdb
e504b4d
8738a73
afe6bad
6f85082
381a22a
d6aa26a
3e1ba59
59e0c1f
5da9180
e5e664e
322d46c
c46df95
416d4da
277d667
1112306
22240b3
6303320
9d7cdb4
e757ec6
378836e
8625365
d74a476
9f43415
6a26f1f
2df20d1
e88ace8
fcc4680
86459c7
599d9cc
59a4259
409ed79
ed118fb
11586ce
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,78 @@ | ||
| # java-blackjack | ||
| # java-blackjack | ||
|
|
||
| ## 연료 주입 기능 목록 | ||
|
|
||
| MotorVehicle (Interface) | ||
|
|
||
| - 리터당 이동 거리를 반환 getDistancePerLiter | ||
| - 여행할 거리를 반환 getTripDistance | ||
| - 차종 이름을 반환 getName | ||
|
|
||
| Car (abstract class) (implements MotorVehicle) | ||
|
|
||
| - 거리에 따른 연료량을 계산 후 반환 getChargeQuantity | ||
| - 멤버변수 distance | ||
|
|
||
| Sonata, Avante, K5 (extends Car) | ||
|
|
||
| - 생성자로 distance 받기 | ||
| - private static final 로 연비를 가짐. (10km/리터, 15, 13) | ||
|
|
||
| RentCompany | ||
|
|
||
| - 차 List를 가짐. | ||
| - private 생성자 | ||
| - static create()을 통해 객체 생성 | ||
| - addCar(Car) 를 통해 차 List에 저장 | ||
| - generateReport 를 통해 report String 반환 | ||
|
|
||
| ## 블랙잭 | ||
|
|
||
| [Card : Denomination, Shape] | ||
|
|
||
| - [x] enum으로 1~10,J,Q,K를 구현한다. | ||
| - [x] enum으로 하트,스페이드,다이아몬드,클로버를 구현한다. | ||
| - [x] value와 shape를 합쳐 한 장의 카드를 생성한다. | ||
|
|
||
| [Person] | ||
|
|
||
| - [x] 모든 사람들은 카드 목록을 갖고 있다. | ||
| - [x] 카드 1장을 인자로 전달 받아 카드 목록에 추가한다. | ||
|
|
||
| [Player extends Person] | ||
|
|
||
| - [x] 플레이어는 추가적으로 이름을 갖고 있다. | ||
| - [x] 생성 시에 플레이어 이름만 인자로 전달 받아서 자기의 이름을 초기화한다. | ||
| - [x] 전달 받은 1장의 카드를 자신의 카드 목록에 추가한다. (Person 기능) | ||
|
|
||
| [Dealer extends Person] | ||
| 딜러가 카드를 섞어서 뽑는 역할. CardDeck으로 분리. | ||
|
|
||
| - [x] 생성 시에 CardDeck을 초기화한다. | ||
| - [x] 인자로 전달 받은 1장의 카드를 자신의 카드 목록에 추가한다. (Person 기능) | ||
| - [x] 전달 인자로 받은 장수만큼 카드를 반환한다. | ||
|
|
||
| [CardDeck] | ||
|
|
||
| - [x] 전체 카드를 만들어서 리스트로 반환한다. (static) | ||
| - [x] 인스턴스 생성 시, 만들어진 52장의 카드로 멤버변수를 초기화한다. | ||
| - [x] shuffle한 뒤 전달인자로 받은 수만큼 카드를 뽑아서 반환한다. (제거하면서 반환한다.) | ||
|
|
||
| [GameApplication] | ||
|
|
||
| - [x] GameSetup의 Dealer와 List<Player>를 입력받고, 생성된 setup 내용을 ResultView에게 넘긴다. | ||
|
|
||
| - [ ] 카드의 합이 21 이하인지 카드를 추가로 뽑을 것인지 질문한다. | ||
| - [ ] 딜러에게 필요한 장수만큼 카드를 요구한다. | ||
| - [ ] 반환 받은 카드를 통해 딜러와 플레이어들을 초기화한다. | ||
|
|
||
| [InputView] | ||
|
|
||
| -[x] 플레이어 이름을 입력받아서 쉼표 기준으로 분리한 List<String>을 반환한다. | ||
| -[x] 플레이어에게 카드를 추가로 받을 것인지 입력받는다. | ||
|
|
||
| [ResultView] | ||
|
|
||
| -[x] 딜러와 플레이어 List<>를 전달 받아 이름과 카드 목록을 출력한다. | ||
| -[x] 처음 시작 때 딜러는 1장의 카드만 출력한다. | ||
| -[ ] 딜러와 플레이어의 최종 승패를 출력한다. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package blackjack; | ||
|
|
||
| import blackjack.controller.BlackJackGame; | ||
|
|
||
| public class BlackjackApplication { | ||
|
|
||
| public static void main(String[] args) { | ||
| BlackJackGame blackJackGame = new BlackJackGame(); | ||
| blackJackGame.play(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package blackjack.controller; | ||
|
|
||
| import blackjack.domain.cards.DealerCards; | ||
| import blackjack.domain.cards.PlayerCards; | ||
| import blackjack.domain.game.GameResult; | ||
| import blackjack.domain.person.Dealer; | ||
| import blackjack.domain.person.Player; | ||
| import blackjack.view.InputView; | ||
| import blackjack.view.ResultView; | ||
| import java.util.List; | ||
|
|
||
| public class BlackJackGame { | ||
|
|
||
| private final Dealer dealer; | ||
| private final List<Player> players; | ||
|
Comment on lines
+14
to
+15
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 BlackJackGame() { | ||
| dealer = new Dealer(); | ||
| players = Player.createPlayers(InputView.getPlayerNames(), dealer); | ||
| ResultView.printSetUpResult(dealer.getOpenedCard(), players); | ||
| } | ||
|
|
||
| public void play() { | ||
| askPlayers(); | ||
| giveDealerCard(); | ||
| printGameResult(); | ||
| } | ||
|
|
||
| private void giveDealerCard() { | ||
| final DealerCards dealerCards = dealer.getDealerCards(); | ||
| if (dealerCards.canReceiveMoreCard()) { | ||
| dealerCards.addCard(dealer.getPickedCard()); | ||
| ResultView.printDealerReceiveCard(); | ||
| } | ||
| } | ||
|
|
||
| private void askPlayers() { | ||
| for (Player player : players) { | ||
| askPlayer(player); | ||
| } | ||
| } | ||
|
|
||
| private void askPlayer(Player player) { | ||
| final PlayerCards playerCards = player.getPlayerCards(); | ||
| while (playerCards.canReceiveMoreCard() && InputView.isHit(player)) { | ||
| playerCards.addCard(dealer.getPickedCard()); | ||
| } | ||
| } | ||
|
|
||
| private void printGameResult() { | ||
| ResultView.printDealerAndPlayerCardResult(dealer.getDealerCards(), players); | ||
| ResultView.printGameResult(new GameResult(dealer.getDealerCards().getSumOfCards(), players)); | ||
|
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. 디미터 법칙을 위반하고 있습니다. |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package blackjack.domain.card; | ||
|
|
||
| public class Card { | ||
|
|
||
| private final Shape shape; | ||
| private final Denomination denomination; | ||
|
|
||
| public Card(Shape shape, Denomination denomination) { | ||
| this.shape = shape; | ||
| this.denomination = denomination; | ||
| } | ||
|
|
||
| public Shape getShape() { | ||
| return shape; | ||
| } | ||
|
|
||
| public Denomination getDenomination() { | ||
| return denomination; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package blackjack.domain.card; | ||
|
|
||
| public enum Denomination { | ||
|
|
||
| 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 sign; | ||
| private final int value; | ||
|
|
||
| Denomination(String sign, int value) { | ||
| this.sign = sign; | ||
| this.value = value; | ||
| } | ||
|
|
||
| public int getValue() { | ||
| return value; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package blackjack.domain.card; | ||
|
|
||
| public enum Shape { | ||
|
|
||
| HEART("하트"), | ||
| DIAMOND("다이아몬드"), | ||
| SPADE("스페이드"), | ||
| CLUB("클로버"); | ||
|
|
||
| private final String name; | ||
|
|
||
| Shape(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package blackjack.domain.cards; | ||
|
|
||
| import blackjack.domain.card.Card; | ||
| import blackjack.domain.card.Denomination; | ||
| import blackjack.domain.card.Shape; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class CardDeck { | ||
|
|
||
| public static final int FIRST_INDEX = 0; | ||
|
|
||
| private final List<Card> cards; | ||
|
|
||
| public CardDeck() { | ||
| cards = createCardDeck(); | ||
| } | ||
|
|
||
| public Card pickOneCard() { | ||
| validateEmptyCardDeck(); | ||
| Collections.shuffle(cards); | ||
| Card pickedCard = cards.get(FIRST_INDEX); | ||
| cards.remove(FIRST_INDEX); | ||
| return pickedCard; | ||
| } | ||
|
|
||
| public List<Card> createCardDeck() { | ||
| List<Card> cards = new ArrayList<>(); | ||
| for (Shape shape : Shape.values()) { | ||
| cards.addAll(DenominationByShape(shape)); | ||
| } | ||
| return cards; | ||
| } | ||
|
|
||
| private List<Card> DenominationByShape(Shape shape) { | ||
|
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 Arrays.stream(Denomination.values()) | ||
| .map(denomination -> new Card(shape, denomination)) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| private void validateEmptyCardDeck() { | ||
| if (cards.isEmpty()) { | ||
| throw new IllegalArgumentException("[ERROR] 카드덱이 비어 카드를 뽑을 수 없습니다."); | ||
| } | ||
| } | ||
|
|
||
| public List<Card> getCards() { | ||
| return new ArrayList<>(cards); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package blackjack.domain.cards; | ||
|
|
||
| import blackjack.domain.card.Card; | ||
|
|
||
| public interface Cards { | ||
|
|
||
| /** | ||
| * 카드를 카드 목록에 추가한다. | ||
| * | ||
| * @return void | ||
| * @Param Card | ||
| */ | ||
|
Comment on lines
+7
to
+12
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. 이름으로 표현이 되니 주석은 삭제해주는건 어떨까요? |
||
| void addCard(Card card); | ||
|
|
||
| /** | ||
| * 카드 denomination 의 합을 반환 | ||
| * | ||
| * @return int | ||
| */ | ||
| int getSumOfCards(); | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package blackjack.domain.cards; | ||
|
|
||
| import blackjack.domain.card.Card; | ||
| import java.util.List; | ||
|
|
||
| public class DealerCards extends PersonCards { | ||
|
|
||
| private static final int DEALER_MAXIMUM_SUM = 16; | ||
|
|
||
| public DealerCards(List<Card> cards) { | ||
| super(cards); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean canReceiveMoreCard() { | ||
| return sum <= DEALER_MAXIMUM_SUM; | ||
| } | ||
|
|
||
| public Card getCardByIndex(int index) { | ||
| return cards.get(index); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package blackjack.domain.cards; | ||
|
|
||
| import blackjack.domain.card.Card; | ||
| import blackjack.domain.card.Denomination; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public abstract class PersonCards implements Cards { | ||
|
|
||
| protected List<Card> cards; | ||
| protected int sum; | ||
|
|
||
| public PersonCards(List<Card> cards) { | ||
| initCard(cards); | ||
| initSum(); | ||
| } | ||
|
|
||
| @Override | ||
| public void addCard(Card card) { | ||
| cards.add(card); | ||
| updateSumByDenomination(card.getDenomination()); | ||
| } | ||
|
|
||
| @Override | ||
| public int getSumOfCards() { | ||
| return sum; | ||
| } | ||
|
|
||
| abstract boolean canReceiveMoreCard(); | ||
|
|
||
| private void updateSumByDenomination(Denomination denomination) { | ||
| if (canAddBiggerValueByAce(denomination)) { | ||
| sum += 11; | ||
| return; | ||
| } | ||
| sum += denomination.getValue(); | ||
| } | ||
|
Comment on lines
+31
to
+37
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. 반환값이 없어서 이 부분에 대한 테스트가 불가능할 것 같아요. |
||
|
|
||
| private boolean canAddBiggerValueByAce(Denomination denomination) { | ||
| return denomination.equals(Denomination.ACE) && sum <= 10; | ||
| } | ||
|
|
||
| private void initCard(List<Card> cards) { | ||
| this.cards = new ArrayList<>(); | ||
| this.cards.addAll(cards); | ||
| } | ||
|
|
||
| private void initSum() { | ||
| this.cards.forEach(card -> updateSumByDenomination(card.getDenomination())); | ||
| } | ||
|
|
||
| public List<Card> getCards() { | ||
| return new ArrayList<>(cards); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package blackjack.domain.cards; | ||
|
|
||
| import blackjack.domain.card.Card; | ||
| import java.util.List; | ||
|
|
||
| public class PlayerCards extends PersonCards { | ||
|
|
||
| private static final int PLAYER_MAXIMUM_SUM = 21; | ||
|
|
||
| public PlayerCards(List<Card> cards) { | ||
| super(cards); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean canReceiveMoreCard() { | ||
| return sum <= PLAYER_MAXIMUM_SUM; | ||
| } | ||
| } |
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.
구현이 완료되었으면 완료 표시를 해주시면 어떨까요?