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 #10

Open
wants to merge 10 commits into
base: master
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
3 changes: 3 additions & 0 deletions .idea/.gitignore

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

1 change: 1 addition & 0 deletions .idea/.name

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

7 changes: 7 additions & 0 deletions .idea/codeStyles/Project.xml

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

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

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

6 changes: 6 additions & 0 deletions .idea/compiler.xml

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

6 changes: 6 additions & 0 deletions .idea/encodings.xml

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

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

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

5 changes: 5 additions & 0 deletions .idea/misc.xml

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

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.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,13 @@ repositories {
}

dependencies {
testImplementation "org.junit.jupiter:junit-jupiter:5.6.2"
testImplementation "org.hamcrest:hamcrest-all:1.3"
testCompile group: 'junit', name: 'junit', version: '4.12'
}
test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
}
29 changes: 21 additions & 8 deletions src/main/java/BlackJack.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
import ui.Game;

public class BlackJack {
public static void main(String[] args) {
Game game = new Game();
game.play();
}
}
//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);
// }
//}
42 changes: 42 additions & 0 deletions src/main/java/domain/Card.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package domain;

import java.util.Objects;

public class Card {

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);
}

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

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

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

private void cardShuffle(){
cards.create();
Collections.shuffle(cards.getCards());
}


public Card pick(){
Card card = cards.toList().get(0);
remove(card);
return card;
}

public void remove(Card card){

cards.getCards().remove(card);
}

}
23 changes: 23 additions & 0 deletions src/main/java/domain/CardShape.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package domain;
public enum CardShape {
SPADE("SPADE"),
HEART( "HEART"),
DIAMOND("DIAMOND"),
CLUB("CLUB");

private String shape;

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

}

public String getShape() {
return shape;
}

public void setShape(String shape) {
this.shape = shape;
}

}
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));
}
}



}
44 changes: 40 additions & 4 deletions src/main/java/domain/Dealer.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
package domain;

public class Dealer {
}
//package domain;
//import java.util.ArrayList;
//import java.util.List;
//
//public class Dealer implements Player{
//
// Cards dealerCards;
// List<Card> dealerCardList= new ArrayList<>();
// private static final int MAX_CARD=3;
//
//
// public Dealer() {
// dealerCards = new Cards(dealerCardList);
// }
// public Dealer(Cards dealerCards){
// this.dealerCards=dealerCards;
// }
// @Override
// public Cards openCard(){
// return dealerCards;
// }
//
// @Override
// public void addCard(CardDeck cardDeck){
// if(dealerCards.getCards().size()<MAX_CARD)
// dealerCards.toList(cardDeck.pick());
// }
// @Override
// public void firstPick(CardDeck cardDeck){
// dealerCards.toList(cardDeck.pick());
// dealerCards.toList(cardDeck.pick());
// System.out.println("Dealer first Point: "+dealerCards.getCards().get(0).getPattern().getScore());
// System.out.println("Dealer Second Point: "+dealerCards.getCards().get(1).getPattern().getScore());
// }
// public void additionalPick(Rule rule,CardDeck cardDeck){
// if(rule.choosePick(dealerCards))
// dealerCards.toList(cardDeck.pick());
// System.out.println("Dealer Additional Point: "+dealerCards.getCards().get(2).getPattern().getScore());
// }
//}
38 changes: 34 additions & 4 deletions src/main/java/domain/Gamer.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
package domain;

public class Gamer {
}
//package domain;
//
//
//import java.util.ArrayList;
//import java.util.List;
//
//public class Gamer implements Player{
// Cards gamerCards;
// List<Card> gamerCardList= new ArrayList<>();
// private static final int MAX_CARD=3;
// private static final int BOUNDARY_VALUE=17;
//
// public Gamer() {
// gamerCards = new Cards(gamerCardList);
// }
// public Gamer(Cards gamerCards){
// this.gamerCards=gamerCards;
// }
// @Override
// public Cards openCard(){
// return gamerCards;
// }
// @Override
// public void addCard(CardDeck cardDeck){
// gamerCards.toList(cardDeck.pick());
// }
// @Override
// public void firstPick(CardDeck cardDeck){
// gamerCards.toList(cardDeck.pick());
// gamerCards.toList(cardDeck.pick());
// System.out.println("Gamer First Point: "+gamerCards.getCards().get(0).getPattern().getScore());
// System.out.println("Gamer Second Point: "+gamerCards.getCards().get(1).getPattern().getScore());
// }
//}
32 changes: 32 additions & 0 deletions src/main/java/domain/Pattern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package domain;

public enum Pattern {
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 int score;
private String name;

Pattern(int score, String name) {
this.score = score;
this.name = name;
}
public int getScore() {
return score;
}

public String getName() {
return name;
}
}
8 changes: 8 additions & 0 deletions src/main/java/domain/Player.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package domain;
import java.util.List;

public interface Player {
public Cards openCard();
public void firstPick(CardDeck cardDeck);
public void addCard(CardDeck cardDeck);
}
Loading