-
Notifications
You must be signed in to change notification settings - Fork 3
Self feedback #1
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: master
Are you sure you want to change the base?
Changes from all commits
7ad7425
056922a
650623b
5c0e32f
ac9314a
860a0a2
e2b3c0b
7e0a35d
614d83e
532ba2b
22487bc
0b8d7f9
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 |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| [구현 기능 목록] | ||
| 1. Main 클래스 : Card, Player, Dealer, Board | ||
| 2. 클래스 객체 | ||
| 3. 지역변수 정의 | ||
| 4. 지역 메소드 정의 | ||
|
|
||
| [구현할 메서드 기능 목록(Before OMOF rule)]<br> | ||
|
|
||
|
|
||
| 1. 본 게임 전 초기설정 | ||
| - 카드 숫자 설정 | ||
| - 참여 인원 받기 | ||
| - 배팅 금액 받기 | ||
|
|
||
|
|
||
| 2. 게임 시작 | ||
| - 모두에게 카드 2장 지급 | ||
| - 한 사람의 카드 숫자 계산(합 21=>블랙잭) | ||
| - 카드 숫자 계산해서 딜러vs 플레이어 승패 정하기 (합21 or 더가까운) | ||
| - 플레이어의 카드 판단 (21 넘는다 or 안넘는다) | ||
| - 프레이어 배팅 금액 잃음 (21 넘을경우) | ||
| - 플레이어 카드 뽑기 (21 안넘을 경우) | ||
| - 보드에서 게임을 순서대로 진행하기 | ||
| - 처음 2장부터 블랙잭이 되면 베팅금액 1.5배 딜러에게 받고 둘다 블랙잭이면 플레이어는 베팅 금액 돌려받기 | ||
| - 딜러는 처음 2장의 조건으로 행동 판단. (16이하, 17이상, 21초과) | ||
|
|
||
| 3. 주안점 | ||
| - 블랙잭은 계산함수 안에서? 아니면 메서드 하나로? 메서드 하나라면 숫자 계산함수와 포함 관계는? | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import domain.board.Blackjack; | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| Blackjack board = new Blackjack(); | ||
| board.game(); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| package domain.board; | ||
|
|
||
| import domain.card.*; | ||
| import domain.user.*; | ||
| import java.util.*; | ||
|
|
||
| public class Blackjack { | ||
| Scanner sc; | ||
| List<Card> cards; | ||
| List<Player> players; | ||
| Dealer dealer; | ||
| Rule rule; | ||
|
|
||
| public Blackjack(){ | ||
| init(); | ||
| } | ||
|
|
||
| public void init() { | ||
| sc = new Scanner(System.in); | ||
| cards = CardFactory.create(); | ||
| dealer = new Dealer(); | ||
| rule = new Rule(); | ||
| rule = new Rule(); | ||
| createPlayers(); | ||
| } | ||
|
|
||
| public void createPlayers() { | ||
| String names[]; | ||
| Map<String,String> users; | ||
| names = getNameInput(); | ||
| users = setBettingMoney(names); | ||
| createPlayer(users); | ||
| } | ||
|
|
||
| public String[] getNameInput() { | ||
| String names[]; | ||
| System.out.println("게임에 참여할 사람의 이름을 입력하세요.(쉼표 기준으로 분리)"); | ||
| names = sc.next().split(","); | ||
| return names; | ||
| } | ||
|
|
||
| public Map<String,String> setBettingMoney(String[] names) { | ||
| Map<String,String> users = new HashMap<String,String>(); | ||
| String bettingMoney; | ||
| for(int i=0 ; i<names.length;i++) { | ||
| System.out.println(names[i]+"의 배팅 금액은?"); | ||
| // bettingMoney = sc.next(); | ||
| bettingMoney = "1000"; | ||
|
Contributor
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. The betting money must be input by user |
||
| users.put(names[i], bettingMoney); | ||
| } | ||
| System.out.println(); | ||
| return users; | ||
| } | ||
|
|
||
| public void createPlayer(Map<String,String> users) { | ||
| players = new ArrayList<Player>(); | ||
| for(Map.Entry<String, String> user : users.entrySet() ) { | ||
| Player player = new Player(user.getKey(),Double.parseDouble(user.getValue())); | ||
| players.add(player); | ||
| } | ||
| } | ||
| /* 딜러, 플레이어에게 카드 두장 주기. | ||
| * cards에서 카드 한장 지우고 그 카드를 유저에게 주는 giveCardTo 함수 2번호출 | ||
| * */ | ||
| public void giveTwoCardToAll() { | ||
| giveCardToDealer(dealer); | ||
| giveCardToDealer(dealer); | ||
| for(Player player : players) { | ||
| giveCardToPlayer(player); | ||
| giveCardToPlayer(player); | ||
| } | ||
| } | ||
|
|
||
| public void giveCardToPlayer(Player player) { | ||
| int random = (int)Math.random()*cards.size(); | ||
| Card card = cards.remove(random); | ||
| player.addCard(card); | ||
|
|
||
| } | ||
|
|
||
| public void giveCardToDealer(Dealer dealer) { | ||
| int random = (int)(Math.random()*(cards.size()-1)); | ||
| Card card = cards.remove(random); | ||
| dealer.addCard(card); | ||
| } | ||
|
|
||
| public void printNoticeTwoCard() { | ||
| System.out.print("딜러와 "); | ||
| for(int i=0 ; i<players.size(); i++) { | ||
| System.out.print(players.get(i).getName()); | ||
| if(i!=players.size()-1) { | ||
| System.out.print(","); | ||
| } | ||
|
Comment on lines
+91
to
+93
Contributor
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. Use Java API. With Join , you can print comma-separated list. |
||
| } | ||
| System.out.println("에게 2장을 나누었습니다."); | ||
| } | ||
|
|
||
| public void printAllPlayerCard() { | ||
| dealer.printCard(); | ||
| for(Player player:players) { | ||
| printOnePlayerCard(player); | ||
| } | ||
| System.out.println(); | ||
| } | ||
|
|
||
| public void printAllPlayerCardwithScore() { | ||
| dealer.printCard(); | ||
| System.out.println("딜러결과:"+rule.getDealerScore(dealer)); | ||
| for(Player player:players) { | ||
| printOnePlayerCard(player); | ||
| System.out.println(player.getName()+"결과:"+rule.getPlayerScore(player)); | ||
| } | ||
| System.out.println(); | ||
| } | ||
|
|
||
| public void printOnePlayerCard(Player player) { | ||
| player.printCard(); | ||
| } | ||
|
|
||
| //카드를 더 받는 메서드가 Player클래스에 없는 이유는 cards에서 card를 remove하려면 | ||
| //cards가 선언된 Board 클래스에서 이루어져야 한다. | ||
| public Player askCard(Player player) { | ||
| String ask="y"; | ||
| Scanner sc = new Scanner(System.in); | ||
| while(true){ | ||
| System.out.println(player.getName()+"는 한장의 카드를 더 받겠습니까?"); | ||
| ask = sc.next(); | ||
| if(ask.equals("n")) { | ||
| printOnePlayerCard(player); | ||
| break; | ||
| } | ||
| giveCardToPlayer(player); | ||
| printOnePlayerCard(player); | ||
| } | ||
| return player; | ||
| } | ||
|
|
||
| void decideDealerGettingCard(Dealer dealer) { | ||
| if(rule.dealerCanGetCard(dealer)) { | ||
| System.out.println("딜러는 16이하라 한장의 카드를 더 받았습니다.\n"); | ||
| giveCardToDealer(dealer); | ||
| } | ||
| } | ||
|
|
||
| public void printBettingResult() { | ||
| double dealerMoney = rule.getBettingResult(dealer, players); | ||
| System.out.println("##최종 수익"); | ||
| System.out.println("딜러: "+dealerMoney); | ||
| for(Player player:players) { | ||
| System.out.println(player.getName()+": "+(int)player.getBettingMoney()); | ||
| } | ||
| } | ||
|
|
||
| public void game() { | ||
| printNoticeTwoCard(); | ||
| giveTwoCardToAll(); | ||
| printAllPlayerCard(); | ||
| for(Player player:players){ | ||
| player = askCard(player); | ||
| } | ||
| decideDealerGettingCard(dealer); | ||
| printAllPlayerCardwithScore(); | ||
| printBettingResult(); | ||
| sc.close(); | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| package domain.board; | ||
| import java.util.List; | ||
|
|
||
| import domain.card.*; | ||
| import domain.user.*; | ||
|
|
||
| /*player, dealer를 받아 그들의 카드를 판단한다. | ||
| * ACE면 1 또는 10으로 계산 | ||
| * King, Queen, Jack 은 10으로 계산 | ||
| * */ | ||
|
|
||
| public class Rule { | ||
| private static final int BLACKJACK_SCORE = 21; | ||
| private static final int DEALER_LIMIT_SCORE =16; | ||
| private static final double BLACKJACK_BONUS = 1.5; | ||
|
|
||
| public int getPlayerScore(Player player) { | ||
| List<Card> cards = player.getCards(); | ||
| int score=0; | ||
| for(Card card:cards) { | ||
| score = score+ card.getScore(); | ||
| } | ||
| return score; | ||
| } | ||
|
|
||
| public int getDealerScore(Dealer dealer) { | ||
| List<Card> cards = dealer.getCards(); | ||
| int score=0; | ||
| for(Card card:cards) { | ||
| score = score+ card.getScore(); | ||
| } | ||
| return score; | ||
| } | ||
|
|
||
| public boolean dealerCanGetCard(Dealer dealer) { | ||
| int score = getDealerScore(dealer); | ||
| if(score<=DEALER_LIMIT_SCORE) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public boolean isPlayerBlackjack(Player player) { | ||
| if(getPlayerScore(player)==BLACKJACK_SCORE) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public boolean isDealerBlackjack(Dealer dealer) { | ||
| if(getDealerScore(dealer)==BLACKJACK_SCORE) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /* 플레이어가 블랙잭 - 1.5배 딜러에게 받는다. | ||
| * 플레이어, 딜러 동시에 블랙잭 - 플레이어는 베팅액 그대로. 아닌 플레이어는 딜러에게 뺏김. | ||
| * 딜러 21 초과 - 베팅액 돌려받는다. | ||
| * */ | ||
| public double getBettingResult(Dealer dealer, List<Player> players) { | ||
| double dealerMoney=0,playerMoney=0; | ||
| if(isDealerBlackjack(dealer)){ | ||
| for(int i=0 ; i<players.size();i++) { | ||
| if(!isPlayerBlackjack(players.get(i))) { | ||
| dealerMoney +=players.get(i).getBettingMoney(); | ||
| players.get(i).setBettingMoney(0); | ||
| } | ||
| }//블랙잭인 플레이어 - 그대로, 아닌플레이어 - 0으로 셋팅됨 | ||
| } | ||
| if(!isDealerBlackjack(dealer)){ | ||
| for(int i=0 ; i<players.size();i++) { | ||
| if(isPlayerBlackjack(players.get(i))) { | ||
| //dealerBettingMoney =players.get(i).getBettingMoney(); | ||
| playerMoney = players.get(i).getBettingMoney()*BLACKJACK_BONUS; | ||
| players.get(i).setBettingMoney(playerMoney); | ||
| } | ||
| if(!isPlayerBlackjack(players.get(i))) { | ||
| players.get(i).setBettingMoney(0); | ||
| } | ||
| } | ||
| } | ||
| if(getDealerScore(dealer)>BLACKJACK_SCORE) { | ||
|
|
||
| } | ||
| return dealerMoney; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| package domain.card; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
|
|
@@ -14,7 +13,7 @@ public static List<Card> create() { | |
| for (Symbol symbol : symbols) { | ||
| createByType(cards, symbol); | ||
| } | ||
| return Collections.unmodifiableList(cards); | ||
| return cards; | ||
|
Contributor
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. The reason It gave the card as an unmodifiable list is because after mixing it randomly in a real game, there will be no changes in the card during that game. Therefore, during the game, you must have an unmodifiable card and mix randomly before return |
||
| } | ||
|
|
||
| private static void createByType(List<Card> cards, Symbol symbol) { | ||
|
|
||
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.
unnecessary line