diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 000000000..031de024d
Binary files /dev/null and b/.DS_Store differ
diff --git a/pom.xml b/pom.xml
index c6ec0cc8b..8c958c68a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,6 +7,30 @@
io.zipcoder
casino
1.0-SNAPSHOT
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 6
+ 6
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 1.8
+ 1.8
+
+
+
+
+
+
+
+
diff --git a/src/.DS_Store b/src/.DS_Store
new file mode 100644
index 000000000..05070c47c
Binary files /dev/null and b/src/.DS_Store differ
diff --git a/src/main/.DS_Store b/src/main/.DS_Store
new file mode 100644
index 000000000..71665f4b3
Binary files /dev/null and b/src/main/.DS_Store differ
diff --git a/src/main/java/.DS_Store b/src/main/java/.DS_Store
new file mode 100644
index 000000000..e8ddb76cc
Binary files /dev/null and b/src/main/java/.DS_Store differ
diff --git a/src/main/java/io/.DS_Store b/src/main/java/io/.DS_Store
new file mode 100644
index 000000000..ed0c90129
Binary files /dev/null and b/src/main/java/io/.DS_Store differ
diff --git a/src/main/java/io/zipcoder/.DS_Store b/src/main/java/io/zipcoder/.DS_Store
new file mode 100644
index 000000000..d8fab7ed2
Binary files /dev/null and b/src/main/java/io/zipcoder/.DS_Store differ
diff --git a/src/main/java/io/zipcoder/casino/CardGame/BlackJack/Blackjack.java b/src/main/java/io/zipcoder/casino/CardGame/BlackJack/Blackjack.java
new file mode 100644
index 000000000..c42a8f3e5
--- /dev/null
+++ b/src/main/java/io/zipcoder/casino/CardGame/BlackJack/Blackjack.java
@@ -0,0 +1,121 @@
+package io.zipcoder.casino.CardGame.BlackJack;
+
+import io.zipcoder.casino.CardGame.CardGame;
+import io.zipcoder.casino.CardGame.Cards.Deck;
+import io.zipcoder.casino.GamblingGame;
+import io.zipcoder.casino.Player;
+import io.zipcoder.casino.utilities.Console;
+
+public class Blackjack extends CardGame implements GamblingGame {
+ private double pot;
+ private BlackjackPlayer blackjackPlayer;
+ private BlackjackPlayer dealer;
+ private Player player;
+ private Deck deck;
+ private double bet;
+ private int playerCardTotal;
+ private int dealerCardTotal;
+ private Console console = Console.getInstance();
+
+
+ public Blackjack(Player player) {
+ this.blackjackPlayer = new BlackjackPlayer(player);
+ this.pot = 0;
+ this.player = new Player("Dealer", 0);
+ this.dealer = new BlackjackPlayer(this.player);
+ this.deck = new Deck(10);
+ this.deck.shuffle();
+ }
+
+ public void takeBet(double amount) {
+ pot += amount;
+ }
+
+ public double payout() {
+
+ return this.pot * 2;
+
+
+ }
+
+
+ public double push(){
+ return 0;
+ }
+
+ public void play() {
+ setBet(console.getDoubleInput("How much money do you want to lose? "));
+
+ while (!validateBet()){
+ setBet(console.getDoubleInput("Whoa there, scammer! You can't bet what you don't have! "));
+
+ }
+
+ blackjackPlayer.bet(getBet());
+ takeBet(getBet());
+
+ blackjackPlayer.setHand(deck.deal(2));
+ dealer.setHand(deck.deal(2));
+
+ console.println(blackjackPlayer.getHand().toString());
+
+ console.println("Your cards total " + blackjackPlayer.sumOfHand().toString());
+
+ if (blackjackPlayer.sumOfHand() == 21){
+ console.println("Congrats, cheater! You win!");
+ blackjackPlayer.collect(payout());
+ this.pot = 0;
+ play();
+ }
+
+ else if (blackjackPlayer.sumOfHand() > 21){
+ console.println("You lose!");
+ this.pot = 0;
+ play();
+ }
+
+ else {
+ int choice = console.getIntegerInput(menu());
+
+ }
+
+
+
+
+
+
+
+
+ }
+
+ public boolean validateBet(){
+ boolean result = false;
+ if (this.bet < this.blackjackPlayer.getBlackjackPlayerWallet()) {
+ result = true;
+
+ }
+
+ return result;
+ }
+
+ public void walkAway() {
+
+ }
+
+ public double getPot(){
+ return pot;
+ }
+
+ public void setBet(double bet) {
+ this.bet = bet;
+ }
+
+ public double getBet() {
+ return this.bet;
+ }
+
+ public String menu() {
+ return "**Enter 1 to Hit\n**Enter 2 to Stand \n**Enter 3 to Double Down\n**Enter 4 to Split\n**Enter 5 to Walk away\n\nMake a Move! ";
+
+ }
+}
diff --git a/src/main/java/io/zipcoder/casino/CardGame/BlackJack/BlackjackActions.java b/src/main/java/io/zipcoder/casino/CardGame/BlackJack/BlackjackActions.java
new file mode 100644
index 000000000..c2948b5c9
--- /dev/null
+++ b/src/main/java/io/zipcoder/casino/CardGame/BlackJack/BlackjackActions.java
@@ -0,0 +1,24 @@
+package io.zipcoder.casino.CardGame.BlackJack;
+
+public enum BlackjackActions {
+
+ HIT(1),
+ STAND(2),
+ DOUBLEDOWN(3),
+ SPLIT(4),
+ WALKAWAY(5);
+
+ int actionValue;
+
+ BlackjackActions (int actionValue) {
+ this.actionValue = actionValue;
+ }
+
+
+ public int getActionValue() {
+ return actionValue;
+ }
+
+
+}
+
diff --git a/src/main/java/io/zipcoder/casino/CardGame/BlackJack/BlackjackPlayer.java b/src/main/java/io/zipcoder/casino/CardGame/BlackJack/BlackjackPlayer.java
new file mode 100644
index 000000000..f34d62d13
--- /dev/null
+++ b/src/main/java/io/zipcoder/casino/CardGame/BlackJack/BlackjackPlayer.java
@@ -0,0 +1,70 @@
+package io.zipcoder.casino.CardGame.BlackJack;
+
+import io.zipcoder.casino.CardGame.Cards.Card;
+import io.zipcoder.casino.CardGame.Cards.Deck;
+import io.zipcoder.casino.CardGame.Hand;
+import io.zipcoder.casino.GamblingPlayer;
+import io.zipcoder.casino.Player;
+
+import java.util.ArrayList;
+
+public class BlackjackPlayer implements GamblingPlayer {
+ private Hand hand;
+ private Player player;
+ private double wallet;
+
+ public BlackjackPlayer(Player player) {
+ this.player = player;
+ this.wallet = player.getWallet();
+
+ }
+
+ public double getBlackjackPlayerWallet() {
+ return this.wallet;
+
+ }
+
+ public void bet(double amount) {
+ this.wallet -= amount;
+
+ }
+
+ public void collect(double amount) {
+ this.wallet += amount;
+ }
+
+ public void hit(Deck deck) {
+ this.hand.drawCard(deck);
+ }
+
+ public void stand() {
+ }
+
+ public void doubleDown() {
+ }
+
+ public void split() {
+ }
+
+ public Integer sumOfHand() {
+ int sum = 0;
+ ArrayList cardsInHand = hand.showMyCards();
+ for (Card c : cardsInHand) {
+ sum += c.getFace().getValue();
+ }
+
+ return sum;
+ }
+
+ public Hand getHand() {
+ return this.hand;
+ }
+
+ public void setHand(ArrayList cards) {
+ this.hand = new Hand(cards);
+ }
+
+ public int numberOfCardsInHand() {
+ return this.hand.getSize();
+ }
+}
diff --git a/src/main/java/io/zipcoder/casino/CardGame/CardGame.java b/src/main/java/io/zipcoder/casino/CardGame/CardGame.java
new file mode 100644
index 000000000..48974e0ff
--- /dev/null
+++ b/src/main/java/io/zipcoder/casino/CardGame/CardGame.java
@@ -0,0 +1,13 @@
+package io.zipcoder.casino.CardGame;
+
+import io.zipcoder.casino.CardGame.Cards.Deck;
+import io.zipcoder.casino.Game;
+import io.zipcoder.casino.Player;
+
+public abstract class CardGame implements Game {
+ private Player player;
+ private Player dealer;
+ private Deck deck;
+
+
+}
diff --git a/src/main/java/io/zipcoder/casino/CardGame/Cards/Card.java b/src/main/java/io/zipcoder/casino/CardGame/Cards/Card.java
new file mode 100644
index 000000000..7758f117c
--- /dev/null
+++ b/src/main/java/io/zipcoder/casino/CardGame/Cards/Card.java
@@ -0,0 +1,32 @@
+package io.zipcoder.casino.CardGame.Cards;
+
+public class Card {
+ private Face face;
+ private Suit suit;
+
+
+ public Card (Face face, Suit suit) {
+ this.face = face;
+ this.suit = suit;
+
+
+
+ }
+
+ public Face getFace() {
+ return face;
+ }
+
+
+ public Suit getSuit() {
+ return suit;
+ }
+
+ public String getCardFaceValue(){
+ return face.getFaceValue();
+ }
+
+ public char getCardSuitValue(){
+ return suit.getSuitIcon();
+ }
+}
diff --git a/src/main/java/io/zipcoder/casino/CardGame/Cards/Deck.java b/src/main/java/io/zipcoder/casino/CardGame/Cards/Deck.java
new file mode 100644
index 000000000..19f680bf4
--- /dev/null
+++ b/src/main/java/io/zipcoder/casino/CardGame/Cards/Deck.java
@@ -0,0 +1,64 @@
+
+
+
+package io.zipcoder.casino.CardGame.Cards;
+
+
+import java.util.ArrayList;
+import java.util.Collections;
+
+public class Deck {
+ public ArrayList deck = new ArrayList<>();
+
+ public Deck(int numberOfDecks) {
+ for (int i = 0; i < numberOfDecks; i++) {
+ createDeck();
+ }
+
+
+ }
+
+ public Card getCard(int cardIndex){
+ return deck.get(cardIndex);
+
+ }
+ public void shuffle() {
+ Collections.shuffle(deck);
+
+ }
+
+ public void removeCardFromDeck(int cardIndex) {
+ deck.remove(cardIndex);
+ }
+
+ public int deckSize() {
+ return deck.size();
+ }
+
+ public ArrayList deal (int numberOfCards) {
+ ArrayList requestedCards = new ArrayList();
+ for (int i = 0; i < numberOfCards; i++ ) {
+ requestedCards.add(deck.get(i));
+ deck.remove(i);
+ }
+
+ return requestedCards;
+
+ }
+
+ private void createDeck() {
+ for (Suit s : Suit.values()) {
+ for (Face f : Face.values()) {
+ deck.add(new Card(f, s));
+
+
+ }
+ }
+ }
+
+ public String toString() {
+ return deck.toString();
+ }
+}
+
+
diff --git a/src/main/java/io/zipcoder/casino/CardGame/Cards/Face.java b/src/main/java/io/zipcoder/casino/CardGame/Cards/Face.java
new file mode 100644
index 000000000..e07901caf
--- /dev/null
+++ b/src/main/java/io/zipcoder/casino/CardGame/Cards/Face.java
@@ -0,0 +1,37 @@
+package io.zipcoder.casino.CardGame.Cards;
+
+public enum Face {
+
+ ACE("A",1),
+ 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("J", 10),
+ QUEEN("Q", 10),
+ KING("K", 10);
+
+ String faceValue;
+ int value;
+
+ private Face(String f, int v){
+ this.faceValue = f;
+ this.value = v;
+ }
+
+ public String getFaceValue(){
+ return faceValue;
+ }
+
+ public int getValue(){
+ return this.value;
+ }
+}
+
+
+
diff --git a/src/main/java/io/zipcoder/casino/CardGame/Cards/Suit.java b/src/main/java/io/zipcoder/casino/CardGame/Cards/Suit.java
new file mode 100644
index 000000000..9ecf9289e
--- /dev/null
+++ b/src/main/java/io/zipcoder/casino/CardGame/Cards/Suit.java
@@ -0,0 +1,21 @@
+package io.zipcoder.casino.CardGame.Cards;
+
+public enum Suit {
+
+ CLUBS('\u2663'),
+ SPADES('\u2660'),
+ HEARTS('\u2665'),
+ DIAMONDS('\u2666');
+
+ private char suitIcon;
+
+ private Suit(char s){
+ this.suitIcon = s;
+ }
+
+ public char getSuitIcon(){
+ return suitIcon;
+ }
+}
+
+
diff --git a/src/main/java/io/zipcoder/casino/CardGame/GoFish.java b/src/main/java/io/zipcoder/casino/CardGame/GoFish.java
new file mode 100644
index 000000000..8096d3af1
--- /dev/null
+++ b/src/main/java/io/zipcoder/casino/CardGame/GoFish.java
@@ -0,0 +1,547 @@
+package io.zipcoder.casino.CardGame;
+
+import io.zipcoder.casino.CardGame.Cards.Card;
+import io.zipcoder.casino.CardGame.Cards.Deck;
+import io.zipcoder.casino.CardGame.Cards.Face;
+import io.zipcoder.casino.Player;
+import io.zipcoder.casino.utilities.Console;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Random;
+
+public class GoFish extends CardGame {
+ private GoFishPlayer goFishPlayer;
+ private GoFishPlayer dealer;
+ private int playersScoreCounter;
+ private int dealersScoreCounter;
+ private Deck deck;
+ Console console = Console.getInstance();
+ private boolean playing = false;
+ private String input;
+ private boolean playerAskingForCard = false;
+ boolean playerDrawing = false;
+ boolean playersTurn = true;
+ boolean newTurn = true;
+ boolean dealersTurn = false;
+ boolean dealerAskingForCard = false;
+ boolean givingDealerCard = false;
+ boolean dealerDrawing = false;
+ Face requestedCard = null;
+
+ boolean deckIsEmpty = false;
+
+
+ public GoFish(Player player) {
+
+ this.goFishPlayer = new GoFishPlayer(player);
+ this.dealer = new GoFishPlayer(new Player("dealer", 0.0));
+ this.deck = new Deck(1);
+ this.deck.shuffle();
+ }
+
+
+ public void play() {
+
+ startGame();
+ checkExit();
+
+ while (playing) {
+
+ // players turn
+ while (playersTurn) {
+ checkIfOutOfCards();
+ checkAskInput();
+ checkExit();
+
+ // player asking dealer for card
+ while (playerAskingForCard) {
+ checkIfOutOfCards();
+ askDealerForCard();
+ checkExit();
+ }
+
+ // if dealer has card requested by player
+ if ((requestedCard != null) && (input.toLowerCase().equals("ask") || input.toLowerCase().equals("type draw"))) {
+ checkIfOutOfCards();
+ dealerResponse();
+ checkExit();
+
+ // if player has to draw
+ checkDrawInput();
+ checkIfDeckIsEmpty();
+ checkIfOutOfCards();
+ checkExit();
+ while (playerDrawing) {
+ playerDraw();
+ checkExit();
+ }
+ }
+ }
+
+ // dealers turn
+ while (dealersTurn) {
+
+ checkIfOutOfCards();
+ checkExit();
+ // card dealer is asking player for
+ Face dealersRequestedCard = getDealersRequestedCard();
+
+ // dealer requests card
+ while (dealerAskingForCard) {
+ checkIfOutOfCards();
+ checkExit();
+ console.println("\nThe dealer requested the card " + dealersRequestedCard + ".\n\n" + goFishPlayer.getHand().toString());
+ respondToDealer(dealersRequestedCard);
+ }
+
+ // player has card to give to dealer
+ if (givingDealerCard) {
+ checkIfOutOfCards();
+ checkExit();
+ giveDealerCard(dealersRequestedCard);
+ }
+
+ // dealer drawing
+ checkIfDeckIsEmpty();
+ checkExit();
+ if (dealerDrawing) {
+ checkIfOutOfCards();
+ checkExit();
+ dealerDraw(dealersRequestedCard);
+
+ // dealer did not draw the requested card -- switch to players turn
+ if (dealerDrawing) {
+ checkExit();
+ checkIfOutOfCards();
+ dealersTurn = false;
+ dealerDrawing = false;
+ playersTurn = true;
+ }
+ }
+ }
+ }
+ }
+
+
+ public Card getLastCard(GoFishPlayer player) {
+
+ ArrayList cards = player.getHand().showMyCards();
+
+ Card lastCard = player.getHand().showMyCards().get(cards.size() - 1);
+
+ return lastCard;
+ }
+
+
+
+
+ public String getCardOptions() {
+ return "\n" + Arrays.toString(Face.values()) + "\n";
+ }
+
+ public void updatePlayerScore() {
+ playersScoreCounter = goFishPlayer.getCounter4();
+ }
+
+ public void updateDealerScore() {
+ dealersScoreCounter = dealer.getCounter4();
+ }
+
+
+ public GoFishPlayer getGoFishPlayer() {
+ return goFishPlayer;
+ }
+
+ public GoFishPlayer getDealer() {
+ return dealer;
+ }
+
+ public int getPlayersScoreCounter() {
+ return playersScoreCounter;
+ }
+
+ public int getDealersScoreCounter() {
+ return dealersScoreCounter;
+ }
+
+
+ // Starting the game asking for the initial deal of 7 cards for each of the players.
+ // cHeck if the initial dealt cards already contains any 4 of a kind if yes updates the player's scores.
+
+ public void startGame() {
+
+ input = console.getStringInput("Welcome to Go Fish! Type 'deal' to play!");
+
+ if (input.equals("deal")) {
+ goFishPlayer.getHand().addCardsToHand(deck.deal(7));
+ dealer.getHand().addCardsToHand(deck.deal(7));
+ playing = true;
+
+ console.println(goFishPlayer.getHand().toString());
+
+ if (goFishPlayer.fourOfAKindFinder()) {
+ updatePlayerScore();
+ console.println("Wow! You were dealt four of a kind! Your new score is %d.", playersScoreCounter);
+ }
+
+ if (dealer.fourOfAKindFinder()) {
+ updateDealerScore();
+ console.println("The dealer was dealt four of a kind! The dealers score is %d.", dealersScoreCounter);
+ }
+ }
+ }
+
+
+ public void checkAskInput() {
+ if (newTurn) {
+ input = console.getStringInput("\nType 'ASK' to ask for a card.");
+ }
+ if (input.toLowerCase().equals("ask")) {
+ playerAskingForCard = true;
+ }
+ }
+
+
+ public void askDealerForCard() {
+ console.println("\n" + goFishPlayer.getHand().toString());
+ String cardInput = console.getStringInput("Enter the card you want to ask the dealer for!\n" + getCardOptions());
+ try {
+ requestedCard = Face.valueOf(cardInput.toUpperCase());
+ playerAskingForCard = false;
+ } catch (IllegalArgumentException iae) {
+ console.println("Invalid card requested.\n");
+
+ }
+ }
+
+
+ public void dealerResponse() {
+ if (dealer.hasRequestedCard(requestedCard)) {
+ goFishPlayer.requestCard(dealer, requestedCard);
+ console.println("\n" + goFishPlayer.getHand().toString());
+ console.println("The dealer gave you all their " + requestedCard.name() + " cards! Go again!\n");
+
+ if (goFishPlayer.fourOfAKindFinder()) {
+ updatePlayerScore();
+ console.println("\nYou got four of a kind! Your new score is %d.", playersScoreCounter);
+ playerAskingForCard = true;
+ }
+ } else {
+ input = console.getStringInput("\nThe dealer does not have any " + requestedCard.name() + " cards. Enter 'DRAW' to Go Fish!");
+ }
+ }
+
+ public void checkDrawInput() {
+ if (input.toLowerCase().equals("draw")) {
+ playerDrawing = true;
+ newTurn = true;
+ } else if (input.toLowerCase().equals("ask")) {
+ newTurn = true;
+ } else {
+ console.println("Invalid input.");
+ newTurn = false;
+ input = "type draw";
+ }
+ }
+
+ public void playerDraw() {
+ goFishPlayer.getHand().drawCard(deck);
+ printPlayersDraw();
+ if (goFishPlayer.fourOfAKindFinder()) {
+ updatePlayerScore();
+ console.println("You got 4 of a kind! Your new score is %d!\n", playersScoreCounter);
+ }
+ }
+
+ public void printPlayersDraw() {
+ if (getLastCard(goFishPlayer).getFace().equals(requestedCard)) {
+
+ console.println("You drew a %s! Go again!", requestedCard.name());
+ playerDrawing = false;
+ playerAskingForCard = true;
+ checkIfDeckIsEmpty();
+ } else {
+ console.println("\n" + goFishPlayer.getHand().toString());
+ console.println("You drew a %s. It's the dealer's turn.", getLastCard(goFishPlayer).getFace().name());
+ playerDrawing = false;
+ playersTurn = false;
+ dealersTurn = true;
+ dealerAskingForCard = true;
+ }
+ }
+
+ public Face getDealersRequestedCard() {
+ int sizeOfDealersHand = dealer.getHand().getSize();
+ Face dealersRequestedCard;
+ Random random = new Random();
+ if(sizeOfDealersHand >0) {
+ Integer indexOfCard = random.nextInt(sizeOfDealersHand);
+ dealersRequestedCard = dealer.getHand().showMyCards().get(indexOfCard).getFace();
+ }
+ else{
+ dealersRequestedCard = Face.ACE;
+ }
+
+ return dealersRequestedCard;
+ }
+
+
+ public void respondToDealer(Face dealersRequestedCard) {
+ if (goFishPlayer.hasRequestedCard(dealersRequestedCard)) {
+ input = console.getStringInput("You have the card the dealer requested. Type 'GIVE' to it to the dealer.");
+ if (!input.toLowerCase().equals("give")) {
+ console.println("Invalid input.");
+ } else {
+ dealerAskingForCard = false;
+ givingDealerCard = true;
+ }
+ } else {
+ input = console.getStringInput("You don't have the requested card! Tell the dealer to 'GO FISH'.");
+ if (input.toLowerCase().equals("go fish")) {
+ dealerAskingForCard = false;
+ dealerDrawing = true;
+ } else {
+ console.println("Invalid input.");
+ }
+ }
+ }
+
+
+ public void dealerDraw(Face dealersRequestedCard) {
+ dealer.getHand().drawCard(deck);
+
+ if (getLastCard(dealer).getFace().equals(dealersRequestedCard)) {
+ console.println("The dealer drew the card they requested. It's their turn again!");
+ dealerDrawing = false;
+ dealerAskingForCard = true;
+ }
+ if (dealer.fourOfAKindFinder()) {
+ updateDealerScore();
+ console.println("The dealer got 4 of a kind. Their score is %d", dealersScoreCounter);
+ }
+ }
+
+
+ public void giveDealerCard(Face dealersRequestedCard) {
+ dealer.requestCard(goFishPlayer, dealersRequestedCard);
+
+ if (dealer.fourOfAKindFinder()) {
+ updateDealerScore();
+ console.println("The dealer got 4 of a kind. Their score is %d", dealersScoreCounter);
+ }
+ givingDealerCard = false;
+ dealerAskingForCard = true;
+ }
+
+
+ public boolean deckIsEmpty(Deck deck) {
+
+ if (deck.deckSize() <= 1) {
+ this.deckIsEmpty = true;
+ return true;
+ }
+
+ return false;
+ }
+
+
+ public boolean handHasCards(GoFishPlayer goFishPlayer) {
+ return goFishPlayer.isPlayersHandNotEmpty();
+ }
+
+
+ public void drawNewCardsIfHandIsEmpty(GoFishPlayer goFishPlayer) {
+ if (!handHasCards(goFishPlayer)) {
+ if (deck.deckSize() > 7) {
+ deck.deal(7);
+ console.println("Hand is empty. Dealing 7 more cards.");
+ } else if (!deckIsEmpty) {
+ deck.deal(deck.deckSize() - 1);
+ deckIsEmpty = true;
+ console.println("Hand is empty. Dealing the rest of the cards in the deck.");
+ } else {
+ playing = false;
+ endOfGameMessage(goFishPlayer);
+ }
+ }
+ }
+
+ public void checkIfOutOfCards(){
+ drawNewCardsIfHandIsEmpty(goFishPlayer);
+ drawNewCardsIfHandIsEmpty(dealer);
+ }
+
+ public void checkIfDeckIsEmpty(){
+ if (deckIsEmpty(deck)){
+ playerDrawing = false;
+ dealerDrawing = false;
+ console.println("The deck is empty so there are no cards to draw.");
+ }
+ }
+
+
+ public void endOfGameMessage(GoFishPlayer goFishPlayer){
+ setAllBooleansFalse();
+ if (goFishPlayer.equals(dealer)) {
+ console.println("The deck is empty and the dealer is out of cards!");
+ }
+ if (goFishPlayer.equals(this.goFishPlayer)){
+ console.println("The deck is empty and you are out of cards!");
+ }
+ console.println("Your score is %d. The dealer's score is %d.", playersScoreCounter, dealersScoreCounter);
+ if(playersScoreCounter > dealersScoreCounter){
+ console.println("You win!!!!! You are a Go Fish wizard!");
+ }
+ else{
+ console.println("You lose! Better luck next time!");
+ }
+ }
+
+ public void setAllBooleansFalse(){
+ playing = false;
+ playerAskingForCard = false;
+ playerDrawing = false;
+ playersTurn = false;
+ newTurn = false;
+ dealersTurn = false;
+ dealerAskingForCard = false;
+ givingDealerCard = false;
+ dealerDrawing = false;
+ requestedCard = null;
+ }
+
+ public void checkExit(){
+ if("exit".equals(input)){
+ walkAway();
+ }
+ }
+
+ public void walkAway() {
+ setAllBooleansFalse();
+ console.println("Thanks for playing Go Fish!");
+ console.println("Your score is %d. The dealer's score is %d.", playersScoreCounter, dealersScoreCounter);
+ }
+
+
+
+ public void setGoFishPlayer(GoFishPlayer goFishPlayer) {
+ this.goFishPlayer = goFishPlayer;
+ }
+
+ public void setDealer(GoFishPlayer dealer) {
+ this.dealer = dealer;
+ }
+
+ public void setPlayersScoreCounter(int playersScoreCounter) {
+ this.playersScoreCounter = playersScoreCounter;
+ }
+
+ public void setDealersScoreCounter(int dealersScoreCounter) {
+ this.dealersScoreCounter = dealersScoreCounter;
+ }
+
+ public Deck getDeck() {
+ return deck;
+ }
+
+ public void setDeck(Deck deck) {
+ this.deck = deck;
+ }
+
+ public Console getConsole() {
+ return console;
+ }
+
+ public void setConsole(Console console) {
+ this.console = console;
+ }
+
+ public boolean isPlaying() {
+ return playing;
+ }
+
+ public void setPlaying(boolean playing) {
+ this.playing = playing;
+ }
+
+ public String getInput() {
+ return input;
+ }
+
+ public void setInput(String input) {
+ this.input = input;
+ }
+
+ public boolean isPlayerAskingForCard() {
+ return playerAskingForCard;
+ }
+
+ public void setPlayerAskingForCard(boolean playerAskingForCard) {
+ this.playerAskingForCard = playerAskingForCard;
+ }
+
+ public boolean isPlayerDrawing() {
+ return playerDrawing;
+ }
+
+ public void setPlayerDrawing(boolean playerDrawing) {
+ this.playerDrawing = playerDrawing;
+ }
+
+ public boolean isPlayersTurn() {
+ return playersTurn;
+ }
+
+ public void setPlayersTurn(boolean playersTurn) {
+ this.playersTurn = playersTurn;
+ }
+
+ public boolean isNewTurn() {
+ return newTurn;
+ }
+
+ public void setNewTurn(boolean newTurn) {
+ this.newTurn = newTurn;
+ }
+
+ public boolean isDealersTurn() {
+ return dealersTurn;
+ }
+
+ public void setDealersTurn(boolean dealersTurn) {
+ this.dealersTurn = dealersTurn;
+ }
+
+ public boolean isDealerAskingForCard() {
+ return dealerAskingForCard;
+ }
+
+ public void setDealerAskingForCard(boolean dealerAskingForCard) {
+ this.dealerAskingForCard = dealerAskingForCard;
+ }
+
+ public boolean isGivingDealerCard() {
+ return givingDealerCard;
+ }
+
+ public void setGivingDealerCard(boolean givingDealerCard) {
+ this.givingDealerCard = givingDealerCard;
+ }
+
+ public boolean isDealerDrawing() {
+ return dealerDrawing;
+ }
+
+ public void setDealerDrawing(boolean dealerDrawing) {
+ this.dealerDrawing = dealerDrawing;
+ }
+
+ public Face getRequestedCard() {
+ return requestedCard;
+ }
+
+ public void setRequestedCard(Face requestedCard) {
+ this.requestedCard = requestedCard;
+ }
+}
diff --git a/src/main/java/io/zipcoder/casino/CardGame/GoFishPlayer.java b/src/main/java/io/zipcoder/casino/CardGame/GoFishPlayer.java
new file mode 100644
index 000000000..14705190f
--- /dev/null
+++ b/src/main/java/io/zipcoder/casino/CardGame/GoFishPlayer.java
@@ -0,0 +1,271 @@
+package io.zipcoder.casino.CardGame;
+
+import io.zipcoder.casino.CardGame.Cards.Card;
+import io.zipcoder.casino.CardGame.Cards.Deck;
+import io.zipcoder.casino.CardGame.Cards.Face;
+import io.zipcoder.casino.Player;
+import io.zipcoder.casino.utilities.Console;
+
+import javax.swing.*;
+import java.util.ArrayList;
+
+import static io.zipcoder.casino.CardGame.Cards.Face.*;
+
+public class GoFishPlayer {
+ private Hand hand;
+ private String name;
+ private Player player;
+
+ // Four of a kind counter
+ private int counter4 = 0;
+
+
+
+ boolean playersHandNotEmpty;
+
+
+ // Constructor
+
+ public GoFishPlayer(Player player) {
+
+ this.name = player.getName();
+ this.player = player;
+ this.hand = new Hand(new ArrayList<>());
+
+
+ }
+
+ public int getCounter4() {
+ return counter4;
+ }
+
+ public Hand getHand() {
+ return hand;
+ }
+
+ public Player getPlayer() {
+ return player;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ // method return boolean to check whether the opponent has the requested face
+ public boolean hasRequestedCard(Face cardRequested) {
+
+ for (Card card : hand.showMyCards()) {
+
+ if (card.getFace().equals(cardRequested)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ //A player is requesting a particular Face of Card from the opponent.
+ //Once the particular face enum is requested, check opponents hand for that face if true return all the cards in opponents hands having the same face to the requesting player's hand.
+ // Adds the cards to the player's deck and removes the cards from the other player.
+ public void requestCard(GoFishPlayer otherPlayer, Face face) {
+
+ ArrayList cardsInHand = otherPlayer.hand.showMyCards();
+
+ ArrayList cardsToRemove = new ArrayList<>();
+
+
+ for (Card card : cardsInHand) {
+
+ if (card.getFace().equals(face)) {
+
+ cardsToRemove.add(card);
+ }
+
+ }
+
+ otherPlayer.getHand().removeCardsFromHand(cardsToRemove);
+ hand.addCardsToHand(cardsToRemove);
+
+ }
+
+
+ // Provided that a player has a particular face 4 times the player can lay stack of 4 of a kind.
+ public void layDown4OfAKind(Face face4) {
+
+ ArrayList fourOfAKind = new ArrayList<>();
+ for (Card c : hand.showMyCards()) {
+ if (c.getFace().equals(face4)) {
+ fourOfAKind.add(c);
+ }
+ }
+
+ hand.removeCardsFromHand(fourOfAKind);
+ counter4++;
+
+
+ }
+
+
+ public Integer[] getCardCountInHand() {
+ Integer[] counter = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+
+
+ for (Card card : hand.showMyCards()) {
+
+ Face face = card.getFace();
+
+ switch (face) {
+
+ case ACE:
+
+ counter[0]++;
+ break;
+
+ case TWO:
+ counter[1]++;
+ break;
+
+ case THREE:
+ counter[2]++;
+ break;
+
+ case FOUR:
+ counter[3]++;
+ break;
+
+ case FIVE:
+ counter[4]++;
+ break;
+
+ case SIX:
+ counter[5]++;
+ break;
+
+ case SEVEN:
+ counter[6]++;
+ break;
+
+ case EIGHT:
+ counter[7]++;
+ break;
+
+ case NINE:
+ counter[8]++;
+ break;
+
+ case TEN:
+ counter[9]++;
+ break;
+
+ case JACK:
+ counter[10]++;
+ break;
+
+ case QUEEN:
+ counter[11]++;
+ break;
+
+ case KING:
+ counter[12]++;
+ break;
+ }
+ }
+ return counter;
+ }
+
+ public boolean fourOfAKindFinder() {
+
+ Integer[] cardCounter = getCardCountInHand();
+ Boolean hasFourOfAKind = false;
+
+ for (int i = 0; i < 13; i++) {
+ if (cardCounter[i] == 4) {
+ if (i == 0) {
+ layDown4OfAKind(Face.ACE);
+ hasFourOfAKind = true;
+ }
+ if (i == 1) {
+ layDown4OfAKind(Face.TWO);
+ hasFourOfAKind = true;
+ }
+ if (i == 2) {
+ layDown4OfAKind(Face.THREE);
+ hasFourOfAKind = true;
+ }
+ if (i == 3) {
+ layDown4OfAKind(Face.FOUR);
+ hasFourOfAKind = true;
+ }
+ if (i == 4) {
+ layDown4OfAKind(Face.FIVE);
+ hasFourOfAKind = true;
+ }
+ if (i == 5) {
+ layDown4OfAKind(Face.SIX);
+ hasFourOfAKind = true;
+ }
+ if (i == 6) {
+ layDown4OfAKind(Face.SEVEN);
+ hasFourOfAKind = true;
+ }
+ if (i == 7) {
+ layDown4OfAKind(Face.EIGHT);
+ hasFourOfAKind = true;
+ }
+ if (i == 8) {
+ layDown4OfAKind(Face.NINE);
+ hasFourOfAKind = true;
+ }
+ if (i == 9) {
+ layDown4OfAKind(Face.TEN);
+ hasFourOfAKind = true;
+ }
+ if (i == 10) {
+ layDown4OfAKind(Face.JACK);
+ hasFourOfAKind = true;
+ }
+ if (i == 11) {
+ layDown4OfAKind(Face.QUEEN);
+ hasFourOfAKind = true;
+ }
+ if (i == 12) {
+ layDown4OfAKind(Face.KING);
+ hasFourOfAKind = true;
+ }
+ }
+ }
+ return hasFourOfAKind;
+ }
+
+ public void setHand(Hand hand) {
+ this.hand = hand;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setPlayer(Player player) {
+ this.player = player;
+ }
+
+ public void setCounter4(int counter4) {
+ this.counter4 = counter4;
+ }
+
+ public boolean isPlayersHandNotEmpty (){
+
+ if(getHand().getSize() > 0){
+
+ return true;
+ }
+
+ else {
+
+ return false;
+ }
+
+ }
+
+
+}
diff --git a/src/main/java/io/zipcoder/casino/CardGame/Hand.java b/src/main/java/io/zipcoder/casino/CardGame/Hand.java
new file mode 100644
index 000000000..eed7136c5
--- /dev/null
+++ b/src/main/java/io/zipcoder/casino/CardGame/Hand.java
@@ -0,0 +1,58 @@
+package io.zipcoder.casino.CardGame;
+
+import io.zipcoder.casino.CardGame.Cards.Card;
+import io.zipcoder.casino.CardGame.Cards.Deck;
+import io.zipcoder.casino.CardGame.Cards.Suit;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+
+public class Hand {
+ private int size;
+ private ArrayList cards = new ArrayList<>();
+
+ public Hand(ArrayList cards) {
+ this.cards = cards;
+ }
+
+ public void drawCard(Deck deck) {
+ cards.add(deck.getCard(0));
+ deck.removeCardFromDeck(0);
+ }
+
+ public ArrayList showMyCards() {
+ return cards;
+ }
+
+ public void addCardsToHand(ArrayList cards) {
+ this.cards.addAll(cards);
+ }
+
+ public void removeCardsFromHand(ArrayList cards) {
+ this.cards.removeAll(cards);
+
+
+ }
+
+
+
+ public String toString(){
+ String cardsInHand = "";
+
+ for (Card c: cards) {
+
+ cardsInHand += "| " + c.getCardFaceValue() + " " + c.getCardSuitValue() + " | ";
+
+ }
+
+ cardsInHand += "\n";
+
+ return cardsInHand;
+ }
+
+ public int getSize() {
+ return cards.size();
+ }
+}
+
+
diff --git a/src/main/java/io/zipcoder/casino/Casino.java b/src/main/java/io/zipcoder/casino/Casino.java
index 16ca0dd74..3d2b59bf6 100644
--- a/src/main/java/io/zipcoder/casino/Casino.java
+++ b/src/main/java/io/zipcoder/casino/Casino.java
@@ -1,8 +1,93 @@
package io.zipcoder.casino;
+import io.zipcoder.casino.CardGame.BlackJack.Blackjack;
+import io.zipcoder.casino.CardGame.GoFish;
+import io.zipcoder.casino.DiceGame.Craps;
+import io.zipcoder.casino.DiceGame.Yahtzee;
+import io.zipcoder.casino.utilities.Console;
+
public class Casino {
+ private static Player player;
+ private static Game game;
+
+ public static Player getPlayer() {
+ return player;
+ }
+
+ public static void setPlayer(Player player) {
+ Casino.player = player;
+ }
+
+ public static void setGame(Game game) {
+ Casino.game = game;
+ }
+
+ public static Game getGame(){
+ return game;
+ }
+
public static void main(String[] args) {
- // write your tests before you start fucking with this
+ Casino.run();
+ }
+
+
+ public static void run() {
+ Console console = Console.getInstance();
+ boolean running = true;
+
+ console.println(" \n" +
+ "⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁\n" +
+ "⚅ ♠ ♣ ♥ ♦ ♠ ♣ ♥ ♦ ♠ ♣ ♥ ♦ ♠ ♣ ♥ ♦ ♠ ♣ ♥ ♦ ♠ ♣ ♥ ♦ ♠ ♣ ♥ ♦ ♠ ♣ ♥ ♦ ♠ ♣ ♥ ♦ ⚂\n" +
+ "⚄ ♦ ♠ ⚃\n" +
+ "⚃ ♥ ♠---. .--♥ ♦ .--♠ ♣ ⚄\n" +
+ "⚂ ♣ / ♣ : | : ♣ ♥ ⚅\n" +
+ "⚁ ♠ / . ♦,-. | .-. .-.| .-. | .-.♦ .--♥ . .--. .-. ♦ ⚀\n" +
+ "⚀ ♦ / | | ) : ( )( |(.-' : ( ) `--. | | |( ) ♠ ⚁\n" +
+ "⚅ ♥ '---♥-' `-|`-' `--♥`-' `-'`♠`--♦ `--♣`-'`-♣--'-' `-♠ `♥`-' ♣ ⚂\n" +
+ "⚄ ♣ | ♥ ⚃\n" +
+ "⚃ ♠ ♥ ♦ ⚄\n" +
+ "⚂ ♦ ♠ ♣ ♥ ♦ ♠ ♣ ♥ ♦ ♠ ♣ ♥ ♦ ♠ ♣ ♥ ♦ ♠ ♣ ♥ ♦ ♠ ♣ ♥ ♦ ♠ ♣ ♥ ♦ ♠ ♣ ♥ ♦ ♠ ♣ ♠ ⚅\n" +
+ "⚁ ⚀ ⚅ ⚄ ⚃ ⚂ ⚁ ⚀ ⚅ ⚄ ⚃ ⚂ ⚁ ⚀ ⚅ ⚄ ⚃ ⚂ ⚁ ⚀ ⚅ ⚄ ⚃ ⚂ ⚁ ⚀ ⚅ ⚄ ⚃ ⚂ ⚁ ⚀ ⚅ ⚄ ⚃ ⚂ ⚁ ⚀\n");
+
+ String name = console.getStringInput("Welcome to the Zip Code Casino! What is your name?");
+ Double wallet = console.getDoubleInput("\nThanks for playing, %s! How much money will you be gambling?", name);
+ Casino.setPlayer(new Player(name, wallet));
+
+ while (running) {
+ console.println("\nWhat game would you like to play, %s?", name);
+ String gameToPlay = console.getStringInput("We have Blackjack, Craps, Yahtzee, and Go Fish!");
+
+ switch (gameToPlay.toLowerCase()) {
+
+ case "yahtzee":
+ Casino.setGame(new Yahtzee(player));
+ Casino.game.play();
+ break;
+
+ case "blackjack":
+ Casino.setGame(new Blackjack(player));
+ Casino.game.play();
+ break;
+
+ case "craps":
+ Casino.setGame(new Craps(player));
+ Casino.game.play();
+ break;
+
+ case "go fish":
+ Casino.setGame(new GoFish(player));
+ Casino.game.play();
+ break;
+
+ case "exit":
+ running = false;
+ console.println("Bye %s! Thank you for playing at the Zip Code Casino!", name);
+ break;
+
+ default:
+ console.println("Invalid Game! Try again!");
+ }
+ }
}
}
diff --git a/src/main/java/io/zipcoder/casino/DiceGame/Craps.java b/src/main/java/io/zipcoder/casino/DiceGame/Craps.java
new file mode 100644
index 000000000..efbb52645
--- /dev/null
+++ b/src/main/java/io/zipcoder/casino/DiceGame/Craps.java
@@ -0,0 +1,331 @@
+package io.zipcoder.casino.DiceGame;
+
+import io.zipcoder.casino.GamblingGame;
+import io.zipcoder.casino.GamblingPlayer;
+import io.zipcoder.casino.Player;
+import io.zipcoder.casino.utilities.Console;
+
+import java.util.ArrayList;
+import java.util.Collections;
+
+public class Craps extends DiceGame implements GamblingGame {
+
+ Console crapsConsole = Console.getInstance();
+
+ private CrapsPlayer crapsPlayer;
+ private ArrayList rolledDice;
+ private Integer summedRoll;
+ private Boolean pointOn;
+
+ private int pointNumber;
+ private int comePointNumber;
+ private int hardwayNumber;
+
+ private double passLinePot;
+ private double passLineOddsPot;
+ private double comeLinePot;
+ private double comeLineOddsPot;
+ private double hardWaysPot;
+ private double fieledPot;
+ private double placePot;
+
+ ArrayList fieldNumbers = new ArrayList();
+ ArrayList pointNumbers = new ArrayList();
+ ArrayList winningPointLineNumbers = new ArrayList();
+ ArrayList losingPointNumbers = new ArrayList();
+
+
+ public Craps(Player player) {
+ this.crapsPlayer = new CrapsPlayer(player);
+ this.rolledDice = new ArrayList<>();
+ this.summedRoll = 0;
+ this.passLinePot = 0.0;
+ this.fieledPot = 0.0;
+ this.hardWaysPot = 0.0;
+
+ Collections.addAll(fieldNumbers, 2, 3, 4, 9, 10, 11, 12);
+ Collections.addAll(pointNumbers, 4, 5, 6, 8, 9, 10);
+ Collections.addAll(winningPointLineNumbers, 7, 11);
+ Collections.addAll(losingPointNumbers, 2, 3, 12);
+ }
+
+
+
+ public void play() {
+ boolean playing = false;
+ pointOn = false;
+ boolean comeLine = false;
+ boolean startPromt = false;
+ boolean roll = false;
+
+
+ String input = "";
+
+ String phase1Options = "Type 'pass line' to place a pass line bet.\n" +
+ "Type 'field' to place field bet.\n" +
+ "Type 'hardway' to place a hardway bet\n" +
+ "Type roll to roll the dice \n";
+
+ String phase2Options = "Type 'field' to place a field bet.\n" +
+ "Type pass line odds to place odds on the pass line. \n" +
+ "Type 'hardway' to place a hardway bet. \n" +
+ "Type roll to roll the dice. \n";
+
+ while (!startPromt) {
+ input = crapsConsole.getStringInput("\nHello %s! Welcome to Craps! Type 'Start' to begin!", crapsPlayer.getName());
+
+ if (input.toLowerCase().equals("start")) {
+ startPromt = true;
+ playing = true;
+ }
+ }
+
+
+ while (playing) {
+
+ if (!pointOn && !comeLine) {
+
+ while (!roll) {
+ roll = askForRoll(roll, phase1Options);
+ }
+ rolledDice = rollDice();
+ summedRoll = rollDiceSum(rolledDice);
+
+ checkFieldBetWinner(summedRoll, fieledPot);
+ checkPassLineBetWinner(summedRoll, passLinePot);
+ checkHardwayWinner(summedRoll,hardWaysPot,rolledDice);
+
+ roll = false;
+ summedRoll = 0;
+ printWallet();
+
+ }
+
+ if (pointOn && !comeLine) {
+ while (pointOn) {
+ askForRoll(roll, phase2Options);
+
+ rolledDice = rollDice();
+ summedRoll = rollDiceSum(rolledDice);
+
+ checkPassLineBetPhase2(summedRoll, passLinePot);
+ checkFieldBetWinner(summedRoll, fieledPot);
+ checkPassLineOddsWinner(summedRoll,passLineOddsPot);
+ checkHardwayWinner(summedRoll,hardWaysPot,rolledDice);
+
+ summedRoll = 0;
+ printWallet();
+ roll = false;
+ }
+ }
+ }
+ }
+
+ private boolean askForRoll(boolean roll, String phase1Options) {
+ String input;
+ input = crapsConsole.getStringInput(phase1Options).toUpperCase().replaceAll(" ", "_");
+
+ if (input.equals("ROLL")) {
+ roll = true;
+ } else {
+ CrapsActions.valueOf(input).perform(this, askForBet());
+ }
+ return roll;
+ }
+
+
+ public void walkAway() {
+
+ }
+
+ public double payout() {
+ return 0;
+ }
+
+
+ public void passLineBet(Double amount) {
+ crapsPlayer.bet(amount);
+ passLinePot += amount;
+ }
+
+ public void passLineOddsBet(Double amount) {
+ crapsPlayer.bet(amount);
+ passLineOddsPot += amount;
+ }
+//
+// public void comeLineBet(Double amount) {
+// crapsPlayer.bet(amount);
+// comeLinePot += amount;
+// }
+//
+// public void comeLineOddsBet(Double amount) {
+// crapsPlayer.bet(amount);
+// comeLineOddsPot += amount;
+// }
+//
+ public void hardWayBet(Double amount) {
+ crapsPlayer.bet(amount);
+ hardWaysPot += amount;
+ hardwayNumber = crapsConsole.getIntegerInput("Please enter the number of the Hardway roll you would like to bet on");
+ }
+
+ public void fieldBet(Double amount) {
+ crapsPlayer.bet(amount);
+ fieledPot += amount;
+ }
+
+ public void placeLineBet(Double amount) {
+ crapsPlayer.bet(amount);
+ placePot += amount;
+ }
+
+ public Double askForBet() {
+ Double inputBetAmount = crapsConsole.getDoubleInput("\nPlease enter your bet amount.");
+ return inputBetAmount;
+ }
+
+ public void clearPassLinePot() {
+ this.passLinePot = 0;
+ }
+
+ public void clearfieldPot() {
+ this.fieledPot = 0;
+ }
+
+ public void clearHardwayPot() {
+ this.hardWaysPot = 0;
+ }
+
+ private void clearPassLineOddsPot() {
+ this.passLineOddsPot = 0;
+ }
+
+
+ public void printWallet() {
+ System.out.println("Your current wallet is " + crapsPlayer.getWallet() + "\n");
+ }
+
+ public void checkFieldBetWinner(int sumofRoll, Double betAmount) {
+ if (fieldNumbers.contains(sumofRoll) && betAmount > 0) {
+ System.out.println("You won " + fieledPot + " on your Field bet");
+ crapsPlayer.collectCraps(fieledPot, 2);
+ } else if (!fieldNumbers.contains(sumofRoll) && betAmount > 0) {
+ System.out.println("You lost " + fieledPot + " on your field bet");
+ }
+ clearfieldPot();
+ }
+
+ public void checkPassLineBetWinner(int sumofRoll, Double betAmount) {
+ if (winningPointLineNumbers.contains(sumofRoll) && betAmount > 0) {
+ System.out.println("You won " + passLinePot + " on your Pass Line bet");
+ crapsPlayer.collectCraps(passLinePot, 2);
+ clearPassLinePot();
+ } else if (pointNumbers.contains(sumofRoll)) {
+ System.out.println("The point is now set at " + sumofRoll);
+ setPointOn();
+ setPointNumber(sumofRoll);
+ } else {
+ System.out.println("You lost " + passLinePot + " on you Pass Line bet");
+ clearPassLinePot();
+ }
+ }
+
+ public void checkPassLineBetPhase2(int sumofRoll, Double betAmount) {
+ if (sumofRoll == pointNumber && betAmount > 0) {
+ System.out.println("You won " + passLinePot + " on your Pass Line bet");
+ crapsPlayer.collectCraps(passLinePot, 2.0);
+ clearPassLinePot();
+ setPointOff();
+ } else if (sumofRoll == 7) {
+ System.out.println("You lost " + passLinePot + " on your Pass Line bet");
+ clearPassLinePot();
+ setPointOff();
+ }
+ }
+
+ public void checkPassLineOddsWinner(int sumofRoll, Double betAmount) {
+ if (sumofRoll == pointNumber && betAmount > 0) {
+ System.out.println("You won " + passLineOddsPot + " on your Pass Line Odds");
+ crapsPlayer.collectCraps(passLineOddsPot, 2.0);
+ clearPassLineOddsPot();
+ setPointOff();
+ } else if (sumofRoll == 7) {
+ System.out.println("You lost " + passLineOddsPot + " on your Pass Line Odds");
+ clearPassLineOddsPot();
+ setPointOff();
+ }
+ }
+
+ public void checkHardwayWinner(int sumofRoll, Double betAmount, ArrayList rolledDice) {
+ if(sumofRoll == hardwayNumber && betAmount > 0) {
+ if(areDiceTheSame(rolledDice)) {
+ System.out.println("You won " + hardWaysPot + " on your hardway bet");
+ clearHardwayPot();
+ } else {
+ System.out.println("You lost " + hardWaysPot + " on your hardway bet");
+ clearHardwayPot();
+ }
+ }
+ }
+
+ public ArrayList rollDice() {
+ rolledDice = (crapsPlayer.rollDice(2));
+ return rolledDice;
+ }
+
+ public Integer rollDiceSum(ArrayList lastRoll) {
+ summedRoll += crapsPlayer.sumOfRoll(lastRoll);
+ System.out.println("You rolled " + summedRoll);
+ return summedRoll;
+ }
+
+
+ public CrapsPlayer getCrapsPlayer() {
+ return this.crapsPlayer;
+ }
+
+ public int getPointNumber() {
+ return this.pointNumber;
+ }
+
+ public void setPointNumber(int numberRolled){
+ pointNumber = numberRolled;
+ }
+
+ public boolean getPointOn() {
+ return pointOn;
+ }
+
+ public Double getPassLinePot(){
+ return passLinePot;
+ }
+
+ public Double getFieldBet(){
+ return fieledPot;
+ }
+
+ public Double getHardwayBet(){
+ return hardWaysPot;
+ }
+
+ public void setPointOn() {
+ this.pointOn = true;
+ }
+
+ public void setPointOff() {
+ this.pointOn = false;
+ }
+
+ public void setHardWayPot(Double amount) {
+ this.hardWaysPot = amount;
+ }
+
+ public boolean areDiceTheSame(ArrayList diceRolled) {
+ if (diceRolled.get(0).getValue() == diceRolled.get(1).getValue()){
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+}
diff --git a/src/main/java/io/zipcoder/casino/DiceGame/CrapsActions.java b/src/main/java/io/zipcoder/casino/DiceGame/CrapsActions.java
new file mode 100644
index 000000000..78f25d5ff
--- /dev/null
+++ b/src/main/java/io/zipcoder/casino/DiceGame/CrapsActions.java
@@ -0,0 +1,29 @@
+package io.zipcoder.casino.DiceGame;
+
+import io.zipcoder.casino.utilities.Console;
+
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+
+public enum CrapsActions {
+ PASS_LINE_ODDS((crapsObj, doubleVal) -> crapsObj.passLineOddsBet(doubleVal)),
+ FIELD((crapsObj, doubleVal) -> crapsObj.fieldBet(doubleVal)),
+ HARDWAY((crapsObj, doubleVal) -> crapsObj.hardWayBet(doubleVal)),
+ PLACE((crapsObj, doubleVal) -> crapsObj.placeLineBet(doubleVal)),
+ //COME_LINE((crapsObj, doubleVal) -> crapsObj.comeLineBet(doubleVal)),
+ // ROLL((crapsObj, doubleVal) -> crapsObj.roll),
+ //COME_ODDS((crapsObj, doubleVal) -> crapsObj.comeLineOddsBet(doubleVal)),
+ PASS_LINE((crapsObj, doubleVal) -> crapsObj.passLineBet(doubleVal));
+
+ private final BiConsumer consumer;
+
+ CrapsActions(BiConsumer consumer) {
+ this.consumer = consumer;
+ }
+
+ public void perform(Craps crapsObject, Double doubleValue) {
+ consumer.accept(crapsObject, doubleValue);
+ }
+
+}
+
diff --git a/src/main/java/io/zipcoder/casino/DiceGame/CrapsPlayer.java b/src/main/java/io/zipcoder/casino/DiceGame/CrapsPlayer.java
new file mode 100644
index 000000000..5e8ee4267
--- /dev/null
+++ b/src/main/java/io/zipcoder/casino/DiceGame/CrapsPlayer.java
@@ -0,0 +1,55 @@
+package io.zipcoder.casino.DiceGame;
+
+import io.zipcoder.casino.GamblingPlayer;
+import io.zipcoder.casino.Player;
+
+import java.util.ArrayList;
+
+public class CrapsPlayer implements GamblingPlayer {
+ private String name;
+ private double wallet;
+ private Player player;
+
+
+ public CrapsPlayer(Player player) {
+ this.wallet = player.getWallet();
+ this.name = player.getName();
+ }
+
+ public void bet(double amount) {
+ this.wallet = wallet - amount;
+ }
+
+ public ArrayList rollDice(int numberOfDice) {
+
+ ArrayList rolledDice = new ArrayList<>();
+
+ for (int i = 0; i < numberOfDice; i++) {
+ Dice die = new Dice(1);
+ int dieValue = die.rollDice();
+ rolledDice.add(new Dice(1, dieValue));
+ }
+ return rolledDice;
+ }
+
+ public int sumOfRoll(ArrayList diceRoll){
+ return diceRoll.get(0).getValue() + diceRoll.get(1).getValue();
+ }
+
+
+ public void collect(double amount) {
+ this.wallet += amount;
+ }
+
+ public String getName(){
+ return name;
+ }
+
+ public void collectCraps(double amount, double winningsMultiplier){
+ this.wallet += (amount*winningsMultiplier);
+ }
+
+ public double getWallet(){
+ return this.wallet;
+ }
+}
diff --git a/src/main/java/io/zipcoder/casino/DiceGame/Dice.java b/src/main/java/io/zipcoder/casino/DiceGame/Dice.java
new file mode 100644
index 000000000..c08c354b3
--- /dev/null
+++ b/src/main/java/io/zipcoder/casino/DiceGame/Dice.java
@@ -0,0 +1,28 @@
+package io.zipcoder.casino.DiceGame;
+
+import java.util.ArrayList;
+import java.util.Random;
+
+public class Dice {
+ private int numberOfDice;
+ private int value;
+
+ public Dice(int numberOfDice){
+ this.numberOfDice = numberOfDice;
+ }
+
+ public Dice(int numberOfDice, int value){
+ this.numberOfDice = numberOfDice;
+ this.value = value;
+ }
+
+
+ public int getValue() {
+ return value;
+ }
+
+ int rollDice(){
+ Random random = new Random();
+ return random.nextInt(6) + 1;
+ }
+}
diff --git a/src/main/java/io/zipcoder/casino/DiceGame/DiceGame.java b/src/main/java/io/zipcoder/casino/DiceGame/DiceGame.java
new file mode 100644
index 000000000..a679485ca
--- /dev/null
+++ b/src/main/java/io/zipcoder/casino/DiceGame/DiceGame.java
@@ -0,0 +1,10 @@
+package io.zipcoder.casino.DiceGame;
+
+import io.zipcoder.casino.Game;
+import io.zipcoder.casino.Player;
+
+public abstract class DiceGame implements Game {
+
+ public void play(){
+ }
+}
diff --git a/src/main/java/io/zipcoder/casino/DiceGame/Yahtzee.java b/src/main/java/io/zipcoder/casino/DiceGame/Yahtzee.java
new file mode 100644
index 000000000..d38f928e7
--- /dev/null
+++ b/src/main/java/io/zipcoder/casino/DiceGame/Yahtzee.java
@@ -0,0 +1,941 @@
+package io.zipcoder.casino.DiceGame;
+
+import io.zipcoder.casino.Player;
+import io.zipcoder.casino.utilities.Console;
+
+import java.util.ArrayList;
+import java.util.TooManyListenersException;
+import java.util.TreeMap;
+
+public class Yahtzee extends DiceGame {
+ private YahtzeePlayer yahtzeePlayer;
+ private int score;
+ private TreeMap scoreCard;
+ private ArrayList savedDice;
+ private ArrayList rolledDice;
+ private boolean playing = false;
+ Console console = Console.getInstance();
+ String input = "";
+
+
+ public Yahtzee(Player player) {
+ this.yahtzeePlayer = new YahtzeePlayer(player);
+ this.score = 0;
+ this.scoreCard = setUpScoreCard();
+ this.savedDice = new ArrayList<>();
+ this.rolledDice = new ArrayList<>();
+ }
+
+ @Override
+ public void play() {
+
+ console.println(welcomeToYahtzeeString());
+ input = console.getStringInput("\nHello %s! Welcome to Yahtzee! Type 'roll' to begin!", yahtzeePlayer.getName());
+ playing = true;
+
+ while (playing) {
+
+ if (input.toLowerCase().equals("roll")) {
+ roll();
+ }
+
+ if (input.toLowerCase().equals("save")) {
+ saveDice();
+ }
+
+ if (input.toLowerCase().equals("return")) {
+ returnDice();
+ }
+
+ if (input.toLowerCase().equals("scorecard")) {
+ showScorecard();
+ }
+
+ if (input.toLowerCase().equals("mark")) {
+ input = console.getStringInput(categoryString());
+
+ if (input.toLowerCase().equals("back")) {
+ back();
+ } else {
+ markScore();
+ }
+ }
+ if (input.toLowerCase().equals("exit")) {
+ walkAway();
+ }
+ invalidInputCheck();
+ }
+ }
+
+
+ // walkAway takes user back to the casino
+ public void walkAway() {
+ playing = false;
+ System.out.println("Thank you for playing Yahtzee!");
+ }
+
+
+ // getAllDice merges all rolledDice and savedDice into one ArrayList
+ public ArrayList getAllDice(ArrayList rolledDice, ArrayList savedDice) {
+ ArrayList allDice = rolledDice;
+ for (Dice die : savedDice) {
+ allDice.add(die);
+ }
+ return allDice;
+ }
+
+
+ // this method will get the score for the entered category based on the dice
+ public Integer getScoreForCategory(String category, ArrayList allDice) {
+ int score = 0;
+ String categoryToScore = category.toLowerCase();
+
+ switch (categoryToScore) {
+ case "aces":
+ score = scoreAces(allDice);
+ break;
+
+ case "twos":
+ score = scoreTwos(allDice);
+ break;
+
+ case "threes":
+ score = scoreThrees(allDice);
+ break;
+
+ case "fours":
+ score = scoreFours(allDice);
+ break;
+
+ case "fives":
+ score = scoreFives(allDice);
+ break;
+
+ case "sixes":
+ score = scoreSixes(allDice);
+ break;
+
+ case "3 of a kind":
+ score = scoreThreeOfAKind(allDice);
+ break;
+
+ case "4 of a kind":
+ score = scoreFourOfAKind(allDice);
+ break;
+
+ case "full house":
+ score = scoreFullHouse(allDice);
+ break;
+
+ case "small straight":
+ score = scoreSmallStraight(allDice);
+ break;
+
+ case "large straight":
+ score = scoreLargeStraight(allDice);
+ break;
+
+ case "yahtzee":
+ score = scoreYahtzee(allDice);
+ break;
+
+ case "chance":
+ score = scoreChance(allDice);
+ break;
+
+ default:
+ System.out.println("Invalid category.");
+ }
+ return score;
+ }
+
+
+ public int scoreAces(ArrayList allDice) {
+ int score = 0;
+ for (Dice die : allDice) {
+ if (die.getValue() == 1) {
+ score += 1;
+ }
+ }
+ return score;
+ }
+
+ public int scoreTwos(ArrayList allDice) {
+ int score = 0;
+ for (Dice die : allDice) {
+ if (die.getValue() == 2) {
+ score += 2;
+ }
+ }
+ return score;
+ }
+
+ public int scoreThrees(ArrayList allDice) {
+ int score = 0;
+ for (Dice die : allDice) {
+ if (die.getValue() == 3) {
+ score += 3;
+ }
+ }
+ return score;
+ }
+
+ public int scoreFours(ArrayList allDice) {
+ int score = 0;
+ for (Dice die : allDice) {
+ if (die.getValue() == 4) {
+ score += 4;
+ }
+ }
+ return score;
+ }
+
+ public int scoreFives(ArrayList allDice) {
+ int score = 0;
+ for (Dice die : allDice) {
+ if (die.getValue() == 5) {
+ score += 5;
+ }
+ }
+ return score;
+ }
+
+ public int scoreSixes(ArrayList allDice) {
+ int score = 0;
+ for (Dice die : allDice) {
+ if (die.getValue() == 6) {
+ score += 6;
+ }
+ }
+ return score;
+ }
+
+ public Integer upperSectionBonus(TreeMap scoreCard) {
+ if (getUpperSectionTotal(scoreCard) >= 63) {
+ return 35;
+ } else {
+ return 0;
+ }
+ }
+
+ public Integer getUpperSectionTotal(TreeMap scoreCard) {
+ Integer upperTotal = 0;
+
+ if (scoreCard.get("aces") != null) {
+ upperTotal += scoreCard.get("aces");
+ }
+ if (scoreCard.get("twos") != null) {
+ upperTotal += scoreCard.get("twos");
+ }
+ if (scoreCard.get("threes") != null) {
+ upperTotal += scoreCard.get("threes");
+ }
+ if (scoreCard.get("fours") != null) {
+ upperTotal += scoreCard.get("fours");
+ }
+ if (scoreCard.get("fives") != null) {
+ upperTotal += scoreCard.get("fives");
+ }
+ if (scoreCard.get("sixes") != null) {
+ upperTotal += scoreCard.get("sixes");
+ }
+
+ return upperTotal;
+ }
+
+ public boolean hasThreeOfAKind(ArrayList allDice) {
+ Integer[] diceCount = countDice(allDice);
+ for (Integer dieCount : diceCount) {
+ if (dieCount >= 3) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public int scoreThreeOfAKind(ArrayList allDice) {
+ if (hasThreeOfAKind(allDice)) {
+ return getSumOfDice(allDice);
+ }
+ return 0;
+ }
+
+
+ public boolean hasFourOfAKind(ArrayList allDice) {
+ Integer[] diceCount = countDice(allDice);
+ for (Integer dieCount : diceCount) {
+ if (dieCount >= 4) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ public int scoreFourOfAKind(ArrayList allDice) {
+ if (hasFourOfAKind(allDice)) {
+ return getSumOfDice(allDice);
+ }
+ return 0;
+ }
+
+
+ public boolean hasFullHouse(ArrayList allDice) {
+ Integer[] diceCount = countDice(allDice);
+ boolean hasTwoCount = false;
+ boolean hasThreeCount = false;
+
+ for (Integer dieCount : diceCount) {
+ if (dieCount == 2) {
+ hasTwoCount = true;
+ }
+ if (dieCount == 3) {
+ hasThreeCount = true;
+ }
+ }
+ if (hasTwoCount && hasThreeCount) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+
+ public int scoreFullHouse(ArrayList allDice) {
+ if (hasFullHouse(allDice)) {
+ return 25;
+ } else {
+ return 0;
+ }
+ }
+
+
+ public boolean hasSmallStraight(ArrayList allDice) {
+ Integer[] diceCount = countDice(allDice);
+
+ if ((diceCount[0] >= 1) && (diceCount[1] >= 1) && (diceCount[2] >= 1) && (diceCount[3] >= 1)) {
+ return true;
+ }
+ if ((diceCount[1] >= 1) && (diceCount[2] >= 1) && (diceCount[3] >= 1) && (diceCount[4] >= 1)) {
+ return true;
+ }
+ if ((diceCount[2] >= 1) && (diceCount[3] >= 1) && (diceCount[4] >= 1) && (diceCount[5] >= 1)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+
+ public int scoreSmallStraight(ArrayList allDice) {
+ if (hasSmallStraight(allDice)) {
+ return 30;
+ } else {
+ return 0;
+ }
+ }
+
+
+ public boolean hasLargeStraight(ArrayList allDice) {
+ Integer[] diceCount = countDice(allDice);
+
+ if ((diceCount[0] == 1) && (diceCount[1] == 1) && (diceCount[2] == 1) && (diceCount[3] == 1) && (diceCount[4] == 1)) {
+ return true;
+ }
+ if ((diceCount[1] == 1) && (diceCount[2] == 1) && (diceCount[3] == 1) && (diceCount[4] == 1) && (diceCount[5] == 1)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+
+ public int scoreLargeStraight(ArrayList allDice) {
+ if (hasLargeStraight(allDice)) {
+ return 40;
+ } else {
+ return 0;
+ }
+ }
+
+
+ public boolean hasYahtzee(ArrayList allDice) {
+ Integer[] diceCount = countDice(allDice);
+
+ for (Integer dieCount : diceCount) {
+ if (dieCount == 5) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ public int scoreYahtzee(ArrayList allDice) {
+ if (hasYahtzee(allDice)) {
+ return 50;
+ } else {
+ return 0;
+ }
+ }
+
+
+ public int scoreChance(ArrayList allDice) {
+ return getSumOfDice(allDice);
+ }
+
+ public int getLowerSectionTotal(TreeMap scoreCard) {
+ int lowerTotal = 0;
+ if (scoreCard.get("3 of a kind") != null) {
+ lowerTotal += scoreCard.get("3 of a kind");
+ }
+ if (scoreCard.get("4 of a kind") != null) {
+ lowerTotal += scoreCard.get("4 of a kind");
+ }
+ if (scoreCard.get("full house") != null) {
+ lowerTotal += scoreCard.get("full house");
+ }
+ if (scoreCard.get("small straight") != null) {
+ lowerTotal += scoreCard.get("small straight");
+ }
+ if (scoreCard.get("large straight") != null) {
+ lowerTotal += scoreCard.get("large straight");
+ }
+ if (scoreCard.get("yahtzee") != null) {
+ lowerTotal += scoreCard.get("yahtzee");
+ }
+ if (scoreCard.get("chance") != null) {
+ lowerTotal += scoreCard.get("chance");
+ }
+
+ return lowerTotal;
+ }
+
+
+ public int getTotalScore(TreeMap scoreCard) {
+ return getLowerSectionTotal(scoreCard) + getUpperSectionTotal(scoreCard) + upperSectionBonus(scoreCard);
+ }
+
+
+ public YahtzeePlayer getYahtzeePlayer() {
+ return this.yahtzeePlayer;
+ }
+
+
+ public TreeMap getScoreCard() {
+ return this.scoreCard;
+ }
+
+
+ public ArrayList getSavedDice() {
+ return this.savedDice;
+ }
+
+
+ public int getScore() {
+ return score;
+ }
+
+
+ public ArrayList getRolledDice() {
+ return rolledDice;
+ }
+
+
+ public Integer[] countDice(ArrayList dice) {
+ Integer[] diceCounter = {0, 0, 0, 0, 0, 0};
+ for (Dice die : dice) {
+ if (die.getValue() == 1) {
+ diceCounter[0]++;
+ } else if (die.getValue() == 2) {
+ diceCounter[1]++;
+ } else if (die.getValue() == 3) {
+ diceCounter[2]++;
+ } else if (die.getValue() == 4) {
+ diceCounter[3]++;
+ } else if (die.getValue() == 5) {
+ diceCounter[4]++;
+ } else if (die.getValue() == 6) {
+ diceCounter[5]++;
+ }
+ }
+ return diceCounter;
+ }
+
+
+ public int getSumOfDice(ArrayList dice) {
+ int sum = 0;
+
+ for (Dice die : dice) {
+ sum += die.getValue();
+ }
+ return sum;
+ }
+
+ public void markScoreCard(String category, ArrayList dice) {
+ int score = getScoreForCategory(category, dice);
+ scoreCard.put(category.toLowerCase(), score);
+
+ if (upperSectionScoresComplete()) {
+ scoreCard.put("upper bonus", upperSectionBonus(scoreCard));
+ }
+ }
+
+
+ public String listOfDiceToDiceString(ArrayList diceList) {
+ String diceString = "";
+ for (Dice die : diceList) {
+ if (die.getValue() == 1) {
+ diceString = diceString + " ⚀ |";
+ } else if (die.getValue() == 2) {
+ diceString = diceString + " ⚁ |";
+ } else if (die.getValue() == 3) {
+ diceString = diceString + " ⚂ |";
+ } else if (die.getValue() == 4) {
+ diceString = diceString + " ⚃ |";
+ } else if (die.getValue() == 5) {
+ diceString = diceString + " ⚄ |";
+ } else if (die.getValue() == 6) {
+ diceString = diceString + " ⚅ |";
+ }
+ }
+ return diceString;
+
+ }
+
+
+ public String getCurrentDiceString(ArrayList rolledDice, ArrayList savedDice) {
+ String currentDiceString = "";
+ String spacerString = "\n|------------------------------------------|\n";
+ String numberString = "| | 1 | 2 | 3 | 4 | 5 |";
+
+
+ String rolledDiceString = "|Rolled Dice |" + listOfDiceToDiceString(rolledDice);
+ for (int i = 0; i < 5 - rolledDice.size(); i++) {
+ rolledDiceString = rolledDiceString + " |";
+ }
+
+ String savedDiceString = "| Saved Dice |";
+
+ for (int i = 0; i < rolledDice.size(); i++) {
+ savedDiceString = savedDiceString + " |";
+ }
+
+ savedDiceString = savedDiceString + listOfDiceToDiceString(savedDice);
+ currentDiceString = spacerString + numberString + spacerString + rolledDiceString + spacerString + savedDiceString + spacerString;
+
+ return currentDiceString;
+ }
+
+
+ public String getScoreCardString() {
+ String scoreCardString = "";
+ String spacerString = "|---------------------------------|\n";
+ String categoryString = " Category | Score \n";
+ scoreCardString = scoreCardString + spacerString +
+ categoryString + spacerString +
+ getAcesScoreString() + spacerString +
+ getTwosScoreString() + spacerString +
+ getThreesScoreString() + spacerString +
+ getFoursScoreString() + spacerString +
+ getFivesScoreString() + spacerString +
+ getSixesScoreString() + spacerString +
+ getUpperBonusScoreString() + spacerString +
+ getThreeOfAKindScoreString() + spacerString +
+ getFourOfAKindScoreString() + spacerString +
+ getFullHouseScoreString() + spacerString +
+ getSmallStraightScoreString() + spacerString +
+ getLargeStraightScoreString() + spacerString +
+ getYahtzeeScoreString() + spacerString +
+ getChanceScoreString() + spacerString +
+ getTotalScoreString() + spacerString;
+
+ return scoreCardString;
+ }
+
+
+ public TreeMap setUpScoreCard() {
+ TreeMap scoreCard = new TreeMap<>();
+ scoreCard.put("aces", null);
+ scoreCard.put("twos", null);
+ scoreCard.put("threes", null);
+ scoreCard.put("fours", null);
+ scoreCard.put("fives", null);
+ scoreCard.put("sixes", null);
+ scoreCard.put("upper bonus", null);
+ scoreCard.put("3 of a kind", null);
+ scoreCard.put("4 of a kind", null);
+ scoreCard.put("full house", null);
+ scoreCard.put("small straight", null);
+ scoreCard.put("large straight", null);
+ scoreCard.put("yahtzee", null);
+ scoreCard.put("chance", null);
+ scoreCard.put("total score", null);
+
+ return scoreCard;
+ }
+
+
+ public String getAcesScoreString() {
+ if (scoreCard.get("aces") == null) {
+ return " Aces |\n";
+ } else {
+ return " Aces | " + scoreCard.get("aces") + "\n";
+ }
+ }
+
+
+ public String getTwosScoreString() {
+ if (scoreCard.get("twos") == null) {
+ return " Twos |\n";
+ } else {
+ return " Twos | " + scoreCard.get("twos") + "\n";
+ }
+ }
+
+
+ public String getThreesScoreString() {
+ if (scoreCard.get("threes") == null) {
+ return " Threes |\n";
+ } else {
+ return " Threes | " + scoreCard.get("threes") + "\n";
+ }
+ }
+
+
+ public String getFoursScoreString() {
+ if (scoreCard.get("fours") == null) {
+ return " Fours |\n";
+ } else {
+ return " Fours | " + scoreCard.get("fours") + "\n";
+ }
+ }
+
+
+ public String getFivesScoreString() {
+ if (scoreCard.get("fives") == null) {
+ return " Fives |\n";
+ } else {
+ return " Fives | " + scoreCard.get("fives") + "\n";
+ }
+ }
+
+
+ public String getSixesScoreString() {
+ if (scoreCard.get("sixes") == null) {
+ return " Sixes |\n";
+ } else {
+ return " Sixes | " + scoreCard.get("sixes") + "\n";
+ }
+ }
+
+
+ public String getThreeOfAKindScoreString() {
+ if (scoreCard.get("3 of a kind") == null) {
+ return " 3 of a Kind |\n";
+ } else {
+ return " 3 of a Kind | " + scoreCard.get("3 of a kind") + "\n";
+ }
+ }
+
+ public String getFourOfAKindScoreString() {
+ if (scoreCard.get("4 of a kind") == null) {
+ return " 4 of a Kind |\n";
+ } else {
+ return " 4 of a Kind | " + scoreCard.get("4 of a kind") + "\n";
+ }
+ }
+
+
+ public String getFullHouseScoreString() {
+ if (scoreCard.get("full house") == null) {
+ return " Full House |\n";
+ } else {
+ return " Full House | " + scoreCard.get("full house") + "\n";
+ }
+ }
+
+
+ public String getSmallStraightScoreString() {
+ if (scoreCard.get("small straight") == null) {
+ return " Small Straight |\n";
+ } else {
+ return " Small Straight | " + scoreCard.get("small straight") + "\n";
+ }
+ }
+
+
+ public String getLargeStraightScoreString() {
+ if (scoreCard.get("large straight") == null) {
+ return " Large Straight |\n";
+ } else {
+ return " Large Straight | " + scoreCard.get("large straight") + "\n";
+ }
+ }
+
+
+ public String getYahtzeeScoreString() {
+ if (scoreCard.get("yahtzee") == null) {
+ return " Yahtzee |\n";
+ } else {
+ return " Yahtzee | " + scoreCard.get("yahtzee") + "\n";
+ }
+ }
+
+
+ public String getChanceScoreString() {
+ if (scoreCard.get("chance") == null) {
+ return " Chance |\n";
+ } else {
+ return " Chance | " + scoreCard.get("chance") + "\n";
+ }
+ }
+
+
+ public String getUpperBonusScoreString() {
+ if (scoreCard.get("upper bonus") == null) {
+ return " Upper Bonus |\n";
+ } else {
+ return " Upper Bonus | " + scoreCard.get("upper bonus") + "\n";
+ }
+ }
+
+
+ public String getTotalScoreString() {
+ if (scoreCard.get("total score") == null) {
+ return " Total Score |\n";
+ } else {
+ return " Total Score | " + scoreCard.get("total score") + "\n";
+ }
+ }
+
+
+ public boolean upperSectionScoresComplete() {
+ if (scoreCard.get("aces") == null) {
+ return false;
+ }
+ if (scoreCard.get("twos") == null) {
+ return false;
+ }
+ if (scoreCard.get("threes") == null) {
+ return false;
+ }
+ if (scoreCard.get("fours") == null) {
+ return false;
+ }
+ if (scoreCard.get("fives") == null) {
+ return false;
+ }
+ if (scoreCard.get("sixes") == null) {
+ return false;
+ }
+ return true;
+ }
+
+
+ public boolean scorecardComplete() {
+ if (!upperSectionScoresComplete()) {
+ return false;
+ }
+ if (scoreCard.get("3 of a kind") == null) {
+ return false;
+ }
+ if (scoreCard.get("4 of a kind") == null) {
+ return false;
+ }
+ if (scoreCard.get("full house") == null) {
+ return false;
+ }
+ if (scoreCard.get("small straight") == null) {
+ return false;
+ }
+ if (scoreCard.get("large straight") == null) {
+ return false;
+ }
+ if (scoreCard.get("yahtzee") == null) {
+ return false;
+ }
+ if (scoreCard.get("chance") == null) {
+ return false;
+ }
+ return true;
+ }
+
+
+ public boolean isValidCategory(String categoryInput) {
+ String input = categoryInput.toLowerCase();
+ if (input.equals("aces")) {
+ return true;
+ }
+ if (input.equals("twos")) {
+ return true;
+ }
+ if (input.equals("threes")) {
+ return true;
+ }
+ if (input.equals("fours")) {
+ return true;
+ }
+ if (input.equals("fives")) {
+ return true;
+ }
+ if (input.equals("sixes")) {
+ return true;
+ }
+ if (input.equals("3 of a kind")) {
+ return true;
+ }
+ if (input.equals("4 of a kind")) {
+ return true;
+ }
+ if (input.equals("full house")) {
+ return true;
+ }
+ if (input.equals("small straight")) {
+ return true;
+ }
+ if (input.equals("large straight")) {
+ return true;
+ }
+ if (input.equals("yahtzee")) {
+ return true;
+ }
+ if (input.equals("chance")) {
+ return true;
+ }
+ return false;
+ }
+
+ public String welcomeToYahtzeeString() {
+ return "\n⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅\n" +
+ " ___ __ __ ___ ___ __ ___ __ ___ ___ /\n" +
+ "| | |__ | / ` / \\ |\\/| |__ | / \\ \\ / /\\ |__| | / |__ |__ / \n" +
+ "|/\\| |___ |___ \\__, \\__/ | | |___ | \\__/ | /~~\\ | | | /_ |___ |___ . \n\n" +
+ "⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅\n";
+ }
+
+
+ public String allOptions() {
+ return "Type 'save' to save rolled dice.\n" +
+ "Type 'return' to return saved dice to be rolled again.\n" +
+ "Type 'roll' to roll again.\n" +
+ "Type 'scorecard' to see scorecard.\n" +
+ "Type 'mark' to mark a score on you scorecard.\n" +
+ "Type 'exit' to walk away.";
+ }
+
+
+ public void roll() {
+ try {
+ rolledDice = yahtzeePlayer.playerRollDice(5 - savedDice.size());
+ console.println("\nRoll #%d", yahtzeePlayer.getRollNumber());
+ console.println(getCurrentDiceString(rolledDice, savedDice));
+ input = console.getStringInput(allOptions());
+
+ } catch (YahtzeePlayer.TooManyRollsException tooManyRollsException) {
+ input = console.getStringInput("\nYou have already rolled 3 times. Type 'mark' to mark your scorecard.");
+ }
+ }
+
+ public void saveDice() {
+ input = console.getStringInput("Type the locations of the dice you want to save.\n" +
+ "(Ex: '123' to save first three dice)");
+ try {
+ for (Dice die : yahtzeePlayer.saveDice(rolledDice, input)) {
+ savedDice.add(die);
+ }
+ console.println("Dice saved.");
+ console.println("\nRoll #%d", yahtzeePlayer.getRollNumber());
+ console.println(getCurrentDiceString(rolledDice, savedDice));
+ input = console.getStringInput(allOptions());
+
+ } catch (IndexOutOfBoundsException i) {
+ input = console.getStringInput("Invalid input. " + allOptions());
+ }
+ }
+
+
+ public void returnDice() {
+ input = console.getStringInput("Type the locations of the dice you want to return.\n" +
+ "(Ex: '345' to return last three dice)");
+ try {
+ for (Dice die : yahtzeePlayer.returnDice(savedDice, input)) {
+ rolledDice.add(die);
+ }
+ console.println("Dice returned");
+ console.println("\nRoll #%d", yahtzeePlayer.getRollNumber());
+ console.println(getCurrentDiceString(rolledDice, savedDice));
+ input = console.getStringInput(allOptions());
+
+ } catch (ArrayIndexOutOfBoundsException aioobEx) {
+ input = console.getStringInput("Invalid input. " + allOptions());
+ }
+ }
+
+ public void showScorecard() {
+ console.println(getScoreCardString());
+ input = console.getStringInput("Type 'back' to go back. Type 'mark' to mark scorecard");
+ if (input.toLowerCase().equals("back")) {
+ console.println("\nRoll #%d", yahtzeePlayer.getRollNumber());
+ console.println(getCurrentDiceString(rolledDice, savedDice));
+ input = console.getStringInput(allOptions());
+ }
+ }
+
+
+ public String categoryString() {
+ return "Enter the category you want to mark on your scorecard.\n" +
+ " 'aces', 'twos', 'threes', fours', 'fives', 'sixes'\n" +
+ " '3 of a kind', '4 of a kind', 'full house',\n" +
+ "'small straight', large straight', 'yahtzee', 'chance'\n" +
+ " Enter 'back' to go back.\n";
+ }
+
+ public void back() {
+ console.println("\nRoll #%d", yahtzeePlayer.getRollNumber());
+ console.println(getCurrentDiceString(rolledDice, savedDice));
+ input = console.getStringInput(allOptions());
+ }
+
+
+ public void markScore() {
+ if (isValidCategory(input)) {
+ if (scoreCard.get(input.toLowerCase()) != null) {
+ console.println("You already have a score for %s", input);
+ } else {
+ markScoreCard(input.toLowerCase(), getAllDice(rolledDice, savedDice));
+ scoreCard.put("total score", getTotalScore(scoreCard));
+ rolledDice.removeAll(rolledDice);
+ savedDice.removeAll(savedDice);
+ console.println(getScoreCardString());
+ yahtzeePlayer.setRollNumber(0);
+
+ checkScorecardComplete();
+ }
+ } else {
+ input = console.getStringInput("Invalid category. Enter 'mark' to try again.");
+ }
+ }
+
+
+ public void checkScorecardComplete() {
+ if (scorecardComplete()) {
+ console.println("Thank you for playing Yahtzee! Your final score is %d.", getTotalScore(scoreCard));
+ playing = false;
+ input = "back";
+ } else {
+ input = console.getStringInput("Type 'roll' to start your next turn.");
+ }
+ }
+
+
+ public void invalidInputCheck(){
+ if (!(input.toLowerCase().equals("roll") || input.toLowerCase().equals("save") || input.toLowerCase().equals("return") ||
+ input.toLowerCase().equals("scorecard") || input.toLowerCase().equals("mark") || input.toLowerCase().equals("back")
+ || input.toLowerCase().equals("exit"))) {
+
+ input = console.getStringInput("Invalid input. " + allOptions());
+ }
+ }
+}
+
diff --git a/src/main/java/io/zipcoder/casino/DiceGame/YahtzeePlayer.java b/src/main/java/io/zipcoder/casino/DiceGame/YahtzeePlayer.java
new file mode 100644
index 000000000..a7cdbc435
--- /dev/null
+++ b/src/main/java/io/zipcoder/casino/DiceGame/YahtzeePlayer.java
@@ -0,0 +1,108 @@
+package io.zipcoder.casino.DiceGame;
+
+import io.zipcoder.casino.Player;
+
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.TreeMap;
+
+public class YahtzeePlayer {
+ private String name;
+ private Player player;
+ private int rollNumber = 0;
+
+
+ public YahtzeePlayer(Player player) {
+ this.name = player.getName();
+ this.player = player;
+ }
+
+ public ArrayList playerRollDice(int numberOfDice) throws TooManyRollsException{
+ if (rollNumber >= 3){
+ throw new TooManyRollsException();
+ }
+ else {
+ ArrayList rolledDice = new ArrayList<>();
+ for (int i = 0; i < numberOfDice; i++) {
+ Dice die = new Dice(1);
+ int dieValue = die.rollDice();
+ rolledDice.add(new Dice(1, dieValue));
+ }
+ rollNumber++;
+ return rolledDice;
+ }
+ }
+
+
+ public ArrayList saveDice(ArrayList rolledDice, String diceToSaveInput) {
+ ArrayList savedDice = new ArrayList<>();
+ diceToSaveInput = removeDuplicateCharacters(diceToSaveInput);
+ for (int i = 0; i < diceToSaveInput.length(); i++) {
+ int indexOfDieToSave = Character.getNumericValue(diceToSaveInput.charAt(i)) - 1;
+ savedDice.add(rolledDice.get(indexOfDieToSave));
+ }
+ removeSameDice(rolledDice, savedDice);
+
+ return savedDice;
+ }
+
+
+ public ArrayList returnDice(ArrayList savedDice, String diceToReturnInput) {
+ diceToReturnInput = removeDuplicateCharacters(diceToReturnInput);
+ ArrayList returnedDice = new ArrayList<>();
+ for (int i = 0; i < diceToReturnInput.length(); i++){
+ int indexOfDieToReturn = Character.getNumericValue(diceToReturnInput.charAt(i) - (6 - savedDice.size()));
+ returnedDice.add(savedDice.get(indexOfDieToReturn));
+ }
+ removeSameDice(savedDice, returnedDice);
+ return returnedDice;
+ }
+
+ public void removeSameDice(ArrayList diceListToRemoveFrom, ArrayList diceList){
+ for (Dice die : diceList){
+ if(diceListToRemoveFrom.contains(die)){
+ diceListToRemoveFrom.remove(die);
+ }
+ }
+ }
+
+
+ public String removeDuplicateCharacters(String input){
+
+ String inputWithoutDuplicates = "";
+
+ char[] charArray = input.toCharArray();
+ Set charSet = new HashSet<>();
+ for (char c : charArray) {
+ charSet.add(c);
+ }
+
+ for(Character c : charSet){
+ inputWithoutDuplicates = inputWithoutDuplicates + c;
+ }
+
+ return inputWithoutDuplicates;
+ }
+
+
+ public String getName() {
+ return this.name;
+ }
+
+
+ public Player getPlayer() {
+ return this.player;
+ }
+
+ public int getRollNumber() {
+ return rollNumber;
+ }
+
+ public void setRollNumber(int rollNumber) {
+ this.rollNumber = rollNumber;
+ }
+
+ public class TooManyRollsException extends Throwable {}
+}
diff --git a/src/main/java/io/zipcoder/casino/GamblingGame.java b/src/main/java/io/zipcoder/casino/GamblingGame.java
new file mode 100644
index 000000000..79ea74253
--- /dev/null
+++ b/src/main/java/io/zipcoder/casino/GamblingGame.java
@@ -0,0 +1,8 @@
+package io.zipcoder.casino;
+
+public interface GamblingGame extends Game {
+
+ double payout();
+
+ void play();
+}
diff --git a/src/main/java/io/zipcoder/casino/GamblingPlayer.java b/src/main/java/io/zipcoder/casino/GamblingPlayer.java
new file mode 100644
index 000000000..b8f0ca67a
--- /dev/null
+++ b/src/main/java/io/zipcoder/casino/GamblingPlayer.java
@@ -0,0 +1,7 @@
+package io.zipcoder.casino;
+
+public interface GamblingPlayer {
+ void bet(double amount);
+
+ void collect(double amount);
+}
diff --git a/src/main/java/io/zipcoder/casino/Game.java b/src/main/java/io/zipcoder/casino/Game.java
new file mode 100644
index 000000000..ddde3272a
--- /dev/null
+++ b/src/main/java/io/zipcoder/casino/Game.java
@@ -0,0 +1,9 @@
+package io.zipcoder.casino;
+
+import io.zipcoder.casino.DiceGame.Yahtzee;
+
+public interface Game {
+ public void play();
+
+ void walkAway();
+}
diff --git a/src/main/java/io/zipcoder/casino/Player.java b/src/main/java/io/zipcoder/casino/Player.java
new file mode 100644
index 000000000..f7bb32b3f
--- /dev/null
+++ b/src/main/java/io/zipcoder/casino/Player.java
@@ -0,0 +1,23 @@
+package io.zipcoder.casino;
+
+public class Player {
+ private String name;
+ private double wallet;
+
+ public Player(String name, double wallet){
+ this.name = name;
+ this.wallet = wallet;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public double getWallet(){
+ return wallet;
+ }
+}
diff --git a/src/main/java/io/zipcoder/casino/utilities/Console.java b/src/main/java/io/zipcoder/casino/utilities/Console.java
index ab896c956..a0a16111a 100644
--- a/src/main/java/io/zipcoder/casino/utilities/Console.java
+++ b/src/main/java/io/zipcoder/casino/utilities/Console.java
@@ -12,11 +12,18 @@ public final class Console {
private final Scanner input;
private final PrintStream output;
- public Console(InputStream in, PrintStream out) {
+ private Console(InputStream in, PrintStream out) {
this.input = new Scanner(in);
this.output = out;
}
+ static Console console = new Console(System.in, System.out);
+
+ public static Console getInstance(){
+ return console;
+ }
+
+
public void print(String val, Object... args) {
output.format(val, args);
}
diff --git a/src/test/java/io/zipcoder/casino/CardGame/BlackJack/BlackjackPlayerTest.java b/src/test/java/io/zipcoder/casino/CardGame/BlackJack/BlackjackPlayerTest.java
new file mode 100644
index 000000000..3f9774c10
--- /dev/null
+++ b/src/test/java/io/zipcoder/casino/CardGame/BlackJack/BlackjackPlayerTest.java
@@ -0,0 +1,112 @@
+package io.zipcoder.casino.CardGame.BlackJack;
+
+import io.zipcoder.casino.CardGame.Cards.Card;
+import io.zipcoder.casino.CardGame.Cards.Deck;
+import io.zipcoder.casino.CardGame.Cards.Face;
+import io.zipcoder.casino.CardGame.Cards.Suit;
+import io.zipcoder.casino.Player;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.ArrayList;
+
+import static org.junit.Assert.*;
+
+public class BlackjackPlayerTest {
+
+ Player player;
+ Deck deck;
+ ArrayList cards;
+ Card card1;
+ Card card2;
+
+
+
+ @Before
+ public void setUp(){
+ player = new Player("Delenda", 100);
+ deck = new Deck(10);
+ cards = new ArrayList<>();
+ card1 = new Card(Face.FOUR, Suit.CLUBS);
+ card2 = new Card(Face.JACK, Suit.DIAMONDS);
+ cards.add(card1);
+ cards.add(card2);
+
+ }
+
+
+
+ @Test
+ public void bet() {
+
+ //GIVEN
+ BlackjackPlayer blackjackPlayer = new BlackjackPlayer(this.player);
+ double expected = 90;
+
+
+
+ //WHEN
+ blackjackPlayer.bet(10);
+ double actual = blackjackPlayer.getBlackjackPlayerWallet();
+
+ //THEN
+ Assert.assertEquals(expected, actual, 0);
+ }
+
+ @Test
+ public void collect() {
+
+ //GIVEN
+ BlackjackPlayer blackjackPlayer = new BlackjackPlayer(this.player);
+ double expected = 110;
+
+ //WHEN
+ blackjackPlayer.collect(10);
+ double actual = blackjackPlayer.getBlackjackPlayerWallet();
+
+
+ //THEN
+ Assert.assertEquals(expected, actual, 0);
+ }
+
+ @Test
+ public void hit() {
+ //GIVEN
+ BlackjackPlayer blackjackPlayer = new BlackjackPlayer(this.player);
+ blackjackPlayer.setHand(deck.deal(2));
+ int expected = 3;
+
+ //WHEN
+ blackjackPlayer.hit(deck);
+ int actual = blackjackPlayer.numberOfCardsInHand();
+
+ //THEN
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void doubleDown() {
+ }
+
+ @Test
+ public void split() {
+ }
+
+ @Test
+ public void testSumOfHand() {
+ //GIVEN
+ BlackjackPlayer blackjackPlayer = new BlackjackPlayer(this.player);
+ blackjackPlayer.setHand(cards);
+ int expected = 14;
+
+ //WHEN
+ int actual = blackjackPlayer.sumOfHand();
+
+
+ //THEN
+ Assert.assertEquals(expected, actual);
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/casino/CardGame/BlackJack/BlackjackTest.java b/src/test/java/io/zipcoder/casino/CardGame/BlackJack/BlackjackTest.java
new file mode 100644
index 000000000..dded3579f
--- /dev/null
+++ b/src/test/java/io/zipcoder/casino/CardGame/BlackJack/BlackjackTest.java
@@ -0,0 +1,110 @@
+package io.zipcoder.casino.CardGame.BlackJack;
+
+import io.zipcoder.casino.Player;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class BlackjackTest {
+
+ private Player player;
+
+ @Before
+ public void setUp(){
+ player = new Player("name", 1000);
+ }
+ @Test
+ public void constructorTest(){
+ //Given
+ Blackjack blackjack = new Blackjack(player);
+ double expected = 0;
+
+ //When
+ double actual = blackjack.getPot();
+
+ //Then
+ Assert.assertEquals(expected, actual, 0);
+ }
+
+ @Test
+ public void testPush() {
+ }
+
+
+ @Test
+ public void testValidateBet() {
+ //Given
+ Blackjack blackjack = new Blackjack(player);
+
+
+
+ //When
+ blackjack.setBet(100);
+ boolean actual = blackjack.validateBet();
+
+ //Then
+ Assert.assertTrue(actual);
+ }
+
+ @Test
+ public void testInvalidBet(){
+ //Given
+ Blackjack blackjack = new Blackjack(player);
+
+ //When
+ blackjack.setBet(2000);
+ boolean actual = blackjack.validateBet();
+
+ //Then
+ Assert.assertFalse(actual);
+
+ }
+
+ @Test
+ public void setBet() {
+ //Given
+ Blackjack blackjack = new Blackjack(player);
+ double expected = 100;
+
+ //When
+ blackjack.setBet(100);
+ double actual = blackjack.getBet();
+
+
+ //Then
+ Assert.assertEquals(expected, actual, 0);
+ }
+
+ @Test
+ public void takeBet() {
+ //Given
+ Blackjack blackjack = new Blackjack(player);
+ double expected = 100;
+
+ //When
+ blackjack.takeBet(100);
+ double actual = blackjack.getPot();
+
+ //Then
+ Assert.assertEquals(expected, actual,0);
+
+
+
+ }
+
+ @Test
+ public void payout() {
+ //Given
+ Blackjack blackjack = new Blackjack(player);
+ double expected = 200;
+
+ //When
+ blackjack.takeBet(100);
+ double actual = blackjack.payout();
+
+ //Then
+ Assert.assertEquals(expected, actual, 0);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/casino/CardGame/HandTest.java b/src/test/java/io/zipcoder/casino/CardGame/HandTest.java
new file mode 100644
index 000000000..bc73f86f6
--- /dev/null
+++ b/src/test/java/io/zipcoder/casino/CardGame/HandTest.java
@@ -0,0 +1,75 @@
+package io.zipcoder.casino.CardGame;
+
+import io.zipcoder.casino.CardGame.Cards.Card;
+import io.zipcoder.casino.CardGame.Cards.Deck;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+
+import static org.junit.Assert.*;
+
+public class HandTest {
+
+ Deck deck;
+ ArrayList cards;
+
+ @Before
+ public void setUp() {
+ deck = new Deck(1);
+ cards = deck.deal(7);
+ }
+
+
+ @Test
+ public void drawCard() {
+ //GIVEN
+ Hand hand = new Hand(cards);
+ int expected = hand.getSize();
+
+
+
+ //WHEN
+ hand.drawCard(deck);
+ int actual = hand.getSize();
+
+
+ //THEN
+ Assert.assertNotEquals(expected, actual);
+ }
+
+
+ @Test
+ public void addCardsToHand() {
+ //GIVEN
+ Hand hand = new Hand(cards);
+ int expected = hand.getSize();
+
+ //WHEN
+ hand.addCardsToHand(cards);
+ int actual = hand.getSize();
+
+ //THEN
+ Assert.assertNotEquals(expected, actual);
+
+ }
+
+ @Test
+ public void removeCardsFromHand() {
+
+ //GIVEN
+ Hand hand = new Hand(cards);
+ int expected = hand.getSize();
+
+ //WHEN
+ hand.removeCardsFromHand(cards);
+ int actual = hand.getSize();
+
+ //THEN
+ Assert.assertNotEquals(expected, actual);
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/casino/CasinoTest.java b/src/test/java/io/zipcoder/casino/CasinoTest.java
index e92865236..75fc9e6bf 100644
--- a/src/test/java/io/zipcoder/casino/CasinoTest.java
+++ b/src/test/java/io/zipcoder/casino/CasinoTest.java
@@ -1,5 +1,38 @@
package io.zipcoder.casino;
+import io.zipcoder.casino.DiceGame.Yahtzee;
+import org.junit.Assert;
+import org.junit.Test;
+
public class CasinoTest {
+
+ @Test
+ public void setPlayerTest() {
+ // Given
+ Player expected = new Player("Cara", 1000);
+
+ // When
+ Casino.setPlayer(expected);
+ Player actual = Casino.getPlayer();
+
+ // Then
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void setGameTest(){
+ // Given
+ Player player = new Player("Cara", 1000);
+ Game expected = new Yahtzee(player);
+ Casino.setGame(expected);
+
+ // When
+ Game actual = Casino.getGame();
+
+ // Then
+ Assert.assertEquals(expected, actual);
+ }
+
+
}
diff --git a/src/test/java/io/zipcoder/casino/CrapsActions.java b/src/test/java/io/zipcoder/casino/CrapsActions.java
new file mode 100644
index 000000000..a1566572c
--- /dev/null
+++ b/src/test/java/io/zipcoder/casino/CrapsActions.java
@@ -0,0 +1,4 @@
+package io.zipcoder.casino;
+
+public class CrapsActions {
+}
diff --git a/src/test/java/io/zipcoder/casino/CrapsTest.java b/src/test/java/io/zipcoder/casino/CrapsTest.java
new file mode 100644
index 000000000..11c85fe06
--- /dev/null
+++ b/src/test/java/io/zipcoder/casino/CrapsTest.java
@@ -0,0 +1,325 @@
+package io.zipcoder.casino;
+
+import com.sun.org.apache.xpath.internal.operations.Bool;
+import io.zipcoder.casino.DiceGame.Craps;
+import io.zipcoder.casino.DiceGame.CrapsPlayer;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+//Given
+//When
+//Then
+
+
+public class CrapsTest {
+
+ private Craps craps;
+ private Player player = new Player("Jimmy", 1000);
+ private CrapsPlayer crapsPlayer;
+
+ @Before
+ public void setup() {
+ this.craps = new Craps(player);
+ crapsPlayer = craps.getCrapsPlayer();
+ }
+
+
+ @After
+ public void tearDown() {
+ craps = null;
+
+ }
+
+ @Test
+ public void passLineBetTest() {
+ //Given
+ Double expected = 100.0;
+ Double amount = 100.0;
+
+ //When
+ craps.passLineBet(amount);
+ Double actual = craps.getPassLinePot();
+
+ // Then
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void hardWayBetTest() {
+ //Given
+ Double expected = 100.0;
+ Double amount = 100.0;
+
+ //When
+ craps.setHardWayPot(100.0);
+ Double actual = craps.getHardwayBet();
+
+ // Then
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void fieldBetTest() {
+ //Given
+ Double expected = 100.0;
+ Double amount = 100.0;
+
+ //When
+ craps.fieldBet(amount);
+ Double actual = craps.getFieldBet();
+
+ // Then
+ Assert.assertEquals(expected, actual);
+ }
+
+// @Test
+// public void placeLineBet() {
+// }
+
+ @Test
+ public void askForBet() {
+ }
+
+ @Test
+ public void clearPassLinePotTest() {
+ Double expected = 0.0;
+
+ craps.passLineBet(100.0);
+ craps.clearPassLinePot();
+
+ Double actual = craps.getFieldBet();
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void clearfieldPotTest() {
+ Double expected = 0.0;
+
+ craps.fieldBet(100.0);
+ craps.clearfieldPot();
+
+ Double actual = craps.getFieldBet();
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void clearHardwayPot() {
+ Double expected = 0.0;
+
+ craps.setHardWayPot(1000.0);
+ craps.clearHardwayPot();
+
+ Double actual = craps.getFieldBet();
+ Assert.assertEquals(expected, actual);
+ }
+
+// @Test
+// public void clearComeLinePot() {
+// }
+
+ @Test
+ public void printWallet() {
+ Double expected = 1000.0;
+
+ Double actual = player.getWallet();
+
+ Assert.assertEquals(expected, actual);
+
+ }
+
+ @Test
+ public void checkSetPointOn() {
+ craps.setPointOn();
+
+ Assert.assertTrue(craps.getPointOn());
+ }
+
+ @Test
+ public void checkSetPointOff() {
+ craps.setPointOff();
+
+ Assert.assertFalse(craps.getPointOn());
+ }
+
+ @Test
+ public void checkFieldBetWinner() {
+ Double expected = 1100.0;
+ craps.fieldBet(100.0);
+
+ craps.checkFieldBetWinner(2, 100.0);
+ Double actual = crapsPlayer.getWallet();
+
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void checkFieldBetWinner2() {
+ Double expected = 900.0;
+ craps.fieldBet(100.0);
+
+ craps.checkFieldBetWinner(1, 100.0);
+ Double actual = crapsPlayer.getWallet();
+
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void checkPassLineBetWinner() {
+ Double expected = 1100.0;
+ craps.passLineBet(100.0);
+
+ craps.checkPassLineBetWinner(7, 100.0);
+ Double actual = crapsPlayer.getWallet();
+
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void checkPassLineBetWinner2() {
+ Double expected = 900.0;
+ craps.passLineBet(100.0);
+
+ craps.checkPassLineBetWinner(12, 100.0);
+ Double actual = crapsPlayer.getWallet();
+
+ Assert.assertEquals(expected, actual);
+ }
+
+
+ @Test
+ public void checkPassLineBetWinner3() {
+ Double expected = 900.0;
+ craps.passLineBet(100.0);
+ int expectedPoint = 4;
+
+ craps.checkPassLineBetWinner(4, 100.0);
+ Double actual = crapsPlayer.getWallet();
+
+ int actualPoint = craps.getPointNumber();
+
+ Assert.assertEquals(expected, actual);
+ Assert.assertEquals(expectedPoint, actualPoint);
+ }
+
+
+ @Test
+ public void checkPassLineBetPhase2Test1() {
+ Double expected = 1100.0;
+ craps.passLineBet(100.0);
+ craps.setPointNumber(4);
+ int expectedPoint = 4;
+
+ craps.checkPassLineBetPhase2(4, 100.0);
+ Double actual = crapsPlayer.getWallet();
+
+ int actualPoint = craps.getPointNumber();
+
+ Assert.assertEquals(expected, actual);
+ Assert.assertEquals(expectedPoint, actualPoint);
+ }
+
+ @Test
+ public void checkPassLineBetPhase2Test2() {
+ Double expected = 900.0;
+ craps.passLineBet(100.0);
+ craps.setPointNumber(4);
+ int expectedPoint = 4;
+
+ craps.checkPassLineBetPhase2(7, 100.0);
+ Double actual = crapsPlayer.getWallet();
+
+ int actualPoint = craps.getPointNumber();
+
+ Assert.assertEquals(expected, actual);
+ Assert.assertEquals(expectedPoint, actualPoint);
+ }
+
+ @Test
+ public void checkPassLineBetPhase2Test3() {
+ Double expected = 900.0;
+ craps.passLineBet(100.0);
+ craps.setPointNumber(4);
+ int expectedPoint = 4;
+
+ craps.checkPassLineBetPhase2(6, 100.0);
+ Double actual = crapsPlayer.getWallet();
+
+ int actualPoint = craps.getPointNumber();
+
+ Assert.assertEquals(expected, actual);
+ Assert.assertEquals(expectedPoint, actualPoint);
+ }
+
+ @Test
+ public void checkPassLineOddsTest1() {
+ Double expected = 1100.0;
+ craps.passLineOddsBet(100.0);
+ craps.setPointNumber(5);
+ int expectedPoint = 5;
+
+ craps.checkPassLineOddsWinner(5, 100.0);
+ Double actual = crapsPlayer.getWallet();
+
+ int actualPoint = craps.getPointNumber();
+
+ Assert.assertEquals(expected, actual);
+ Assert.assertEquals(expectedPoint, actualPoint);
+ }
+
+ @Test
+ public void checkPassLineOddsTest2() {
+ Double expected = 900.0;
+ craps.passLineOddsBet(100.0);
+ craps.setPointNumber(4);
+ int expectedPoint = 4;
+
+ craps.checkPassLineOddsWinner(7, 100.0);
+ Double actual = crapsPlayer.getWallet();
+
+ int actualPoint = craps.getPointNumber();
+
+ Assert.assertEquals(expected, actual);
+ Assert.assertEquals(expectedPoint, actualPoint);
+ }
+
+ @Test
+ public void checkPassLineOddsTest3() {
+ Double expected = 900.0;
+ craps.passLineOddsBet(100.0);
+ craps.setPointNumber(4);
+ int expectedPoint = 4;
+
+ craps.checkPassLineOddsWinner(6, 100.0);
+ Double actual = crapsPlayer.getWallet();
+
+ int actualPoint = craps.getPointNumber();
+
+ Assert.assertEquals(expected, actual);
+ Assert.assertEquals(expectedPoint, actualPoint);
+ }
+
+// @Test
+// public void rollDiceSumTest() {
+// Integer summedRoll = craps.rollDiceSum();
+// Boolean test = false;
+//
+// if ((summedRoll <= 12) && (summedRoll > 0)) {
+// test = true;
+// }
+//
+// Assert.assertTrue(test);
+// }
+
+// @Test
+// public void checkHardwayWinnerTest(){
+// //Given
+// craps.setHardwayRoll(4);
+// craps.checkHardwayWinner(crapsPlayer.rollDice(2));
+//
+//
+// //When
+// //Then
+// }
+}
diff --git a/src/test/java/io/zipcoder/casino/DeckTest.java b/src/test/java/io/zipcoder/casino/DeckTest.java
new file mode 100644
index 000000000..570538e37
--- /dev/null
+++ b/src/test/java/io/zipcoder/casino/DeckTest.java
@@ -0,0 +1,83 @@
+package io.zipcoder.casino;
+
+import io.zipcoder.casino.CardGame.Cards.Card;
+import io.zipcoder.casino.CardGame.Cards.Deck;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.ArrayList;
+
+public class DeckTest {
+
+
+
+
+
+ @Test
+ public void testShuffle() {
+ //GIVEN
+ Deck deck = new Deck(1);
+ String expected = deck.toString();
+
+ //WHEN
+ deck.shuffle();
+ String actual = deck.toString();
+
+
+ //THEN
+ Assert.assertNotEquals(expected, actual);
+
+ }
+
+ @Test
+ public void removeCardFromDeck() {
+ //GIVEN
+ Deck deck = new Deck(1);
+ int expected = deck.deckSize();
+
+ //WHEN
+ deck.removeCardFromDeck(26);
+ int actual = deck.deckSize();
+
+
+ //THEN
+ Assert.assertNotEquals(expected, actual);
+
+ }
+
+ @Test
+ public void testDeal() {
+ //GIVEN
+ Deck deck = new Deck(10);
+ ArrayList cards = new ArrayList<>();
+
+
+ //WHEN
+ cards = deck.deal(7);
+ int expected = cards.size();
+
+ //THEN
+ Assert.assertTrue(expected == 7);
+ }
+
+ @Test
+ public void testCardRemovedAfterDeal(){
+ //GIVEN
+ Deck deck = new Deck(1);
+ ArrayList cards = new ArrayList<>();
+ int expected = 42;
+
+ //WHEN
+ cards = deck.deal(10);
+ int actual = deck.deckSize();
+
+ //THEN
+ Assert.assertEquals(expected, actual);
+
+
+ }
+
+
+
+
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/casino/GoFishPlayerTest.java b/src/test/java/io/zipcoder/casino/GoFishPlayerTest.java
new file mode 100644
index 000000000..2e1b9c8d2
--- /dev/null
+++ b/src/test/java/io/zipcoder/casino/GoFishPlayerTest.java
@@ -0,0 +1,330 @@
+package io.zipcoder.casino;
+
+import io.zipcoder.casino.CardGame.Cards.Card;
+import io.zipcoder.casino.CardGame.Cards.Face;
+import io.zipcoder.casino.CardGame.Cards.Suit;
+import io.zipcoder.casino.CardGame.GoFishPlayer;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.ArrayList;
+
+public class GoFishPlayerTest {
+
+
+ Card hA = new Card(Face.ACE, Suit.HEARTS);
+ Card sA = new Card(Face.ACE, Suit.SPADES);
+ Card cA = new Card(Face.ACE, Suit.CLUBS);
+ Card dA = new Card(Face.ACE, Suit.DIAMONDS);
+ Card h2 = new Card(Face.TWO, Suit.HEARTS);
+ Card s2 = new Card(Face.TWO, Suit.SPADES);
+ Card c2 = new Card(Face.TWO, Suit.CLUBS);
+ Card d2 = new Card(Face.TWO, Suit.DIAMONDS);
+ Card h3 = new Card(Face.THREE, Suit.HEARTS);
+ Card s3 = new Card(Face.THREE, Suit.SPADES);
+ Card c3 = new Card(Face.THREE, Suit.CLUBS);
+ Card d3 = new Card(Face.THREE, Suit.DIAMONDS);
+ Card h4 = new Card(Face.FOUR, Suit.HEARTS);
+ Card s4 = new Card(Face.FOUR, Suit.SPADES);
+ Card c4 = new Card(Face.FOUR, Suit.CLUBS);
+ Card d4 = new Card(Face.FOUR, Suit.DIAMONDS);
+ Card h5 = new Card(Face.FIVE, Suit.HEARTS);
+ Card s5 = new Card(Face.FIVE, Suit.SPADES);
+ Card c5 = new Card(Face.FIVE, Suit.CLUBS);
+ Card d5 = new Card(Face.FIVE, Suit.DIAMONDS);
+ Card h6 = new Card(Face.SIX, Suit.HEARTS);
+ Card s6 = new Card(Face.SIX, Suit.SPADES);
+ Card c6 = new Card(Face.SIX, Suit.CLUBS);
+ Card d6 = new Card(Face.SIX, Suit.DIAMONDS);
+ Card h7 = new Card(Face.SEVEN, Suit.HEARTS);
+ Card s7 = new Card(Face.SEVEN, Suit.SPADES);
+ Card c7 = new Card(Face.SEVEN, Suit.CLUBS);
+ Card d7 = new Card(Face.SEVEN, Suit.DIAMONDS);
+ Card h8 = new Card(Face.EIGHT, Suit.HEARTS);
+ Card s8 = new Card(Face.EIGHT, Suit.SPADES);
+ Card c8 = new Card(Face.EIGHT, Suit.CLUBS);
+ Card d8 = new Card(Face.EIGHT, Suit.DIAMONDS);
+ Card h9 = new Card(Face.NINE, Suit.HEARTS);
+ Card s9 = new Card(Face.NINE, Suit.SPADES);
+ Card c9 = new Card(Face.NINE, Suit.CLUBS);
+ Card d9 = new Card(Face.NINE, Suit.DIAMONDS);
+ Card h10 = new Card(Face.TEN, Suit.HEARTS);
+ Card s10 = new Card(Face.TEN, Suit.SPADES);
+ Card c10 = new Card(Face.TEN, Suit.CLUBS);
+ Card d10 = new Card(Face.TEN, Suit.DIAMONDS);
+ Card hJ = new Card(Face.JACK, Suit.HEARTS);
+ Card sJ = new Card(Face.JACK, Suit.SPADES);
+ Card cJ = new Card(Face.JACK, Suit.CLUBS);
+ Card dJ = new Card(Face.JACK, Suit.DIAMONDS);
+ Card hQ = new Card(Face.QUEEN, Suit.HEARTS);
+ Card sQ = new Card(Face.QUEEN, Suit.SPADES);
+ Card cQ = new Card(Face.QUEEN, Suit.CLUBS);
+ Card dQ = new Card(Face.QUEEN, Suit.DIAMONDS);
+ Card hK = new Card(Face.KING, Suit.HEARTS);
+ Card sK = new Card(Face.KING, Suit.SPADES);
+ Card cK = new Card(Face.KING, Suit.CLUBS);
+ Card dK = new Card(Face.KING, Suit.DIAMONDS);
+
+ @Test
+ public void goFishPlayerConstructorTest() {
+
+ // Given
+ String expectedName = "Cara";
+ Player expectedPlayer = new Player(expectedName, 10000);
+
+ // When
+ GoFishPlayer goFishPlayer = new GoFishPlayer(expectedPlayer);
+ Player actualPlayer = goFishPlayer.getPlayer();
+ String actualName = goFishPlayer.getName();
+
+ // Then
+ Assert.assertEquals(expectedPlayer, actualPlayer);
+ Assert.assertEquals(expectedName, actualName);
+ }
+
+
+ @Test
+ public void addCardsToHandsTest() {
+ // Given
+ Player player = new Player("Cara", 1000);
+ GoFishPlayer goFishPlayer = new GoFishPlayer(player);
+
+ goFishPlayer.getHand().showMyCards().add(h3);
+ goFishPlayer.getHand().showMyCards().add(d9);
+ goFishPlayer.getHand().showMyCards().add(cK);
+
+ ArrayList cardsToAdd = new ArrayList<>();
+ cardsToAdd.add(sK);
+ cardsToAdd.add(hK);
+ cardsToAdd.add(dK);
+
+ ArrayList expected = new ArrayList<>();
+ expected.add(h3);
+ expected.add(d9);
+ expected.add(cK);
+ expected.add(sK);
+ expected.add(hK);
+ expected.add(dK);
+
+ // When
+ goFishPlayer.getHand().addCardsToHand(cardsToAdd);
+ ArrayList actual = goFishPlayer.getHand().showMyCards();
+
+ // Then
+ Assert.assertEquals(expected, actual);
+ }
+
+
+ @Test
+ public void getCardCountInHandTest() {
+ // Given
+ Player player = new Player("Cara", 1000);
+ GoFishPlayer goFishPlayer = new GoFishPlayer(player);
+
+ ArrayList cards = new ArrayList<>();
+ cards.add(dA);
+ cards.add(hA);
+ cards.add(s3);
+ cards.add(s4);
+ cards.add(d4);
+ cards.add(c4);
+ cards.add(h4);
+ cards.add(s6);
+ cards.add(h8);
+ cards.add(c8);
+ cards.add(sQ);
+ cards.add(hQ);
+
+ goFishPlayer.getHand().addCardsToHand(cards);
+
+ Integer[] expected = {2, 0, 1, 4, 0, 1, 0, 2, 0, 0, 0, 2, 0};
+
+ // When
+ Integer[] actual = goFishPlayer.getCardCountInHand();
+
+ // Then
+ Assert.assertArrayEquals(expected, actual);
+ }
+
+
+ @Test
+ public void layDown4OfAKindTest() {
+ // Given
+ Player player = new Player("Cara", 1000);
+ GoFishPlayer goFishPlayer = new GoFishPlayer(player);
+
+ ArrayList cards = new ArrayList<>();
+ cards.add(dA);
+ cards.add(hA);
+ cards.add(s3);
+ cards.add(s4);
+ cards.add(d4);
+ cards.add(c4);
+ cards.add(h4);
+ cards.add(s6);
+ cards.add(h8);
+ cards.add(c8);
+ cards.add(sQ);
+ cards.add(hQ);
+
+ goFishPlayer.getHand().addCardsToHand(cards);
+
+ int expectedCounter4 = 1;
+ ArrayList expectedCards = new ArrayList<>();
+ expectedCards.add(dA);
+ expectedCards.add(hA);
+ expectedCards.add(s3);
+ expectedCards.add(s6);
+ expectedCards.add(h8);
+ expectedCards.add(c8);
+ expectedCards.add(sQ);
+ expectedCards.add(hQ);
+
+ // When
+ goFishPlayer.layDown4OfAKind(Face.FOUR);
+ ArrayList actualCards = goFishPlayer.getHand().showMyCards();
+ int actualCounter4 = goFishPlayer.getCounter4();
+
+ // Then
+ Assert.assertEquals(expectedCards, actualCards);
+ Assert.assertEquals(expectedCounter4, actualCounter4);
+ }
+
+
+ @Test
+ public void fourOfAKindFinderTest() {
+ // Given
+ Player player = new Player("Cara", 1000);
+ GoFishPlayer goFishPlayer = new GoFishPlayer(player);
+
+ ArrayList cards = new ArrayList<>();
+ cards.add(dA);
+ cards.add(hA);
+ cards.add(s3);
+ cards.add(s4);
+ cards.add(d4);
+ cards.add(c4);
+ cards.add(h4);
+ cards.add(s6);
+ cards.add(h8);
+ cards.add(c8);
+ cards.add(sQ);
+ cards.add(hQ);
+ cards.add(sK);
+ cards.add(cK);
+ cards.add(dK);
+ cards.add(hK);
+
+ goFishPlayer.getHand().addCardsToHand(cards);
+
+ int expectedCounter4 = 2;
+ ArrayList expectedCards = new ArrayList<>();
+ expectedCards.add(dA);
+ expectedCards.add(hA);
+ expectedCards.add(s3);
+ expectedCards.add(s6);
+ expectedCards.add(h8);
+ expectedCards.add(c8);
+ expectedCards.add(sQ);
+ expectedCards.add(hQ);
+
+ // When
+ boolean actual = goFishPlayer.fourOfAKindFinder();
+ int actualCounter4 = goFishPlayer.getCounter4();
+ ArrayList actualCards = goFishPlayer.getHand().showMyCards();
+
+ // Then
+ Assert.assertEquals(expectedCounter4, actualCounter4);
+ Assert.assertEquals(expectedCards, actualCards);
+ Assert.assertTrue(actual);
+ }
+
+
+ @Test
+ public void requestCardTest() {
+ // Given
+ Player player = new Player("Cara", 1000);
+ Player otherPlayer = new Player("Neela", 1000);
+ GoFishPlayer goFishPlayer = new GoFishPlayer(player);
+ GoFishPlayer otherGoFishPlayer = new GoFishPlayer(otherPlayer);
+
+ ArrayList cards = new ArrayList<>();
+ cards.add(d4);
+ cards.add(hQ);
+ cards.add(s2);
+ cards.add(sJ);
+ cards.add(d10);
+ cards.add(c3);
+ cards.add(h5);
+ cards.add(s7);
+ cards.add(h9);
+
+ goFishPlayer.getHand().addCardsToHand(cards);
+
+ ArrayList expectedCards = new ArrayList<>();
+ expectedCards.addAll(cards);
+ expectedCards.add(s5);
+ expectedCards.add(c5);
+ expectedCards.add(d5);
+
+ ArrayList otherPlayersCards = new ArrayList<>();
+ otherPlayersCards.add(s5);
+ otherPlayersCards.add(c5);
+ otherPlayersCards.add(c7);
+ otherPlayersCards.add(d7);
+ otherPlayersCards.add(s8);
+ otherPlayersCards.add(d6);
+ otherPlayersCards.add(c6);
+ otherPlayersCards.add(d5);
+
+ otherGoFishPlayer.getHand().addCardsToHand(otherPlayersCards);
+
+ ArrayList expectedOtherPlayersCards = new ArrayList<>();
+ expectedOtherPlayersCards.add(c7);
+ expectedOtherPlayersCards.add(d7);
+ expectedOtherPlayersCards.add(s8);
+ expectedOtherPlayersCards.add(d6);
+ expectedOtherPlayersCards.add(c6);
+
+ // When
+ goFishPlayer.requestCard(otherGoFishPlayer, Face.FIVE);
+ ArrayList actualCards = goFishPlayer.getHand().showMyCards();
+ ArrayList actualOtherPlayersCards = otherGoFishPlayer.getHand().showMyCards();
+
+ // Then
+ Assert.assertEquals(expectedCards, actualCards);
+ Assert.assertEquals(expectedOtherPlayersCards, actualOtherPlayersCards);
+
+ }
+
+
+ @Test
+ public void hasRequestedCardTest() {
+ // Given
+ Player player = new Player("Cara", 1000);
+ GoFishPlayer goFishPlayer = new GoFishPlayer(player);
+
+ ArrayList cards = new ArrayList<>();
+ cards.add(cJ);
+ cards.add(dJ);
+ cards.add(sA);
+ cards.add(c2);
+ cards.add(s10);
+ cards.add(c10);
+ cards.add(d8);
+ cards.add(dQ);
+ cards.add(h6);
+
+ goFishPlayer.getHand().addCardsToHand(cards);
+
+ // When
+ boolean expectedTrue = goFishPlayer.hasRequestedCard(Face.TEN);
+ boolean expectedTrue2 = goFishPlayer.hasRequestedCard(Face.SIX);
+ boolean expectedFalse = goFishPlayer.hasRequestedCard(Face.THREE);
+
+ // Then
+ Assert.assertTrue(expectedTrue);
+ Assert.assertTrue(expectedTrue2);
+ Assert.assertFalse(expectedFalse);
+ }
+}
diff --git a/src/test/java/io/zipcoder/casino/GoFishTests.java b/src/test/java/io/zipcoder/casino/GoFishTests.java
new file mode 100644
index 000000000..5c5ac2e61
--- /dev/null
+++ b/src/test/java/io/zipcoder/casino/GoFishTests.java
@@ -0,0 +1,612 @@
+package io.zipcoder.casino;
+
+import io.zipcoder.casino.CardGame.Cards.Card;
+import io.zipcoder.casino.CardGame.Cards.Face;
+import io.zipcoder.casino.CardGame.Cards.Suit;
+import io.zipcoder.casino.CardGame.GoFish;
+import io.zipcoder.casino.CardGame.GoFishPlayer;
+import io.zipcoder.casino.utilities.Console;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.ArrayList;
+
+import static io.zipcoder.casino.CardGame.Cards.Face.*;
+
+public class GoFishTests {
+
+ Card hA = new Card(Face.ACE, Suit.HEARTS);
+ Card sA = new Card(Face.ACE, Suit.SPADES);
+ Card cA = new Card(Face.ACE, Suit.CLUBS);
+ Card dA = new Card(Face.ACE, Suit.DIAMONDS);
+ Card h2 = new Card(TWO, Suit.HEARTS);
+ Card s2 = new Card(TWO, Suit.SPADES);
+ Card c2 = new Card(TWO, Suit.CLUBS);
+ Card d2 = new Card(TWO, Suit.DIAMONDS);
+ Card h3 = new Card(THREE, Suit.HEARTS);
+ Card s3 = new Card(THREE, Suit.SPADES);
+ Card c3 = new Card(THREE, Suit.CLUBS);
+ Card d3 = new Card(THREE, Suit.DIAMONDS);
+ Card h4 = new Card(Face.FOUR, Suit.HEARTS);
+ Card s4 = new Card(Face.FOUR, Suit.SPADES);
+ Card c4 = new Card(Face.FOUR, Suit.CLUBS);
+ Card d4 = new Card(Face.FOUR, Suit.DIAMONDS);
+ Card h5 = new Card(Face.FIVE, Suit.HEARTS);
+ Card s5 = new Card(Face.FIVE, Suit.SPADES);
+ Card c5 = new Card(Face.FIVE, Suit.CLUBS);
+ Card d5 = new Card(Face.FIVE, Suit.DIAMONDS);
+ Card h6 = new Card(Face.SIX, Suit.HEARTS);
+ Card s6 = new Card(Face.SIX, Suit.SPADES);
+ Card c6 = new Card(Face.SIX, Suit.CLUBS);
+ Card d6 = new Card(Face.SIX, Suit.DIAMONDS);
+ Card h7 = new Card(Face.SEVEN, Suit.HEARTS);
+ Card s7 = new Card(Face.SEVEN, Suit.SPADES);
+ Card c7 = new Card(Face.SEVEN, Suit.CLUBS);
+ Card d7 = new Card(Face.SEVEN, Suit.DIAMONDS);
+ Card h8 = new Card(Face.EIGHT, Suit.HEARTS);
+ Card s8 = new Card(Face.EIGHT, Suit.SPADES);
+ Card c8 = new Card(Face.EIGHT, Suit.CLUBS);
+ Card d8 = new Card(Face.EIGHT, Suit.DIAMONDS);
+ Card h9 = new Card(Face.NINE, Suit.HEARTS);
+ Card s9 = new Card(Face.NINE, Suit.SPADES);
+ Card c9 = new Card(Face.NINE, Suit.CLUBS);
+ Card d9 = new Card(Face.NINE, Suit.DIAMONDS);
+ Card h10 = new Card(Face.TEN, Suit.HEARTS);
+ Card s10 = new Card(Face.TEN, Suit.SPADES);
+ Card c10 = new Card(Face.TEN, Suit.CLUBS);
+ Card d10 = new Card(Face.TEN, Suit.DIAMONDS);
+ Card hJ = new Card(Face.JACK, Suit.HEARTS);
+ Card sJ = new Card(Face.JACK, Suit.SPADES);
+ Card cJ = new Card(Face.JACK, Suit.CLUBS);
+ Card dJ = new Card(Face.JACK, Suit.DIAMONDS);
+ Card hQ = new Card(Face.QUEEN, Suit.HEARTS);
+ Card sQ = new Card(Face.QUEEN, Suit.SPADES);
+ Card cQ = new Card(Face.QUEEN, Suit.CLUBS);
+ Card dQ = new Card(Face.QUEEN, Suit.DIAMONDS);
+ Card hK = new Card(Face.KING, Suit.HEARTS);
+ Card sK = new Card(Face.KING, Suit.SPADES);
+ Card cK = new Card(Face.KING, Suit.CLUBS);
+ Card dK = new Card(Face.KING, Suit.DIAMONDS);
+
+ @Test
+ public void getLastCardTest() {
+ // Given
+ Player player = new Player("Cara", 1000);
+ GoFish goFish = new GoFish(player);
+ GoFishPlayer goFishPlayer = goFish.getGoFishPlayer();
+
+ ArrayList cards = new ArrayList<>();
+ cards.add(dJ);
+ cards.add(cK);
+ cards.add(h9);
+
+ goFishPlayer.getHand().addCardsToHand(cards);
+
+ Card expected = h9;
+
+ // When
+ Card actual = goFish.getLastCard(goFishPlayer);
+
+ // Then
+ Assert.assertEquals(expected, actual);
+ }
+
+
+ /* @Test
+ public void getCardOptionsTest(){
+ // Given
+ Player player = new Player("Cara", 1000);
+ GoFish goFish = new GoFish(player);
+
+ String expected = "\n'Ace' 'Two' 'Three' 'Four' 'Five' 'Six' 'Seven' 'Eight' 'Nine ' Ten' 'Jack' 'Queen' 'King'\n";
+
+ // When
+ String actual = goFish.getCardOptions();
+
+ // Then
+ Assert.assertEquals(expected, actual);
+ }
+*/
+
+ @Test
+ public void updatePlayerScoreTest() {
+ // Given
+ Player player = new Player("Cara", 1000);
+ GoFish goFish = new GoFish(player);
+ GoFishPlayer goFishPlayer = goFish.getGoFishPlayer();
+
+ int expected = 5;
+ goFishPlayer.setCounter4(expected);
+
+ // When
+ goFish.updatePlayerScore();
+ int actual = goFish.getPlayersScoreCounter();
+
+ // Then
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void updateDealerScoreTest() {
+ // Given
+ Player player = new Player("Cara", 1000);
+ GoFish goFish = new GoFish(player);
+ GoFishPlayer dealer = goFish.getDealer();
+
+ int expected = 5;
+ dealer.setCounter4(expected);
+
+ // When
+ goFish.updateDealerScore();
+ int actual = goFish.getDealersScoreCounter();
+
+ // Then
+ Assert.assertEquals(expected, actual);
+ }
+
+
+ @Test
+ public void checkAskInputTest() {
+ // Given
+ Player player = new Player("Cara", 1000);
+ GoFish goFish = new GoFish(player);
+ goFish.setNewTurn(false);
+
+ // When
+ goFish.setInput("notAsk");
+ goFish.checkAskInput();
+ boolean actualFalse = goFish.isPlayerAskingForCard();
+
+ goFish.setInput("ask");
+ goFish.checkAskInput();
+ boolean actualTrue = goFish.isPlayerAskingForCard();
+
+ // Then
+ Assert.assertFalse(actualFalse);
+ Assert.assertTrue(actualTrue);
+ }
+
+
+ @Test
+ public void checkDrawInputTest() {
+ // Given
+ Player player = new Player("Cara", 1000);
+ GoFish goFish = new GoFish(player);
+ goFish.setNewTurn(false);
+ goFish.setPlayerDrawing(false);
+
+ // When
+ goFish.setInput("draw");
+ goFish.checkDrawInput();
+ boolean expectedNewTurnTrue = goFish.isNewTurn();
+ boolean expectedPlayerDrawingTrue = goFish.isPlayerDrawing();
+
+ goFish.setPlayerDrawing(false);
+ goFish.setNewTurn(false);
+ goFish.setInput("ask");
+ goFish.checkDrawInput();
+ boolean expectedNewTurnTrue2 = goFish.isNewTurn();
+ boolean expectedPlayerDrawingFalse = goFish.isPlayerDrawing();
+
+ goFish.setNewTurn(true);
+ goFish.setInput("notDrawOrAsk");
+ goFish.checkDrawInput();
+ boolean expectedNewTurnFalse = goFish.isNewTurn();
+
+ // Then
+ Assert.assertTrue(expectedNewTurnTrue);
+ Assert.assertTrue(expectedPlayerDrawingTrue);
+ Assert.assertTrue(expectedNewTurnTrue2);
+ Assert.assertFalse(expectedPlayerDrawingFalse);
+ Assert.assertFalse(expectedNewTurnFalse);
+
+ }
+
+
+ @Test
+ public void getDealersRequestedCardTest() {
+ // Given
+ Player player = new Player("Cara", 1000);
+ GoFish goFish = new GoFish(player);
+ GoFishPlayer dealer = goFish.getDealer();
+ ArrayList cards = new ArrayList<>();
+ cards.add(h3);
+ cards.add(s9);
+ cards.add(d2);
+ dealer.getHand().addCardsToHand(cards);
+
+ // When
+ ArrayList expected = new ArrayList<>();
+ expected.add(THREE);
+ expected.add(NINE);
+ expected.add(QUEEN);
+ expected.add(TWO);
+ expected.add(SEVEN);
+ expected.add(JACK);
+
+ ArrayList notExpected = new ArrayList<>();
+ notExpected.add(ACE);
+ notExpected.add(FOUR);
+ notExpected.add(FIVE);
+ notExpected.add(SIX);
+ notExpected.add(EIGHT);
+ notExpected.add(TEN);
+ notExpected.add(KING);
+
+ Face requestedCard = goFish.getDealersRequestedCard();
+ boolean actualTrue = expected.contains(requestedCard);
+ boolean actualFalse = notExpected.contains(requestedCard);
+
+ // Then
+ Assert.assertTrue(actualTrue);
+ Assert.assertFalse(actualFalse);
+ }
+
+
+/*
+ @Test
+ public void respondToDealerTest() {
+ // Given
+ Player player = new Player("Cara", 1000);
+ GoFish goFish = new GoFish(player);
+ GoFishPlayer dealer = goFish.getDealer();
+ Face requestedCard = KING;
+ }
+*/
+
+
+ @Test
+ public void setAllBooleansFalseTest() {
+ // Given
+ Player player = new Player("Nhu", 1000);
+ GoFish goFish = new GoFish(player);
+
+
+ // When
+
+ goFish.setAllBooleansFalse();
+
+ // Then
+
+ Assert.assertFalse(goFish.isPlaying());
+ Assert.assertFalse(goFish.isPlayerAskingForCard());
+ Assert.assertFalse(goFish.isPlayerDrawing());
+ Assert.assertFalse(goFish.isPlayersTurn());
+ Assert.assertFalse(goFish.isNewTurn());
+ Assert.assertFalse(goFish.isDealersTurn());
+ Assert.assertFalse(goFish.isDealerAskingForCard());
+ Assert.assertFalse(goFish.isGivingDealerCard());
+ Assert.assertNull(goFish.getRequestedCard());
+
+
+ }
+
+ @Test
+ public void checkExitTest() {
+ // Given
+ Player player = new Player("Nhu", 1000);
+ GoFish goFish = new GoFish(player);
+ String input1 = "exit";
+ goFish.setInput(input1);
+
+
+ // When
+ goFish.checkExit();
+
+ // Then
+ Assert.assertFalse(goFish.isPlaying());
+ Assert.assertFalse(goFish.isPlayerAskingForCard());
+ Assert.assertFalse(goFish.isPlayerDrawing());
+ Assert.assertFalse(goFish.isPlayersTurn());
+ Assert.assertFalse(goFish.isNewTurn());
+ Assert.assertFalse(goFish.isDealersTurn());
+ Assert.assertFalse(goFish.isDealerAskingForCard());
+ Assert.assertFalse(goFish.isGivingDealerCard());
+ Assert.assertNull(goFish.getRequestedCard());
+
+
+ }
+
+
+ @Test
+ public void walkAwayTest() {
+
+
+ // Given
+ Player player = new Player("Nhu", 1000);
+ GoFish goFish = new GoFish(player);
+
+
+ // When
+ goFish.walkAway();
+
+ // Then
+ Assert.assertFalse(goFish.isPlaying());
+
+
+ }
+
+ @Test
+ public void walkAwayTest2() {
+
+
+ // Given
+ Player player = new Player("Nhu", 1000);
+ GoFish goFish = new GoFish(player);
+
+
+ // When
+ goFish.walkAway();
+
+ // Then
+
+ Assert.assertFalse(goFish.isPlayerAskingForCard());
+
+
+ }
+
+ @Test
+ public void walkAwayTest3() {
+
+
+ // Given
+ Player player = new Player("Nhu", 1000);
+ GoFish goFish = new GoFish(player);
+
+
+ // When
+ goFish.walkAway();
+
+ // Then
+
+ Assert.assertFalse(goFish.isPlayerDrawing());
+
+ }
+
+ @Test
+ public void walkAwayTest4() {
+
+
+ // Given
+ Player player = new Player("Nhu", 1000);
+ GoFish goFish = new GoFish(player);
+
+
+ // When
+ goFish.walkAway();
+
+ // Then
+
+
+ Assert.assertFalse(goFish.isPlayersTurn());
+
+
+ }
+
+ @Test
+ public void walkAwayTest5() {
+
+
+ // Given
+ Player player = new Player("Nhu", 1000);
+ GoFish goFish = new GoFish(player);
+
+
+ // When
+ goFish.walkAway();
+
+ // Then
+
+ Assert.assertFalse(goFish.isNewTurn());
+
+ }
+
+ @Test
+ public void walkAwayTest6() {
+
+
+ // Given
+ Player player = new Player("Nhu", 1000);
+ GoFish goFish = new GoFish(player);
+
+
+ // When
+ goFish.walkAway();
+
+ // Then
+
+ Assert.assertFalse(goFish.isDealersTurn());
+
+
+ }
+
+ @Test
+ public void walkAwayTest7() {
+
+
+ // Given
+ Player player = new Player("Nhu", 1000);
+ GoFish goFish = new GoFish(player);
+
+
+ // When
+ goFish.walkAway();
+
+ // Then
+
+ Assert.assertFalse(goFish.isDealerAskingForCard());
+
+ }
+
+ @Test
+ public void walkAwayTest8() {
+
+
+ // Given
+ Player player = new Player("Nhu", 1000);
+ GoFish goFish = new GoFish(player);
+
+
+ // When
+ goFish.walkAway();
+
+ // Then
+
+ Assert.assertFalse(goFish.isGivingDealerCard());
+
+
+ }
+
+ @Test
+ public void walkAwayTest9() {
+
+
+ // Given
+ Player player = new Player("Nhu", 1000);
+ GoFish goFish = new GoFish(player);
+
+
+ // When
+ goFish.walkAway();
+
+ // Then
+
+ Assert.assertNull(goFish.getRequestedCard());
+
+
+ }
+
+ @Test
+ public void deckIsEmptyTest() {
+
+
+ // Given
+ Player player = new Player("Nhu", 1000);
+ GoFish goFish = new GoFish(player);
+
+ goFish.getDeck().deck.removeAll(goFish.getDeck().deck);
+
+
+ // When
+ boolean actual = goFish.deckIsEmpty(goFish.getDeck());
+
+
+ // Then
+ Assert.assertTrue(actual);
+
+ }
+
+ @Test
+
+ public void checkIfDeckIsEmptyTest() {
+
+ // Given
+ Player player = new Player("Nhu", 1000);
+ GoFish goFish = new GoFish(player);
+
+ goFish.getDeck().deck.removeAll(goFish.getDeck().deck);
+
+
+ // When
+
+ goFish.checkIfDeckIsEmpty();
+
+ // Then
+ Assert.assertFalse(goFish.isPlayerDrawing());
+
+
+ }
+
+ @Test
+
+ public void checkIfDeckIsEmptyTest2() {
+
+ // Given
+ Player player = new Player("Nhu", 1000);
+ GoFish goFish = new GoFish(player);
+
+ goFish.getDeck().deck.removeAll(goFish.getDeck().deck);
+
+
+ // When
+
+ goFish.checkIfDeckIsEmpty();
+
+ // Then
+ Assert.assertFalse(goFish.isDealerDrawing());
+
+
+ }
+
+ @Test
+
+ public void drawNewCardsIfHandIsEmptyTest(){
+
+ // Given
+ Player player = new Player("Nhu", 1000);
+ GoFish goFish = new GoFish(player);
+
+ goFish.getDeck().deck.removeAll(goFish.getDeck().deck);
+
+
+ // When
+ goFish.drawNewCardsIfHandIsEmpty(goFish.getGoFishPlayer());
+
+ //goFish.checkIfDeckIsEmpty();
+
+ // Then
+ Assert.assertTrue(goFish.deckIsEmpty(goFish.getDeck()));
+
+
+ }
+
+ @Test
+ public void endOfGameMessageTest(){
+
+ // Given
+ Player player = new Player("Nhu", 1000);
+ GoFish goFish = new GoFish(player);
+
+
+ // When
+ goFish.endOfGameMessage(goFish.getGoFishPlayer());
+
+
+ // Then
+ Assert.assertFalse(goFish.isPlaying());
+ Assert.assertFalse(goFish.isPlayerAskingForCard());
+ Assert.assertFalse(goFish.isPlayerDrawing());
+ Assert.assertFalse(goFish.isPlayersTurn());
+ Assert.assertFalse(goFish.isNewTurn());
+ Assert.assertFalse(goFish.isDealersTurn());
+ Assert.assertFalse(goFish.isDealerAskingForCard());
+ Assert.assertFalse(goFish.isGivingDealerCard());
+ Assert.assertNull(goFish.getRequestedCard());
+
+
+
+ }
+
+ @Test
+ public void checkIfOutOfCardsTest(){
+
+ // Given
+ Player player = new Player("Nhu", 1000);
+ GoFish goFish = new GoFish(player);
+
+ goFish.getDeck().deck.removeAll(goFish.getDeck().deck);
+
+
+ // When
+
+ goFish.drawNewCardsIfHandIsEmpty(goFish.getDealer());
+
+
+ // Then
+ Assert.assertTrue(goFish.deckIsEmpty(goFish.getDeck()));
+
+ }
+
+
+
+}
diff --git a/src/test/java/io/zipcoder/casino/YahtzeePlayerTests.java b/src/test/java/io/zipcoder/casino/YahtzeePlayerTests.java
new file mode 100644
index 000000000..1135e1e1d
--- /dev/null
+++ b/src/test/java/io/zipcoder/casino/YahtzeePlayerTests.java
@@ -0,0 +1,193 @@
+package io.zipcoder.casino;
+
+import io.zipcoder.casino.DiceGame.Dice;
+import io.zipcoder.casino.DiceGame.YahtzeePlayer;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.TreeMap;
+
+public class YahtzeePlayerTests {
+
+ Dice d1 = new Dice(1, 1);
+ Dice d2 = new Dice(1, 2);
+ Dice d3 = new Dice(1, 3);
+ Dice d4 = new Dice(1, 4);
+ Dice d5 = new Dice(1, 5);
+ Dice d6 = new Dice(1, 6);
+
+ @Test
+ public void YahtzeePlayerConstructorTest(){
+ // Given
+ String expectedName = "Cara";
+ Player expectedPlayer = new Player(expectedName, 1000.0);
+
+ // When
+ YahtzeePlayer yahtzeePlayer = new YahtzeePlayer(expectedPlayer);
+ Player actualPlayer = yahtzeePlayer.getPlayer();
+ String actualName = yahtzeePlayer.getName();
+
+ // Then
+ Assert.assertEquals(expectedName, actualName);
+ Assert.assertEquals(expectedPlayer, actualPlayer);
+ }
+
+
+ @Test
+ public void playerRollDiceTest() throws YahtzeePlayer.TooManyRollsException {
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ YahtzeePlayer yahtzeePlayer = new YahtzeePlayer(player);
+ int expected = 5;
+
+ // When
+ ArrayList rolledDice = yahtzeePlayer.playerRollDice(5);
+ int actual = rolledDice.size();
+
+ // Then
+ Assert.assertEquals(expected, actual);
+ }
+
+
+ @Test
+ public void saveDiceTest(){
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ YahtzeePlayer yahtzeePlayer = new YahtzeePlayer(player);
+
+ ArrayList rolledDice = new ArrayList<>();
+ rolledDice.add(d3);
+ rolledDice.add(d6);
+ rolledDice.add(d1);
+ rolledDice.add(d6);
+ rolledDice.add(d2);
+
+ String diceToSaveInput = "135";
+
+ ArrayList expectedSaved = new ArrayList<>();
+ expectedSaved.add(d3);
+ expectedSaved.add(d1);
+ expectedSaved.add(d2);
+
+ ArrayList expectedRolled = new ArrayList<>();
+ expectedRolled.add(d6);
+ expectedRolled.add(d6);
+
+ // When
+ ArrayList actualSaved = yahtzeePlayer.saveDice(rolledDice, diceToSaveInput);
+
+ // Then
+ Assert.assertEquals(expectedSaved, actualSaved);
+ Assert.assertEquals(expectedRolled, rolledDice);
+ }
+
+
+ @Test
+ public void returnDiceTest(){
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ YahtzeePlayer yahtzeePlayer = new YahtzeePlayer(player);
+
+ ArrayList savedDice = new ArrayList<>();
+ savedDice.add(d1);
+ savedDice.add(d3);
+ savedDice.add(d2);
+ savedDice.add(d3);
+ savedDice.add(d6);
+
+ String diceToReturnInput = "324";
+
+ ArrayList expectedReturned = new ArrayList<>();
+ expectedReturned.add(d3);
+ expectedReturned.add(d2);
+ expectedReturned.add(d3);
+
+ ArrayList expectedSaved = new ArrayList<>();
+ expectedSaved.add(d1);
+ expectedSaved.add(d6);
+
+ // When
+ ArrayList actualReturned = yahtzeePlayer.returnDice(savedDice, diceToReturnInput);
+
+ // Then
+ Assert.assertEquals(expectedReturned, actualReturned);
+ Assert.assertEquals(expectedSaved, savedDice);
+ }
+
+
+ @Test
+ public void removeSameDiceTest(){
+ Player player = new Player("Cara", 1000.00);
+ YahtzeePlayer yahtzeePlayer = new YahtzeePlayer(player);
+
+ ArrayList diceList = new ArrayList<>();
+ diceList.add(d1);
+ diceList.add(d2);
+ diceList.add(d3);
+ diceList.add(d4);
+
+ ArrayList diceListToRemoveFrom = new ArrayList<>();
+ diceListToRemoveFrom.add(d3);
+ diceListToRemoveFrom.add(d4);
+ diceListToRemoveFrom.add(d5);
+ diceListToRemoveFrom.add(d6);
+
+ ArrayList expectedRemovedFromDiceList = new ArrayList<>();
+ expectedRemovedFromDiceList.add(d5);
+ expectedRemovedFromDiceList.add(d6);
+
+ // When
+ yahtzeePlayer.removeSameDice(diceListToRemoveFrom, diceList);
+
+ // Then
+ Assert.assertEquals(expectedRemovedFromDiceList, diceListToRemoveFrom);
+ }
+
+
+ @Test
+ public void removeDuplicateCharactersTest(){
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ YahtzeePlayer yahtzeePlayer = new YahtzeePlayer(player);
+
+ String input = "1122334454435";
+ String expected = "12345";
+
+ // When
+ String actual = yahtzeePlayer.removeDuplicateCharacters(input);
+
+ // Then
+ Assert.assertEquals(expected, actual);
+ }
+
+
+ @Test(expected = YahtzeePlayer.TooManyRollsException.class)
+ public void tooManyRollsExceptionTest() throws YahtzeePlayer.TooManyRollsException{
+ Player player = new Player("Cara", 1000);
+ YahtzeePlayer yahtzeePlayer = new YahtzeePlayer(player);
+ yahtzeePlayer.setRollNumber(3);
+ yahtzeePlayer.playerRollDice(5);
+ }
+
+ @Test
+ public void getRollNumberTest(){
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ YahtzeePlayer yahtzeePlayer = new YahtzeePlayer(player);
+
+ int expected = 2;
+ yahtzeePlayer.setRollNumber(expected);
+
+ // When
+ int actual = yahtzeePlayer.getRollNumber();
+
+ // Then
+ Assert.assertEquals(expected, actual);
+
+
+
+ }
+
+
+}
diff --git a/src/test/java/io/zipcoder/casino/YahtzeeTests.java b/src/test/java/io/zipcoder/casino/YahtzeeTests.java
new file mode 100644
index 000000000..b175cf1be
--- /dev/null
+++ b/src/test/java/io/zipcoder/casino/YahtzeeTests.java
@@ -0,0 +1,1795 @@
+package io.zipcoder.casino;
+
+import io.zipcoder.casino.DiceGame.Dice;
+import io.zipcoder.casino.DiceGame.Yahtzee;
+import io.zipcoder.casino.DiceGame.YahtzeePlayer;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.TreeMap;
+
+public class YahtzeeTests {
+
+ Dice d1 = new Dice(1, 1);
+ Dice d2 = new Dice(1, 2);
+ Dice d3 = new Dice(1, 3);
+ Dice d4 = new Dice(1, 4);
+ Dice d5 = new Dice(1, 5);
+ Dice d6 = new Dice(1, 6);
+
+ @Test
+ public void YahtzeeConstructorTest() {
+ // Given
+ String expectedYahtzeePlayerName = "Cara";
+ Player player = new Player(expectedYahtzeePlayerName, 1000.00);
+ ArrayList expectedSavedDice = new ArrayList<>();
+ ArrayList expectedRolledDice = new ArrayList<>();
+ int expectedScore = 0;
+
+ // When
+ Yahtzee yahtzee = new Yahtzee(player);
+ String actualYahtzeePlayerName = yahtzee.getYahtzeePlayer().getName();
+ ArrayList actualSavedDice = yahtzee.getSavedDice();
+ ArrayList actualRolledDice = yahtzee.getRolledDice();
+ int actualScore = yahtzee.getScore();
+
+ // Then
+ Assert.assertEquals(expectedYahtzeePlayerName, actualYahtzeePlayerName);
+ Assert.assertEquals(expectedSavedDice, actualSavedDice);
+ Assert.assertEquals(expectedRolledDice, actualRolledDice);
+ Assert.assertEquals(expectedScore, actualScore);
+ }
+
+
+ @Test
+ public void getAllDiceTest() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ yahtzee.getRolledDice().add(d1);
+ yahtzee.getRolledDice().add(d2);
+ yahtzee.getRolledDice().add(d3);
+
+ yahtzee.getSavedDice().add(d4);
+ yahtzee.getSavedDice().add(d5);
+
+ ArrayList expectedAllDice = new ArrayList();
+ expectedAllDice.add(d1);
+ expectedAllDice.add(d2);
+ expectedAllDice.add(d3);
+ expectedAllDice.add(d4);
+ expectedAllDice.add(d5);
+
+ // When
+ ArrayList actualAllDice = yahtzee.getAllDice(yahtzee.getRolledDice(), yahtzee.getSavedDice());
+
+ // Then
+ Assert.assertEquals(expectedAllDice, actualAllDice);
+ }
+
+
+ @Test
+ public void getScoreForCategoryTest() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ // Aces
+ ArrayList acesDice = new ArrayList<>();
+ acesDice.add(d1);
+ acesDice.add(d2);
+ acesDice.add(d3);
+ acesDice.add(d1);
+ acesDice.add(d1);
+ int expectedAcesScore = 3;
+
+ // Twos
+ ArrayList twosDice = new ArrayList<>();
+ twosDice.add(d2);
+ twosDice.add(d6);
+ twosDice.add(d5);
+ twosDice.add(d2);
+ twosDice.add(d1);
+ int expectedTwosScore = 4;
+
+ // Threes
+ ArrayList threesDice = new ArrayList<>();
+ threesDice.add(d3);
+ threesDice.add(d3);
+ threesDice.add(d4);
+ threesDice.add(d3);
+ threesDice.add(d3);
+ int expectedThreesScore = 12;
+
+ // Fours
+ ArrayList foursDice = new ArrayList<>();
+ foursDice.add(d4);
+ foursDice.add(d1);
+ foursDice.add(d4);
+ foursDice.add(d5);
+ foursDice.add(d2);
+ int expectedFoursScore = 8;
+
+ // Fives
+ ArrayList fivesDice = new ArrayList<>();
+ fivesDice.add(d5);
+ fivesDice.add(d5);
+ fivesDice.add(d5);
+ fivesDice.add(d5);
+ fivesDice.add(d5);
+ int expectedFivesScore = 25;
+
+ // Sixes
+ ArrayList sixesDice = new ArrayList<>();
+ sixesDice.add(d1);
+ sixesDice.add(d6);
+ sixesDice.add(d6);
+ sixesDice.add(d6);
+ sixesDice.add(d1);
+ int expectedSixesScore = 18;
+
+ // Three of a Kind
+ ArrayList threeOfAKindDice = new ArrayList<>();
+ threeOfAKindDice.add(d5);
+ threeOfAKindDice.add(d4);
+ threeOfAKindDice.add(d5);
+ threeOfAKindDice.add(d5);
+ threeOfAKindDice.add(d2);
+ int expectedThreeOfAKindScore = 21;
+ int expectedNotThreeOfAKindScore = 0;
+
+ // Four of a Kind
+ ArrayList fourOfAKindDice = new ArrayList<>();
+ fourOfAKindDice.add(d1);
+ fourOfAKindDice.add(d1);
+ fourOfAKindDice.add(d1);
+ fourOfAKindDice.add(d6);
+ fourOfAKindDice.add(d1);
+ int expectedFourOfAKindScore = 10;
+ int expectedNotFourOfAKindScore = 0;
+
+ // Small Straight
+ ArrayList smallStraightDice = new ArrayList<>();
+ smallStraightDice.add(d3);
+ smallStraightDice.add(d2);
+ smallStraightDice.add(d1);
+ smallStraightDice.add(d3);
+ smallStraightDice.add(d4);
+ int expectedSmallStraightScore = 30;
+ int expectedNotSmallStraightScore = 0;
+
+ // Large Straight
+ ArrayList largeStraightDice = new ArrayList<>();
+ largeStraightDice.add(d2);
+ largeStraightDice.add(d3);
+ largeStraightDice.add(d4);
+ largeStraightDice.add(d6);
+ largeStraightDice.add(d5);
+ int expectedLargeStraight = 40;
+ int expectedNotLargeStraight = 0;
+
+ // Yahtzee
+ ArrayList yahtzeeDice = new ArrayList<>();
+ yahtzeeDice.add(d2);
+ yahtzeeDice.add(d2);
+ yahtzeeDice.add(d2);
+ yahtzeeDice.add(d2);
+ yahtzeeDice.add(d2);
+ int expectedYahtzeeScore = 50;
+ int expectedNotYahtzeeScore = 0;
+
+ // Chance
+ ArrayList chanceDice = new ArrayList<>();
+ chanceDice.add(d1);
+ chanceDice.add(d2);
+ chanceDice.add(d5);
+ chanceDice.add(d6);
+ chanceDice.add(d6);
+ int expectedChanceScore = 20;
+
+
+ // When
+ int actualAcesScore = yahtzee.getScoreForCategory("Aces", acesDice);
+ int actualTwosScore = yahtzee.getScoreForCategory("Twos", twosDice);
+ int actualThreesScore = yahtzee.getScoreForCategory("Threes", threesDice);
+ int actualFoursScore = yahtzee.getScoreForCategory("Fours", foursDice);
+ int actualFivesScore = yahtzee.getScoreForCategory("Fives", fivesDice);
+ int actualSixesScore = yahtzee.getScoreForCategory("Sixes", sixesDice);
+
+ int actualThreeOfAKindScore = yahtzee.getScoreForCategory("3 of a kind", threeOfAKindDice);
+ int actualNotThreeOfAKindScore = yahtzee.getScoreForCategory("3 of a kind", twosDice);
+
+ int actualFourOfAKindScore = yahtzee.getScoreForCategory("4 of a kind", fourOfAKindDice);
+ int actualNotFourOfAKindScore = yahtzee.getScoreForCategory("4 of a kind", foursDice);
+
+ int actualSmallStraightScore = yahtzee.getScoreForCategory("Small straight", smallStraightDice);
+ int actualNotSmallStraightScore = yahtzee.getScoreForCategory("Small straight", fourOfAKindDice);
+
+ int actualLargeStraightScore = yahtzee.getScoreForCategory("Large straight", largeStraightDice);
+ int actualNotLargeStraightScore = yahtzee.getScoreForCategory("Large straight", smallStraightDice);
+
+ int actualYahtzeeScore = yahtzee.getScoreForCategory("Yahtzee", yahtzeeDice);
+ int actualNotYahtzeeScore = yahtzee.getScoreForCategory("Yahtzee", fourOfAKindDice);
+
+ int actualChanceScore = yahtzee.getScoreForCategory("Chance", chanceDice);
+
+
+ // Then
+ Assert.assertEquals(expectedAcesScore, actualAcesScore);
+ Assert.assertEquals(expectedTwosScore, actualTwosScore);
+ Assert.assertEquals(expectedThreesScore, actualThreesScore);
+ Assert.assertEquals(expectedFoursScore, actualFoursScore);
+ Assert.assertEquals(expectedFivesScore, actualFivesScore);
+ Assert.assertEquals(expectedSixesScore, actualSixesScore);
+
+ Assert.assertEquals(expectedThreeOfAKindScore, actualThreeOfAKindScore);
+ Assert.assertEquals(expectedNotThreeOfAKindScore, actualNotThreeOfAKindScore);
+
+ Assert.assertEquals(expectedFourOfAKindScore, actualFourOfAKindScore);
+ Assert.assertEquals(expectedNotFourOfAKindScore, actualNotFourOfAKindScore);
+
+ Assert.assertEquals(expectedSmallStraightScore, actualSmallStraightScore);
+ Assert.assertEquals(expectedNotSmallStraightScore, actualNotSmallStraightScore);
+
+ Assert.assertEquals(expectedLargeStraight, actualLargeStraightScore);
+ Assert.assertEquals(expectedNotLargeStraight, actualNotLargeStraightScore);
+
+ Assert.assertEquals(expectedYahtzeeScore, actualYahtzeeScore);
+ Assert.assertEquals(expectedNotYahtzeeScore, actualNotYahtzeeScore);
+
+ Assert.assertEquals(expectedChanceScore, actualChanceScore);
+ }
+
+
+ @Test
+ public void scoreAcesTest() {
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ ArrayList diceWith2Aces = new ArrayList<>();
+ diceWith2Aces.add(d1);
+ diceWith2Aces.add(d2);
+ diceWith2Aces.add(d3);
+ diceWith2Aces.add(d1);
+ diceWith2Aces.add(d5);
+ int expectedScore1 = 2;
+
+ ArrayList diceWith0Aces = new ArrayList<>();
+ diceWith0Aces.add(d5);
+ diceWith0Aces.add(d2);
+ diceWith0Aces.add(d3);
+ diceWith0Aces.add(d4);
+ diceWith0Aces.add(d6);
+ int expectedScore2 = 0;
+
+ // When
+ int actualScore1 = yahtzee.scoreAces(diceWith2Aces);
+ int actualScore2 = yahtzee.scoreAces(diceWith0Aces);
+
+ // Then
+ Assert.assertEquals(expectedScore1, actualScore1);
+ Assert.assertEquals(expectedScore2, actualScore2);
+ }
+
+
+ @Test
+ public void scoreTwosTest() {
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ ArrayList diceWith4Twos = new ArrayList<>();
+ diceWith4Twos.add(d2);
+ diceWith4Twos.add(d3);
+ diceWith4Twos.add(d2);
+ diceWith4Twos.add(d2);
+ diceWith4Twos.add(d2);
+ int expectedScore1 = 8;
+
+ ArrayList diceWith0Twos = new ArrayList<>();
+ diceWith0Twos.add(d5);
+ diceWith0Twos.add(d6);
+ diceWith0Twos.add(d1);
+ diceWith0Twos.add(d3);
+ diceWith0Twos.add(d4);
+ int expectedScore2 = 0;
+
+ // When
+ int actualScore1 = yahtzee.scoreTwos(diceWith4Twos);
+ int actualScore2 = yahtzee.scoreTwos(diceWith0Twos);
+
+ // Then
+ Assert.assertEquals(expectedScore1, actualScore1);
+ Assert.assertEquals(expectedScore2, actualScore2);
+ }
+
+
+ @Test
+ public void scoreThreesTest() {
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ ArrayList diceWith3Threes = new ArrayList<>();
+ diceWith3Threes.add(d3);
+ diceWith3Threes.add(d2);
+ diceWith3Threes.add(d2);
+ diceWith3Threes.add(d3);
+ diceWith3Threes.add(d3);
+ int expectedScore1 = 9;
+
+ ArrayList diceWith0Threes = new ArrayList<>();
+ diceWith0Threes.add(d1);
+ diceWith0Threes.add(d2);
+ diceWith0Threes.add(d4);
+ diceWith0Threes.add(d5);
+ diceWith0Threes.add(d6);
+ int expectedScore2 = 0;
+
+ // When
+ int actualScore1 = yahtzee.scoreThrees(diceWith3Threes);
+ int actualScore2 = yahtzee.scoreThrees(diceWith0Threes);
+
+ // Then
+ Assert.assertEquals(expectedScore1, actualScore1);
+ Assert.assertEquals(expectedScore2, actualScore2);
+ }
+
+
+ @Test
+ public void scoreFoursTest() {
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ ArrayList diceWith4Fours = new ArrayList<>();
+ diceWith4Fours.add(d4);
+ diceWith4Fours.add(d2);
+ diceWith4Fours.add(d4);
+ diceWith4Fours.add(d4);
+ diceWith4Fours.add(d4);
+ int expectedScore1 = 16;
+
+ ArrayList diceWith0Fours = new ArrayList();
+ diceWith0Fours.add(d1);
+ diceWith0Fours.add(d2);
+ diceWith0Fours.add(d3);
+ diceWith0Fours.add(d5);
+ diceWith0Fours.add(d6);
+ int expectedScore2 = 0;
+
+ // When
+ int actualScore1 = yahtzee.scoreFours(diceWith4Fours);
+ int actualScore2 = yahtzee.scoreFours(diceWith0Fours);
+
+ // Then
+ Assert.assertEquals(expectedScore1, actualScore1);
+ Assert.assertEquals(expectedScore2, actualScore2);
+ }
+
+
+ @Test
+ public void scoreFivesTest() {
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ ArrayList diceWith3Fives = new ArrayList<>();
+ diceWith3Fives.add(d1);
+ diceWith3Fives.add(d2);
+ diceWith3Fives.add(d5);
+ diceWith3Fives.add(d5);
+ diceWith3Fives.add(d5);
+ int expectedScore1 = 15;
+
+ ArrayList diceWith0Fives = new ArrayList<>();
+ diceWith0Fives.add(d1);
+ diceWith0Fives.add(d2);
+ diceWith0Fives.add(d3);
+ diceWith0Fives.add(d4);
+ diceWith0Fives.add(d6);
+ int expectedScore2 = 0;
+
+ // When
+ int actualScore1 = yahtzee.scoreFives(diceWith3Fives);
+ int actualScore2 = yahtzee.scoreFives(diceWith0Fives);
+
+ // Then
+ Assert.assertEquals(expectedScore1, actualScore1);
+ Assert.assertEquals(expectedScore2, actualScore2);
+ }
+
+
+ @Test
+ public void scoreSixesTest() {
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ ArrayList diceWith4Sixes = new ArrayList<>();
+ diceWith4Sixes.add(d6);
+ diceWith4Sixes.add(d6);
+ diceWith4Sixes.add(d1);
+ diceWith4Sixes.add(d6);
+ diceWith4Sixes.add(d6);
+ int expectedScore1 = 24;
+
+ ArrayList diceWith0Sixes = new ArrayList<>();
+ diceWith0Sixes.add(d1);
+ diceWith0Sixes.add(d2);
+ diceWith0Sixes.add(d3);
+ diceWith0Sixes.add(d4);
+ diceWith0Sixes.add(d5);
+ int expectedScore2 = 0;
+
+ // When
+ int actualScore1 = yahtzee.scoreSixes(diceWith4Sixes);
+ int actualScore2 = yahtzee.scoreSixes(diceWith0Sixes);
+
+ // Then
+ Assert.assertEquals(expectedScore1, actualScore1);
+ Assert.assertEquals(expectedScore2, actualScore2);
+ }
+
+
+ @Test
+ public void hasThreeOfAKindTest() {
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ ArrayList diceWithThreeOfAKind = new ArrayList<>();
+ diceWithThreeOfAKind.add(d3);
+ diceWithThreeOfAKind.add(d2);
+ diceWithThreeOfAKind.add(d3);
+ diceWithThreeOfAKind.add(d4);
+ diceWithThreeOfAKind.add(d3);
+
+ ArrayList diceWithoutThreeOfAKind = new ArrayList<>();
+ diceWithoutThreeOfAKind.add(d1);
+ diceWithoutThreeOfAKind.add(d2);
+ diceWithoutThreeOfAKind.add(d3);
+ diceWithoutThreeOfAKind.add(d4);
+ diceWithoutThreeOfAKind.add(d3);
+
+ // When
+ boolean actualThreeOfAKind = yahtzee.hasThreeOfAKind(diceWithThreeOfAKind);
+ boolean actualNotThreeOfAKind = yahtzee.hasThreeOfAKind(diceWithoutThreeOfAKind);
+
+ // Then
+ Assert.assertTrue(actualThreeOfAKind);
+ Assert.assertFalse(actualNotThreeOfAKind);
+ }
+
+
+ @Test
+ public void hasFourOfAKindTest() {
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ ArrayList diceWithFourOfAKind = new ArrayList<>();
+ diceWithFourOfAKind.add(d2);
+ diceWithFourOfAKind.add(d2);
+ diceWithFourOfAKind.add(d6);
+ diceWithFourOfAKind.add(d2);
+ diceWithFourOfAKind.add(d2);
+
+ ArrayList diceWithoutFourOfAKind = new ArrayList<>();
+ diceWithoutFourOfAKind.add(d2);
+ diceWithoutFourOfAKind.add(d3);
+ diceWithoutFourOfAKind.add(d4);
+ diceWithoutFourOfAKind.add(d2);
+ diceWithoutFourOfAKind.add(d2);
+
+ // When
+ boolean actualFourOfAKind = yahtzee.hasFourOfAKind(diceWithFourOfAKind);
+ boolean actualNotFourOfAKind = yahtzee.hasFourOfAKind(diceWithoutFourOfAKind);
+
+ // Then
+ Assert.assertTrue(actualFourOfAKind);
+ Assert.assertFalse(actualNotFourOfAKind);
+ }
+
+
+ @Test
+ public void hasFullHouseTest() {
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ ArrayList diceWithFullHouse = new ArrayList<>();
+ diceWithFullHouse.add(d3);
+ diceWithFullHouse.add(d6);
+ diceWithFullHouse.add(d6);
+ diceWithFullHouse.add(d3);
+ diceWithFullHouse.add(d3);
+
+ ArrayList diceWithoutFullHouse = new ArrayList<>();
+ diceWithoutFullHouse.add(d3);
+ diceWithoutFullHouse.add(d6);
+ diceWithoutFullHouse.add(d6);
+ diceWithoutFullHouse.add(d3);
+ diceWithoutFullHouse.add(d2);
+
+ // When
+ boolean actualFullHouse = yahtzee.hasFullHouse(diceWithFullHouse);
+ boolean actualNotFullHouse = yahtzee.hasFullHouse(diceWithoutFullHouse);
+
+ // Then
+ Assert.assertTrue(actualFullHouse);
+ Assert.assertFalse(actualNotFullHouse);
+ }
+
+
+ @Test
+ public void hasSmallStraightTest() {
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ ArrayList diceWithSmallStraight = new ArrayList<>();
+ diceWithSmallStraight.add(d1);
+ diceWithSmallStraight.add(d4);
+ diceWithSmallStraight.add(d6);
+ diceWithSmallStraight.add(d2);
+ diceWithSmallStraight.add(d3);
+
+ ArrayList diceWithoutSmallStraight = new ArrayList<>();
+ diceWithoutSmallStraight.add(d1);
+ diceWithoutSmallStraight.add(d2);
+ diceWithoutSmallStraight.add(d3);
+ diceWithoutSmallStraight.add(d5);
+ diceWithoutSmallStraight.add(d6);
+
+ // When
+ boolean actualSmallStraight = yahtzee.hasSmallStraight(diceWithSmallStraight);
+ boolean actualNotSmallStraight = yahtzee.hasSmallStraight(diceWithoutSmallStraight);
+
+ // Then
+ Assert.assertTrue(actualSmallStraight);
+ Assert.assertFalse(actualNotSmallStraight);
+ }
+
+
+ @Test
+ public void hasLargeStraightTest() {
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ ArrayList diceWithLargeStraight = new ArrayList<>();
+ diceWithLargeStraight.add(d6);
+ diceWithLargeStraight.add(d2);
+ diceWithLargeStraight.add(d5);
+ diceWithLargeStraight.add(d3);
+ diceWithLargeStraight.add(d4);
+
+ ArrayList diceWithoutLargeStraight = new ArrayList<>();
+ diceWithoutLargeStraight.add(d6);
+ diceWithoutLargeStraight.add(d2);
+ diceWithoutLargeStraight.add(d4);
+ diceWithoutLargeStraight.add(d3);
+ diceWithoutLargeStraight.add(d1);
+
+ // When
+ boolean actualLargeStraight = yahtzee.hasLargeStraight(diceWithLargeStraight);
+ boolean actualNotLargeStraight = yahtzee.hasLargeStraight(diceWithoutLargeStraight);
+
+ // Then
+ Assert.assertTrue(actualLargeStraight);
+ Assert.assertFalse(actualNotLargeStraight);
+ }
+
+
+ @Test
+ public void hasYahtzeeTest() {
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ ArrayList diceWithYahtzee = new ArrayList<>();
+ diceWithYahtzee.add(d2);
+ diceWithYahtzee.add(d2);
+ diceWithYahtzee.add(d2);
+ diceWithYahtzee.add(d2);
+ diceWithYahtzee.add(d2);
+
+ ArrayList diceWithoutYahtzee = new ArrayList<>();
+ diceWithoutYahtzee.add(d2);
+ diceWithoutYahtzee.add(d2);
+ diceWithoutYahtzee.add(d2);
+ diceWithoutYahtzee.add(d2);
+ diceWithoutYahtzee.add(d1);
+
+ // When
+ boolean actualYahtzee = yahtzee.hasYahtzee(diceWithYahtzee);
+ boolean actualNotYahtzee = yahtzee.hasYahtzee(diceWithoutYahtzee);
+
+ // Then
+ Assert.assertTrue(actualYahtzee);
+ Assert.assertFalse(actualNotYahtzee);
+ }
+
+
+ @Test
+ public void scoreThreeOfAKindTest() {
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ ArrayList diceWithThreeOfAKind = new ArrayList<>();
+ diceWithThreeOfAKind.add(d5);
+ diceWithThreeOfAKind.add(d5);
+ diceWithThreeOfAKind.add(d3);
+ diceWithThreeOfAKind.add(d4);
+ diceWithThreeOfAKind.add(d5);
+ int expectedScore1 = 22;
+
+ ArrayList diceWithoutThreeOfAKind = new ArrayList<>();
+ diceWithoutThreeOfAKind.add(d1);
+ diceWithoutThreeOfAKind.add(d2);
+ diceWithoutThreeOfAKind.add(d3);
+ diceWithoutThreeOfAKind.add(d4);
+ diceWithoutThreeOfAKind.add(d3);
+ int expectedScore2 = 0;
+
+ // When
+ int actualScore1 = yahtzee.scoreThreeOfAKind(diceWithThreeOfAKind);
+ int actualScore2 = yahtzee.scoreThreeOfAKind(diceWithoutThreeOfAKind);
+
+ // Then
+ Assert.assertEquals(expectedScore1, actualScore1);
+ Assert.assertEquals(expectedScore2, actualScore2);
+ }
+
+
+ @Test
+ public void scoreFourOfAKindTest() {
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ ArrayList diceWithFourOfAKind = new ArrayList<>();
+ diceWithFourOfAKind.add(d5);
+ diceWithFourOfAKind.add(d3);
+ diceWithFourOfAKind.add(d5);
+ diceWithFourOfAKind.add(d5);
+ diceWithFourOfAKind.add(d5);
+ int expectedScore1 = 23;
+
+ ArrayList diceWithoutFourOfAKind = new ArrayList<>();
+ diceWithoutFourOfAKind.add(d5);
+ diceWithoutFourOfAKind.add(d3);
+ diceWithoutFourOfAKind.add(d3);
+ diceWithoutFourOfAKind.add(d5);
+ diceWithoutFourOfAKind.add(d5);
+ int expectedScore2 = 0;
+
+ // When
+ int actualScore1 = yahtzee.scoreFourOfAKind(diceWithFourOfAKind);
+ int actualScore2 = yahtzee.scoreFourOfAKind(diceWithoutFourOfAKind);
+
+ // Then
+ Assert.assertEquals(expectedScore1, actualScore1);
+ Assert.assertEquals(expectedScore2, actualScore2);
+ }
+
+
+ @Test
+ public void scoreFullHouseTest() {
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ ArrayList diceWithFullHouse = new ArrayList<>();
+ diceWithFullHouse.add(d5);
+ diceWithFullHouse.add(d2);
+ diceWithFullHouse.add(d5);
+ diceWithFullHouse.add(d2);
+ diceWithFullHouse.add(d5);
+ int expectedScore1 = 25;
+
+ ArrayList diceWithoutFullHouse = new ArrayList<>();
+ diceWithoutFullHouse.add(d5);
+ diceWithoutFullHouse.add(d2);
+ diceWithoutFullHouse.add(d5);
+ diceWithoutFullHouse.add(d3);
+ diceWithoutFullHouse.add(d5);
+ int expectedScore2 = 0;
+
+ // When
+ int actualScore1 = yahtzee.scoreFullHouse(diceWithFullHouse);
+ int actualScore2 = yahtzee.scoreFullHouse(diceWithoutFullHouse);
+
+ // Then
+ Assert.assertEquals(expectedScore1, actualScore1);
+ Assert.assertEquals(expectedScore2, actualScore2);
+ }
+
+
+ @Test
+ public void scoreSmallStraightTest() {
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ ArrayList diceWithSmallStraight1 = new ArrayList();
+ diceWithSmallStraight1.add(d1);
+ diceWithSmallStraight1.add(d4);
+ diceWithSmallStraight1.add(d6);
+ diceWithSmallStraight1.add(d2);
+ diceWithSmallStraight1.add(d3);
+ int expectedScore1 = 30;
+
+ ArrayList diceWithSmallStraight2 = new ArrayList();
+ diceWithSmallStraight2.add(d5);
+ diceWithSmallStraight2.add(d4);
+ diceWithSmallStraight2.add(d3);
+ diceWithSmallStraight2.add(d2);
+ diceWithSmallStraight2.add(d3);
+ int expectedScore2 = 30;
+
+ ArrayList diceWithSmallStraight3 = new ArrayList();
+ diceWithSmallStraight3.add(d1);
+ diceWithSmallStraight3.add(d4);
+ diceWithSmallStraight3.add(d6);
+ diceWithSmallStraight3.add(d5);
+ diceWithSmallStraight3.add(d3);
+ int expectedScore3 = 30;
+
+ ArrayList diceWithoutSmallStraight = new ArrayList();
+ diceWithoutSmallStraight.add(d1);
+ diceWithoutSmallStraight.add(d2);
+ diceWithoutSmallStraight.add(d3);
+ diceWithoutSmallStraight.add(d5);
+ diceWithoutSmallStraight.add(d6);
+ int expectedScore4 = 0;
+
+ // When
+ int actualScore1 = yahtzee.scoreSmallStraight(diceWithSmallStraight1);
+ int actualScore2 = yahtzee.scoreSmallStraight(diceWithSmallStraight2);
+ int actualScore3 = yahtzee.scoreSmallStraight(diceWithSmallStraight3);
+ int actualScore4 = yahtzee.scoreSmallStraight(diceWithoutSmallStraight);
+
+ // Then
+ Assert.assertEquals(expectedScore1, actualScore1);
+ Assert.assertEquals(expectedScore2, actualScore2);
+ Assert.assertEquals(expectedScore3, actualScore3);
+ Assert.assertEquals(expectedScore4, actualScore4);
+ }
+
+
+ @Test
+ public void scoreLargeStraightTest() {
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ ArrayList diceWithLargeStraight1 = new ArrayList();
+ diceWithLargeStraight1.add(d6);
+ diceWithLargeStraight1.add(d2);
+ diceWithLargeStraight1.add(d5);
+ diceWithLargeStraight1.add(d3);
+ diceWithLargeStraight1.add(d4);
+ int expectedScore1 = 40;
+
+ ArrayList diceWithLargeStraight2 = new ArrayList();
+ diceWithLargeStraight2.add(d1);
+ diceWithLargeStraight2.add(d2);
+ diceWithLargeStraight2.add(d5);
+ diceWithLargeStraight2.add(d3);
+ diceWithLargeStraight2.add(d4);
+ int expectedScore2 = 40;
+
+ ArrayList diceWithoutLargeStraight = new ArrayList();
+ diceWithoutLargeStraight.add(d6);
+ diceWithoutLargeStraight.add(d2);
+ diceWithoutLargeStraight.add(d4);
+ diceWithoutLargeStraight.add(d3);
+ diceWithoutLargeStraight.add(d1);
+ int expectedScore3 = 0;
+
+ // When
+ int actualScore1 = yahtzee.scoreLargeStraight(diceWithLargeStraight1);
+ int actualScore2 = yahtzee.scoreLargeStraight(diceWithLargeStraight2);
+ int actualScore3 = yahtzee.scoreLargeStraight(diceWithoutLargeStraight);
+
+ // Then
+ Assert.assertEquals(expectedScore1, actualScore1);
+ Assert.assertEquals(expectedScore2, actualScore2);
+ Assert.assertEquals(expectedScore3, actualScore3);
+ }
+
+
+ @Test
+ public void scoreYahtzeeTest() {
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ ArrayList diceWithYahtzee = new ArrayList();
+ diceWithYahtzee.add(d4);
+ diceWithYahtzee.add(d4);
+ diceWithYahtzee.add(d4);
+ diceWithYahtzee.add(d4);
+ diceWithYahtzee.add(d4);
+ int expectedScore1 = 50;
+
+ ArrayList diceWithoutYahtzee = new ArrayList();
+ diceWithoutYahtzee.add(d4);
+ diceWithoutYahtzee.add(d4);
+ diceWithoutYahtzee.add(d4);
+ diceWithoutYahtzee.add(d4);
+ diceWithoutYahtzee.add(d6);
+ int expectedScore2 = 0;
+
+ // When
+ int actualScore1 = yahtzee.scoreYahtzee(diceWithYahtzee);
+ int actualScore2 = yahtzee.scoreYahtzee(diceWithoutYahtzee);
+
+ // Then
+ Assert.assertEquals(expectedScore1, actualScore1);
+ Assert.assertEquals(expectedScore2, actualScore2);
+ }
+
+
+ @Test
+ public void diceCounterTest() {
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ ArrayList diceToCount1 = new ArrayList();
+ diceToCount1.add(d1);
+ diceToCount1.add(d2);
+ diceToCount1.add(d3);
+ diceToCount1.add(d4);
+ diceToCount1.add(d5);
+ Integer[] expected1 = {1, 1, 1, 1, 1, 0};
+
+ ArrayList diceToCount2 = new ArrayList();
+ diceToCount2.add(d6);
+ diceToCount2.add(d6);
+ diceToCount2.add(d6);
+ diceToCount2.add(d6);
+ diceToCount2.add(d6);
+ Integer[] expected2 = {0, 0, 0, 0, 0, 5};
+
+ ArrayList diceToCount3 = new ArrayList();
+ diceToCount3.add(d3);
+ diceToCount3.add(d2);
+ diceToCount3.add(d3);
+ diceToCount3.add(d2);
+ diceToCount3.add(d3);
+ Integer[] expected3 = {0, 2, 3, 0, 0, 0};
+
+ // When
+ Integer[] actual1 = yahtzee.countDice(diceToCount1);
+ Integer[] actual2 = yahtzee.countDice(diceToCount2);
+ Integer[] actual3 = yahtzee.countDice(diceToCount3);
+
+ // Then
+ Assert.assertArrayEquals(expected1, actual1);
+ Assert.assertArrayEquals(expected2, actual2);
+ Assert.assertArrayEquals(expected3, actual3);
+ }
+
+
+ @Test
+ public void getSumOfDiceTest() {
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ ArrayList diceToSum1 = new ArrayList<>();
+ diceToSum1.add(d1);
+ diceToSum1.add(d4);
+ diceToSum1.add(d2);
+ diceToSum1.add(d6);
+ diceToSum1.add(d1);
+ int expectedSum1 = 14;
+
+ ArrayList diceToSum2 = new ArrayList<>();
+ diceToSum2.add(d6);
+ diceToSum2.add(d3);
+ diceToSum2.add(d6);
+ diceToSum2.add(d4);
+ diceToSum2.add(d6);
+ int expectedSum2 = 25;
+
+ // When
+ int actualSum1 = yahtzee.getSumOfDice(diceToSum1);
+ int actualSum2 = yahtzee.getSumOfDice(diceToSum2);
+
+ // Then
+ Assert.assertEquals(expectedSum1, actualSum1);
+ Assert.assertEquals(expectedSum2, actualSum2);
+ }
+
+ @Test
+ public void markScoreCardTest() {
+ //Given
+ Player player = new Player("Cara", 1000.00);
+ Yahtzee yahtzee = new Yahtzee(player);
+ TreeMap scoreCard = yahtzee.getScoreCard();
+
+ // Mark Aces
+ ArrayList rollAces = new ArrayList<>();
+ rollAces.add(d1);
+ rollAces.add(d2);
+ rollAces.add(d3);
+ rollAces.add(d1);
+ rollAces.add(d1);
+ int expectedAces = 3;
+
+ // Mark Twos
+ ArrayList rollTwos = new ArrayList<>();
+ rollTwos.add(d2);
+ rollTwos.add(d2);
+ rollTwos.add(d3);
+ rollTwos.add(d2);
+ rollTwos.add(d1);
+ int expectedTwos = 6;
+
+ // Mark Threes
+ ArrayList rollThrees = new ArrayList<>();
+ rollThrees.add(d3);
+ rollThrees.add(d2);
+ rollThrees.add(d3);
+ rollThrees.add(d3);
+ rollThrees.add(d3);
+ int expectedThrees = 12;
+
+ // Mark Fours
+ ArrayList rollFours = new ArrayList<>();
+ rollFours.add(d3);
+ rollFours.add(d4);
+ rollFours.add(d1);
+ rollFours.add(d5);
+ rollFours.add(d4);
+ int expectedFours = 8;
+
+ // Mark Fives
+ ArrayList rollFives = new ArrayList<>();
+ rollFives.add(d1);
+ rollFives.add(d5);
+ rollFives.add(d5);
+ rollFives.add(d5);
+ rollFives.add(d5);
+ int expectedFives = 20;
+
+ // Mark Sixes
+ ArrayList rollSixes = new ArrayList<>();
+ rollSixes.add(d6);
+ rollSixes.add(d1);
+ rollSixes.add(d4);
+ rollSixes.add(d6);
+ rollSixes.add(d6);
+ int expectedSixes = 18;
+
+ // Mark Three of A Kind
+ ArrayList rollThreeOfAKind = new ArrayList<>();
+ rollThreeOfAKind.add(d4);
+ rollThreeOfAKind.add(d4);
+ rollThreeOfAKind.add(d3);
+ rollThreeOfAKind.add(d6);
+ rollThreeOfAKind.add(d4);
+ int expectedThreeOfAKind = 21;
+
+ // Mark Four of A Kind
+ ArrayList rollFourOfAKind = new ArrayList<>();
+ rollFourOfAKind.add(d6);
+ rollFourOfAKind.add(d6);
+ rollFourOfAKind.add(d1);
+ rollFourOfAKind.add(d6);
+ rollFourOfAKind.add(d6);
+ int expectedFourOfAKind = 25;
+
+ // Mark Full House
+ ArrayList rollFullHouse = new ArrayList<>();
+ rollFullHouse.add(d3);
+ rollFullHouse.add(d3);
+ rollFullHouse.add(d4);
+ rollFullHouse.add(d3);
+ rollFullHouse.add(d4);
+ int expectedFullHouse = 25;
+
+ // Mark Small Straight
+ ArrayList rollSmallStraight = new ArrayList<>();
+ rollSmallStraight.add(d2);
+ rollSmallStraight.add(d3);
+ rollSmallStraight.add(d5);
+ rollSmallStraight.add(d3);
+ rollSmallStraight.add(d4);
+ int expectedSmallStraight = 30;
+
+ // Mark Large Straight
+ ArrayList rollLargeStraight = new ArrayList<>();
+ rollLargeStraight.add(d6);
+ rollLargeStraight.add(d5);
+ rollLargeStraight.add(d4);
+ rollLargeStraight.add(d2);
+ rollLargeStraight.add(d3);
+ int expectedLargeStraight = 40;
+
+ // Mark Yahtzee
+ ArrayList rollYahtzee = new ArrayList<>();
+ rollYahtzee.add(d1);
+ rollYahtzee.add(d1);
+ rollYahtzee.add(d1);
+ rollYahtzee.add(d1);
+ rollYahtzee.add(d1);
+ int expectedYahtzee = 50;
+
+ // Mark Chance
+ ArrayList rollChance = new ArrayList<>();
+ rollChance.add(d5);
+ rollChance.add(d6);
+ rollChance.add(d5);
+ rollChance.add(d4);
+ rollChance.add(d4);
+ int expectedChance = 24;
+
+
+ // When
+ yahtzee.markScoreCard("Aces", rollAces);
+ int actualAces = yahtzee.getScoreCard().get("aces");
+
+ yahtzee.markScoreCard("Twos", rollTwos);
+ int actualTwos = yahtzee.getScoreCard().get("twos");
+
+ yahtzee.markScoreCard("Threes", rollThrees);
+ int actualThrees = yahtzee.getScoreCard().get("threes");
+
+ yahtzee.markScoreCard("Fours", rollFours);
+ int actualFours = yahtzee.getScoreCard().get("fours");
+
+ yahtzee.markScoreCard("Fives", rollFives);
+ int actualFives = yahtzee.getScoreCard().get("fives");
+
+ yahtzee.markScoreCard("Sixes", rollSixes);
+ int actualSixes = yahtzee.getScoreCard().get("sixes");
+
+ yahtzee.markScoreCard("3 of a kind", rollThreeOfAKind);
+ int actualThreeOfAKind = yahtzee.getScoreCard().get("3 of a kind");
+
+ yahtzee.markScoreCard("4 of a kind", rollFourOfAKind);
+ int actualFourOfAKind = yahtzee.getScoreCard().get("4 of a kind");
+
+ yahtzee.markScoreCard("Full House", rollFullHouse);
+ int actualFullHouse = yahtzee.getScoreCard().get("full house");
+
+ yahtzee.markScoreCard("Small straight", rollSmallStraight);
+ int actualSmallStraight = yahtzee.getScoreCard().get("small straight");
+
+ yahtzee.markScoreCard("Large straight", rollLargeStraight);
+ int actualLargeStraight = yahtzee.getScoreCard().get("large straight");
+
+ yahtzee.markScoreCard("Yahtzee", rollYahtzee);
+ int actualYahtzee = yahtzee.getScoreCard().get("yahtzee");
+
+ yahtzee.markScoreCard("Chance", rollChance);
+ int actualChance = yahtzee.getScoreCard().get("chance");
+
+
+ // Then
+ Assert.assertEquals(expectedAces, actualAces);
+ Assert.assertEquals(expectedTwos, actualTwos);
+ Assert.assertEquals(expectedThrees, actualThrees);
+ Assert.assertEquals(expectedFours, actualFours);
+ Assert.assertEquals(expectedFives, actualFives);
+ Assert.assertEquals(expectedSixes, actualSixes);
+ Assert.assertEquals(expectedThreeOfAKind, actualThreeOfAKind);
+ Assert.assertEquals(expectedFourOfAKind, actualFourOfAKind);
+ Assert.assertEquals(expectedFullHouse, actualFullHouse);
+ Assert.assertEquals(expectedSmallStraight, actualSmallStraight);
+ Assert.assertEquals(expectedLargeStraight, actualLargeStraight);
+ Assert.assertEquals(expectedYahtzee, actualYahtzee);
+ Assert.assertEquals(expectedChance, actualChance);
+ }
+
+
+ @Test
+ public void listOfDiceToStringTest() {
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ ArrayList diceList1 = new ArrayList<>();
+ diceList1.add(d1);
+ diceList1.add(d2);
+ diceList1.add(d3);
+ diceList1.add(d4);
+ diceList1.add(d5);
+
+ String expected1 = " ⚀ | ⚁ | ⚂ | ⚃ | ⚄ |";
+
+ ArrayList diceList2 = new ArrayList<>();
+ diceList2.add(d6);
+ diceList2.add(d2);
+
+ String expected2 = " ⚅ | ⚁ |";
+
+ // When
+ String actual1 = yahtzee.listOfDiceToDiceString(diceList1);
+ String actual2 = yahtzee.listOfDiceToDiceString(diceList2);
+
+ // Then
+ Assert.assertEquals(expected1, actual1);
+ Assert.assertEquals(expected2, actual2);
+ }
+
+
+ @Test
+ public void getCurrentDiceStringTest() {
+ // Given
+ Player player = new Player("Cara", 1000.00);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ ArrayList rolledDice = new ArrayList<>();
+ rolledDice.add(d4);
+ rolledDice.add(d6);
+
+ ArrayList savedDice = new ArrayList<>();
+ savedDice.add(d2);
+ savedDice.add(d2);
+ savedDice.add(d5);
+
+ String expected = "\n|------------------------------------------|\n" +
+ "| | 1 | 2 | 3 | 4 | 5 |\n" +
+ "|------------------------------------------|\n" +
+ "|Rolled Dice | ⚃ | ⚅ | | | |\n" +
+ "|------------------------------------------|\n" +
+ "| Saved Dice | | | ⚁ | ⚁ | ⚄ |\n" +
+ "|------------------------------------------|\n";
+
+
+ // When
+ String actual = yahtzee.getCurrentDiceString(rolledDice, savedDice);
+
+ // Then
+ Assert.assertEquals(expected, actual);
+ System.out.println(actual);
+
+ }
+
+
+ @Test
+ public void setUpScoreCardTest() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ // When
+ TreeMap actualScoreCard = yahtzee.setUpScoreCard();
+ Integer actualAces = actualScoreCard.get("aces");
+ Integer actualTwos = actualScoreCard.get("twos");
+ Integer actualThrees = actualScoreCard.get("threes");
+ Integer actualFours = actualScoreCard.get("fours");
+ Integer actualFives = actualScoreCard.get("fives");
+ Integer actualSixes = actualScoreCard.get("sixes");
+ Integer actualUpperBonus = actualScoreCard.get("upper bonus");
+ Integer actualThreeOfAKind = actualScoreCard.get("3 of a kind");
+ Integer actualFourOfAKind = actualScoreCard.get("4 of a kind");
+ Integer actualFullHouse = actualScoreCard.get("full house");
+ Integer actualSmallStraight = actualScoreCard.get("small straight");
+ Integer actualLargeStraight = actualScoreCard.get("large straight");
+ Integer actualYahtzee = actualScoreCard.get("yahtzee");
+ Integer actualChance = actualScoreCard.get("chance");
+ Integer actualTotalScore = actualScoreCard.get("total score");
+
+ // Then
+ Assert.assertNull(actualAces);
+ Assert.assertNull(actualTwos);
+ Assert.assertNull(actualThrees);
+ Assert.assertNull(actualFours);
+ Assert.assertNull(actualFives);
+ Assert.assertNull(actualSixes);
+ Assert.assertNull(actualUpperBonus);
+ Assert.assertNull(actualThreeOfAKind);
+ Assert.assertNull(actualFourOfAKind);
+ Assert.assertNull(actualFullHouse);
+ Assert.assertNull(actualSmallStraight);
+ Assert.assertNull(actualLargeStraight);
+ Assert.assertNull(actualYahtzee);
+ Assert.assertNull(actualChance);
+ Assert.assertNull(actualTotalScore);
+
+ }
+
+
+ @Test
+ public void getScoreCardStringTest() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ String expected = "" +
+ "|---------------------------------|\n" +
+ " Category | Score \n" +
+ "|---------------------------------|\n" +
+ " Aces |\n" +
+ "|---------------------------------|\n" +
+ " Twos |\n" +
+ "|---------------------------------|\n" +
+ " Threes |\n" +
+ "|---------------------------------|\n" +
+ " Fours |\n" +
+ "|---------------------------------|\n" +
+ " Fives |\n" +
+ "|---------------------------------|\n" +
+ " Sixes |\n" +
+ "|---------------------------------|\n" +
+ " Upper Bonus |\n" +
+ "|---------------------------------|\n" +
+ " 3 of a Kind |\n" +
+ "|---------------------------------|\n" +
+ " 4 of a Kind |\n" +
+ "|---------------------------------|\n" +
+ " Full House |\n" +
+ "|---------------------------------|\n" +
+ " Small Straight |\n" +
+ "|---------------------------------|\n" +
+ " Large Straight |\n" +
+ "|---------------------------------|\n" +
+ " Yahtzee |\n" +
+ "|---------------------------------|\n" +
+ " Chance |\n" +
+ "|---------------------------------|\n" +
+ " Total Score |\n" +
+ "|---------------------------------|\n";
+
+ System.out.println(expected);
+
+ // When
+ String actual = yahtzee.getScoreCardString();
+
+ // Then
+ Assert.assertEquals(expected, actual);
+ }
+
+
+ @Test
+ public void getAcesScoreStringTest() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee = new Yahtzee(player);
+ String expected1 = " Aces |\n";
+ String expected2 = " Aces | 3\n";
+
+ // When
+ String actual1 = yahtzee.getAcesScoreString();
+
+ yahtzee.getScoreCard().put("aces", 3);
+ String actual2 = yahtzee.getAcesScoreString();
+
+ // Then
+ Assert.assertEquals(expected1, actual1);
+ Assert.assertEquals(expected2, actual2);
+ }
+
+
+ @Test
+ public void getTwosScoreStringTest() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee = new Yahtzee(player);
+ String expected1 = " Twos |\n";
+ String expected2 = " Twos | 8\n";
+
+ // When
+ String actual1 = yahtzee.getTwosScoreString();
+
+ yahtzee.getScoreCard().put("twos", 8);
+ String actual2 = yahtzee.getTwosScoreString();
+
+ // Then
+ Assert.assertEquals(expected1, actual1);
+ Assert.assertEquals(expected2, actual2);
+ }
+
+
+ @Test
+ public void getThreesScoreStringTest() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee = new Yahtzee(player);
+ String expected1 = " Threes |\n";
+ String expected2 = " Threes | 12\n";
+
+ // When
+ String actual1 = yahtzee.getThreesScoreString();
+
+ yahtzee.getScoreCard().put("threes", 12);
+ String actual2 = yahtzee.getThreesScoreString();
+
+ // Then
+ Assert.assertEquals(expected1, actual1);
+ Assert.assertEquals(expected2, actual2);
+ }
+
+
+ @Test
+ public void getFoursScoreStringTest() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee = new Yahtzee(player);
+ String expected1 = " Fours |\n";
+ String expected2 = " Fours | 8\n";
+
+ // When
+ String actual1 = yahtzee.getFoursScoreString();
+
+ yahtzee.getScoreCard().put("fours", 8);
+ String actual2 = yahtzee.getFoursScoreString();
+
+ // Then
+ Assert.assertEquals(expected1, actual1);
+ Assert.assertEquals(expected2, actual2);
+ }
+
+
+ @Test
+ public void getFivesScoreStringTest() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee = new Yahtzee(player);
+ String expected1 = " Fives |\n";
+ String expected2 = " Fives | 0\n";
+
+ // When
+ String actual1 = yahtzee.getFivesScoreString();
+
+ yahtzee.getScoreCard().put("fives", 0);
+ String actual2 = yahtzee.getFivesScoreString();
+
+ // Then
+ Assert.assertEquals(expected1, actual1);
+ Assert.assertEquals(expected2, actual2);
+ }
+
+
+ @Test
+ public void getSixesScoreStringTest() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee = new Yahtzee(player);
+ String expected1 = " Sixes |\n";
+ String expected2 = " Sixes | 24\n";
+
+ // When
+ String actual1 = yahtzee.getSixesScoreString();
+
+ yahtzee.getScoreCard().put("sixes", 24);
+ String actual2 = yahtzee.getSixesScoreString();
+
+ // Then
+ Assert.assertEquals(expected1, actual1);
+ Assert.assertEquals(expected2, actual2);
+ }
+
+
+ @Test
+ public void getUpperBonusScoreStringTest() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee = new Yahtzee(player);
+ String expected1 = " Upper Bonus |\n";
+ String expected2 = " Upper Bonus | 35\n";
+
+ // When
+ String actual1 = yahtzee.getUpperBonusScoreString();
+
+ yahtzee.getScoreCard().put("upper bonus", 35);
+ String actual2 = yahtzee.getUpperBonusScoreString();
+
+ // Then
+ Assert.assertEquals(expected1, actual1);
+ Assert.assertEquals(expected2, actual2);
+ }
+
+
+ @Test
+ public void getThreeOfAKindScoreString() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee = new Yahtzee(player);
+ String expected1 = " 3 of a Kind |\n";
+ String expected2 = " 3 of a Kind | 22\n";
+
+ // When
+ String actual1 = yahtzee.getThreeOfAKindScoreString();
+
+ yahtzee.getScoreCard().put("3 of a kind", 22);
+ String actual2 = yahtzee.getThreeOfAKindScoreString();
+
+ // Then
+ Assert.assertEquals(expected1, actual1);
+ Assert.assertEquals(expected2, actual2);
+ }
+
+
+ @Test
+ public void getFourOfAKindScoreStringTest() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee = new Yahtzee(player);
+ String expected1 = " 4 of a Kind |\n";
+ String expected2 = " 4 of a Kind | 20\n";
+
+ // When
+ String actual1 = yahtzee.getFourOfAKindScoreString();
+
+ yahtzee.getScoreCard().put("4 of a kind", 20);
+ String actual2 = yahtzee.getFourOfAKindScoreString();
+
+ // Then
+ Assert.assertEquals(expected1, actual1);
+ Assert.assertEquals(expected2, actual2);
+ }
+
+
+ @Test
+ public void getFullHouseScoreStringTest() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee = new Yahtzee(player);
+ String expected1 = " Full House |\n";
+ String expected2 = " Full House | 25\n";
+
+ // When
+ String actual1 = yahtzee.getFullHouseScoreString();
+
+ yahtzee.getScoreCard().put("full house", 25);
+ String actual2 = yahtzee.getFullHouseScoreString();
+
+ // Then
+ Assert.assertEquals(expected1, actual1);
+ Assert.assertEquals(expected2, actual2);
+ }
+
+
+ @Test
+ public void getSmallStraightScoreStringTest() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee = new Yahtzee(player);
+ String expected1 = " Small Straight |\n";
+ String expected2 = " Small Straight | 30\n";
+
+ // When
+ String actual1 = yahtzee.getSmallStraightScoreString();
+
+ yahtzee.getScoreCard().put("small straight", 30);
+ String actual2 = yahtzee.getSmallStraightScoreString();
+
+ // Then
+ Assert.assertEquals(expected1, actual1);
+ Assert.assertEquals(expected2, actual2);
+ }
+
+
+ @Test
+ public void getLargeStraightScoreStringTest() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee = new Yahtzee(player);
+ String expected1 = " Large Straight |\n";
+ String expected2 = " Large Straight | 40\n";
+
+ // When
+ String actual1 = yahtzee.getLargeStraightScoreString();
+
+ yahtzee.getScoreCard().put("large straight", 40);
+ String actual2 = yahtzee.getLargeStraightScoreString();
+
+ // Then
+ Assert.assertEquals(expected1, actual1);
+ Assert.assertEquals(expected2, actual2);
+ }
+
+
+ @Test
+ public void getYahtzeeScoreStringTest() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee = new Yahtzee(player);
+ String expected1 = " Yahtzee |\n";
+ String expected2 = " Yahtzee | 50\n";
+
+ // When
+ String actual1 = yahtzee.getYahtzeeScoreString();
+
+ yahtzee.getScoreCard().put("yahtzee", 50);
+ String actual2 = yahtzee.getYahtzeeScoreString();
+
+ // Then
+ Assert.assertEquals(expected1, actual1);
+ Assert.assertEquals(expected2, actual2);
+ }
+
+
+ @Test
+ public void getChanceScoreStringTest() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee = new Yahtzee(player);
+ String expected1 = " Chance |\n";
+ String expected2 = " Chance | 23\n";
+
+ // When
+ String actual1 = yahtzee.getChanceScoreString();
+
+ yahtzee.getScoreCard().put("chance", 23);
+ String actual2 = yahtzee.getChanceScoreString();
+
+ // Then
+ Assert.assertEquals(expected1, actual1);
+ Assert.assertEquals(expected2, actual2);
+ }
+
+
+ @Test
+ public void getTotalScoreStringTest() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee = new Yahtzee(player);
+ String expected1 = " Total Score |\n";
+ String expected2 = " Total Score | 200\n";
+
+ // When
+ String actual1 = yahtzee.getTotalScoreString();
+
+ yahtzee.getScoreCard().put("total score", 200);
+ String actual2 = yahtzee.getTotalScoreString();
+
+ // Then
+ Assert.assertEquals(expected1, actual1);
+ Assert.assertEquals(expected2, actual2);
+ }
+
+
+ @Test
+ public void getUpperSectionTotalTest() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee1 = new Yahtzee(player);
+ Yahtzee yahtzee2 = new Yahtzee(player);
+ Yahtzee yahtzee3 = new Yahtzee(player);
+ int expected1 = 63;
+ int expected2 = 62;
+ int expected3 = 68;
+
+ // When
+ yahtzee1.getScoreCard().put("aces", 3);
+ yahtzee1.getScoreCard().put("twos", 2);
+ yahtzee1.getScoreCard().put("threes", 12);
+ yahtzee1.getScoreCard().put("fours", 8);
+ yahtzee1.getScoreCard().put("fives", 20);
+ yahtzee1.getScoreCard().put("sixes", 18);
+ int actual1 = yahtzee1.getUpperSectionTotal(yahtzee1.getScoreCard());
+
+ yahtzee2.getScoreCard().put("aces", 2);
+ yahtzee2.getScoreCard().put("twos", 2);
+ yahtzee2.getScoreCard().put("threes", 12);
+ yahtzee2.getScoreCard().put("fours", 8);
+ yahtzee2.getScoreCard().put("fives", 20);
+ yahtzee2.getScoreCard().put("sixes", 18);
+ int actual2 = yahtzee2.getUpperSectionTotal(yahtzee2.getScoreCard());
+
+ yahtzee3.getScoreCard().put("aces", 2);
+ yahtzee3.getScoreCard().put("twos", 2);
+ yahtzee3.getScoreCard().put("threes", 12);
+ yahtzee3.getScoreCard().put("fours", 8);
+ yahtzee3.getScoreCard().put("fives", 20);
+ yahtzee3.getScoreCard().put("sixes", 24);
+ int actual3 = yahtzee3.getUpperSectionTotal(yahtzee3.getScoreCard());
+
+ // Then
+ Assert.assertEquals(expected1, actual1);
+ Assert.assertEquals(expected2, actual2);
+ Assert.assertEquals(expected3, actual3);
+ }
+
+
+ @Test
+ public void upperSectionBonusTest() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee1 = new Yahtzee(player);
+ Yahtzee yahtzee2 = new Yahtzee(player);
+ Yahtzee yahtzee3 = new Yahtzee(player);
+ int expected1 = 35;
+ int expected2 = 0;
+ int expected3 = 35;
+
+ // When
+ yahtzee1.getScoreCard().put("aces", 3);
+ yahtzee1.getScoreCard().put("twos", 2);
+ yahtzee1.getScoreCard().put("threes", 12);
+ yahtzee1.getScoreCard().put("fours", 8);
+ yahtzee1.getScoreCard().put("fives", 20);
+ yahtzee1.getScoreCard().put("sixes", 18);
+ int actual1 = yahtzee1.upperSectionBonus(yahtzee1.getScoreCard());
+
+ yahtzee2.getScoreCard().put("aces", 2);
+ yahtzee2.getScoreCard().put("twos", 2);
+ yahtzee2.getScoreCard().put("threes", 12);
+ yahtzee2.getScoreCard().put("fours", 8);
+ yahtzee2.getScoreCard().put("fives", 20);
+ yahtzee2.getScoreCard().put("sixes", 18);
+ int actual2 = yahtzee2.upperSectionBonus(yahtzee2.getScoreCard());
+
+ yahtzee3.getScoreCard().put("aces", 2);
+ yahtzee3.getScoreCard().put("twos", 2);
+ yahtzee3.getScoreCard().put("threes", 12);
+ yahtzee3.getScoreCard().put("fours", 8);
+ yahtzee3.getScoreCard().put("fives", 20);
+ yahtzee3.getScoreCard().put("sixes", 24);
+ int actual3 = yahtzee3.upperSectionBonus(yahtzee3.getScoreCard());
+
+ // Then
+ Assert.assertEquals(expected1, actual1);
+ Assert.assertEquals(expected2, actual2);
+ Assert.assertEquals(expected3, actual3);
+ }
+
+ @Test
+ public void getLowerSectionTotalTest() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee = new Yahtzee(player);
+ int expected = 210;
+
+ // When
+ yahtzee.getScoreCard().put("3 of a kind", 20);
+ yahtzee.getScoreCard().put("4 of a kind", 22);
+ yahtzee.getScoreCard().put("full house", 25);
+ yahtzee.getScoreCard().put("small straight", 30);
+ yahtzee.getScoreCard().put("large straight", 40);
+ yahtzee.getScoreCard().put("yahtzee", 50);
+ yahtzee.getScoreCard().put("chance", 23);
+ int actual = yahtzee.getLowerSectionTotal(yahtzee.getScoreCard());
+
+ // Then
+ Assert.assertEquals(expected, actual);
+
+ }
+
+ @Test
+ public void getTotalScoreTest() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ yahtzee.getScoreCard().put("aces", 3);
+ yahtzee.getScoreCard().put("twos", 2);
+ yahtzee.getScoreCard().put("threes", 12);
+ yahtzee.getScoreCard().put("fours", 8);
+ yahtzee.getScoreCard().put("fives", 20);
+ yahtzee.getScoreCard().put("sixes", 18);
+ yahtzee.getScoreCard().put("upper bonus", 35);
+ yahtzee.getScoreCard().put("3 of a kind", 20);
+ yahtzee.getScoreCard().put("4 of a kind", 22);
+ yahtzee.getScoreCard().put("full house", 25);
+ yahtzee.getScoreCard().put("small straight", 30);
+ yahtzee.getScoreCard().put("large straight", 40);
+ yahtzee.getScoreCard().put("yahtzee", 50);
+ yahtzee.getScoreCard().put("chance", 23);
+
+ int expected = 308;
+
+ // When
+ int actual = yahtzee.getTotalScore(yahtzee.getScoreCard());
+
+ // Then
+ Assert.assertEquals(expected, actual);
+ }
+
+
+ @Test
+ public void upperSectionScoresCompleteTest() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ // When
+ boolean expectedFalse1 = yahtzee.upperSectionScoresComplete();
+
+ yahtzee.getScoreCard().put("aces", 3);
+ yahtzee.getScoreCard().put("twos", 2);
+ yahtzee.getScoreCard().put("threes", 12);
+
+ boolean expectedFalse2 = yahtzee.upperSectionScoresComplete();
+
+ yahtzee.getScoreCard().put("fours", 8);
+ yahtzee.getScoreCard().put("fives", 20);
+ yahtzee.getScoreCard().put("sixes", 18);
+
+ boolean expectedTrue = yahtzee.upperSectionScoresComplete();
+
+ // Then
+ Assert.assertFalse(expectedFalse1);
+ Assert.assertFalse(expectedFalse2);
+ Assert.assertTrue(expectedTrue);
+ }
+
+
+ @Test
+ public void scorecardCompleteTest() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ // When
+ boolean expectedFalse = yahtzee.scorecardComplete();
+
+ yahtzee.getScoreCard().put("aces", 3);
+ yahtzee.getScoreCard().put("twos", 2);
+ yahtzee.getScoreCard().put("threes", 12);
+ yahtzee.getScoreCard().put("fours", 8);
+ yahtzee.getScoreCard().put("fives", 20);
+ yahtzee.getScoreCard().put("sixes", 18);
+
+ boolean expectedFalse2 = yahtzee.scorecardComplete();
+
+ yahtzee.getScoreCard().put("3 of a kind", 20);
+ yahtzee.getScoreCard().put("4 of a kind", 22);
+ yahtzee.getScoreCard().put("full house", 25);
+ yahtzee.getScoreCard().put("small straight", 30);
+ yahtzee.getScoreCard().put("large straight", 40);
+ yahtzee.getScoreCard().put("yahtzee", 50);
+ yahtzee.getScoreCard().put("chance", 23);
+
+ boolean expectedTrue = yahtzee.scorecardComplete();
+
+ // Then
+ Assert.assertFalse(expectedFalse);
+ Assert.assertFalse(expectedFalse2);
+ Assert.assertTrue(expectedTrue);
+ }
+
+
+ @Test
+ public void isValidCategoryTest() {
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee = new Yahtzee(player);
+
+ String validCategory = "full house";
+ String invalidCategory = "small straihgt";
+
+ // When
+ boolean actualTrue = yahtzee.isValidCategory(validCategory);
+ boolean actualFalse = yahtzee.isValidCategory(invalidCategory);
+
+ // Then
+ Assert.assertTrue(actualTrue);
+ Assert.assertFalse(actualFalse);
+ }
+
+
+ @Test
+ public void welcomeToYahtzeeStringTest(){
+ // Given
+ Player player = new Player("Cara", 1000.0);
+ Yahtzee yahtzee = new Yahtzee(player);
+ String expected = "\n⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅\n" +
+ " ___ __ __ ___ ___ __ ___ __ ___ ___ /\n" +
+ "| | |__ | / ` / \\ |\\/| |__ | / \\ \\ / /\\ |__| | / |__ |__ / \n" +
+ "|/\\| |___ |___ \\__, \\__/ | | |___ | \\__/ | /~~\\ | | | /_ |___ |___ . \n\n" +
+ "⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅\n";
+
+ // When
+ String actual = yahtzee.welcomeToYahtzeeString();
+
+ // Then
+ Assert.assertEquals(expected, actual);
+ }
+
+
+}