diff --git a/.gitignore b/.gitignore index 53c83987d..c416744b6 100644 --- a/.gitignore +++ b/.gitignore @@ -104,3 +104,6 @@ target/* .project .classpath .settings + + +*DS_Store \ No newline at end of file diff --git a/README.md b/README.md index 14d017d9b..941e05cf3 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ## Minimum Viable Product (MVP) * Your application must have at the very least 4 games: * Go Fish a card game - * BlackJack a card game + * io.zipcoder.casino.CardGames.BlackJack a card game * Craps a dice game * An additional dice game @@ -25,7 +25,7 @@ ## Developmental Notes * `GoFish` is a friendly game and should not involve gambling. -* `BlackJack` and `GoFish` are both card games and should therefore inherit from a common `CardGame`. -* Any common logic or fields between the games should live CardGame class, **not** BlackJack **nor** GoFish. +* `io.zipcoder.casino.CardGames.BlackJack` and `GoFish` are both card games and should therefore inherit from a common `CardGame`. +* Any common logic or fields between the games should live CardGame class, **not** io.zipcoder.casino.CardGames.BlackJack **nor** GoFish. * You must have a completed and approved UML diagram before you proceed to do any development * All public methods should be tested. diff --git a/src/main/java/io/zipcoder/casino/App.java b/src/main/java/io/zipcoder/casino/App.java new file mode 100644 index 000000000..8944053ad --- /dev/null +++ b/src/main/java/io/zipcoder/casino/App.java @@ -0,0 +1,171 @@ +package io.zipcoder.casino; + +import io.zipcoder.casino.CardGames.BlackJack; +import io.zipcoder.casino.CardGames.GoFish; +import io.zipcoder.casino.DiceGames.Craps; +import io.zipcoder.casino.DiceGames.Yahtzee; +import io.zipcoder.casino.Player.Player; +import io.zipcoder.casino.Player.PlayerWarehouse; +import io.zipcoder.casino.utilities.Console; + +import java.util.concurrent.TimeUnit; + +public class App { + + private Console menu; + private String userId = ""; + private String userPassword = ""; + private Player newPlayer; + private PlayerWarehouse warehouse = new PlayerWarehouse(); + private int counter = 0; + + public void App (){ + + this.menu = new Console(System.in,System.out); + this.menu.printWelcome(); + consolePrintDelay(1000); + mainMenu(); // log in ... + + } + + + private void mainMenu(){ + int userInput; + userInput = this.menu.printMainMenu(); + mainMenuActions(userInput); + } + + private void mainMenuActions(Integer userSelection){ + + switch (userSelection) { + case 1: + // Log in + if (authenticatePlayer()) { + this.menu.print("Logging in ."); + consolePrintDelay(500); + this.menu.print("."); + consolePrintDelay(500); + this.menu.print(".\n\n"); + consolePrintDelay(500); + + selectGameToPlay(); + } else { + this.menu.print("We could not find this user. Please try again!\n\n"); + consolePrintDelay(500); + counter++; + this.userId = ""; + this.userPassword = ""; + if ((counter > 1)) { + counter = 0; + this.menu.print("You exceeded the allowed number of tries!\n\n"); + mainMenu(); + } else { + mainMenuActions(userSelection); + } + } + break; + case 2: + // Create new account + consolePrintDelay(500); + this.menu.println("Creating new account ...\n"); + if (authenticatePlayer()){ + this.menu.println("This user already exists, please log in.\n"); + consolePrintDelay(1000); + mainMenu(); + } else { + createPlayer(); + selectGameToPlay(); + } + break; + + case 3: + // Exit + this.menu.print("Have a great day!"); + System.exit(0); + break; + + default: + this.menu.print("Error! Please enter another option!\n\n"); + consolePrintDelay(1000); + mainMenu(); + + } // main menu actions + + } // menuActions + + private void selectGameToPlay() { + int userInput; + consolePrintDelay(500); + this.menu.println("You are now logged in - enjoy the ride!\n"); + userInput = this.menu.printSelectGame(); + + selectGameToPlayActions(userInput); + } // select game + + private void selectGameToPlayActions(Integer gameSelected){ + consolePrintDelay(1000); + this.menu.clearScreen(); + this.menu.printGameName(gameSelected); + consolePrintDelay(1000); + switch (gameSelected){ + case 1: + GoFish newGoFish = new GoFish(this.newPlayer); + newGoFish.startGame(); + break; + case 2: + Yahtzee newYahtzee = new Yahtzee(this.newPlayer); + newYahtzee.startGame(); + break; + case 3: + BlackJack newBlackJack = new BlackJack(this.newPlayer); + addMoneyToPlayer(); + newBlackJack.startGame(); + break; + case 4: + Craps newCraps = new Craps(this.newPlayer); + addMoneyToPlayer(); + newCraps.startGame(); + break; + case 5: + mainMenu(); + break; + default: + this.menu.print("Error! Invalid Selection!\n\n"); + break; + } + + selectGameToPlay(); + + + } // game actions + + + private Boolean authenticatePlayer(){ + consolePrintDelay(1000); + this.userId = this.menu.getStringInput("Enter your ID:"); + this.userPassword = this.menu.getStringInput("Enter your password:"); + + this.newPlayer = this.warehouse.getPlayer(this.userId+this.userPassword); + return this.newPlayer != null; + } + + private void createPlayer(){ + this.warehouse.addPlayer(this.userId,this.userPassword); + this.newPlayer = warehouse.getPlayer(this.userId+this.userPassword); + } + + private void consolePrintDelay (int miliSeconds){ + try { + TimeUnit.MILLISECONDS.sleep(miliSeconds); + } catch (InterruptedException e){ + System.out.println(e.getMessage()); + } + } + + private void addMoneyToPlayer (){ + double amount; + amount = this.menu.getDoubleInput("How much money would you like to add to your account?"); + this.newPlayer.addAmount(amount); + } + +} // class diff --git a/src/main/java/io/zipcoder/casino/CardGames/BlackJack.java b/src/main/java/io/zipcoder/casino/CardGames/BlackJack.java new file mode 100644 index 000000000..1c24602de --- /dev/null +++ b/src/main/java/io/zipcoder/casino/CardGames/BlackJack.java @@ -0,0 +1,279 @@ +package io.zipcoder.casino.CardGames; + +import io.zipcoder.casino.Interfaces.GamblingGame; +import io.zipcoder.casino.Player.GamblingPlayer; +import io.zipcoder.casino.Player.Player; +import io.zipcoder.casino.utilities.Console; + +import java.util.HashMap; + + +public class BlackJack implements GamblingGame { + Console input = new Console(System.in, System.out); + GamblingPlayer gamblingPlayer; + CardHand gamblingPlayerHand; + Deck blackJackDeck; + CardHand computerHand; + boolean winGame = false; + + + private Player user; + private int wageBucket; + private Card card; + + public Integer playerRefactoredHandValue; + public Integer dealerRefactoredHandValue; + + public boolean playerHasBlackJack; + public boolean dealerHasBlackJack; + public boolean playerAndDealerHaveBlackJack; + public boolean playerBust; + public boolean dealerBust; + public boolean playerWin; + public boolean dealerWin; + public boolean playerDealerPush; + private boolean continuePlay; + + + public BlackJack(Player user) { + this.continuePlay = true; + this.gamblingPlayer = new GamblingPlayer(user); + } + + + public void startGame() { + input.println(checkForChips()); + while (continuePlay) { + playBlackJack(); + if(!continuePlay){return;} + } + } + + public String checkForChips() { + if (gamblingPlayer.getBalance() < 10) { + return "You need at least $10.00 to play"; + } else { + return "Welcome to BlackJack!"; + } + } + + public void playBlackJack() { + + promptUserForWagerAmount(); + initializeBlackJackHands(); + + checkInitialHandValue(gamblingPlayerHand); + checkHandForAces(gamblingPlayerHand); + playerRefactoredHandValue = refactorAndCalculateHandValue(checkInitialHandValue(gamblingPlayerHand), checkHandForAces(gamblingPlayerHand)); + + checkInitialHandValue(computerHand); + checkHandForAces(computerHand); + dealerRefactoredHandValue = refactorAndCalculateHandValue(checkInitialHandValue(computerHand), checkHandForAces(computerHand)); + + input.println(gamblingPlayerHand.displayHand()); + promptHitOrStay(); + evaluateHands(); + if(!continuePlay){return;} + + } + + + public void promptUserForWagerAmount() { + + double userWagerAmount = input.getDoubleInput("How much would you like to wager?"); + boolean wagerAmountSuccessful = gamblingPlayer.placeWager(userWagerAmount); + while (!wagerAmountSuccessful) { + userWagerAmount = input.getDoubleInput("Wager exceeds your balance. Please wage a smaller amount."); + wagerAmountSuccessful = gamblingPlayer.placeWager(userWagerAmount); + } + } + + public void initializeBlackJackHands() { + + blackJackDeck = new Deck(1); + blackJackDeck.shuffleDeck(); + gamblingPlayerHand = new CardHand(blackJackDeck.dealCards(2)); + computerHand = new CardHand(blackJackDeck.dealCards(2)); + } + + + //takes arrayList of cards from hand and separates them by card and totals point based on default Ace value of 11. + public Integer checkInitialHandValue(CardHand hand) { + Integer handValueForDefaultAce11 = 0; + + for (Card card : hand.userHand) { + Rank rank = card.getRank(); + handValueForDefaultAce11 += (Integer) blackJackCardRank.get(rank); + } + return handValueForDefaultAce11; + } + + //counts the number of Aces in cardHand. + public Integer checkHandForAces(CardHand hand) { + Integer aceCounter = 0; + for (Card card : hand.userHand) { + if (card.getRank() == Rank.ACE) { + aceCounter++; + } + } + return aceCounter; + } + + + //evaluates score of blackjack hand and determines whether or not the value of each Ace should remain at 11 points or be reassigned to 1 point. Returns new hand value. + public Integer refactorAndCalculateHandValue(Integer handValueForDefaultAce11, Integer numberOfAces) { + Integer refactoredHandValue = handValueForDefaultAce11; //default set to no changes. + if (numberOfAces == 1 && handValueForDefaultAce11 > 21) { + refactoredHandValue = handValueForDefaultAce11 - 10; //one Ace value changed to 1 point. + } else if (numberOfAces == 2 && handValueForDefaultAce11 > 21) { + if (handValueForDefaultAce11 - 10 <= 21) { + refactoredHandValue = handValueForDefaultAce11 - 10; //one Ace value changed to 1 point. + } else { + refactoredHandValue = handValueForDefaultAce11 - 20; //two Ace values changed to 1 point. + } + } else if (numberOfAces == 3 && handValueForDefaultAce11 > 21) { + if (handValueForDefaultAce11 - 20 <= 21) { + refactoredHandValue = handValueForDefaultAce11 - 20; + } else { + refactoredHandValue = handValueForDefaultAce11 - 30; //three Ace values change to 1 point. + } + } + return refactoredHandValue; + } + + public Integer promptHitOrStay() { + Integer hitOrStayUserInput = input.getIntegerInput("Press 1 to hit or 2 to stay."); + + while(hitOrStayUserInput != 2 && hitOrStayUserInput != 1) { + switch (hitOrStayUserInput) { + case 1: + hit(); + hitOrStayUserInput = 1; + break; + case 2: + stay(); + hitOrStayUserInput = 2; + break; + default: + hitOrStayUserInput = input.getIntegerInput("Invalid key, press 1 to hit or 2 to stay."); + break; + } + } + return hitOrStayUserInput; + } + +// public void hitOrStayAction(CardHand hand, Integer hitOrStayUserInput) { +// if (hitOrStayUserInput == 1) { +// hand.userHand.add(blackJackDeck.drawCard()); +// hit(); +// } else { +// stay(); +// } +// +// } + + public void stay() { + evaluateHands(); + input.println(String.valueOf(playerRefactoredHandValue)); + // check against the dealer + } + + public void hit() { + this.gamblingPlayerHand.userHand.add(blackJackDeck.drawCard()); + checkInitialHandValue(this.gamblingPlayerHand); + checkHandForAces(this.gamblingPlayerHand); + playerRefactoredHandValue = refactorAndCalculateHandValue(checkInitialHandValue(this.gamblingPlayerHand), checkHandForAces(this.gamblingPlayerHand)); + input.println(this.gamblingPlayerHand.displayHand()); + evaluateHands(); + } + + public void evaluateHands() { + // TODO if both are over 21 or both under 21 but stay + playerHasBlackJack = (playerRefactoredHandValue == 21); + dealerHasBlackJack = (dealerRefactoredHandValue == 21); + playerAndDealerHaveBlackJack = (playerHasBlackJack && dealerHasBlackJack); + + if (playerRefactoredHandValue > 21 || dealerRefactoredHandValue > 21) { + + } + if (dealerRefactoredHandValue > playerRefactoredHandValue){ + + } + if (displayScore() == 2) promptLeaveGame(); + + } + + + public void getWinner(CardHand dealer, CardHand player) { + } + + public void promptLeaveGame() { + this.continuePlay = false; + } + + public Integer displayScore() { + if (playerAndDealerHaveBlackJack) { + return displayPlayerNDealerPushWithBlackJack(); + } else if (playerHasBlackJack && !dealerHasBlackJack) { + return displayPlayerWinsWithBlackJack(" You got BlackJack!\n", "Your hand: \n", "Press 1 to play again or 2 to quit.\n"); + } else if (dealerHasBlackJack && !playerHasBlackJack) { + return dealerWinsWithBlackJack(" Dealer got BlackJack!\n", "Your hand: \n", "Press 1 to play again or 2 to quit.\n"); + } else if (playerRefactoredHandValue == dealerRefactoredHandValue){ + return displayPlayerNDealerPush("Push!\n", "Your hand: \n"); + } else { + return displayPlayerNDealerPush("Push!\n", "Your hand: \n"); // TODO if both are over 21 or both under 21 but stay + } + + } + + private Integer displayPlayerWinsWithBlackJack(String s, String s2, String s3) { + return input.getIntegerInput(s + + s2 + gamblingPlayerHand.displayHand() + "\n" + + "Dealer hand: \n" + computerHand.displayHand() + "\n" + + s3); + } + + private Integer dealerWinsWithBlackJack(String s, String s2, String s3) { + return displayPlayerWinsWithBlackJack(s, s2, s3); + } + + private Integer displayPlayerNDealerPush(String s, String s2) { + return dealerWinsWithBlackJack(s, s2, "Press 1 to play again or 2 to quit.\n"); + } + + private Integer displayPlayerNDealerPushWithBlackJack() { + return displayPlayerNDealerPush(" You and Dealer both got BlackJack!\n", "Your hand: \n"); + } + + private HashMap blackJackCardRank = new HashMap() {{ + + put(Rank.TWO, 2); + put(Rank.THREE, 3); + put(Rank.FOUR, 4); + put(Rank.FIVE, 5); + put(Rank.SIX, 6); + put(Rank.SEVEN, 7); + put(Rank.EIGHT, 8); + put(Rank.NINE, 9); + put(Rank.TEN, 10); + put(Rank.ACE, 11); + put(Rank.JACK, 10); + put(Rank.QUEEN, 10); + put(Rank.KING, 10); + }}; + + + +// public boolean playerBust = playerRefactoredHandValue > 21; +// public boolean dealerBust = dealerRefactoredHandValue > 21; +// public boolean playerWin = !playerBust && playerRefactoredHandValue > dealerRefactoredHandValue; +// public boolean dealerWin = !dealerBust && dealerRefactoredHandValue > playerRefactoredHandValue; +// public boolean playerDealerPush = playerBust && dealerBust || playerRefactoredHandValue == dealerRefactoredHandValue; + + +// public void displayPostInitialFlopWinner() { +// if(playerHasBlackJack && !dealerHasBlackJack) { +// input.getIntegerInput(); +// +// } +} diff --git a/src/main/java/io/zipcoder/casino/CardGames/Card.java b/src/main/java/io/zipcoder/casino/CardGames/Card.java new file mode 100644 index 000000000..85ec151d4 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/CardGames/Card.java @@ -0,0 +1,67 @@ +package io.zipcoder.casino.CardGames; + +import java.util.HashMap; +import java.util.Collections; + + +public class Card { + + private Suit suit; + private Rank rank; + + + public Card() { + + } + + public Card(Suit suit, Rank rank) { + this.suit = suit; + this.rank = rank; + } + + public Suit getSuit() { + return suit; + } + + public Rank getRank() { + return rank; + } + + public String toString() { + + String suitCard = ""; + + //return String.format("%s of %s \n\n", rank, suit.toString().toLowerCase()); + + if(suit.toString() == "HEARTS") + suitCard = "♡"; + else if(suit.toString() == "SPADES") + suitCard = "♠"; + else if(suit.toString() == "CLUBS") + suitCard = "♣"; + else + suitCard = "♢"; + + + return String.format("%s %s \n", rank, suitCard); + } + +// public HashMap blackJackCardRank = new HashMap() {{ +// +// put(Rank.TWO, 2); +// put(Rank.THREE, 3); +// put(Rank.FOUR, 4); +// put(Rank.FIVE, 5); +// put(Rank.SIX, 6); +// put(Rank.SEVEN, 7); +// put(Rank.EIGHT, 8); +// put(Rank.NINE, 9); +// put(Rank.TEN, 10); +// put(Rank.ACE, 11); +// put(Rank.JACK, 10); +// put(Rank.QUEEN, 10); +// put(Rank.KING, 10); +// }}; + + +} diff --git a/src/main/java/io/zipcoder/casino/CardGames/CardHand.java b/src/main/java/io/zipcoder/casino/CardGames/CardHand.java new file mode 100644 index 000000000..ddc5bec62 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/CardGames/CardHand.java @@ -0,0 +1,25 @@ +package io.zipcoder.casino.CardGames; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; + +public class CardHand { + + ArrayList userHand = new ArrayList(); + + + public CardHand(ArrayList dealtCards){ + + userHand.addAll(dealtCards); + } + + public String displayHand() { + + userHand.sort(Comparator.comparing(Card::getRank)); + + return userHand.toString().replace(",", "") + .replace("[", " ").replace("]", ""); + } + +} diff --git a/src/main/java/io/zipcoder/casino/CardGames/Deck.java b/src/main/java/io/zipcoder/casino/CardGames/Deck.java new file mode 100644 index 000000000..6d6a2768e --- /dev/null +++ b/src/main/java/io/zipcoder/casino/CardGames/Deck.java @@ -0,0 +1,62 @@ +package io.zipcoder.casino.CardGames; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Stack; + +public class Deck { + + private Stack deckOfCards = new Stack(); + + public Deck(int numberOfDecks) { + + for (int index = 0; index < numberOfDecks; index++) { + + for (Suit suit : Suit.values()) { + for (Rank rank : Rank.values()) { + deckOfCards.add(new Card(suit, rank)); + } + } + } + } + + public Integer getSize() { + return deckOfCards.size(); + } + + + public Stack shuffleDeck() { + Collections.shuffle(deckOfCards); + + return deckOfCards; + } + + + public ArrayList dealCards(int numberOfCards) { + + ArrayList dealingCards = new ArrayList(); + + for (int index = 0; index < numberOfCards; index++) { + dealingCards.add(deckOfCards.pop()); + } + return dealingCards; + } + + + public Card drawCard() { + if (!deckOfCards.isEmpty()) { + Card drawnCard = deckOfCards.pop(); + return drawnCard; + + } else + System.out.println("Deck is empty"); + + return null; + } + + +} + + + + diff --git a/src/main/java/io/zipcoder/casino/CardGames/GoFish.java b/src/main/java/io/zipcoder/casino/CardGames/GoFish.java new file mode 100644 index 000000000..1ae11e428 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/CardGames/GoFish.java @@ -0,0 +1,262 @@ +package io.zipcoder.casino.CardGames; + +import io.zipcoder.casino.Interfaces.Game; +import io.zipcoder.casino.Player.Player; +import io.zipcoder.casino.utilities.Console; + +import java.util.*; + +public class GoFish implements Game { + + + //------------------------------------------------------------------------------------------------------------------ + // Fields ---------------------------------------------------------------------------------------------------------- + + private Console newConsole = new Console(System.in, System.out); + private Random random = new Random(); + private Player player; + private Deck goFishDeck; + private CardHand playerHand; + private CardHand computerHand; + private ArrayList winnings; + + + //------------------------------------------------------------------------------------------------------------------ + // Constructor and Initializing game ------------------------------------------------------------------------------ + + public GoFish(Player player) { + this.player = player; + + } + + public void initializeGame(){ + + //initialize and shuffle deck + this.goFishDeck = new Deck(1); + goFishDeck.shuffleDeck(); + + //initialize players' hand and deal cards + playerHand = new CardHand(goFishDeck.dealCards(5)); + computerHand = new CardHand(goFishDeck.dealCards(5)); + + } + + //------------------------------------------------------------------------------------------------------------------ + // Method called to play the game ---------------------------------------------------------------------------------- + + public void startGame() { + + initializeGame(); + + newConsole.getStringInput("\n\n\n\n\n Press Enter to start the game! \n\n\n\n\n\n" ); + + do { + + newConsole.println("\n >>>>>> %s's turn <<<<<< \n\n", this.player.getID()); + playerTurn(); + + //Check if player has 4 of a kind + if (checkIfWinner(playerHand)){ + newConsole.println("\n" + player.getID() + " is the winner with : \n"); + displayResults(); + break; + } + + newConsole.println("\n >>>>>> Computer's Turn <<<<<< \n"); + computerTurn(); + + //Check if computer has 4 of a kind + if (checkIfWinner(computerHand)){ + newConsole.println("\n Computer is the winner with : \n"); + displayResults(); + break; + } + + } while (!false); + + promptLeaveGame(); + } + + + //------------------------------------------------------------------------------------------------------------------ + // Player's and Computer's turn ------------------------------------------------------------------------------------- + + public void playerTurn() { + + displayPlayerHand(); + + String cardWanted = newConsole.getStringInput("\n Which value would you like to ask for? \n ").toUpperCase(); + + //If Player has the card asked in their hand + if (haveCard(playerHand, cardWanted)) { + + if (haveCard(computerHand, cardWanted)) { + newConsole.println("\n The computer has this card, you can take it! \n"); + newConsole.println("\n NEW CARD(S) ADDED >>> \n"); + + printCards(tradeCards(computerHand, cardWanted, playerHand).toString()); + + } else { + newConsole.println("\n GO FISH!!! \n"); + newConsole.println("\n NEW CARD ADDED >>> \n" ); + printCards(goFishForCard(playerHand).toString()); + } + + displayPlayerHand(); + + }else{ + newConsole.println("\n\n You don't have this card. Try a different card. \n\n"); + playerTurn(); + } + + newConsole.getStringInput("\n Press Enter to continue... \n"); + } + + public void computerTurn() { + + String newCard = getCompCard().toString(); + newConsole.println("\n Computer is asking for " + newCard); + + newConsole.getStringInput("\n Press Enter to continue... \n" ); + + if (haveCard(playerHand, newCard)) { + tradeCards(playerHand, newCard, computerHand); + newConsole.println("\n You have this card, the computer will take it! "); + + } else { + newConsole.println("\n GO FISH!!!!"); + goFishForCard(computerHand); + } + + newConsole.getStringInput("\n Press Enter to continue... \n" ); + + } + + + //------------------------------------------------------------------------------------------------------------------ + // Check if other play has card and trading ------------------------------------------------------------------------ + + public boolean haveCard(CardHand opponent, String wantedCard) { + + for (Card card : opponent.userHand) + if (card.getRank().toString().equals(wantedCard)) + return true; + + return false; + } + + public ArrayList tradeCards(CardHand givingHand, String wantedCard, CardHand receivingHand){ + + ArrayList tradingCards = new ArrayList(); + + for (Card card : givingHand.userHand) { + if (card.getRank().toString().equals(wantedCard)) + tradingCards.add(card); + } + + givingHand.userHand.removeAll(tradingCards); + receivingHand.userHand.addAll(tradingCards); + + return tradingCards; + + } + + + //------------------------------------------------------------------------------------------------------------------ + // Getting card from deck ------------------------------------------------------------------------------------------ + + public Card goFishForCard(CardHand hand) { + + Card newCard = goFishDeck.drawCard(); + hand.userHand.add(newCard); + + return newCard; + } + + + //------------------------------------------------------------------------------------------------------------------ + // Check if a hand has 4 of a kind -------------------------------------------------------------------------------- + + public boolean checkIfWinner(CardHand hand) { + int counter; + + for (Card checkCard : hand.userHand) { + winnings = new ArrayList<>(); + counter = 0; + + for (Card card : hand.userHand) { + if (checkCard.getRank() == card.getRank()) { + winnings.add(card); + counter++; + } + } + + if (counter == 4) { + return true; + } + + + } + + return false; + } + + + //------------------------------------------------------------------------------------------------------------------ + // Gets a random rank from computer's hand ------------------------------------------------------------------------- + + public Rank getCompCard() { + + Card newCard = computerHand.userHand.get(random.nextInt(computerHand.userHand.size())); + return newCard.getRank(); + } + + + //------------------------------------------------------------------------------------------------------------------ + //Printing Tools --------------------------------------------------------------------------------------------------- + + + @Override + public void displayResults() { + + printCards(winnings.toString()); + } + + public void printCards(String printString) { + + + newConsole.println(printString.replace("[", "").replace("]", "") + .replace(", ", "")); + + } + + public void displayPlayerHand(){ + + newConsole.println("--- Your Cards ---\n\n"); + newConsole.println(playerHand.displayHand()); + newConsole.println("------------------"); + } + + + + public void promptLeaveGame() { + String exitOrNo; + + exitOrNo = newConsole.getStringInput("Would you like to play again?\n" + + "1. Play again\n" + + "2. Exit"); + + switch (exitOrNo.charAt(0)) { + case '1': + startGame(); + break; + case '2': + break; + default: + newConsole.println("Please choose one of the options."); + break; + } + } + +} + diff --git a/src/main/java/io/zipcoder/casino/CardGames/Rank.java b/src/main/java/io/zipcoder/casino/CardGames/Rank.java new file mode 100644 index 000000000..eb606fc39 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/CardGames/Rank.java @@ -0,0 +1,25 @@ +package io.zipcoder.casino.CardGames; + +import java.util.HashMap; + +public enum Rank { + + ACE, + TWO, + THREE, + FOUR, + FIVE, + SIX, + SEVEN, + EIGHT, + NINE, + TEN, + JACK, + QUEEN, + KING; + + + + + +} diff --git a/src/main/java/io/zipcoder/casino/CardGames/Suit.java b/src/main/java/io/zipcoder/casino/CardGames/Suit.java new file mode 100644 index 000000000..11ce9e3b8 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/CardGames/Suit.java @@ -0,0 +1,10 @@ +package io.zipcoder.casino.CardGames; + +public enum Suit { + + CLUBS, + SPADES, + HEARTS, + DIAMONDS; + +} diff --git a/src/main/java/io/zipcoder/casino/Casino.java b/src/main/java/io/zipcoder/casino/Casino.java index 16ca0dd74..eb6ce65a2 100644 --- a/src/main/java/io/zipcoder/casino/Casino.java +++ b/src/main/java/io/zipcoder/casino/Casino.java @@ -1,8 +1,17 @@ package io.zipcoder.casino; -public class Casino { +import io.zipcoder.casino.utilities.Console; + +public class + Casino { + public static void main(String[] args) { // write your tests before you start fucking with this + + App newCasino = new App(); + newCasino.App(); + } + } diff --git a/src/main/java/io/zipcoder/casino/DiceGames/Craps.java b/src/main/java/io/zipcoder/casino/DiceGames/Craps.java new file mode 100644 index 000000000..c2f9be24f --- /dev/null +++ b/src/main/java/io/zipcoder/casino/DiceGames/Craps.java @@ -0,0 +1,143 @@ +package io.zipcoder.casino.DiceGames; + +import io.zipcoder.casino.Interfaces.GamblingGame; +import io.zipcoder.casino.Player.GamblingPlayer; +import io.zipcoder.casino.Player.Player; +import io.zipcoder.casino.utilities.Console; + + +public class Craps implements GamblingGame { + + + private Dice[] crapsDice; + private GamblingPlayer crapsPlayer; + private Console console; + private boolean continuePlay; + private Integer turn = 0; + private Integer targetScore; + private int sum; + + //------------- Constructor---------------------------- + + public Craps(Player player) { + + this.crapsPlayer = new GamblingPlayer(player); + this.crapsDice = createDice(); + this.console = new Console(System.in, System.out); + + } + + //------------------------------------------------------ + + public Dice[] createDice() { + Dice[] crapsDice = new Dice[2]; + for (int i = 0; i < crapsDice.length; i++) { + crapsDice[i] = new Dice(); + } + return crapsDice; + } + + + public void startGame() { + + turn = 0; + continuePlay = true; + console.println(checkForChips()); + if (crapsPlayer.getBalance() < 10) { return; } + promptUserForWagerAmount(); + createDice(); + + do { + console.println(crapsRoll()); + console.println(evaluateRoll()); + turn++; + } + while (continuePlay == true); + + crapsPlayer.resetPot(); + promptLeaveGame(); + + } + + public String checkForChips(){ + if (crapsPlayer.getBalance() < 10){return "You need at least $10.00 to play\n";} + else {return "Welcome to Craps!";} + } + + + + public String crapsRoll() { + + console.getStringInput("Press enter to roll."); + + for (Dice s : this.crapsDice) { s.rollDice(); } + sum = crapsDice[0].getValue() + crapsDice[1].getValue(); + + String roll = "You rolled a " + sum; + String target =" | Target Roll: " + targetScore; + + return (turn == 0) ? roll : roll + target; + } + + + public String evaluateRoll() { + + String msg = ""; + + if (turn == 0) { + + if (sum == 7 || sum == 11) { + crapsPlayer.getWinnings(); + msg = "Winner Winner, Chicken Dinner!\n" + crapsPlayer.getPot() + "\n"; + continuePlay = false; + } else if (sum == 2 || sum == 3 || sum == 12) { + msg = "You've Crapped out!!" + "\n"; + continuePlay = false; + } else { + targetScore = sum; + msg = "Your Target Score is " + targetScore + "\n"; + } + + } else { + + if (sum == 7) { + msg = "You've Crapped out!!"; + continuePlay = false; + } else if (sum == targetScore) { + crapsPlayer.getWinnings(); + msg = "Winner Winner, Chicken Dinner!\n" + crapsPlayer.getPot() + "\n"; + continuePlay = false; + } + } + + return msg; + } + + + public void promptUserForWagerAmount() { + + double userWagerAmount = console.getDoubleInput("Your balance is now $ " + crapsPlayer.getBalance()+ "\nHow much would you like to wager?"); + boolean wagerAmountSuccessful = crapsPlayer.placeWager(userWagerAmount); + + while (!wagerAmountSuccessful) { + userWagerAmount = console.getDoubleInput("Wager exceeds your balance. Please wage a smaller amount."); + wagerAmountSuccessful = crapsPlayer.placeWager(userWagerAmount); + } + + } + + + public void promptLeaveGame() { + + int userInput = console.getIntegerInput("Your balance is " + crapsPlayer.getBalance() + "\n\nDo you want to play again? \n" + + "1. Yes\n" + "2. No"); + + if (userInput == 1) { + startGame(); + + } + + } + + +} diff --git a/src/main/java/io/zipcoder/casino/DiceGames/Dice.java b/src/main/java/io/zipcoder/casino/DiceGames/Dice.java new file mode 100644 index 000000000..e16ca3d78 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/DiceGames/Dice.java @@ -0,0 +1,65 @@ +package io.zipcoder.casino.DiceGames; +import io.zipcoder.casino.Interfaces.GamblingGame; + +import java.util.ArrayList; + + +public class Dice { + + // fields----------------------------------------------------------------------------------------------------------- + + private boolean kept; + private int value; + + // constructor------------------------------------------------------------------------------------------------------ + + public Dice(){ + kept = false; + value = 0; + } + + // methods---------------------------------------------------------------------------------------------------------- + + public void rollDice(){ + this.value = (int)(Math.random() * ((6 - 1) + 1)) + 1; + } + + public void keptOrRolled(){ + kept = !kept; + } + + // getters and setters---------------------------------------------------------------------------------------------- + + public boolean isKept() { + return kept; + } + + public void setKept(boolean kept) { + this.kept = kept; + } + + public int getValue() { + return value; + } + + // toString--------------------------------------------------------------------------------------------------------- + + public String toString(){ + if(this.isKept()){ + return String.format(this.value + " : " + "Keep"); + } + else{ + return String.format(this.value + " : " + "Re-roll"); + } + } + public String toString2(){ + if(this.isKept()){ + return "Keep"; + } + else{ + return "Re-roll"; + } + } + +} + diff --git a/src/main/java/io/zipcoder/casino/DiceGames/Yahtzee.java b/src/main/java/io/zipcoder/casino/DiceGames/Yahtzee.java new file mode 100644 index 000000000..ef8373226 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/DiceGames/Yahtzee.java @@ -0,0 +1,422 @@ +package io.zipcoder.casino.DiceGames; + +import io.zipcoder.casino.DiceGames.Dice; +import io.zipcoder.casino.Interfaces.Game; +import io.zipcoder.casino.Player.Player; +import io.zipcoder.casino.utilities.Console; + + +public class Yahtzee implements Game { + + + //------------------------------------------------------------------------------------------------------------------ + // Fields----------------------------------------------------------------------------------------------------------- + + private Player user; + private static Console console = new Console(System.in, System.out); + private Dice[] myDice; + private int points; + + private String[] availableOptions = {" ","1s", "2s", "3s", "4s", "5s", "6s", "3 of a kind", "4 of a kind", + "Small Straight", "Large Straight", "Full House", "Yahtzee", "Chance"}; + private boolean continuePlay; + + + //------------------------------------------------------------------------------------------------------------------ + // Constructor------------------------------------------------------------------------------------------------------ + + public Yahtzee(Player player){ + this.user = player; + this.myDice = createDice(); + this.points = 0; + continuePlay = true; + } + + + //------------------------------------------------------------------------------------------------------------------ + // Method called to play the game----------------------------------------------------------------------------------- + + public void startGame(){ + console.println("Welcome to Yahtzee!"); + + while(continuePlay) { + for (int i = 0; i < 13; i++) { + resetDice(); + console.getStringInput("Press enter to make your first roll."); + console.println("First roll results:"); + roll5Dice(); + chooseToKeep(); + console.println("Second roll results:"); + roll5Dice(); + chooseToKeep(); + console.println("Final roll results:"); + roll5Dice(); + int pointsAdded = checkForEvaluation(chooseEvaluation(),getMyDice2()); + updateScore(pointsAdded); + } + displayResults(); + promptLeaveGame(); + if (!this.continuePlay) { return; } + resetGame(); + } + } + + + //------------------------------------------------------------------------------------------------------------------ + // Method for game setup and score keeping-------------------------------------------------------------------------- + + public Dice[] createDice(){ + Dice[] dice = new Dice[5]; + for(int i = 0; i < dice.length; i++){ + dice[i] = new Dice(); + } + return dice; + } + + public void updateScore(int pointsAdded) { + console.println("points added: " + pointsAdded); + this.points += pointsAdded; + console.println("Your current score is: " + this.points); + } + + public void displayResults(){ + console.println("Your final score is: " + this.getPoints()); + } + + public void promptLeaveGame(){ + String exitOrNo; + boolean c = false; + while (!c) { + + exitOrNo = console.getStringInput("Would you like to play again?\n1. Play again\n2. Exit"); + + if(exitOrNo.equals("")){ + exitOrNo = " "; + } + + switch (exitOrNo.charAt(0)) { + case '1': case 'p': case 'P': + this.continuePlay = true; + c = true; + break; + case '2': case 'e': case 'E': + this.continuePlay = false; + c = true; + break; + default: + console.println("Please choose one of the options."); + break; + } + } + } + + public void resetGame(){ + this.points = 0; + String[] availableOptionsReset = {" ","1s", "2s", "3s", "4s", "5s", "6s", "3 of a kind", "4 of a kind", + "Small Straight", "Large Straight", "Full House", "Yahtzee", "Chance"}; + for(int i = 0; i < this.availableOptions.length; i++ ){ + this.availableOptions[i] = availableOptionsReset[i]; + } + resetDice(); + + } + + + //------------------------------------------------------------------------------------------------------------------ + // Following methods are for rolling dice and choosing which ones to keep------------------------------------------- + + public void resetDice(){ + for(int i = 0; i < myDice.length; i++){ + myDice[i].setKept(false); + } + } + + public void roll5Dice(){ + for(Dice s : this.myDice){ + if(!s.isKept()){ + s.rollDice(); + } + } + } + + public void chooseToKeep(){ + String keepthis = ""; + while(!keepthis.toLowerCase().equals("roll")) { + + console.print(this.printScreen()); + keepthis = console.getStringInput("\nType the corresponding number of the dice and press enter to "+ + "switch it between keeping and re-rolling.\n" + + "Type 'continue' when finished"); + if(keepthis.equals("")){ keepthis = " "; } + + switch (keepthis.charAt(0)){ + case '1': this.myDice[0].keptOrRolled(); break; + case '2': this.myDice[1].keptOrRolled(); break; + case '3': this.myDice[2].keptOrRolled(); break; + case '4': this.myDice[3].keptOrRolled(); break; + case '5': this.myDice[4].keptOrRolled(); break; + case 'c': keepthis = "roll"; break; + default: break; + } + } + } + + + //------------------------------------------------------------------------------------------------------------------ + // Following methods are for evaluating the dice at the end of three rolls------------------------------------------ + + public int chooseEvaluation(){ + int choice = 0; + boolean goodChoice = false; + + console.print(this.printScreen()); + + while(!goodChoice){ + try{ + + choice = console.getIntegerInput("\n\nWhich one do you want to choose? "); + if(choice == 0){} + else if(choice < 1 || choice > 13){ + console.println("Please pick an option within the bounds."); + } + else if(this.availableOptions[choice].equals(" ")){ + console.println("Box already picked. Please choose again."); + } + else{ + availableOptions[choice] = " "; + goodChoice = true; + } + } + catch(Exception NumberFormatException){ + console.println("Please enter a number."); + choice = 0; + } + } + return choice; + } + + public int checkForEvaluation(int choice, Integer[] diceValues){ + + switch (choice){ + case 1: return checkForFaces(diceValues, 1); + case 2: return checkForFaces(diceValues, 2); + case 3: return checkForFaces(diceValues, 3); + case 4: return checkForFaces(diceValues, 4); + case 5: return checkForFaces(diceValues, 5); + case 6: return checkForFaces(diceValues, 6); + case 7: return checkForSameKind(diceValues, 3); + case 8: return checkForSameKind(diceValues,4); + case 9: return checkForStraight(diceValues, 4); + case 10: return checkForStraight(diceValues, 5); + case 11: return checkForFullHouse(diceValues); + case 12: return checkForYahtzee(diceValues); + case 13: return chance(diceValues); + default: return 0; + } + } + + public int checkForFaces(Integer[] diceValues, int valueToLookFor){ + int results = 0; + for(int i = 0; i < diceValues.length; i++){ + if(diceValues[i] == valueToLookFor){ + results += valueToLookFor; + } + } + return results; + } + + public int chance(Integer[] diceValues){ + int points = 0; + for(int i = 0; i < diceValues.length; i++){ + points += diceValues[i]; + } + return points; + } + + public int checkForSameKind(Integer[] diceValues, int threeOrFour){ + int counter; + for(int i = 0; i < diceValues.length - (threeOrFour - 1); i++){ + counter = 1; + for(int j = i + 1; j < diceValues.length; j++){ + if(diceValues[i] == diceValues[j]){ + counter++; + } + } + if(counter >= threeOrFour){ return this.chance(diceValues); } + } + return 0; + } + + public int checkForFullHouse(Integer[] diceValues){ + if(this.checkForSameKind(diceValues, 3) != 0){ + int counter; + for(int i = 0; i < diceValues.length - 2; i++){ + counter = 1; + for(int j = 0; j < diceValues.length; j++){ + if(diceValues[i] == diceValues[j] && i !=j){ + counter++; + } + } + if(counter == 2){ + return 25; + } + } + } + return 0; + } + + + public int checkForStraight(Integer[]diceValues, int size){ + boolean found1 = false; + boolean found2 = false; + boolean found3 = false; + boolean found4 = false; + boolean found5 = false; + boolean found6 = false; + + for (int i = 0; i < diceValues.length; i++){ + if(diceValues[i] == 1){ found1 = true; } + else if(diceValues[i] == 2){ found2 = true; } + else if(diceValues[i] == 3){ found3 = true; } + else if(diceValues[i] == 4){ found4 = true; } + else if(diceValues[i] == 5){ found5 = true; } + else if(diceValues[i] == 6){ found6 = true; } + } + switch(size){ + case 4: + if((found1 && found2 && found3 && found4)|| + (found2 && found3 && found4 && found5)|| + (found3 && found4 && found5 && found6)){ + return 30; + } + case 5: + if((found1 && found2 && found3 && found4 && found5)|| + (found2 && found3 && found4 && found5 && found6)){ + return 40; + } + default: + return 0; + } + } + + public int checkForYahtzee(Integer[] diceValues){ + for(int i = 0; i < diceValues.length; i++){ + if(diceValues[0] != diceValues[i]){ + return 0; + } + } + return 50; + } + + + //------------------------------------------------------------------------------------------------------------------ + // getters and setters---------------------------------------------------------------------------------------------- + + + public Player getUser() { + return user; + } + + public Dice[] getMyDice() { + return myDice; + } + + public Integer[] getMyDice2(){ + Integer[] diceValues = new Integer[5]; + for(int i = 0; i < this.myDice.length; i++){ + diceValues[i] = this.myDice[i].getValue(); + } + return diceValues; + } + + public String[] getAvailableOptions() { + return availableOptions; + } + + public int getPoints() { + return points; + } + + + //------------------------------------------------------------------------------------------------------------------ + // Method for getting ASCII screen art------------------------------------------------------------------------------ + + public String printScreen(){ + + String[][] a = {{" ", " ", " ", " ", " ", " ", " "}, + {" ", " ", " ", " ", " ", " ", " "}, + {" ", " ", " ", " ", " ", " ", " "}, + {" ", " ", " ", " ", " ", " ", " "}, + {" ", " ", " ", " ", " ", " ", " "}}; + + for(int i = 0; i < myDice.length; i++){ + switch(myDice[i].getValue()){ + case 1: + a[i][3] = "0"; + break; + case 2: + a[i][0] = "0"; + a[i][6] = "0"; + break; + case 3: + a[i][0] = "0"; + a[i][3] = "0"; + a[i][6] = "0"; + break; + case 4: + a[i][0] = "0"; + a[i][1] = "0"; + a[i][5] = "0"; + a[i][6] = "0"; + break; + case 5: + a[i][0] = "0"; + a[i][1] = "0"; + a[i][3] = "0"; + a[i][5] = "0"; + a[i][6] = "0"; + break; + case 6: + a[i][0] = "0"; + a[i][1] = "0"; + a[i][2] = "0"; + a[i][4] = "0"; + a[i][5] = "0"; + a[i][6] = "0"; + break; + } + } + + String diceArt = String.format("-----------------------------------------------------------------------------------------------------------\n"+ + " ------------- " + " ------------- " + " ------------- " + " ------------- " + " ------------- \n" + + " | %s      %s | " + " | %s      %s | " + " | %s      %s | " + " | %s       %s | " + " | %s       %s |\n" + + " |       | " + " |       | " + " |       | " + " |       | " + " |       |\n" + + " | %s  %s   %s | " + " | %s  %s   %s | " + " | %s  %s   %s | " + " | %s  %s   %s | " + " | %s  %s   %s |\n"+ + " |       | " + " |       | " + " |       | " + " |       | " + " |       |\n" + + " | %s      %s | " + " | %s      %s | " + " | %s      %s | " + " | %s       %s | " + " | %s       %s |\n" + + " ------------- " + " ------------- " + " ------------- " + " ------------- " + " ------------- \n\n", + a[0][0], a[0][1], a[1][0], a[1][1], a[2][0], a[2][1], a[3][0], a[3][1], a[4][0], a[4][1], + a[0][2],a[0][3],a[0][4], a[1][2],a[1][3],a[1][4], a[2][2],a[2][3],a[2][4], a[3][2],a[3][3],a[3][4], a[4][2],a[4][3],a[4][4], + a[0][5], a[0][6], a[1][5], a[1][6], a[2][5], a[2][6], a[3][5], a[3][6], a[4][5], a[4][6]); + + + String numAndKeepArt = String.format(" %-17s %-17s %-17s %-17s %-17s", + "1. " + myDice[0].toString2(), + "2. " + myDice[1].toString2(), + "3. " + myDice[2].toString2(), + "4. " + myDice[3].toString2(), + "5. " + myDice[4].toString2()) + "\n\n"; + + + String options = ""; + for(int i = 1; i < availableOptions.length - 7; i++) { + options += String.format("%-25s",(i) + ". " + availableOptions[i]); + options += String.format((i + 6) + ". " + availableOptions[i+6]+ "\n"); + } + options += String.format("%25s13. %s","",availableOptions[13] + "\n"); + + String currentPoints = "Current score: " + this.points + "\n"; + + return diceArt + numAndKeepArt + options + currentPoints; + } +} \ No newline at end of file diff --git a/src/main/java/io/zipcoder/casino/Interfaces/GamblingGame.java b/src/main/java/io/zipcoder/casino/Interfaces/GamblingGame.java new file mode 100644 index 000000000..0c8a7f630 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Interfaces/GamblingGame.java @@ -0,0 +1,8 @@ +package io.zipcoder.casino.Interfaces; + +public interface GamblingGame { + + void promptUserForWagerAmount(); + String checkForChips(); + +} diff --git a/src/main/java/io/zipcoder/casino/Interfaces/GamblingPlayer.java b/src/main/java/io/zipcoder/casino/Interfaces/GamblingPlayer.java new file mode 100644 index 000000000..0742d6d7c --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Interfaces/GamblingPlayer.java @@ -0,0 +1,6 @@ +package io.zipcoder.casino.Interfaces; + +public interface GamblingPlayer { + + Boolean placeWager(double wager); +} diff --git a/src/main/java/io/zipcoder/casino/Interfaces/Game.java b/src/main/java/io/zipcoder/casino/Interfaces/Game.java new file mode 100644 index 000000000..d4cf8b6c2 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Interfaces/Game.java @@ -0,0 +1,9 @@ +package io.zipcoder.casino.Interfaces; + +public interface Game { + + void startGame(); + void promptLeaveGame(); + void displayResults(); + +} diff --git a/src/main/java/io/zipcoder/casino/Player/GamblingPlayer.java b/src/main/java/io/zipcoder/casino/Player/GamblingPlayer.java new file mode 100644 index 000000000..9bdb0ce62 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Player/GamblingPlayer.java @@ -0,0 +1,32 @@ +package io.zipcoder.casino.Player; + + +//Class Starts +public class GamblingPlayer implements io.zipcoder.casino.Interfaces.GamblingPlayer { + + private Player gambler; + private Double pot = 0.0; + + public GamblingPlayer(Player user) { + this.gambler = user; + } + + public Boolean placeWager(double wagerAmount) { + if (gambler.balance < wagerAmount) { return false; } + else if ( wagerAmount < 0 ) { return false;} + else { + gambler.balance -= wagerAmount; + this.pot += wagerAmount; + return true; + } + } + + public void getWinnings() { gambler.balance += pot * 2; } + + public String getPot() { return "Congratulations, your payout is $" + pot * 2; } + + public void resetPot() { pot = 0.0;} + + public Double getBalance(){return gambler.balance;} + +} diff --git a/src/main/java/io/zipcoder/casino/Player/Player.java b/src/main/java/io/zipcoder/casino/Player/Player.java new file mode 100644 index 000000000..a6a853bff --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Player/Player.java @@ -0,0 +1,25 @@ +package io.zipcoder.casino.Player; + +//Class Starts +public class Player { + + protected String ID; + protected String pwd; + protected double balance; + + public Player(String ID, String password){ + this.ID = ID; + this.pwd = password; + this.balance = 0.0; + } + + public String getID() { + return ID; + } + + public void addAmount(double balance) { + this.balance += balance; + } + + +} diff --git a/src/main/java/io/zipcoder/casino/Player/PlayerWarehouse.java b/src/main/java/io/zipcoder/casino/Player/PlayerWarehouse.java new file mode 100644 index 000000000..424942272 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Player/PlayerWarehouse.java @@ -0,0 +1,25 @@ +package io.zipcoder.casino.Player; + +import java.util.HashMap; + +//Class Starts +public class PlayerWarehouse { + + private HashMap warehouse; + + public PlayerWarehouse() { + this.warehouse = new HashMap(); + } + + public void addPlayer(String ID, String pwd) { + Player newUser = new Player(ID, pwd); + String key = newUser.ID + newUser.pwd; + warehouse.put(key, newUser); + } + + public Player getPlayer(String idNum) { + return warehouse.get(idNum); + } + + +} diff --git a/src/main/java/io/zipcoder/casino/utilities/Console.java b/src/main/java/io/zipcoder/casino/utilities/Console.java index ab896c956..ec1e72cff 100644 --- a/src/main/java/io/zipcoder/casino/utilities/Console.java +++ b/src/main/java/io/zipcoder/casino/utilities/Console.java @@ -57,5 +57,95 @@ public Long getLongInput(String prompt, Object... args) { public Integer getIntegerInput(String prompt, Object... args) { return getLongInput(prompt, args).intValue(); } + + public Integer printMainMenu() { + return getIntegerInput("What would you like to do?\n" + + "1.) Log In\n" + + "2.) Create Account\n" + + "3.) Exit"); + } + + public Integer printSelectGame() { + return getIntegerInput("Please select game to play\n" + + "1.) Go Fish\n" + + "2.) Yahtzee\n" + + "3.) BlackJack\n" + + "4.) Craps\n" + + "5.) Go to Main Menu"); + } + + public void printWelcome(){ + String temp = " \n" + + " ,ad8888ba, 88 8888888888 88 \n" + + " d8\"' `\"8b \"\" 88 88 \n" + + "d8' 88 ____ 88 \n" + + "88 ,adPPYYba, ,adPPYba, 88 8b,dPPYba, ,adPPYba, 88a8PPPP8b, 88 \n" + + "88 \"\" `Y8 I8[ \"\" 88 88P' `\"8a a8\" \"8a PP\" `8b 88 \n" + + "Y8, ,adPPPPP88 `\"Y8ba, 88 88 88 8b d8 d8 \"\" \n" + + " Y8a. .a8P 88, ,88 aa ]8I 88 88 88 \"8a, ,a8\" Y8a a8P aa \n" + + " `\"Y8888Y\"' `\"8bbdP\"Y8 `\"YbbdP\"' 88 88 88 `\"YbbdP\"' \"Y88888P\" 88 \n" + + " \n" + + " "; + + println(temp); + } + + public void printGameName(Integer game) { + String gameName = ""; + + switch (game) { + + case 1: + + gameName = " :::::::: :::::::: :::::::::: ::::::::::: :::::::: ::: ::: \n" + + " :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: \n" + + " +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ \n" + + " :#: +#+ +:+ :#::+::# +#+ +#++:++#++ +#++:++#++ \n" + + " +#+ +#+# +#+ +#+ +#+ +#+ +#+ +#+ +#+ \n" + + "#+# #+# #+# #+# #+# #+# #+# #+# #+# #+# \n" + + "######## ######## ### ########### ######## ### ### \n\n"; + break; + + case 2: + + gameName = " ::: ::: ::: ::: ::: ::::::::::: ::::::::: :::::::::: :::::::::: \n" + + " :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: \n" + + " +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ \n" + + " +#++: +#++:++#++: +#++:++#++ +#+ +#+ +#++:++# +#++:++# \n" + + " +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ \n" + + " #+# #+# #+# #+# #+# #+# #+# #+# #+# \n" + + "### ### ### ### ### ### ######### ########## ########## \n\n"; + break; + case 3: + + gameName = " ::::::::: ::: ::: :::::::: ::: ::: ::::::::::: ::: :::::::: ::: ::: \n" + + " :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: \n" + + " +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ \n" + + " +#++:++#+ +#+ +#++:++#++: +#+ +#++:++ +#+ +#++:++#++: +#+ +#++:++ \n" + + " +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ \n" + + " #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# \n" + + "######### ########## ### ### ######## ### ### ##### ### ### ######## ### ### \n\n"; + break; + case 4: + + gameName = " :::::::: ::::::::: ::: ::::::::: :::::::: \n" + + " :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: \n" + + " +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ \n" + + " +#+ +#++:++#: +#++:++#++: +#++:++#+ +#++:++#++ \n" + + " +#+ +#+ +#+ +#+ +#+ +#+ +#+ \n" + + "#+# #+# #+# #+# #+# #+# #+# #+# #+# \n" + + "######## ### ### ### ### ### ######## \n\n"; + break; + } + + println(gameName); + } + + public void clearScreen() { + for (int i = 0; i < 100; i++) { + println("\n"); + } + + } } diff --git a/src/test/java/io/zipcoder/casino/CardGames/BlackJackTest.java b/src/test/java/io/zipcoder/casino/CardGames/BlackJackTest.java new file mode 100644 index 000000000..534269491 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/CardGames/BlackJackTest.java @@ -0,0 +1,73 @@ +package io.zipcoder.casino.CardGames; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class BlackJackTest { + + + @Before + public void setUp(){} + + @After + public void tearDown(){} + + + + + + @Test + public void startGameTest(){} + + @Test + public void promptHitOrStayTest(){} + + @Test + public void dealerHitOrStayTest(){} + + //@Test + //public void hitTest(Player deck, Player player) {} + + @Test + public void stayTest(){} + + @Test + public void distributeWinningsTest(){} + + //@Test + //public void checkCardValueTest(Card firstCard, Card secondCard){} + + //@Test + //public void getWinnerTest(CardHand dealer, CardHand player){} + + @Test + public void promptLeaveGameTest() {} + + @Test + public void displayResultsTest() {} + + + + + + + + + + + + + + + + + + + + + + + + +} diff --git a/src/test/java/io/zipcoder/casino/CardGames/CardHandTest.java b/src/test/java/io/zipcoder/casino/CardGames/CardHandTest.java new file mode 100644 index 000000000..26aa43082 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/CardGames/CardHandTest.java @@ -0,0 +1,42 @@ +package io.zipcoder.casino.CardGames; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.nio.channels.AsynchronousServerSocketChannel; +import java.util.ArrayList; +import java.util.List; + +public class CardHandTest { + + + @Test + public void testCardHand() { + ArrayList dealtCards = new ArrayList<>(); + Deck newDeck = new Deck(1); + dealtCards = newDeck.dealCards(2); + + CardHand testCardHand = new CardHand(dealtCards); + + int expected = 2; + int actual = testCardHand.userHand.size(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void testDisplayHand() { + ArrayList dealtCards = new ArrayList<>(); + Deck newDeck = new Deck(1); + dealtCards = newDeck.dealCards(2); + + CardHand testCardHand = new CardHand(dealtCards); + String actual = testCardHand.displayHand(); + String expected = " QUEEN ♢ \n KING ♢ \n"; + + Assert.assertEquals(expected,actual); + } + +} \ No newline at end of file diff --git a/src/test/java/io/zipcoder/casino/CardGames/DeckTest.java b/src/test/java/io/zipcoder/casino/CardGames/DeckTest.java new file mode 100644 index 000000000..5aed32886 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/CardGames/DeckTest.java @@ -0,0 +1,63 @@ +package io.zipcoder.casino.CardGames; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.Stack; + +import static org.junit.Assert.*; + + +public class DeckTest { + + + @Test + public void testDealCards(){ + Deck newDeck = new Deck(1); + List cardList = new ArrayList<>(); + cardList = newDeck.dealCards(2); + + int expected = 2; + int actual = cardList.size(); + + Assert.assertEquals(expected,actual); + } + + @Test + public void testShuffleDeck(){ + Deck newDeck = new Deck(1); + Card cardStack = new Card(); + Stack newStack= new Stack<>(); + + newStack = newDeck.shuffleDeck(); + + for (int i = 0; i < newStack.size(); i++) { + System.out.println(newStack.get(i)); + } + + int expected = 52; + int actual = newStack.size(); + + Assert.assertEquals(expected,actual); + } + + @Test + public void testDrawCard(){ + Deck newDeck = new Deck(1); + Card newCard = new Card(); + Stack cardStack = new Stack<>(); + + cardStack = newDeck.shuffleDeck(); + + newCard = newDeck.drawCard(); + int expected = 51; + int actual = cardStack.size(); + + Assert.assertEquals(expected,actual); + } + +} \ No newline at end of file diff --git a/src/test/java/io/zipcoder/casino/CardGames/GoFishTest.java b/src/test/java/io/zipcoder/casino/CardGames/GoFishTest.java new file mode 100644 index 000000000..62e068981 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/CardGames/GoFishTest.java @@ -0,0 +1,120 @@ +package io.zipcoder.casino.CardGames; + +import io.zipcoder.casino.Player.Player; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.logging.Logger; + +public class GoFishTest { + + private static final Logger LOGGER = Logger.getLogger(GoFishTest.class.getName()); + + + @Test + public void haveCard() { + boolean result = false; + Player testPlayer = new Player("V","B"); + GoFish testHaveCard = new GoFish(testPlayer); + Card newCard = new Card(Suit.HEARTS,Rank.KING); + ArrayList cards = new ArrayList<>(); + cards.add(newCard); + CardHand testHand = new CardHand(cards); + result = testHaveCard.haveCard(testHand,"KING"); + + Assert.assertTrue(result); + } + + @Test + public void tradeCards() { + boolean result = false; + Player testPlayer = new Player("V","G"); + GoFish testGame = new GoFish(testPlayer); + + Card firstCard = new Card(Suit.CLUBS,Rank.KING); + Card secondCard = new Card(Suit.CLUBS,Rank.ACE); + + ArrayList giveHand = new ArrayList<>(); + giveHand.add(firstCard); + giveHand.add(secondCard); + CardHand handOne = new CardHand(giveHand); + +// ************ + + Card cardThree = new Card(Suit.CLUBS,Rank.JACK); + Card cardFour = new Card(Suit.CLUBS,Rank.QUEEN); + + ArrayList receiveHand = new ArrayList<>(); + receiveHand.add(cardThree); + receiveHand.add(cardFour); + CardHand handTwo = new CardHand(receiveHand); + + result = testGame.tradeCards(handOne,"KING",handTwo).size() > 0; + Assert.assertTrue(result); + + result = testGame.tradeCards(handOne,"TEN",handTwo).size() > 0; + Assert.assertFalse(result); + } + + @Test + public void goFishForCard() { + boolean result = false; + Player testPlayer = new Player("V","G"); + GoFish testGame = new GoFish(testPlayer); + testGame.initializeGame(); + + Card firstCard = new Card(Suit.CLUBS,Rank.KING); + Card testCard; + ArrayList giveHand = new ArrayList<>(); + giveHand.add(firstCard); + CardHand handOne = new CardHand(giveHand); + + testCard = testGame.goFishForCard(handOne); + giveHand.add(testCard); + result = giveHand.size()>1; + + Assert.assertTrue(result); + } + + @Test + public void checkIfWinner() { + boolean result = false; + Player testPlayer = new Player("V","B"); + GoFish testWinner = new GoFish(testPlayer); + Card cardOne = new Card(Suit.HEARTS,Rank.KING); + Card cardTwo = new Card(Suit.CLUBS,Rank.KING); + Card cardThree = new Card(Suit.DIAMONDS,Rank.KING); + Card cardFour = new Card(Suit.SPADES,Rank.KING); + ArrayList cards = new ArrayList<>(); + cards.add(cardOne); + cards.add(cardTwo); + cards.add(cardThree); + cards.add(cardFour); + CardHand testHand = new CardHand(cards); + + result = testWinner.checkIfWinner(testHand); + Assert.assertTrue(result); + + // ************ + + cards.remove(0); + + cardOne = new Card(Suit.HEARTS, Rank.FIVE); + cards.add(cardOne); + testHand = new CardHand(cards); + result = testWinner.checkIfWinner(testHand); + + Assert.assertFalse(result); + } + + @Test + public void getCompCard() { + Player testPlayer = new Player("V","B"); + GoFish testGame = new GoFish(testPlayer); + testGame.initializeGame(); + + Rank testCard = testGame.getCompCard(); + LOGGER.info("Card drawn: " + testCard.toString()); + } +} \ No newline at end of file diff --git a/src/test/java/io/zipcoder/casino/DiceGames/CrapsTest.java b/src/test/java/io/zipcoder/casino/DiceGames/CrapsTest.java new file mode 100644 index 000000000..25023f7ba --- /dev/null +++ b/src/test/java/io/zipcoder/casino/DiceGames/CrapsTest.java @@ -0,0 +1,47 @@ +package io.zipcoder.casino.DiceGames; + +import io.zipcoder.casino.Player.Player; +import org.junit.Assert; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class CrapsTest { + + Player testPlayer = new Player("bogus","bogus"); + Craps testGame = new Craps (testPlayer); + + @Test + public void createDiceTest() { + Dice[] testDice = testGame.createDice(); + Assert.assertEquals(2,testDice.length); + } + + @Test + public void checkForChipsNegativeTest() { + String unexpected = "Welcome to Craps!"; + String actual = testGame.checkForChips(); + Assert.assertNotEquals(unexpected,actual); + } + + @Test + public void checkForChipsPositiveTest() { + String unexpected = "You need at least $10.00 to play\n"; + String actual = testGame.checkForChips(); + Assert.assertEquals(unexpected,actual); + + } + + + + @Test + public void evaluateRollTest() { + String expected = "Your Target Score is " + 0 + "\n"; + String actual = testGame.evaluateRoll(); + Assert.assertEquals(expected, actual); + + } + + + +} \ No newline at end of file diff --git a/src/test/java/io/zipcoder/casino/DiceGamesTests/DiceGameTest.java b/src/test/java/io/zipcoder/casino/DiceGamesTests/DiceGameTest.java new file mode 100644 index 000000000..1a81a537f --- /dev/null +++ b/src/test/java/io/zipcoder/casino/DiceGamesTests/DiceGameTest.java @@ -0,0 +1,4 @@ +package io.zipcoder.casino.DiceGamesTests; + +public class DiceGameTest { +} diff --git a/src/test/java/io/zipcoder/casino/DiceGamesTests/YahtzeeTests/EvaluationTest.java b/src/test/java/io/zipcoder/casino/DiceGamesTests/YahtzeeTests/EvaluationTest.java new file mode 100644 index 000000000..f2406f508 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/DiceGamesTests/YahtzeeTests/EvaluationTest.java @@ -0,0 +1,165 @@ +package io.zipcoder.casino.DiceGamesTests.YahtzeeTests; + +import io.zipcoder.casino.DiceGames.Yahtzee; +import io.zipcoder.casino.Player.Player; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class EvaluationTest { + + Yahtzee detect; + + @Before + public void doThisFirst(){ + detect = new Yahtzee(new Player("1234", "password")); + } + + @Test + public void getFacePointsTest(){ + Integer[] thisIsMyDice = {1,1,1,1,5}; + int actual = detect.checkForFaces(thisIsMyDice, 1); + int expected = 4; + Assert.assertEquals(expected,actual); + } + + @Test + public void getFacePointsTest2(){ + Integer[] thisIsMyDice2 = {1,5,5,5,5}; + int actual2 = detect.checkForFaces(thisIsMyDice2, 5); + int expected2 = 20; + Assert.assertEquals(expected2,actual2); + } + + @Test + public void get3Kind(){ + Integer[] thisIsMyDice = {1,1,1,6,5}; + int expected = 14; + int actual = detect.checkForSameKind(thisIsMyDice, 3); + Assert.assertEquals(expected,actual); + } + + @Test + public void get3Kind2(){ + Integer[] thisIsMyDice = {1,5,2,2,2}; + int expected = 12; + int actual = detect.checkForSameKind(thisIsMyDice, 3); + Assert.assertEquals(expected,actual); + } + + @Test + public void get4Kind(){ + Integer[] thisIsMyDice = {4,4,4,4,1}; + int expected = 17; + int actual = detect.checkForSameKind(thisIsMyDice, 4); + Assert.assertEquals(expected,actual); + } + + @Test + public void get4Kind2(){ + Integer[] thisIsMyDice = {2,4,2,2,1}; + int expected2 = 0; + int actual2 = detect.checkForSameKind(thisIsMyDice, 4); + Assert.assertEquals(expected2,actual2); + } + + @Test + public void getFullHouse(){ + Integer[] thisIsMyDice = {4,1,4,4,1}; + int expected = 25; + int actual = detect.checkForFullHouse(thisIsMyDice); + Assert.assertEquals(expected,actual); + } + + @Test + public void getFullHouse2(){ + Integer[] thisIsMyDice = {4,2,1,4,2}; + int expected = 0; + int actual = detect.checkForFullHouse(thisIsMyDice); + Assert.assertEquals(expected,actual); + } + + @Test + public void getSmallStraight(){ + Integer[] thisIsMyDice = {3,2,2,4,2}; + int expected = 0; + int actual = detect.checkForStraight(thisIsMyDice, 4); + Assert.assertEquals(expected,actual); + } + + @Test + public void getSmallStraight2(){ + Integer[] thisIsMyDice = {3,2,5,4,6}; + int expected = 30; + int actual = detect.checkForStraight(thisIsMyDice, 4); + Assert.assertEquals(expected,actual); + } + + @Test + public void getLargeStraight(){ + Integer[] thisIsMyDice = {3,2,5,4,2}; + int expected = 0; + int actual = detect.checkForStraight(thisIsMyDice, 5); + Assert.assertEquals(expected,actual); + } + + @Test + public void getLargeStraight2(){ + Integer[] thisIsMyDice = {3,2,5,4,6}; + int expected = 40; + int actual = detect.checkForStraight(thisIsMyDice, 5); + Assert.assertEquals(expected,actual); + } + + @Test + public void getYahtzee(){ + Integer[] thisIsMyDice = {3,3,3,3,3}; + int expected = 50; + int actual = detect.checkForYahtzee(thisIsMyDice); + Assert.assertEquals(expected,actual); + } + + @Test + public void getYahtzee2(){ + Integer[] thisIsMyDice = {2,3,3,3,3}; + int expected = 0; + int actual = detect.checkForYahtzee(thisIsMyDice); + Assert.assertEquals(expected,actual); + } + + @Test + public void getChanceValueTest(){ + Integer[] thisIsMyDice = {2,1,1,1,5}; + int actual = detect.chance(thisIsMyDice); + int expected = 10; + Assert.assertEquals(expected,actual); + + } + + @Test + public void getChanceValueTest2(){ + Integer[] thisIsMyDice2 = {1,5,4,5,5}; + int actual2 = detect.chance(thisIsMyDice2); + int expected2 = 20; + Assert.assertEquals(expected2,actual2); + } + + @Test + public void checkForEvaluationTest(){ + Integer[] thisIsMyDice = {1,5,3,5,5}; + int actual = detect.checkForEvaluation(3, thisIsMyDice); + Assert.assertEquals(3,actual); + actual = detect.checkForEvaluation(5, thisIsMyDice); + Assert.assertEquals(15,actual); + } + + @Test + public void checkForEvaluationTest2(){ + Integer[] thisIsMyDice = {5,5,5,5,5}; + int actual = detect.checkForEvaluation(12, thisIsMyDice); + Assert.assertEquals(50,actual); + actual = detect.checkForEvaluation(9, thisIsMyDice); + Assert.assertEquals(0,actual); + } + +} diff --git a/src/test/java/io/zipcoder/casino/DiceGamesTests/YahtzeeTests/ScoreAndSettingsTest.java b/src/test/java/io/zipcoder/casino/DiceGamesTests/YahtzeeTests/ScoreAndSettingsTest.java new file mode 100644 index 000000000..863beae6a --- /dev/null +++ b/src/test/java/io/zipcoder/casino/DiceGamesTests/YahtzeeTests/ScoreAndSettingsTest.java @@ -0,0 +1,48 @@ +package io.zipcoder.casino.DiceGamesTests.YahtzeeTests; + +import io.zipcoder.casino.DiceGames.Yahtzee; +import io.zipcoder.casino.Player.Player; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class ScoreAndSettingsTest { + + Yahtzee scoreTester; + + @Before + public void doThisFirst(){ + scoreTester = new Yahtzee(new Player("1234", "password")); + } + + + @Test + public void scoreTest1(){ + Assert.assertEquals(0, scoreTester.getPoints()); + scoreTester.updateScore(10); + Assert.assertEquals(10, scoreTester.getPoints()); + } + + @Test + public void scoreTest2(){ + Assert.assertEquals(0, scoreTester.getPoints()); + scoreTester.updateScore(15); + scoreTester.updateScore(5); + Assert.assertEquals(20, scoreTester.getPoints()); + } + + @Test + public void resetGameTest(){ + scoreTester.updateScore(10); + scoreTester.roll5Dice(); + Assert.assertNotEquals(0, scoreTester.getPoints()); + + scoreTester.resetGame(); + + String[] expectedOptions = {" ","1s", "2s", "3s", "4s", "5s", "6s", "3 of a kind", "4 of a kind", + "Small Straight", "Large Straight", "Full House", "Yahtzee", "Chance"}; + + Assert.assertEquals(0, scoreTester.getPoints()); + Assert.assertArrayEquals(expectedOptions, scoreTester.getAvailableOptions()); + } +} diff --git a/src/test/java/io/zipcoder/casino/DiceGamesTests/YahtzeeTests/YahtzeeDiceTest.java b/src/test/java/io/zipcoder/casino/DiceGamesTests/YahtzeeTests/YahtzeeDiceTest.java new file mode 100644 index 000000000..462f3a790 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/DiceGamesTests/YahtzeeTests/YahtzeeDiceTest.java @@ -0,0 +1,61 @@ +package io.zipcoder.casino.DiceGamesTests.YahtzeeTests; + +import io.zipcoder.casino.DiceGames.Dice; +import io.zipcoder.casino.DiceGames.Yahtzee; +import io.zipcoder.casino.Player.Player; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class YahtzeeDiceTest { + + private Yahtzee roller; + private Player user; + + @Before + public void doThisFirst(){ + user = new Player("123","pw"); + roller = new Yahtzee(user); + } + + @Test + public void diceRollTest(){ + roller.roll5Dice(); + Dice[] diceValues = roller.getMyDice(); + + for(int i = 0; i < diceValues.length; i++){ + Assert.assertTrue(diceValues[i].getValue() < 7); + Assert.assertTrue(diceValues[i].getValue() > 0); + } + } + + @Test + public void checkForKeepsTest(){ + roller.roll5Dice(); + Dice[] dice = roller.getMyDice(); + + for(int i = 0; i < roller.getMyDice().length; i++){ + Assert.assertFalse(dice[i].isKept()); + } + dice[1].setKept(true); + Assert.assertTrue(dice[1].isKept()); + } + + @Test + public void resetDiceTest(){ + roller.roll5Dice(); + Dice[] dice = roller.getMyDice(); + + for(int i = 0; i < roller.getMyDice().length; i++){ + dice[i].setKept(true); + Assert.assertTrue(dice[i].isKept()); + } + + roller.resetDice(); + + for(int i = 0; i < roller.getMyDice().length; i++){ + Assert.assertFalse(dice[i].isKept()); + } + } +} diff --git a/src/test/java/io/zipcoder/casino/Player/PlayerTest.java b/src/test/java/io/zipcoder/casino/Player/PlayerTest.java new file mode 100644 index 000000000..11fd28206 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/Player/PlayerTest.java @@ -0,0 +1,21 @@ +package io.zipcoder.casino.Player; + +import org.junit.Assert; +import org.junit.Test; + + +import static org.junit.Assert.*; + +public class PlayerTest { + + @Test + public void testAddAmount() { + Player newPlayer = new Player("bogus","bogus"); + + newPlayer.addAmount(50); + double expected = 50.0; + double actual = newPlayer.balance; + + Assert.assertEquals(expected,actual,0.0); + } +}