-
Notifications
You must be signed in to change notification settings - Fork 7
[블랙잭 게임 미션] 김대욱 미션 제출합니다. #2
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: MarriedSenior
Are you sure you want to change the base?
Changes from 18 commits
cb1ce76
6005b68
6410966
a1d3103
dab31ea
3a7d2e5
e2d205d
6b61c4f
9275a17
d8ee674
603bc1c
c791a65
e056d31
323a922
61d4d4f
7f72de0
dab21cf
1c05a50
4d5ea76
2a9723b
2cf308c
dc7e71f
cb90ca1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # 기능 목록 - 블랙잭 게임 | ||
|
|
||
| ## 입력 | ||
| - 게임에 참가할 플레이어의 이름을 입력받는다 (쉼표 기준으로 분리) | ||
| - 플레이어가 카드를 더 받을지 받지 않을지 y 혹은 n으로 입력받는다. | ||
|
|
||
| ## 입력시 예외처리 | ||
| - 플레이어의 이름을 입력받을 때 타입이 맞지 않으면 예외처리 | ||
| - 플레이어가 카드를 더 받을지 유무를 입력받을 때 y 혹은 n이 아니면 예외처리 | ||
|
|
||
| ## 블랙잭 게임 구현 | ||
| - 카드의 숫자 계산은 카드 숫자를 기본으로 ace는 1 또는 11로 계산한다. | ||
| - king, queen, jack은 각각 10으로 계산한다. | ||
| - 게임을 시작하면 플레이어는 두장의 카드를 지급 받으며, 두 장의 카드 숫자가 21을 초과하지 않을 경우에는 카드를 더 뽑을 수 있음. | ||
| - 딜러는 처음에 받은 2장의 합계가 16이하면 반드시 1장의 카드를 추가로 뽑음. | ||
| - 게임의 승패는 딜러보다 높으면서 카드 숫자의 총합이 21을 넘지 않음으로 구분. | ||
|
|
||
| ## 출력 | ||
| - 게임에 참여할 사람의 입력하라는 문구 출력 | ||
| - 플레이 시작시 2장을 나누었다는 문구 출력 | ||
| - 플레이 시작시 딜러와 플레이어들이 받은 카드들을 출력 | ||
| - 각 플레이어가 카드를 더 받을지를 입력하라는 문구 출력 | ||
| - 딜러와 플레이어들이 카드를 받을 때 마다 각자의 카드 소유 현황을 출력. | ||
| - 딜러가 16이하라 카드를 한장 더 받는 경우 그 문구를 출력. | ||
| - 게임의 결과 딜러와 플레이어들의 카드 소유 현황과 점수의 합을 출력. | ||
| - 최종 승패를 출력. | ||
|
Comment on lines
+11
to
+26
Member
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,9 @@ | ||
| import controller.BlackJackController; | ||
| import view.input.InputView; | ||
| import view.output.ResultView; | ||
|
|
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| new BlackJackController(new InputView(), new ResultView()).start(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package controller; | ||
|
|
||
| import domain.BlackJackGame; | ||
| import view.input.InputView; | ||
| import view.output.ResultView; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class BlackJackController { | ||
|
|
||
| private final InputView inputView; | ||
| private final ResultView resultView; | ||
| private BlackJackGame blackJackGame; | ||
|
|
||
| public BlackJackController(InputView inputView, ResultView resultView){ | ||
| this.inputView = inputView; | ||
| this.resultView = resultView; | ||
| } | ||
|
|
||
| public void start(){ | ||
|
|
||
| } | ||
|
|
||
| public void makeBlackJackGame(List<String> playerNames){ | ||
| this.blackJackGame = new BlackJackGame(playerNames); | ||
| } | ||
| public void startBlackJackGame(){ | ||
| blackJackGame.startPhase(); | ||
| blackJackGame.playPhase(inputView.readGetCardMoreOrNot()); | ||
| blackJackGame.dealerPhase(); | ||
| } | ||
|
|
||
| public void showResultBlackJackGame(){ | ||
|
|
||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package domain; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class BlackJackGame { | ||
| private Dealer dealer = new Dealer(); | ||
| private List<Player> players; | ||
| private CardDeck cardDeck = new CardDeck(); | ||
|
Member
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. 개인적인 생각인데, 필드에서 직접적으로 객체를 직접적으로 초기화하는 경우는 크게 없는 것 같아요. 우선 구현체를 고정시켜버린다는 점에서 유연성이 낮아지는게 큰 이유라고 생각합니다. (가령 Dealer를 상속받은 CustomDealer로 블랙잭 게임을 진행하고 싶다면 위 구조는 변경되어야 하겠죠)
Author
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 List<Player> winners = new ArrayList<>(); | ||
| public BlackJackGame(List<String> splitPlayerNames) { | ||
|
Member
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. 인스턴스 필드와 생성자 사이에 개행을 넣어주세요!
Author
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. 수정했습니다. |
||
| players = splitPlayerNames.stream() | ||
| .map(playerNames -> new Player(playerNames)) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| public void startPhase() { | ||
| dealer.receiveCard(cardDeck.draw()); | ||
| dealer.receiveCard(cardDeck.draw()); | ||
| for (Player player : players) { | ||
| player.receiveCard(cardDeck.draw()); | ||
| player.receiveCard(cardDeck.draw()); | ||
| } | ||
| } | ||
| public void playPhase(String getCardMoreOrNot){ | ||
| for (Player player : players){ | ||
| eachPlayerPhase(player, getCardMoreOrNot); | ||
| } | ||
| } | ||
| public void eachPlayerPhase(Player player, String getCardMoreOrNot) { | ||
| String answer = "y"; | ||
| if(player.getScore() > 17) return; | ||
| while(answer.equals("y") || player.getScore() <= 21){ | ||
| answer = getCardMoreOrNot; | ||
| if(answer.equals("n")){ | ||
| break; | ||
| } | ||
| player.receiveCard(cardDeck.draw()); | ||
| } | ||
| } | ||
|
|
||
| public void dealerPhase(){ | ||
| if (dealer.getScore() <= 16) | ||
| dealer.receiveCard(cardDeck.draw()); | ||
| } | ||
|
|
||
| public List<Player> getWinner(){ | ||
| gattherWinner(players); | ||
| return winners; | ||
| } | ||
|
Comment on lines
+53
to
+56
Member
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 void gattherWinner(List<Player> players){ | ||
| for(Player player : players){ | ||
| if(player.getScore() >dealer.getScore()){ | ||
| player.isWinner(); | ||
| this.winners.add(player); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package domain; | ||
|
|
||
| public class Card { | ||
| private String pattern; | ||
| private String mark; | ||
| private int number; | ||
|
|
||
| Card(String pattern, String mark, int number) { | ||
| this.pattern = pattern; | ||
| this.mark = mark; | ||
| this.number = number; | ||
| } | ||
|
|
||
| Card(String pattern, int index) { | ||
| this.pattern = pattern; | ||
| this.mark = indexToMark(index); | ||
| this.number = indexToNumber(index); | ||
| } | ||
|
|
||
| private String indexToMark(int index) { | ||
| if (number == 1) { | ||
| return "A"; | ||
| } | ||
| if (number == 11) { | ||
| return "J"; | ||
| } | ||
| if (number == 12) { | ||
| return "Q"; | ||
| } | ||
| if (number == 13) { | ||
| return "K"; | ||
| } | ||
| return String.valueOf(index); | ||
| } | ||
|
|
||
| private int indexToNumber(int index) { | ||
| if (index > 10) return 10; | ||
| return number; | ||
| } | ||
|
|
||
| public int getNumber(){ | ||
| return number; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package domain; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class CardDeck { | ||
| private List<Card> deck = new CardGenerator().generateCards(); | ||
|
|
||
| public CardDeck() { | ||
| } | ||
|
|
||
| public Card draw() { | ||
| Card selectedCard = getRandomCard(); | ||
| deck.remove(selectedCard); | ||
| return selectedCard; | ||
| } | ||
|
|
||
| public Card getRandomCard(){ | ||
| int selectedCardIndex = (int) (Math.random() * deck.size()); | ||
| return deck.get(selectedCardIndex); | ||
| } | ||
|
|
||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package domain; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class CardGenerator { | ||
|
Member
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. 카드 생성 로직을 따로 클래스로 위임해주셨네요! 그런데, 현재 오로지 어떻게 생각하시나요? 객체를 분리하신 이유에 대해 궁금합니다!
Author
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. 추상화 단위로 나누어야 된다고 생각했는데 카드덱만 관리하므로 굳이 객체를 분리할 필요 없을 것 같습니다. 합치겠습니다.
Author
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 List<Card> cards = new ArrayList<>(); | ||
| private static final String[] PATTERNS = {"스페이드", "하트", "클로버", "다이아몬드"}; | ||
| private static final int MAX_INDEX = 13; | ||
|
|
||
| CardGenerator() { | ||
| } | ||
|
|
||
| public List<Card> generateCards() { | ||
| for (String pattern : PATTERNS) { | ||
| for (int i = 1; i <= MAX_INDEX; i++) { | ||
| Card card = new Card(pattern, i); | ||
| cards.add(card); | ||
| } | ||
| } | ||
| return cards; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package domain; | ||
|
|
||
| public class Dealer extends Player { | ||
| Dealer(){ | ||
| super("Dealer"); | ||
| } | ||
|
|
||
| public Card getStartCard(){ | ||
| return this.getPlayerCardList().get(0); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package domain; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class Player { | ||
| private final String playerName; | ||
| private final List<Card> playerCardList = new ArrayList<>(); | ||
| private int score = 0; | ||
| private boolean winOrNot = false; | ||
|
|
||
| public Player(String playerName){ | ||
| this.playerName = playerName; | ||
| } | ||
|
|
||
| public void receiveCard(Card receivedCard){ | ||
| playerCardList.add(receivedCard); | ||
| } | ||
|
|
||
| public String getPlayerName(){ | ||
| return this.playerName; | ||
| } | ||
|
|
||
| public List<Card> getPlayerCardList(){ | ||
| return this.playerCardList; | ||
| } | ||
|
|
||
| public int getScore() { | ||
| this.calculateScore(); | ||
| return score; | ||
| } | ||
| public void calculateScore(){ | ||
| for (Card card : playerCardList){ | ||
| score += card.getNumber(); | ||
| } | ||
| } | ||
| public void isWinner(){ | ||
| this.winOrNot = true; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package domain; | ||
|
|
||
| public class ScoreCounter { | ||
|
|
||
| } |
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.
타입이 맞지 않는다라는 것은 구현 세부적인 내용이네요! 다른 말로는 개발자가 아니라면 '타입이 뭐지?!' 라는 생각이 들 수 있습니다.기능 목록은 정말로 광화문에 있는 사람 아무나 데려왔을 때에도 이해하는게 가능할 정도로 쉽게 작성하도록 연습하면 좋습니다!
'프로그램을 위한 기능 명세서'를 작성한다기보다, '서비스에 대한 기능 명세서'를 작성한다는 느낌으로 해보시면 좋을 것 같아요 😄