Skip to content
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

Study/new ojy #11

Open
wants to merge 5 commits into
base: study/ojy
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 21 additions & 23 deletions src/main/java/BlackJack.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import domain.*;
import ui.Game;

import java.util.ArrayList;
import java.util.List;

public class BlackJack {

public static void main(String[] args) {
Game game = new Game();
game.play();
CardDeck cardDeck = new CardDeck();
List<Card> dealerCardList = new ArrayList<>();
List<Card> gamerCardList = new ArrayList<>();
Dealer dealer=new Dealer(dealerCardList);
Gamer gamer=new Gamer(gamerCardList);
Rule rule=new Rule();
gamer.firstPick(cardDeck);
dealer.firstPick(cardDeck);
dealer.pick(cardDeck);
rule.Winner(dealer,gamer);
}
}
//import domain.CardDeck;
//import domain.Dealer;
//import domain.Gamer;
//import domain.Rule;
//import ui.Game;
//
//public class BlackJack {
//
// public static void main(String[] args) {
// Game game = new Game();
// game.play();
// CardDeck cardDeck = new CardDeck();
// Dealer dealer=new Dealer();
// Gamer gamer=new Gamer();
// Rule rule=new Rule();
// gamer.firstPick(cardDeck);
// dealer.firstPick(cardDeck);
// dealer.additionalPick(rule,cardDeck);
// rule.winner(dealer,gamer);
// }
//}
73 changes: 36 additions & 37 deletions src/main/java/domain/Card.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
package domain;

import java.util.Objects;

public class Card {
private CardShape pattern;
private String character;
private int point;

public int getPoint() {
return point;
}

public Card(CardShape pattern, String character) {
this.pattern = pattern;
this.character = character;
this.point=cardPoint(character);
}
private int cardPoint(String character){
if(character.equals("A"))
return 1;
else if(character.equals("K")||character.equals("Q")||character.equals("J"))
return 10;
else
return Integer.parseInt(character);
}

public void setPattern(CardShape pattern) {
this.pattern = pattern;
}

public void setCharacter(String character) {
this.character = character;
}

public CardShape getPattern() {
return pattern;
}

public String getCharacter() {
return character;
}

public Pattern getPattern() {
return pattern;
}

public CardShape getCardShape() {
return cardShape;
}

private CardShape cardShape;
private Pattern pattern;


public Card(CardShape cardShape, Pattern pattern) {
this.cardShape = cardShape;
this.pattern = pattern;
}


public boolean isPatternEquals(Card card){
return this.pattern.equals(card.pattern);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Card card = (Card) o;
return cardShape == card.cardShape &&
pattern == card.pattern;
}

@Override
public int hashCode() {
return Objects.hash(cardShape, pattern);
}

}
81 changes: 14 additions & 67 deletions src/main/java/domain/CardDeck.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,84 +3,31 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

public class CardDeck {

List<Card> cards=new ArrayList<>();
private static final int PATTERN_A=1;
private static final int PATTERN_J=11;
private static final int PATTERN_Q=12;
private static final int PATTERN_K=13;
private static final int CARD_DECK_SIZE=13;

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

public void setCards(List<Card> cards) {
//List<Card> cardList = new ArrayList<>();
private Cards cards;
//Cards cards;
public CardDeck(Cards cards) {
this.cards = cards;
cardShuffle();
}

private static String[] patterns={
CardShape.CLUB.name(),
CardShape.DIAMOND.name(),
CardShape.HEART.name(),
CardShape.SPADE.name()
};

public List<Card> create(){
List<Card> cards = new ArrayList<>();
for(int i=0;i<4;i++){
makeCarddeck(patterns[i]);
}
return Collections.unmodifiableList(cards);
private void cardShuffle(){
cards.create();
Collections.shuffle(cards.getCards());
}

public CardDeck() {
makeDeck(patterns);
}

private void makeDeck(String[] patterns){
for(int i=0;i<4;i++)
makeCarddeck(patterns[i]);
public Card pick(){
Card card = cards.toList().get(0);
remove(card);
return card;
}

//카드덱 만들기
private void makeCarddeck(String pattern) {
for(int i=1;i<=CARD_DECK_SIZE;i++){
String character =numberToPattern(i);
Card card = new Card(CardShape.valueOf(pattern), character);
this.cards.add(card);
}
}
private String numberToPattern(int number){
if (number == PATTERN_A)
return "A";
else if (number == PATTERN_J)
return "J";
else if (number == PATTERN_Q)
return "Q";
else if (number == PATTERN_K)
return "K";
else
return String.valueOf(number);
}
public void remove(Card card){

public void addCard(Card card){
this.cards.add(card);
cards.getCards().remove(card);
}

//카드덱에서 카드 한장 뽑기(인덱스 추출)
private int drawCardIndex(){
Random random = new Random();
return random.nextInt(cards.size());
}

//카드덱에서 해당 인덱스에 있는 카드 삭제
public Card pickAndRemove(){
Card pickcard = cards.get(drawCardIndex());
this.cards.remove(pickcard);
return pickcard;
}
}
22 changes: 6 additions & 16 deletions src/main/java/domain/CardShape.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package domain;

public enum CardShape {
SPADE("♠", "SPADE"),
HEART("♥", "HEART"),
DIAMOND("♦", "DIAMOND"),
CLUB("♣", "CLUB");
SPADE("SPADE"),
HEART( "HEART"),
DIAMOND("DIAMOND"),
CLUB("CLUB");

private String shape;
private String title;

CardShape(String shape, String title) {
CardShape(String shape) {
this.shape = shape;
this.title = title;

}

public String getShape() {
Expand All @@ -22,12 +20,4 @@ public void setShape(String shape) {
this.shape = shape;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

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


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Cards {
private List<Card> cards = new ArrayList<>();

public Cards(List<Card> cards) {
this.cards=cards;
}
public List<Card> toList(){
List<Card> cardList=new ArrayList<>();
for(int i=0;i< cards.size();i++)
cardList.add(cards.get(i));
return cardList;
}

public List<Card> create(){
for(Pattern pattern: Pattern.values()){
createByPattern(cards,pattern);
}
return Collections.unmodifiableList(cards);
}

public List<Card> getCards(){
return cards;
}
private void createByPattern(List<Card> cards, Pattern pattern){
for(CardShape cardShape:CardShape.values()){
cards.add(new Card(cardShape,pattern));
}
}



}
Loading