Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7f13e05
docs(rentcompany): README.md 작성
hyeonho8453 Feb 11, 2022
af63466
docs(rentcompany): 불필요한 파일 삭제
hyeonho8453 Feb 11, 2022
d0ece66
feat(rentcompany): Car 클래스 생성
hyeonho8453 Feb 11, 2022
11efcf5
refactor(rentcompany): Car 클래스 수정
hyeonho8453 Feb 11, 2022
c91d116
feat(rentcompany): Sonata, Avante, K5 클래스 생성
hyeonho8453 Feb 11, 2022
c27bd16
feat(rentcompany): RentCompany 클래스 생성
hyeonho8453 Feb 13, 2022
aee5205
feat(rentcompany): RentCompany 클래스 수정
hyeonho8453 Feb 13, 2022
4f354df
feat(rentcompany): RentCompany 클래스 기능 추가
hyeonho8453 Feb 13, 2022
03bda82
feat(rentcompany): RentCompany 클래스 기능 추가
hyeonho8453 Feb 13, 2022
0470c59
feat(rentcompany): RentCompanyTest 생성
hyeonho8453 Feb 13, 2022
8f83230
docs(Blackjack): 블랙잭 README 추가
Gal2o Feb 17, 2022
86813d5
feat(Blackjack): 블랙잭 패키지, 클래스 생성
Gal2o Feb 17, 2022
cdadf6d
feat(Blackjack): 블랙잭 게임을 하는 플레이어 추상 클래스 생성
Gal2o Feb 17, 2022
b241605
feat(Blackjack): GamePlayers를 상속받는 Dealer, Player 생성
Gal2o Feb 17, 2022
f288843
feat(Blackjack): GamePlayers에 필요한 사용자들이 사용하는 OwnCards 생성
Gal2o Feb 17, 2022
b1233be
feat(Blackjack): 카드의 번호, 이름을 가지는 CardNumber 생성
Gal2o Feb 17, 2022
ec4503d
feat(Blackjack): 카드의 문양을 가지는 CardType 생성
Gal2o Feb 17, 2022
5d92ef8
feat(Blackjack): CardNumber, CardType을 갖는 Card 생성
Gal2o Feb 17, 2022
0f92554
feat(Blackjack): 게임에 사용할 52장의 덱을 만드는 Deck 생성
Gal2o Feb 17, 2022
28228aa
feat(Blackjack): 게임 플레이어가 처음 두장의 카드 뽑는 메소드 생성
Gal2o Feb 17, 2022
a26e00a
feat(Blackjack): 사용자가 가진 카드를 통해 카드들의 총 합을 구하는 메서드, 블랙잭인지, 초과했는지 확인하는 …
Gal2o Feb 17, 2022
c552ba4
feat(Blackjack): 딜러, 플레이어가 카드를 뽑을 수 있는지 확인하는 오버라이딩 메서드 생성
Gal2o Feb 17, 2022
a9dbeb2
test(Blackjack): CardNumber 테스트 생성
Gal2o Feb 17, 2022
53e1520
test(Blackjack): CardType 테스트 생성
Gal2o Feb 17, 2022
38de5d3
test(Blackjack): Card 테스트 생성
Gal2o Feb 17, 2022
497ab0a
test(Blackjack): Deck 테스트 생성
Gal2o Feb 17, 2022
d6233dc
test(Blackjack): OwnCardTest 테스트 생성
Gal2o Feb 17, 2022
e8ac38b
feat(Blackjack): 딜러, 플레이어가 카드 한장 뽑는 메서드 생성
Gal2o Feb 17, 2022
dee7ffc
test(Blackjack): Gameplayers, 상속 클래스들 테스트 생성
Gal2o Feb 17, 2022
597f4c3
feat(Blackjack): player를 담는 Players 클래스 생성
Gal2o Feb 17, 2022
88febd1
test(Blackjack): Players 테스트 생성
Gal2o Feb 17, 2022
b2e2f12
feat(Blackjack): 처음 딜러, 플레이어 생성하는 InputView, Parser 생성
Gal2o Feb 17, 2022
8de7a71
feat(Blackjack): 처음 게임 시작에 필요한 ResultView-inputPlayersPrint 메서드 생성
Gal2o Feb 17, 2022
9e8dc3a
feat(Blackjack): Application에서 BlackJackController 실행 메서드 생성
Gal2o Feb 17, 2022
b637290
feat(Blackjack): 딜러, 플레이어가 처음 카드를 받고 추가 카드 받는 InputView, OutputView 생성
Gal2o Feb 17, 2022
2c62248
feat(Blackjack): 게임 결과에 사용할 GameResult, ResultValue 클래스 생성
Gal2o Feb 17, 2022
6dcec25
test(Blackjack): GameResult, ResultValue 테스트 생성
Gal2o Feb 17, 2022
3dcb065
feat(Blackjack): 게임 결과를 출력하는 메서드 생성
Gal2o Feb 17, 2022
abeae48
docs(Blackjack): 블랙잭 README 수정
Gal2o Feb 17, 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
70 changes: 69 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,69 @@
# java-blackjack
# java-rentcompany
# 기능 요구사항
- [X] 이동거리를 입력받아 자동차 객체를 생성한다.
- [X] 이동거리를 활용해 차량 별로 필요한 연료를 계산한다.
- [X] 보고서를 출력한다.

# java-blackjack
## 기능 요구 사항
- 블랙잭 게임을 변형한 프로그램을 구현한다. 블랙잭 게임은 딜러와 플레이어 중 카드의 합이 21 또는 21에 가장 가까운 숫자를 가지는 쪽이 이기는 게임이다.
- 카드의 숫자 계산은 카드 숫자를 기본으로 하며, 예외로 Ace는 1 또는 11로 계산할 수 있으며, King, Queen, Jack은 각각 10으로 계산한다.
- 게임을 시작하면 플레이어는 두 장의 카드를 지급 받으며, 두 장의 카드 숫자를 합쳐 21을 초과하지 않으면서 21에 가깝게 만들면 이긴다. 21을 넘지 않을 경우 원한다면 얼마든지 카드를 계속 뽑을 수 있다.
- 딜러는 처음에 받은 2장의 합계가 16이하이면 반드시 1장의 카드를 추가로 받아야 하고, 17점 이상이면 추가로 받을 수 없다.
- 게임을 완료한 후 각 플레이어별로 승패를 출력한다.

## 기능 설계
- GamePlayers
- GamePlayers는 딜러와 플레이어를 갖고 있다.
- Dealer
- [X] 딜러는 처음에 카드를 두 장 받는다.
- [X] 딜러는 카드의 합이 16이하이면 1장을 반드시 받고, 17 이상이면 추가로 받을 수 없다.
- Players
- Players에는 Player를 담고 있다.
- Player
- [X] 플레이어는 InputView를 통해 입력받는다.
- [X] 입력 받은 Player는 인스턴스 생성
- OwnCards
- 플레이어들이 가지고 있는 카드들
- 이 카드들을 사용하여 게임의 결과를 정한다.
- Deck
- Deck은 Card를 담고 있다.
- 게임에 사용할 52장의 카드를 생성한다.
- Card
- CardNumber
- [X] 카드 번호를 생성하는 객체
- CardType
- [X] 카드 타입을 생성하는 객체
- CardTotal
- [X] 게임 이용자들의 카드 합을 구하는 클래스
- GamePlay
- [X] 게임을 진행하는 클래스
- GameResult
- [X] 게임의 결과를 만드는 클래스
- ResultValue
- [X] 승, 무, 패를 가지고 있는 ENUM 클래스
- InputView
- ResultView

## 프로그래밍 요구 사항
- 자바 코드 컨벤션을 지키면서 프로그래밍한다.
- 기본적으로 Google Java Style Guide을 원칙으로 한다.
- 단, 들여쓰기는 '2 spaces'가 아닌 '4 spaces'로 한다.
- indent(인덴트, 들여쓰기) depth를 2를 넘지 않도록 구현한다. 1까지만 허용한다.
- 예를 들어 while문 안에 if문이 있으면 들여쓰기는 2이다.
- 힌트: indent(인덴트, 들여쓰기) depth를 줄이는 좋은 방법은 함수(또는 메서드)를 분리하면 된다.
- 3항 연산자를 쓰지 않는다.
- else 예약어, switch/case를 사용하지 않는다.
- 힌트: if문에서 값을 반환하는 방식으로 구현하면 else 예약어를 사용하지 않아도 된다.
- 모든 기능을 TDD로 구현해 단위 테스트가 존재해야 한다. 단, UI(System.out, System.in) 로직은 제외
- 핵심 로직을 구현하는 코드와 UI를 담당하는 로직을 구분한다.
- UI 로직을 InputView, ResultView와 같은 클래스를 추가해 분리한다.
- 함수(또는 메서드)의 길이가 10라인을 넘어가지 않도록 구현한다.
- 함수(또는 메소드)가 한 가지 일만 하도록 최대한 작게 만들어라.
- 배열 대신 컬렉션을 사용한다.
- 모든 원시 값과 문자열을 포장한다
- 줄여 쓰지 않는다(축약 금지).
- 일급 컬렉션을 쓴다.
- 모든 엔티티를 작게 유지한다.
- 3개 이상의 인스턴스 변수를 가진 클래스를 쓰지 않는다.
- 딜러와 플레이어에서 발생하는 중복 코드를 제거해야 한다.
10 changes: 10 additions & 0 deletions src/main/java/blackjack/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package blackjack;

import blackjack.controller.BlackJackController;

public class Application {

public static void main(String[] args) {
BlackJackController.playBlackJack();
}
}
47 changes: 47 additions & 0 deletions src/main/java/blackjack/controller/BlackJackController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package blackjack.controller;

import blackjack.domain.Dealer;
import blackjack.domain.Deck;
import blackjack.domain.GameResult;
import blackjack.domain.Players;
import blackjack.view.InputView;
import blackjack.view.ResultView;
import java.util.Objects;

public class BlackJackController {

public static void playBlackJack() {

Choose a reason for hiding this comment

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

메서드 분리를 통해서 각 로직의 책임을 나누어 보는 것이 어떨까요?

Deck deck = Deck.createDeck();
Dealer dealer = new Dealer();
Players players = Players.createPlayers(InputView.getPlayers());

ResultView resultView = new ResultView(dealer, players);
resultView.inputPlayersPrint();

dealer.initOwnCards(deck);
players.getPlayers().forEach(player -> player.initOwnCards(deck));

resultView.playerCardsPrint(dealer);
players.getPlayers().forEach(resultView::playerCardsPrint);

players.getPlayers().forEach(player -> {
while (player.isAvailDraw() && Objects.equals(InputView.doQuestion(player), "y")) {
player.drawOneCards(deck);
resultView.playerCardsPrint(player);
}
});

if (dealer.isAvailDraw()) {
dealer.drawOneCards(deck);
resultView.dealerDrawCardPrint(dealer);
}

resultView.playersGetTotalScore(dealer);
players.getPlayers().forEach(resultView::playersGetTotalScore);

resultView.gameResultMessagePrint();
GameResult gameResult = GameResult.calGameResult(dealer, players);
resultView.dealerGameResultPrint(gameResult);
resultView.playerGameResultPrint(gameResult);
Comment on lines +44 to +45

Choose a reason for hiding this comment

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

resultView 를 두 번 호출하는 행위는 return 을 두 번 하는 것과 유사한 것 같아요
한 번의 호출로 바꾸어 보는 것이 어떨까요?

}
}
28 changes: 28 additions & 0 deletions src/main/java/blackjack/domain/Card.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package blackjack.domain;

public class Card {

private final CardNumber cardNumber;
private final CardType cardType;

public Card(CardNumber cardNumber, CardType cardType) {
this.cardNumber = cardNumber;
this.cardType = cardType;
}

public String getCardName() {
return cardNumber.getName();
}

public int getCardNumber() {
return cardNumber.getScore();
}

public String getCardType() {
return cardType.getType();
}

public boolean isAceCard() {
return cardNumber.isAce();
}
}
37 changes: 37 additions & 0 deletions src/main/java/blackjack/domain/CardNumber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package blackjack.domain;

public enum CardNumber {
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 name;

CardNumber(int score, String name) {
this.score = score;
this.name = name;
}

public int getScore() {
return score;
}

public String getName() {
return name;
}

public boolean isAce() {
return this == ACE;
}
}
18 changes: 18 additions & 0 deletions src/main/java/blackjack/domain/CardType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package blackjack.domain;

public enum CardType {
SPADE("스페이드"),
CLOBER("클로버"),
HEART("하트"),
DIAMOND("다이아몬드");

private final String type;

CardType(String type) {
this.type = type;
}

public String getType() {
return type;
}
}
20 changes: 20 additions & 0 deletions src/main/java/blackjack/domain/Dealer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package blackjack.domain;

public class Dealer extends GamePlayers {

private static final String DEALER_NAME = "딜러";
private final int DEALER_DRAW_LIMIT = 16;

public Dealer() {
super(DEALER_NAME);
}

public Dealer(OwnCards ownCards) {
super(DEALER_NAME, ownCards);
}

public boolean isAvailDraw() {
return ownCards.getTotalScore() <= DEALER_DRAW_LIMIT && !ownCards.isScoreLimit();
}

}
45 changes: 45 additions & 0 deletions src/main/java/blackjack/domain/Deck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package blackjack.domain;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class Deck {

private final int TOP_OF_CARDS = 0;
private final String INVALID_DRAW = "남아있는 카드가 없습니다";
private final List<Card> cards;
Comment on lines +10 to +12

Choose a reason for hiding this comment

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

Suggested change
private final int TOP_OF_CARDS = 0;
private final String INVALID_DRAW = "남아있는 카드가 없습니다";
private final List<Card> cards;
private final int TOP_OF_CARDS = 0;
private final String INVALID_DRAW = "남아있는 카드가 없습니다";
private final List<Card> cards;

상수 영역과 변수 영역의 구분을 지어주는게 가시성이 더 좋을 것 같네요~


private Deck(List<Card> cards) {
this.cards = cards;
}

public static Deck createDeck() {
List<Card> blackJack = makeBlackJackCards();

Collections.shuffle(blackJack);

Choose a reason for hiding this comment

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

랜덤적인 요소가 있을 때 테스트하기 어려운 상태 값을 어떻게 테스트를 진행해 볼 수 있을까요?


return new Deck(blackJack);
}

private static List<Card> makeBlackJackCards() {
return Arrays.stream(CardNumber.values())
.flatMap(number ->
Arrays.stream(CardType.values())
.map(type -> new Card(number, type)))
.collect(Collectors.toList());
}
Comment on lines +26 to +32

Choose a reason for hiding this comment

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

게임이 한번이 아닌 여러번 실행할 수 있을 때 카드를 매번 52장을 생성해야할까요?
카드의 생성을 어떻게 줄여볼 수 있을까요?


public Card cardDraw() {
if (cards.isEmpty()) {
throw new RuntimeException(INVALID_DRAW);
}

return cards.remove(TOP_OF_CARDS);
}

public List<Card> getCards() {
return cards;

Choose a reason for hiding this comment

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

cards 의 주솟값이 외부에 노출이 되면 어떤 일이 일어날 수 있을까요?

}
}
39 changes: 39 additions & 0 deletions src/main/java/blackjack/domain/GamePlayers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package blackjack.domain;

public abstract class GamePlayers {

Choose a reason for hiding this comment

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

클래스 명이 복수 보다는 단수가 어울리네요 :)


private static final int INIT_CNT = 2;

protected final String playerName;
protected final OwnCards ownCards;

protected GamePlayers(String playerName) {
this.playerName = playerName;
this.ownCards = new OwnCards();
}

protected GamePlayers(String playerName, OwnCards ownCards) {
this.playerName = playerName;
this.ownCards = ownCards;
}

public abstract boolean isAvailDraw();

public void initOwnCards(Deck deck) {
for (int i = 0; i < INIT_CNT; i++) {
ownCards.addCard(deck.cardDraw());
}
}

public void drawOneCards(Deck deck) {
ownCards.addCard(deck.cardDraw());
}

public String getPlayerName() {
return playerName;
}

public OwnCards myOwnCards() {
return ownCards;
}
}
Loading