diff --git a/Casino.puml b/Casino.puml new file mode 100644 index 000000000..404067bdb --- /dev/null +++ b/Casino.puml @@ -0,0 +1,179 @@ +@startuml +'https://plantuml.com/sequence-diagram + +class PlayerClass { +private String playerName; +private final int playerID; +private int wallet; +private int chipBalance; + +get/setter name; +get ID; +get/set chipBalance; +get/set wallet; +addToWallet; + +wageMoney; +cashOut; +getMoreChips; +} + +interface Game { +playGame; +checkWinner; +} + +interface GamblingGame { +addToPot; +winPot; +} + +interface GamblingPlayer { +wageMoney; +cashOut; +getMoreChips; +} + +abstract class CardGame { +private ArrayList deck; +private ArrayList discardPile; +private ArrayList playerHand; +private ArrayList dealerHand; + +playGame; +checkWinner; +makeDeck; +shuffleDeck; +dealCards; +discardPile; +} + +abstract class DiceGame { +private int totalNumOfDice; +ArrayList playerDiceHand; +int sizeOfPot; + +playGame; +checkWinner; +addToPot; +winPot; +rollDice; +} + +class ChipMoneyExchange { +chipsToMoney; +moneyToChips; +} + +class GoFish { +ArrayList playerHand; +ArrayList dealerHand; +int numOfPlayerMatches; +int numOfDealerMatches; + +doYouHaveCard; +removeCardFromHand; +addToPlayerMatches; +addToDealerMatches; +checkWinner; +} + +class BlackJack { +ArrayList playerHand; +ArrayList playerSplitHand; +ArrayList dealerHand; +ArrayList dealerSplitHand; +int playerTotal; +int dealerTotal; +int sizeOfPot; + +addToPot; +winPot; +checkWinner; +splitHand; +hitMe; +(boolean)didIBust; +} + +class Craps { +String stateOfGame(passOrNot); +int currentRound; +} + +class ExtraDiceGame { +ArrayList dealerDiceHand; +int playerCount; +int dealerCount; + +countMatches; +checkWinner; +holdDice(int... index); +} + +class PlayerWarehouse { +HashSet currentPlayers; + +addPlayer; +removePlayer; +howManyPlayers; +} + +class PlayerFactory { +createPlayer; +} + +class CardFactory { +createCard; +} + + +class CardMaker { +private String nameOfCard; +private String suitOfCard; +private int valueOfCard; +} + +class Display { +enterCasinoScreen; +chipMoneyExchangeScreen; +chooseGameScreen; +goFish(all the screens); +blackJack(all the screens); +craps(all the screens); +extraDiceGame(all the screens); +} + +class cardWarehouse { +ArrayList deckOfCards; +} + + +class MainCasino { +runCasino; +} + +DiceGame <|--- Craps +DiceGame <|--- ExtraDiceGame + +CardGame <|--- GoFish +CardGame <|--- BlackJack + +Game <|--- GamblingGame + + +GamblingGame <|--- BlackJack +GamblingGame <|--- DiceGame + +GamblingPlayer <|-- PlayerClass + +Game <|-- CardGame + + + +'Alice -> Bob: Authentication Request +'Bob --> Alice: Authentication Response +' +'Alice -> Bob: Another authentication Request +'Alice <-- Bob: another authentication Response + +@enduml \ No newline at end of file diff --git a/pom.xml b/pom.xml index c6ec0cc8b..80b0d1115 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,18 @@ io.zipcoder casino 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 7 + 7 + + + + @@ -15,5 +27,17 @@ 4.12 test + + org.junit.jupiter + junit-jupiter + RELEASE + compile + + + junit + junit + 4.13.2 + compile + 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..10eea62b5 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/CardGames/BlackJack.java @@ -0,0 +1,122 @@ +package io.zipcoder.casino.CardGames; + +import io.zipcoder.casino.GamblingGame; +import io.zipcoder.casino.Player.Player; + +import java.util.ArrayList; +import java.util.List; + +public class BlackJack extends CardGame implements GamblingGame { + public Player currentPlayer; + public List playerHand = new ArrayList<>(); + public List dealerHand = new ArrayList<>(); + public List playerSplitHand = new ArrayList<>(); + public List currentHand = playerHand; + public int playerTotal; + public int playerSplitTotal; + public int dealerTotal; + public int sizeOfPot; + + public BlackJack(Player currentPlayer) { this.currentPlayer = currentPlayer; } + + public void addToPot(int chipsAdded) { + currentPlayer.wageMoney(chipsAdded); + sizeOfPot += chipsAdded; + } + + public void passPot(int multiplier) { + currentPlayer.winChips(getPot()*multiplier); + sizeOfPot = 0; + currentHand = playerHand; + } + + public void hitMe() { + dealCards(currentHand); + int currentValue = 0; + if(currentHand == playerHand) { + for(int i = 0; i < playerHand.size(); i++) { + currentValue += playerHand.get(i).getValue(); + } + playerTotal = currentValue; + } else if(currentHand == playerSplitHand) { + for(int i = 0; i < playerSplitHand.size(); i++) { + currentValue += playerSplitHand.get(i).getValue(); + } + playerSplitTotal = currentValue; + } else if(currentHand == dealerHand) { + for(int i = 0; i < dealerHand.size(); i++) { + currentValue += dealerHand.get(i).getValue(); + } + dealerTotal = currentValue; + } + } + + public void hold() { + if(currentHand == playerHand && playerSplitHand.size() == 2) { + currentHand = playerSplitHand; + } else if (currentHand == playerSplitHand) { + currentHand = dealerHand; + } else currentHand = dealerHand; + } + + @Override + public void playGame() { + makeDeck(); + shuffleDeck(); + for(int i = 0; i < 2; i++) { + dealCards(playerHand); + playerTotal += playerHand.get(i).getValue(); + dealCards(dealerHand); + dealerTotal += dealerHand.get(i).getValue(); + } + } + + @Override + public String checkWinner() { + if(playerTotal > dealerTotal && playerTotal <= 21 || playerSplitTotal > dealerTotal && playerSplitTotal <= 21) return "Player"; + else if(dealerTotal > 21) return "Player"; + else if(playerTotal > 21 && playerSplitTotal > 21) return "Dealer"; + else if(playerTotal > 21 && dealerTotal > playerSplitTotal) return "Dealer"; + else if(dealerTotal == 21 && playerTotal != 21 && playerSplitTotal != 21) return "Dealer"; + else if ((dealerTotal > playerTotal || playerTotal > 21) && (dealerTotal > playerSplitTotal || playerSplitTotal > 21)) return "Dealer"; + else return "Tie"; + } + + public void playerHandSplit() { + addToPot(sizeOfPot); + + playerTotal -= playerHand.get(0).getValue(); + playerSplitHand.add(playerHand.remove(0)); + playerSplitTotal += playerSplitHand.get(0).getValue(); + + dealCards(playerHand); + playerTotal += playerHand.get(1).getValue(); + dealCards(playerSplitHand); + playerSplitTotal += playerSplitHand.get(1).getValue(); + } + + public String blackJackCheck() { + if (dealerTotal == 21 && dealerHand.size() == 2 && (playerTotal == 21 && playerHand.size() == 2 || playerSplitTotal == 21 && playerSplitHand.size() == 2)) { + return "Tie"; + } else if (playerTotal == 21 && playerHand.size() == 2 || playerSplitTotal == 21 && playerSplitHand.size() == 2) { + return "Player"; + } else if (dealerTotal == 21 && dealerHand.size() == 2) + return "Dealer"; + else return "None"; + } + + public boolean dealerHaveBlackJack() { + if (dealerTotal == 21 && (dealerHand.get(0).getCardName().equals("A") || dealerHand.get(1).getCardName().equals("A"))) { + return true; + } return false; + } + + public boolean playerBust() { return playerTotal > 21; } + + public boolean playerSplitHandBust() { return playerSplitTotal > 21; } + + public boolean dealerBust() { return dealerTotal > 21; } + + @Override + public int getPot() { return sizeOfPot; } +} diff --git a/src/main/java/io/zipcoder/casino/CardGames/BlackJackEngine.java b/src/main/java/io/zipcoder/casino/CardGames/BlackJackEngine.java new file mode 100644 index 000000000..7bf45e3c9 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/CardGames/BlackJackEngine.java @@ -0,0 +1,247 @@ +package io.zipcoder.casino.CardGames; + +import io.zipcoder.casino.Player.Player; +import io.zipcoder.casino.Screens.BlackJackScreens; +import io.zipcoder.casino.utilities.Console; + +public class BlackJackEngine { + Player player; + + public BlackJackEngine(Player player) { + this.player = player; + } + + public void blackJack() { + Console console = new Console(System.in, System.out); + BlackJack blackJack = new BlackJack(player); + BlackJackScreens screens = new BlackJackScreens(blackJack, player); + + System.out.println(String.format("Hello %s", player.getPlayerName())); + System.out.println("Welcome To BlackJack!"); + + boolean validInput = true; + while(validInput) { + Integer input = console.getIntegerInput("Play? 1 - Yes or 2 - No"); + switch (input) { + case 1: + startGame(blackJack, player, console, screens); + break; + case 2: + System.out.println("Good bye!"); + validInput = false; + break; + default: + System.out.println("Not a valid input. Please choose 1 or 2"); + break; + } + } + } + + public void startGame(BlackJack blackJack, Player player, Console console, BlackJackScreens screens) { + screens.currentChipCount(player); + boolean decision = true; + while (decision) { + Integer bet = console.getIntegerInput("What is your bet?"); + if (bet > player.getChipBalance()) { + System.out.println("Balance not enough, please lower your bet"); + continue; + } else if (bet < 0) { + System.out.println("Please enter a positive amount"); + continue; + } + blackJack.addToPot(bet); + blackJack.playGame(); + roundStart(blackJack, player, console, screens); + decision = false; + } + } + + public void roundStart(BlackJack blackJack, Player player, Console console, BlackJackScreens screens) { + System.out.println(String.format("Hello %s", player.getPlayerName())); + + boolean round = true; + while(round) { + roundStartOperations(blackJack, player, screens); + if(blackJack.playerTotal == 21 && blackJack.playerHand.size() == 2 || blackJack.playerSplitTotal == 21 && blackJack.playerSplitHand.size() == 2 || blackJack.dealerTotal == 21 && blackJack.dealerHand.size() == 2) { + screens.currentHands(blackJack); + blackJackWinner(blackJack, blackJack.blackJackCheck()); + break; + } + Integer decision = console.getIntegerInput("What would you like to do?\n1 - Hit\t\t2 - Hold\t\t3 - Double Down\t\t4 - Split"); + switch (decision) { + case 1: + blackJack.hitMe(); + playerChangeAce(blackJack); + round = bustCheck(blackJack, screens); + break; + case 2: + blackJack.hold(); + while (blackJack.currentHand == blackJack.dealerHand && blackJack.dealerTotal < 16) { + dealerTurn(blackJack, screens); + } + if(blackJack.currentHand == blackJack.dealerHand && blackJack.dealerTotal >= 16) { + String winner = blackJack.checkWinner(); + checkWinner(blackJack, screens, winner); + round = false; + } + break; + case 3: + if(blackJack.currentHand == blackJack.playerHand && blackJack.playerHand.size() == 2 && (blackJack.playerTotal == 9 || blackJack.playerTotal == 10 || blackJack.playerTotal == 11) + || blackJack.currentHand == blackJack.playerSplitHand && blackJack.playerSplitHand.size() == 2 && blackJack.playerSplitTotal == 9 || blackJack.playerSplitTotal == 10 || blackJack.playerSplitTotal == 11) { + blackJack.addToPot(blackJack.sizeOfPot); + blackJack.hitMe(); + playerChangeAce(blackJack); + round = bustCheck(blackJack, screens); + blackJack.hold(); + } else System.out.println("Can only double down if starting hand equals 9, 10, or 11."); + while (blackJack.currentHand == blackJack.dealerHand && blackJack.dealerTotal < 16) { + dealerTurn(blackJack, screens); + } + if(blackJack.currentHand == blackJack.dealerHand && blackJack.dealerTotal >= 16) { + String winner = blackJack.checkWinner(); + checkWinner(blackJack, screens, winner); + round = false; + } + break; + case 4: + if(blackJack.playerHand.get(0).getCardName().equals(blackJack.playerHand.get(1).getCardName()) && blackJack.playerSplitHand.isEmpty()) { + blackJack.playerHandSplit(); + } else if (!blackJack.playerSplitHand.isEmpty()) { + System.out.println("Already split! Cannot split again!"); + } else System.out.println("Not a pair, cannot split. Please select a valid action"); + break; + default: + System.out.println("Not a valid input"); + break; + } + } + } + + public void dealerTurn(BlackJack blackJack, BlackJackScreens screens) { + blackJack.hitMe(); + dealerChangeAce(blackJack); + System.out.println(String.format("Dealer hits and gets a %s", blackJack.dealerHand.get(blackJack.dealerHand.size() - 1))); + screens.currentHands(blackJack); + } + + public void blackJackWinner(BlackJack blackJack, String winner) { + if (winner.equals("Player")) { + System.out.println(String.format("BLACKJACK! You won %s chips.", (blackJack.sizeOfPot*3))); + getPot(blackJack, 3); + } else if (winner.equals("Tie")) { + System.out.println(String.format("Both BLACKJACK! You get %s chips back.", (blackJack.sizeOfPot))); + getPot(blackJack, 1); + } else if (winner.equals("Dealer")) { + System.out.println("Dealer BLACKJACK! Sorry, better luck next time!"); + getPot(blackJack, 0); + } + } + + public boolean bustCheck(BlackJack blackJack, BlackJackScreens screens) { + if(blackJack.playerBust() && blackJack.playerSplitHand.isEmpty()) { + screens.currentHands(blackJack); + System.out.println("BUST! Sorry, better luck next time!"); + getPot(blackJack, 0); + return false; + } else if (blackJack.playerBust() && !blackJack.playerSplitHand.isEmpty()) { + System.out.println("BUST! On to the next hand."); + blackJack.hold(); + return true; + } else if (blackJack.playerSplitHandBust()) { + String winner = blackJack.checkWinner(); + checkWinner(blackJack, screens, winner); + return false; + } return true; + } + + public void checkWinner(BlackJack blackJack, BlackJackScreens screens, String winner) { + switch (winner) { + case "Player": + screens.finalHandWin(blackJack); + getPot(blackJack, 2); + break; + case "Dealer": + screens.finalHandLose(blackJack); + getPot(blackJack, 0); + break; + case "Tie": + screens.finalHandTie(blackJack); + getPot(blackJack, 1); + break; + } + } + + public void getPot(BlackJack blackJack, int multiplier) { + blackJack.passPot(multiplier); + resetValues(blackJack); + } + + public void resetValues(BlackJack blackJack) { + resetHandAndValues(blackJack); + blackJack.clearDiscardAndDeck(); + } + + public void playerChangeAce(BlackJack blackJack) { + int currentValue = 0; + int splitCurrentValue = 0; + + if (blackJack.playerBust()) { + for (int i = 0; i < blackJack.playerHand.size(); i++) { + if (blackJack.playerHand.get(i).getCardName().equals("A")) { + blackJack.playerHand.get(i).setValue(1); + } + } + for (int i = 0; i < blackJack.playerHand.size(); i++) { + currentValue += blackJack.playerHand.get(i).getValue(); + } + blackJack.playerTotal = currentValue; + } + + if (blackJack.playerSplitHandBust()) { + for (int i = 0; i < blackJack.playerSplitHand.size(); i++) { + if (blackJack.playerSplitHand.get(i).getCardName().equals("A")) { + blackJack.playerSplitHand.get(i).setValue(1); + } + } + for (int i = 0; i < blackJack.playerSplitHand.size(); i++) { + splitCurrentValue += blackJack.playerSplitHand.get(i).getValue(); + } + blackJack.playerSplitTotal = splitCurrentValue; + } + } + + public void dealerChangeAce(BlackJack blackJack) { + int currentValue = 0; + if (blackJack.dealerBust()) { + for (int i = 0; i < blackJack.dealerHand.size(); i++) { + if (blackJack.dealerHand.get(i).getCardName().equals("A")) { + blackJack.dealerHand.get(i).setValue(1); + } + } + for(int i = 0; i < blackJack.dealerHand.size(); i++) { + currentValue += blackJack.dealerHand.get(i).getValue(); + } + blackJack.dealerTotal = currentValue; + } + } + + public void resetHandAndValues(BlackJack blackJack) { + blackJack.discardHand(blackJack.playerHand); + blackJack.discardHand(blackJack.playerSplitHand); + blackJack.discardHand(blackJack.dealerHand); + blackJack.playerTotal = 0; + blackJack.playerSplitTotal = 0; + blackJack.dealerTotal = 0; + blackJack.AceOfClubs.setValue(11); + blackJack.AceOfDiamonds.setValue(11); + blackJack.AceOfHearts.setValue(11); + blackJack.AceOfSpades.setValue(11); + } + + public void roundStartOperations(BlackJack blackJack, Player player, BlackJackScreens screens) { + screens.playerTurnHands(blackJack); + screens.currentChipCount(player); + screens.currentPot(blackJack); + screens.currentTurnIndicator(blackJack); + } +} 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..15aa90367 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/CardGames/Card.java @@ -0,0 +1,38 @@ +package io.zipcoder.casino.CardGames; + +public class Card { + //value from ace to king + private String cardName; + //Spade, Diamond, Heart, Clubs + private String cardSuit; + //value = name from 2-10. Jack queen and king are also ten, with ace being 1 or 11 in blackjack. + private Integer cardValue; + + public Card(String name, String suit, Integer value){ + cardName=name; + cardSuit=suit; + cardValue=value; + } + + public String getCardName(){ + return cardName; + } + + public Integer getValue(){ + return cardValue; + } + + public void setValue(int newValue) { + cardValue = newValue; + } + + public String getCardSuit(){ + return cardSuit; + } + + + @Override + public String toString() { + return String.format("%s of %s", cardName, cardSuit); + } +} diff --git a/src/main/java/io/zipcoder/casino/CardGames/CardGame.java b/src/main/java/io/zipcoder/casino/CardGames/CardGame.java new file mode 100644 index 000000000..4f4c74667 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/CardGames/CardGame.java @@ -0,0 +1,174 @@ +package io.zipcoder.casino.CardGames; + +import io.zipcoder.casino.Game; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +abstract class CardGame implements Game { + private List deck=new ArrayList(); + private ListdiscardPile=new ArrayList(); + + + public Card AceOfSpades=new Card("A", "Spades", 11); + private Card TwoOfSpades=new Card("2", "Spades", 2); + private Card ThreeOfSpades=new Card("3", "Spades", 3); + private Card FourOfSpades=new Card("4", "Spades", 4); + private Card FiveOfSpades=new Card("5", "Spades", 5); + private Card SixOfSpades=new Card("6", "Spades", 6); + private Card SevenOfSpades=new Card("7", "Spades", 7); + private Card EightOfSpades=new Card("8", "Spades", 8); + private Card NineOfSpades=new Card("9", "Spades", 9); + private Card TenOfSpades=new Card("10", "Spades", 10); + private Card JackOfSpades=new Card("J", "Spades", 10); + private Card QueenOfSpades=new Card("Q", "Spades", 10); + private Card KingOfSpades=new Card("K", "Spades", 10); + + public Card AceOfClubs=new Card("A", "Clubs", 11); + private Card TwoOfClubs=new Card("2", "Clubs", 2); + private Card ThreeOfClubs=new Card("3", "Clubs", 3); + private Card FourOfClubs=new Card("4", "Clubs", 4); + private Card FiveOfClubs=new Card("5", "Clubs", 5); + private Card SixOfClubs=new Card("6", "Clubs", 6); + private Card SevenOfClubs=new Card("7", "Clubs", 7); + private Card EightOfClubs=new Card("8", "Clubs", 8); + private Card NineOfClubs=new Card("9", "Clubs", 9); + private Card TenOfClubs=new Card("10", "Clubs", 10); + private Card JackOfClubs=new Card("J", "Clubs", 10); + private Card QueenOfClubs=new Card("Q", "Clubs", 10); + private Card KingOfClubs=new Card("K", "Clubs", 10); + + public Card AceOfDiamonds=new Card("A", "Diamonds", 11); + private Card TwoOfDiamonds=new Card("2", "Diamonds", 2); + private Card ThreeOfDiamonds=new Card("3", "Diamonds", 3); + private Card FourOfDiamonds=new Card("4", "Diamonds", 4); + private Card FiveOfDiamonds=new Card("5", "Diamonds", 5); + private Card SixOfDiamonds=new Card("6", "Diamonds", 6); + private Card SevenOfDiamonds=new Card("7", "Diamonds", 7); + private Card EightOfDiamonds=new Card("8", "Diamonds", 8); + private Card NineOfDiamonds=new Card("9", "Diamonds", 9); + private Card TenOfDiamonds=new Card("10", "Diamonds", 10); + private Card JackOfDiamonds=new Card("J", "Diamonds", 10); + private Card QueenOfDiamonds=new Card("Q", "Diamonds", 10); + private Card KingOfDiamonds=new Card("K", "Diamonds", 10); + + public Card AceOfHearts=new Card("A", "Hearts", 11); + private Card TwoOfHearts=new Card("2", "Hearts", 2); + private Card ThreeOfHearts=new Card("3", "Hearts", 3); + private Card FourOfHearts=new Card("4", "Hearts", 4); + private Card FiveOfHearts=new Card("5", "Hearts", 5); + private Card SixOfHearts=new Card("6", "Hearts", 6); + private Card SevenOfHearts=new Card("7", "Hearts", 7); + private Card EightOfHearts=new Card("8", "Hearts", 8); + private Card NineOfHearts=new Card("9", "Hearts", 9); + private Card TenOfHearts=new Card("10", "Hearts", 10); + private Card JackOfHearts=new Card("J", "Hearts", 10); + private Card QueenOfHearts=new Card("Q", "Hearts", 10); + private Card KingOfHearts=new Card("K", "Hearts", 10); + + + + + + //method to set deck to new deck. + public void makeDeck(){ + deck.add(AceOfSpades); + deck.add(TwoOfSpades); + deck.add(ThreeOfSpades); + deck.add(FourOfSpades); + deck.add(FiveOfSpades); + deck.add(SixOfSpades); + deck.add(SevenOfSpades); + deck.add(EightOfSpades); + deck.add(NineOfSpades); + deck.add(TenOfSpades); + deck.add(JackOfSpades); + deck.add(QueenOfSpades); + deck.add(KingOfSpades); + + deck.add(AceOfClubs); + deck.add(TwoOfClubs); + deck.add(ThreeOfClubs); + deck.add(FourOfClubs); + deck.add(FiveOfClubs); + deck.add(SixOfClubs); + deck.add(SevenOfClubs); + deck.add(EightOfClubs); + deck.add(NineOfClubs); + deck.add(TenOfClubs); + deck.add(JackOfClubs); + deck.add(QueenOfClubs); + deck.add(KingOfClubs); + + deck.add(AceOfDiamonds); + deck.add(TwoOfDiamonds); + deck.add(ThreeOfDiamonds); + deck.add(FourOfDiamonds); + deck.add(FiveOfDiamonds); + deck.add(SixOfDiamonds); + deck.add(SevenOfDiamonds); + deck.add(EightOfDiamonds); + deck.add(NineOfDiamonds); + deck.add(TenOfDiamonds); + deck.add(JackOfDiamonds); + deck.add(QueenOfDiamonds); + deck.add(KingOfDiamonds); + + deck.add(AceOfHearts); + deck.add(TwoOfHearts); + deck.add(ThreeOfHearts); + deck.add(FourOfHearts); + deck.add(FiveOfHearts); + deck.add(SixOfHearts); + deck.add(SevenOfHearts); + deck.add(EightOfHearts); + deck.add(NineOfHearts); + deck.add(TenOfHearts); + deck.add(JackOfHearts); + deck.add(QueenOfHearts); + deck.add(KingOfHearts); + + }; + + //shuffles the deck. That's it. Needed since the deck is private. + public void shuffleDeck(){ + Collections.shuffle(deck); + }; + + //I want this method to pick a random card from the deck and deal it to another arrayList. + public void dealCards(List player){ + player.add(deck.get(0)); + deck.remove(0); + } + + //Lets player or dealer discard into discard pile + public void discardCards(int cardIndex, List player){ + discardPile.add(player.get(cardIndex)); + player.remove(cardIndex); + } + + //Lets player or dealer discard whole hand into discard pile + public void discardHand(List player){ + discardPile.addAll(player); + player.clear(); + } + + //Lets you reshuffle the discard into the deck. + public void discardPileReshuffle(){ + deck.addAll(discardPile); + discardPile.clear(); + shuffleDeck(); + }; + + //Empties deck and discard pile. Helps to make new games + public void clearDiscardAndDeck(){ + deck.clear(); + discardPile.clear(); + } + + public Integer getCardsLeftInDeck(){ + return deck.size(); + } + +} 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..1478ca098 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/CardGames/GoFish.java @@ -0,0 +1,258 @@ +package io.zipcoder.casino.CardGames; + +import io.zipcoder.casino.Player.Player; +import io.zipcoder.casino.utilities.Console; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +public class GoFish extends CardGame { + private List oswald= new ArrayList<>(); + private List dealer= new ArrayList<>(); + Player currentplayer; + private List books=new ArrayList(); + int playerScore=0; + int dealerScore=0; + Console gamecube=new Console(System.in,System.out); + + + public GoFish(Player current){ + currentplayer=current; + } + + //blank constructor, mostly to make tests easier. + public GoFish(){ + + } + + public void playGame() { + System.out.println("Welcome to Go Fish, "+currentplayer.getPlayerName()); + System.out.println("This is a nice, friendly game so don't worry about " + + "the chips, okay?"); + String input = gamecube.getStringInput("Are you ready to begin? (enter 'yes' or 'y')"); + Boolean stillPlaying; + //The game setup for if you agree to play starts here + while(input.equalsIgnoreCase("yes")||input.equalsIgnoreCase("y")){ + newGameState(); + for(int i=0; i<7;i++){ + if (completeSet(oswald, oswald.get(0).getCardName())){ + playerScore++; + } + if (completeSet(dealer, dealer.get(0).getCardName())){ + dealerScore++; + } + } + if(playerScore>0||dealerScore>0){ + System.out.println("We already have some books! Crazy!");} + stillPlaying=true; + //The actual GAME starts here. + while(stillPlaying) { + //player takes their turn + if(stillPlaying){ turnStructure();} + //end step for player, checks for winner + if(dealer.size()==0||oswald.size()==0||books.size()==12){ + stillPlaying=false;} + if(stillPlaying){turnStructureAI();} + //end step for dealer, checks for winner + if(dealer.size()==0||oswald.size()==0||books.size()==12){ + stillPlaying=false;} + } + System.out.println(checkWinner()); + input = gamecube.getStringInput("Did you want to play again? (enter 'yes' or 'y')"); + } + System.out.println("Okay then, take care and thanks for playing!"); + } + + public String checkWinner() { + if(oswald.size()==0){System.out.println("The game ends! Your out of cards!");} + if(dealer.size()==0){System.out.println("The game ends! The dealer is out of cards!");} + if(dealerScore>playerScore){return "Dealer wins! Sorry....";} + else return "You win! Congrats!"; + } + + public void newGameState(){ + clearDiscardAndDeck(); + oswald.clear(); + dealer.clear(); + dealerScore=0; + playerScore=0; + makeDeck(); + shuffleDeck(); + dealCards(oswald); + dealCards(dealer); + dealCards(oswald); + dealCards(dealer); + dealCards(oswald); + dealCards(dealer); + dealCards(oswald); + dealCards(dealer); + dealCards(oswald); + dealCards(dealer); + dealCards(oswald); + dealCards(dealer); + dealCards(oswald); + dealCards(dealer); + } + + + + public void turnStructure(){ + Boolean legalchoice; + Boolean takeAnotherTurn=true; + String input; + while (takeAnotherTurn&&oswald.size()>0) { + System.out.print(seeHand(oswald)); + if(books.size()>0){System.out.println(showBooks()); + System.out.println("You have "+playerScore+" books."); + System.out.println("The dealer has "+dealerScore+" books.");} + takeAnotherTurn=false; + legalchoice=false; + input=""; + while (!legalchoice) { + input = gamecube.getStringInput("Alright, go fish!"); + input=input.toUpperCase(); + legalchoice = true; + if (!gotAnyKings(oswald, input)) { + System.out.println("You can only pick card names you have in hand"); + legalchoice = false; + } + } + if (gotAnyKings(dealer, input)) { + takeCards(oswald, dealer, input); + takeAnotherTurn=true; + System.out.println("You caught a fish! You get another turn!"); + if(completeSet(oswald, input)){ + playerScore++; + System.out.println("Congrats, you closed a book!"); + } + } else { + System.out.println("Whoops! No bites, better draw!"); + dealCards(oswald); + System.out.println("You drew: "+showCard(oswald, oswald.size()-1)); + if(drawAnyKings(oswald,input)){ + takeAnotherTurn=true; + System.out.println("You caught a fish! You get another turn!"); + } + if(completeSet(oswald, oswald.get(oswald.size()-1).getCardName())){ + playerScore++; + System.out.println("Congrats, you closed a book!"); + } + } + } + System.out.println("Turn over!"); + } + + public void turnStructureAI(){ + Boolean takeAnotherTurn=true; + String input=""; + while (takeAnotherTurn&&dealer.size()>0) { + System.out.println("Okay, now it's the dealer's turn!"); + takeAnotherTurn=false; + Random r=new Random(); + Integer rand=r.nextInt(dealer.size()); + input=dealer.get(rand).getCardName(); + System.out.println("Dealer asks: 'got any "+input+"'s?"); + + if (gotAnyKings(oswald, input)) { + takeCards(dealer,oswald,input); + System.out.println("Dealer caught a fish! They get another turn!"); + takeAnotherTurn=true; + if(completeSet(dealer, input)){ + dealerScore++; + System.out.println("Dealer closes a book!"); + } + } else { + dealCards(dealer); + System.out.println("You didn't! Dealer draws a "+showCard(dealer, dealer.size()-1)+"!"); + if(drawAnyKings(dealer,input)){ + takeAnotherTurn=true; + System.out.println("Dealer drew a fish! They get another turn!"); + } + if(completeSet(dealer, dealer.get(dealer.size()-1).getCardName())){ + dealerScore++; + System.out.println("Dealer closes a book!"); + } + } + } + System.out.println("Dealer's turn over!"); + } + + public Integer cardsInHand(List player){ + return player.size(); + } + + public String showCard(List player, int indexOfCard) { + String name=player.get(indexOfCard).getCardName(); + String suit=player.get(indexOfCard).getCardSuit(); + return name+" of "+suit; + } + + public String seeHand(List player){ + String wholeHand="Your hand is:\n"; + for(int i=0; i hand, String name) { + for(Card i:hand){ + if(name.equals(i.getCardName())){ + return true; + } + } + return false; + } + + public void takeCards(List taker, List taken, String name) { + for(int i=0;i player, String name) { + if(name.equals(player.get(player.size()-1).getCardName())){ + return true; + } + return false; + } + + public String showBooks(){ + String temp="Completed books so far: "; + for(String i:books){ + temp=temp.concat(i+", "); + } + return temp; + } + + public Boolean completeSet(List player, String name) { + int first=0; + int second=0; + int third=0; + int fourth=0; + int nameFound=0; + for (int i=0;i= 0) { + craps.addToPot(input); + rollTheDice(craps, player, console); + getOut = false; + } else { + getMoreChips(craps, player, console); + getOut = false; + } + } + } + + public void getMoreChips(Craps craps, Player player, Console console) { + cScreens.getMoreChips(); + boolean getOut = true; + while (getOut) { + Integer input = console.getIntegerInput(""); + if (input == 0) { + getOut = false; + } else if (input == 1) { + betAmountRoundOneScreen(craps, player, console); + getOut = false; + } else { + System.out.println("Invalid Entry"); + } + } + } + + public void rollTheDice(Craps craps, Player player, Console console) { + cScreens.rollTheDice(); + boolean getOut = true; + while (getOut) { + Integer input = console.getIntegerInput(""); + if (input == 1) { + craps.sumOfDice(); + if (craps.getBetStatus().equalsIgnoreCase("Pass")) { + if (craps.getCurrentSum() == 7 || craps.getCurrentSum() == 11) { + winRollScreen(craps, player, console); + } else if (craps.getCurrentSum() == 2 || craps.getCurrentSum() == 3 || craps.getCurrentSum() == 12) { + loseRollScreen(craps, player, console); + } else { + craps.setPointer(craps.getCurrentSum()); + rollAgainScreen(craps, player, console); + } + } else if (craps.getBetStatus().equalsIgnoreCase("Not Pass")) { + if (craps.getCurrentSum() == 2 || craps.getCurrentSum() == 3 || craps.getCurrentSum() == 12) { + winRollScreen(craps, player, console); + } else if (craps.getCurrentSum() == 7 || craps.getCurrentSum() == 11) { + loseRollScreen(craps, player, console); + } else { + craps.setPointer(craps.getCurrentSum()); + rollAgainScreen(craps, player, console); + } + } + getOut = false; + } else { + System.out.println("Invalid Entry"); + } + } + } + + public void loseRollScreen(Craps craps, Player player, Console console) { + cScreens.loseRollScreen(craps.getGameRound(), craps.getPot(), craps.getCurrentSum(), craps.getBetStatus()); + boolean getOut = true; + while (getOut) { + Integer input = console.getIntegerInput(""); + if (input.equals(1)) { + craps.setGameRound(1); + passOrNotPassRoundOneScreen(craps.getGameRound(), craps, player, console); + getOut = false; + } else if (input.equals(2)) { + goodLuckScreen(craps, player, console); + getOut = false; + } else { + System.out.println("Invalid Entry"); + } + } + } + + public void goodLuckScreen(Craps craps, Player player, Console console) { + cScreens.leaveCrapsScreen(); + boolean getOut = true; + while (getOut) { + Integer input = console.getIntegerInput(""); + if (input == 0) { + getOut = false; + } else { + System.out.println("Invalid Entry"); + } + } + } + + public void winRollScreen(Craps craps, Player player, Console console) { + cScreens.winRollScreen(craps.getGameRound(), craps.getPot(), craps.getCurrentSum(), craps.getBetStatus()); + craps.playerWinsPot(craps.getPot()); + boolean getOut = true; + while (getOut) { + Integer input = console.getIntegerInput(""); + if (input.equals(1)) { + craps.setGameRound(1); + passOrNotPassRoundOneScreen(craps.getGameRound(), craps, player, console); + getOut = false; + } else if (input.equals(2)) { + goodLuckScreen(craps, player, console); + getOut = false; + } else { + System.out.println("Invalid Entry"); + } + } + } + + public void rollAgainScreen(Craps craps, Player player, Console console) { + cScreens.passOrNotPassRoundTwoScreen(craps.getGameRound(), craps.getPot(), craps.getCurrentSum(), craps.getBetStatus(), craps.getPointer()); + boolean getOut = true; + while (getOut) { + Integer input = console.getIntegerInput(""); + if (input.equals(1)) { + craps.setBetStatus("Pass"); + rollAgainBetScreen(craps, player, console); + getOut = false; + } else if (input.equals(2)) { + craps.setBetStatus("Not Pass"); + rollAgainBetScreen(craps, player, console); + getOut = false; + } else { + System.out.println("Please enter 1 or 2"); + } + } + } + + public void rollAgainBetScreen(Craps craps, Player player, Console console) { + cScreens.rollAgainBetScreen(craps.getGameRound(), craps.getPot(), craps.getCurrentSum(), craps.getBetStatus(), craps.getPointer()); + boolean getOut = true; + while (getOut) { + Integer input = console.getIntegerInput(""); + if (input <= player.getChipBalance() && input >=0) { + craps.addToPot(input); + rollTheDiceOnward(craps, player, console); + getOut = false; + } else { + System.out.println("Insufficient Chips"); + } + } + } + + private void rollTheDiceOnward(Craps craps, Player player, Console console) { + craps.setGameRound(2); + cScreens.rollAgainOnward(craps.getGameRound(),craps.getBetStatus(), craps.getPot(), craps.getPointer()); + boolean getOut = true; + while (getOut) { + Integer input = console.getIntegerInput(""); + if (input == 1) { + craps.sumOfDice(); + if (craps.getBetStatus().equalsIgnoreCase("Pass")) { + if (craps.getCurrentSum() == craps.getPointer()) { + winRollScreen(craps, player, console); + } else if (craps.getCurrentSum() == 7) { + loseRollScreen(craps, player, console); + } else { + rollAgainBetScreen(craps, player, console); + } + } else if (craps.getBetStatus().equalsIgnoreCase("Not Pass")) { + if (craps.getCurrentSum() == 7) { + winRollScreen(craps, player, console); + } else if (craps.getCurrentSum() == craps.getPointer()) { + loseRollScreen(craps, player, console); + } else { + rollAgainBetScreen(craps, player, console); + } + } + getOut = false; + } else { + System.out.println("Invalid Entry"); + } + } + } +} diff --git a/src/main/java/io/zipcoder/casino/DiceGames/DiceGame.java b/src/main/java/io/zipcoder/casino/DiceGames/DiceGame.java new file mode 100644 index 000000000..b03b871e3 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/DiceGames/DiceGame.java @@ -0,0 +1,30 @@ +package io.zipcoder.casino.DiceGames; + +import io.zipcoder.casino.GamblingGame; + +import java.util.ArrayList; + +public abstract class DiceGame implements GamblingGame { + private int totalNumOfDice; + public ArrayList playerDiceHand = new ArrayList(); + public int pot = 0; + + public void addToPot() { + } + + public void clearPot() { + pot = 0; + } + + public int getPot() { + return pot; + } + + public boolean checkWinner() { + return false; + } + + public int rollDice() { + return (int) (Math.random() * 6) + 1; + } +} diff --git a/src/main/java/io/zipcoder/casino/DiceGames/MostOfAKindEngine.java b/src/main/java/io/zipcoder/casino/DiceGames/MostOfAKindEngine.java new file mode 100644 index 000000000..05dee2d0e --- /dev/null +++ b/src/main/java/io/zipcoder/casino/DiceGames/MostOfAKindEngine.java @@ -0,0 +1,169 @@ +package io.zipcoder.casino.DiceGames; + +import io.zipcoder.casino.Screens.MostOfAKindScreens; +import io.zipcoder.casino.Player.Player; +import io.zipcoder.casino.utilities.Console; + +import java.util.ArrayList; + +public class MostOfAKindEngine { + Player player; + MostOfAKindScreens mScreens = new MostOfAKindScreens(); + + public MostOfAKindEngine(Player player) { + this.player = player; + } + + public void moak() { + MostOfAKindGame moak = new MostOfAKindGame(player); + Console console = new Console(System.in, System.out); + System.out.println(String.format("Hello %s", player.getPlayerName())); + System.out.println("Welcome To Most Of A Kind!"); + + startMoakGame(moak, player, console); + } + + private void startMoakGame(MostOfAKindGame moak, Player player, Console console) { + mScreens.welcomeMoakScreen(); + System.out.println(player.getPlayerName()); + System.out.println(player.getChipBalance()); + boolean getOut = true; + while (getOut) { + Integer input = console.getIntegerInput(""); + if (input == 1) { + anteUpScreen(moak, player, console); + getOut = false; + } else if (input == 2) { + getOut = false; + } else { + welcomeInvalidScreen(moak, player, console); + } + } + } + + private void welcomeInvalidScreen(MostOfAKindGame moak, Player player, Console console) { + mScreens.welcomeInvalidMoakScreen(); + } + + //Takes 5 chips, makes dealer and player hands + private void anteUpScreen(MostOfAKindGame moak, Player player, Console console) { + moak.clearPot(); + moak.clearPlayerHand(); + moak.clearDealerHand(); + mScreens.anteUpScreen(); + boolean getOut = true; + while (getOut) { + Integer input = console.getIntegerInput(""); + if (input == 1) { + if (player.getChipBalance() < 10) { + //needMoreChipsScreen(moak, player, console); + System.out.println("Insufficient Chips"); + } else { + moak.anteUp(); + moak.makePlayerHand(5); + moak.makeDealerHand(5); + firstRollScreen(moak.getPot(), moak.getPlayerHand(), moak, player, console); + } + getOut = false; + } else { + System.out.println("Invalid Entry"); + } + } + } + + private void firstRollScreen(int pot, ArrayList playerHand, MostOfAKindGame moak, Player player, Console console) { + mScreens.firstRollScreen(pot, playerHand); + boolean getOut = true; + while (getOut) { + Integer input = console.getIntegerInput(""); + if (input <= player.getChipBalance() && input >= 0) { + moak.addToPot(input); + numberToKeepScreen(moak.getPot(), moak.getPlayerHand(), moak, player, console); + getOut = false; + } else { + System.out.println("Insufficient Chips");; + } + } + } + + private void numberToKeepScreen(int pot, ArrayList playerHand, MostOfAKindGame moak, Player player, Console console) { + mScreens.numberToKeepScreen(pot, playerHand); + boolean getOut = true; + while (getOut) { + Integer input = console.getIntegerInput(""); + if (moak.getPlayerHand().contains(input)) { + moak.exchangePlayerDice(input); + moak.dealerAINumbersToKeep(moak.getDealerHand()); + moak.exchangeDealerDice(moak.dealerMatchingNum); + secondRollScreen(moak.getPot(), moak.getPlayerHand(), moak, player, console); + getOut = false; + } else if (input == 0) { + moak.clearPlayerHand(); + moak.makePlayerHand(5); + moak.dealerAINumbersToKeep(moak.getDealerHand()); + secondRollScreen(moak.getPot(), moak.getPlayerHand(), moak, player, console); + getOut = false; + } else { + System.out.println("Invalid Entry"); + } + } + } + + private void secondRollScreen(int pot, ArrayList playerHand, MostOfAKindGame moak, Player player, Console console) { + mScreens.secondRollScreen(pot, playerHand); + boolean getOut = true; + while (getOut) { + Integer input = console.getIntegerInput(""); + if (input <= player.getChipBalance() && input >= 0) { + moak.addToPot(input); + moak.playerNumOfMatches(playerHand); + moak.dealerNumOfMatches(moak.dealerHand); + if (moak.checkWinner() == true) { + revealHandsPlayerWins(moak.getPot(), moak.getPlayerHand(), moak.getDealerHand(), moak, player, console); + getOut = false; + } else if (moak.checkWinner() == false) { + //catches when dealer wins + revealHandsDealerWins(moak.getPot(), moak.getPlayerHand(), moak.getDealerHand(), moak, player, console); + getOut = false; + } + } else { + System.out.println("Insufficient Chips"); + } + } + } + + private void revealHandsDealerWins(int pot, ArrayList playerHand, ArrayList dealerHand, MostOfAKindGame moak, Player player, Console console) { + mScreens.revealHandsDealerWins(pot, playerHand, dealerHand); + boolean getOut = true; + while (getOut) { + Integer input = console.getIntegerInput(""); + if (input == 1) { + anteUpScreen(moak, player, console); + getOut = false; + } else if (input == 2) { + System.out.println("Goodbye and good luck!"); + getOut = false; + } else { + System.out.println("Invalid Entry"); + } + } + } + + private void revealHandsPlayerWins(int pot, ArrayList playerHand, ArrayList dealerHand, MostOfAKindGame moak, Player player, Console console) { + mScreens.revealHandsPlayerWins(pot, playerHand, dealerHand); + moak.playerWinsPot(moak.getPot()); + boolean getOut = true; + while (getOut) { + Integer input = console.getIntegerInput(""); + if (input == 1) { + anteUpScreen(moak, player, console); + getOut = false; + } else if (input == 2) { + System.out.println("Goodbye and good luck!"); + getOut = false; + } else { + System.out.println("Invalid Entry"); + } + } + } +} diff --git a/src/main/java/io/zipcoder/casino/DiceGames/MostOfAKindGame.java b/src/main/java/io/zipcoder/casino/DiceGames/MostOfAKindGame.java new file mode 100644 index 000000000..76bb83f36 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/DiceGames/MostOfAKindGame.java @@ -0,0 +1,195 @@ +package io.zipcoder.casino.DiceGames; + +import io.zipcoder.casino.Player.Player; + +import java.util.ArrayList; + +public class MostOfAKindGame extends DiceGame { + public ArrayList dealerHand = new ArrayList(); + public int playerMatchingNum; + public int dealerMatchingNum; + public int dealerCount; + public int playerCount; + public Player currentPlayer; + + public MostOfAKindGame(Player player) { + this.currentPlayer = player; + } + + public int getPot() { + return pot; + } + + public int getDealerCount() { + return dealerCount; + } + + public int getPlayerCount() { + return playerCount; + } + + public boolean checkWinner() { + boolean doIWin = false; + if (getPlayerCount() > getDealerCount()) { + doIWin = true; + } else if (getDealerCount() > getPlayerCount()) { + doIWin = false; + } else if (getDealerCount() == getPlayerCount()) { + if (playerMatchingNum > dealerMatchingNum) { + doIWin = true; + } else if (dealerMatchingNum > playerMatchingNum) { + //catches when dealerMatchingNum bigger + doIWin = false; + } + } + return doIWin; + } + + + public void addToPlayerCount(int numOfSameNum) { + playerCount += numOfSameNum; + } + + public void addToDealerCount(int numOfSameNum) { + dealerCount += numOfSameNum; + } + + public void makeDealerHand(int numOfDice) { + int i = 0; + while (i < numOfDice) { + dealerHand.add(rollDice()); + i++; + } + } + + public void makePlayerHand(int numOfDice) { + int i = 0; + while (i < numOfDice) { + playerDiceHand.add(rollDice()); + i++; + } + } + + public ArrayList getDealerHand() { + return this.dealerHand; + } + + public ArrayList getPlayerHand() { + return playerDiceHand; + } + + public void exchangePlayerDice(int numToKeep) { + playerMatchingNum = numToKeep; + ArrayList newHand = new ArrayList(); + int numOfDiceKeeping = 0; + for (int i = 0; i < getPlayerHand().size(); i++) { + if (getPlayerHand().get(i) == numToKeep) { + newHand.add(getPlayerHand().get(i)); + numOfDiceKeeping++; + } + } + int numOfDiceRollAgain = 5 - numOfDiceKeeping; + playerDiceHand = newHand; + makePlayerHand(numOfDiceRollAgain); + } + + public void exchangeDealerDice(int numToKeep) { + dealerMatchingNum = numToKeep; + ArrayList newDealerHand = new ArrayList(); + int numOfDiceKeeping = 0; + for (int i = 0; i < getDealerHand().size(); i++) { + if (getDealerHand().get(i) == numToKeep) { + newDealerHand.add(getDealerHand().get(i)); + numOfDiceKeeping++; + } + } + int numOfDiceRollAgain = 5 - numOfDiceKeeping; + dealerHand = newDealerHand; + makeDealerHand(numOfDiceRollAgain); + } + + + public void setPlayerMatchingNum(int matchingNum) { + this.playerMatchingNum = matchingNum; + } + + public int getPlayerMatchingNum() { + return playerMatchingNum; + } + + public void setDealerMatchingNum(int matchingNum) { + this.dealerMatchingNum = matchingNum; + } + + public int getDealerMatchingNum() { + return dealerMatchingNum; + } + + public void playerNumOfMatches(ArrayList playerSecondHand) { + playerCount = 1; + for (int i = 1; i < playerSecondHand.size(); i++) { + if (playerSecondHand.get(i) == playerSecondHand.get(0)) { + playerCount++; + } + } + } + + public void dealerNumOfMatches(ArrayList dealerSecondHand) { + dealerCount = 1; + for (int i = 1; i < dealerSecondHand.size(); i++) { + if (dealerSecondHand.get(i) == dealerSecondHand.get(0)) { + dealerCount++; + } + } + } + + public void dealerAINumbersToKeep(ArrayList dealerHand) { + int matchOne; + int counterOne = 1; + int matchTwo = 0; + int counterTwo = 1; + + for (int i = 0; i < dealerHand.size()-1; i++) { + matchOne = dealerHand.get(i); + for (int j = i+1; j < dealerHand.size(); j++) { + if (dealerHand.get(j) == dealerHand.get(i)) { + counterOne++; + } + } + if (counterOne > counterTwo) { + matchTwo = matchOne; + counterTwo = counterOne; + } else if (counterOne == counterTwo) { + if (matchOne > matchTwo) { + matchTwo = matchOne; + counterTwo = counterOne; + } + } + counterOne = 1; + } + dealerMatchingNum = matchTwo; + dealerCount = counterTwo; + } + + public void anteUp() { + currentPlayer.wageMoney(5); + pot += 5; + } + + public void addToPot(int numOfChips) { + pot += numOfChips; + currentPlayer.wageMoney(numOfChips); + } + + public void clearPlayerHand() { + playerDiceHand.clear(); + } + + public void clearDealerHand() { + dealerHand.clear(); + } + + public void playerWinsPot(int pot) { + currentPlayer.winChips(pot * 2); + } +} 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..10b4745e8 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/GamblingGame.java @@ -0,0 +1,6 @@ +package io.zipcoder.casino; + +public interface GamblingGame { + void addToPot(int amount); + int getPot(); +} 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..c0faecc77 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/GamblingPlayer.java @@ -0,0 +1,8 @@ +package io.zipcoder.casino; + +public interface GamblingPlayer { + void wageMoney(int wageAmount); + void cashOut(); + void getMoreChips(int buyAmount); + void winChips(int chipsWon); +} 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..175051246 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Game.java @@ -0,0 +1,6 @@ +package io.zipcoder.casino; + +public interface Game { + void playGame(); + String checkWinner(); +} diff --git a/src/main/java/io/zipcoder/casino/Main.java b/src/main/java/io/zipcoder/casino/Main.java new file mode 100644 index 000000000..ee911d066 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Main.java @@ -0,0 +1,14 @@ +package io.zipcoder.casino; + +import io.zipcoder.casino.Player.PlayerWarehouse; + +public class Main { + + public static void main (String[] args) { + Casino casino = new Casino(); + PlayerWarehouse.initializePlayers(); + while (true) { + casino.run(); + } + } +} 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..801066b71 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Player/Player.java @@ -0,0 +1,74 @@ +package io.zipcoder.casino.Player; + +import io.zipcoder.casino.GamblingPlayer; + +public class Player implements GamblingPlayer { + private String playerName; + private final int playerID; + private int wallet; + private int chipBalance; + + public Player(String playerName, int wallet) { + this.playerName = playerName; + this.playerID = (int)(Math.random() * ((9999 - 1000) + 1) + 1000); + this.wallet = wallet; + this.chipBalance = 0; + } + + public String getPlayerName() { + return playerName; + } + + public void setPlayerName(String playerName) { + this.playerName = playerName; + } + + public int getPlayerID() { + return playerID; + } + + public int getWallet() { + return wallet; + } + + public void setWallet(int wallet) { + this.wallet = wallet; + } + + public int getChipBalance() { + return chipBalance; + } + + public void setChipBalance(int chipBalance) { + this.chipBalance = chipBalance; + } + + public void addToWallet(int newMoney) { + if(newMoney >= 0) { + wallet += newMoney; + } + } + + public void wageMoney(int wageAmount) { + if(wageAmount >= 0) { + chipBalance -= wageAmount; + } + } + + public void cashOut() { + wallet += chipBalance; + chipBalance = 0; + } + + public void getMoreChips(int buyAmount) { + if(buyAmount >= 0) { + wallet -= buyAmount; + chipBalance += buyAmount; + } + } + + public void winChips(int chipsWon) { + chipBalance += chipsWon; + } + +} diff --git a/src/main/java/io/zipcoder/casino/Player/PlayerFactory.java b/src/main/java/io/zipcoder/casino/Player/PlayerFactory.java new file mode 100644 index 000000000..3c4c77bb4 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Player/PlayerFactory.java @@ -0,0 +1,8 @@ +package io.zipcoder.casino.Player; + +public class PlayerFactory { + + public static Player createPlayer(String name, int wallet) { + return new Player(name, wallet); + } +} 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..82ae94028 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Player/PlayerWarehouse.java @@ -0,0 +1,37 @@ +package io.zipcoder.casino.Player; + +import java.util.HashMap; +import java.util.Map; + +public class PlayerWarehouse { + public static Map currentPlayers = new HashMap<>(); + + public static void initializePlayers() { + Player gerg = PlayerFactory.createPlayer("Greg", 5000); + Player nixog = PlayerFactory.createPlayer("Xiong", 5000); + Player eab = PlayerFactory.createPlayer("Abe", 5000); + gerg.setChipBalance(5000); + nixog.setChipBalance(5000); + eab.setChipBalance(5000); + + currentPlayers.put(100, nixog); + currentPlayers.put(200, gerg); + currentPlayers.put(300, eab); + } + + public static void addPlayer(int playerID, Player player) { + currentPlayers.put(playerID, player); + } + + public static void removePlayer(int playerID) { + currentPlayers.remove(playerID); + } + + public static Integer getNumberOfCurrentPlayers() { + return currentPlayers.size(); + } + + public static void removeAllPlayers() { + currentPlayers.clear(); + } +} diff --git a/src/main/java/io/zipcoder/casino/Screens/BlackJackScreens.java b/src/main/java/io/zipcoder/casino/Screens/BlackJackScreens.java new file mode 100644 index 000000000..754ce7f5b --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Screens/BlackJackScreens.java @@ -0,0 +1,72 @@ +package io.zipcoder.casino.Screens; + +import io.zipcoder.casino.CardGames.BlackJack; +import io.zipcoder.casino.Player.Player; + +public class BlackJackScreens { + Player player; + BlackJack blackJack; + + public BlackJackScreens(BlackJack blackJack, Player player) { + this.blackJack = blackJack; + this.player = player; + } + + public void currentChipCount(Player player) { + System.out.println(String.format("%s : Your current chip count is %7d\n", player.getPlayerName(), player.getChipBalance())); + } + + public void currentPot(BlackJack blackJack) { + System.out.println(String.format("The current bet is %s\n", blackJack.sizeOfPot)); + } + + public void finalHandTie(BlackJack blackJack) { + System.out.println("\n\t\t\t\t\t**********FINAL HANDS**********\t\t\t\t\t\n"); + currentHands(blackJack); + System.out.println(String.format("TIED! You get %s chips back.", blackJack.sizeOfPot)); + } + + public void finalHandLose(BlackJack blackJack) { + System.out.println("\n\t\t\t\t\t**********FINAL HANDS**********\t\t\t\t\t\n"); + currentHands(blackJack); + System.out.println("Sorry, better luck next time!"); + } + + public void finalHandWin(BlackJack blackJack) { + System.out.println("\n\t\t\t\t\t**********FINAL HANDS**********\t\t\t\t\t\n"); + currentHands(blackJack); + System.out.println(String.format("Congrats! You won %s chips.", (blackJack.sizeOfPot*2))); + } + + public void playerTurnHands(BlackJack blackJack) { + System.out.println("Dealer current hand:"); + System.out.println(String.format("\t\t\t\t\t=== %s + HIDDEN CARD ===", blackJack.dealerHand.get(0))); + if(!blackJack.playerSplitHand.isEmpty()) { + System.out.println(String.format("\nPlayer current split hand: %s\n", blackJack.playerSplitTotal)); + System.out.println(String.format("\t\t\t\t\t=== %s ===", blackJack.playerSplitHand)); + } + System.out.println(String.format("\nPlayer current hand: %s\n", blackJack.playerTotal)); + System.out.println(String.format("\t\t\t\t\t=== %s ===\n", blackJack.playerHand)); + } + + public void currentHands(BlackJack blackJack) { + System.out.println(String.format("Dealer current hand: %s\n",blackJack.dealerTotal)); + System.out.println(String.format("\t\t\t\t\t=== %s ===", blackJack.dealerHand)); + if(!blackJack.playerSplitHand.isEmpty()) { + System.out.println(String.format("\nPlayer current split hand: %s\n", blackJack.playerSplitTotal)); + System.out.println(String.format("\t\t\t\t\t=== %s ===", blackJack.playerSplitHand)); + } + System.out.println(String.format("\nPlayer current hand: %s\n", blackJack.playerTotal)); + System.out.println(String.format("\t\t\t\t\t=== %s ===\n", blackJack.playerHand)); + } + + public void currentTurnIndicator(BlackJack blackJack) { + if(blackJack.currentHand == blackJack.playerHand) { + System.out.println(String.format("Turn to act : *** %s ***", blackJack.currentPlayer.getPlayerName())); + } else if(blackJack.currentHand == blackJack.playerSplitHand) { + System.out.println(String.format("Turn to act : *** %s Split Hand***", blackJack.currentPlayer.getPlayerName())); + }else if(blackJack.currentHand == blackJack.dealerHand) { + System.out.println("Turn to act : *** Dealer ***"); + } + } +} diff --git a/src/main/java/io/zipcoder/casino/Screens/CrapsScreens.java b/src/main/java/io/zipcoder/casino/Screens/CrapsScreens.java new file mode 100644 index 000000000..f9eaa135f --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Screens/CrapsScreens.java @@ -0,0 +1,221 @@ +package io.zipcoder.casino.Screens; + +public class CrapsScreens extends Displays { + //WELCOME + public void crapsWelcomeScreen() { + println(" "); + println(" HHHHH "); + println(" H((((HHH "); + println(" (H((((((((HHX "); + println(" HH((((((HHHHXXX "); + println(" XHH((HHHHHHXXXXX "); + println(" HH((HHHHHHHXXXXXXXX "); + println(" XHHHHHHHHXXXXXXXXXXHH((HHX "); + println(" ,XHXXXXXXXXXXXXXHH((((HHHHHX "); + println(" X,......,HHHH((((H,.... .,X "); + println(" HHH. @@@@ .(((HHHH. @@@@ .HHH "); + println(" HH((( @@@@@@ .HHHXX. @@@@@@ *HHHX "); + println(" XHHHHH. @@@@& HXXXXXX *@@@@ .HHHXXX "); + println(" XXXXXXX. .XHHHH((((. .XXXXXXX "); + println(" XHHHHHHHHHH(((((((((HHHHHHHHXXXXXXXXXHHH "); + println(" HH((((((((((((///////////////////XXXXXHHH(HHHXX "); + println(" HHHHHHHHHHHHHHHHH. ,XXXXHH(((HHHHXXXXX "); + println("XXHHHHHHHHHHHHXXXXXXXXX,..,*XXXXHHH((((HHHHXXXXXXXX "); + println(" XXXXXXXXXXXXXXXXXXXXXXXXXHHHH(((((HHHHXXXXXXXXXXX "); + println(" XXXXXXXXXXXXXXXXHHHHHHHHHHHHHHHXXXXXXXXXXXXX& "); + println(" "); + println(" ARE YOU READY TO PLAY SOME CRAPS? "); + println(" 1: Yes 2: No "); + println(" "); + } + + public void crapsInvalidWelcomeScreen() { + println(" "); + println(" Invalid Entry "); + println(" ------------- "); + println(" ARE YOU READY TO PLAY SOME CRAPS? "); + println(" 1: Yes 2: No "); + println(" "); + } + + //ROUND ONE PREP + public void passOrNotPassRoundOneScreen(int roundOfGame) { + println(" "); + println(" ROUND: %s ", roundOfGame); + println(" "); + println(" How are you betting? "); + println(" -------------------- "); + println(" 1: Pass "); + println(" 2: Not Pass "); + println(" "); + } + + public void betAmountRoundOneScreen(int roundOfGame) { + println(" "); + println(" ROUND: %s ", roundOfGame); + println(" "); + println(" How much are you betting? "); + println(" ------------------------- "); + println(" "); + } + + public void rollTheDice() { + println(" "); + println(" Enter 1 to roll dice "); + println(" "); + } + + + //ROUND TWO SCREENS + public void passOrNotPassRoundTwoScreen(int roundOfGame, int pot, int sumOfDice, String betStatus, int pointer) { + println(" "); + println(" ROUND: %s ", roundOfGame); + println(" "); + println(" Bet Status: %s ", betStatus); + println(" "); + println(" Chips in pot: %s ", pot); + println(" "); + println(" Pointer: %s ", pointer); + println(" "); + println(" Your roll: %s ", sumOfDice); + println(" "); + println(" How are you betting? "); + println(" -------------------- "); + println(" 1: Pass "); + println(" 2: Not Pass "); + println(" "); + } + +// public void betAmountRoundTwoScreen(int roundOfGame, String betStatus, int pot, int pointer, int sumOfDice) { +// println(" "); +// println(" ROUND: %s ", roundOfGame); +// println(" "); +// println(" Bet Status: %s ", betStatus); +// println(" "); +// println(" Chips in pot: %s ", pot); +// println(" "); +// println(" Pointer: %s ", pointer); +// println(" "); +// println(" Your roll: %s ", sumOfDice); +// println(" "); +// println(" How much are you betting? "); +// println(" ------------------------- "); +// println(" "); +// } + + public void rollAgainOnward(int roundOfGame, String betStatus, int pot, int pointer) { + println(" "); + println(" ROUND: %s ", roundOfGame); + println(" "); + println(" Bet Status: %s ", betStatus); + println(" "); + println(" Chips in pot: %s ", pot); + println(" "); + println(" Pointer: %s ", pointer); + println(" ------------- "); + println(" Enter 1 to roll dice "); + println(" "); + } + + + //OUTCOME OPTIONS + public void winRollScreen(int roundOfGame, int pot, int sumOfDice, String betStatus) { + println(" "); + println(" ROUND: %s ", roundOfGame); + println(" "); + println(" Bet Status: %s ", betStatus); + println(" "); + println(" Chips in Pot: %s ", pot); + println(" "); + println(" You rolled a %s ", sumOfDice); + println(" --------------- "); + println(" You Win! "); + println(" "); + println(" Play again? "); + println(" 1: Yes 2: No "); + println(" "); + } + + public void loseRollScreen(int roundOfGame, int pot, int sumOfDice, String betStatus) { + println(" "); + println(" ROUND: %s ", roundOfGame); + println(" "); + println(" Bet Status: %s ", betStatus); + println(" "); + println(" Chips in Pot: %s ", pot); + println(" "); + println(" You rolled a %s ", sumOfDice); + println(" --------------- "); + println(" You Lose... "); + println(" "); + println(" Play again? "); + println(" 1: Yes 2: No "); + println(" "); + } + +// public void rollAgainScreen(int roundOfGame, int pot, int sumOfDice, String betStatus, int pointer) { +// println(" "); +// println(" ROUND: %s ", roundOfGame); +// println(" "); +// println(" Bet Status: %s ", betStatus); +// println(" "); +// println(" Chips in Pot: %s ", pot); +// println(" "); +// println(" You rolled a %s ", sumOfDice); +// println(" "); +// println(" Pointer: %s ", pointer); +// println(" --------------- "); +// println(" Roll again! "); +// println(" "); +// println(" How are you betting? "); +// println(" ------------------------- "); +// println(" "); +// } + + public void rollAgainBetScreen(int roundOfGame, int pot, int sumOfDice, String betStatus, int pointer) { + println(" "); + println(" ROUND: %s ", roundOfGame); + println(" "); + println(" Bet Status: %s ", betStatus); + println(" "); + println(" Chips in Pot: %s ", pot); + println(" "); + println(" You rolled a %s ", sumOfDice); + println(" "); + println(" Pointer: %s ", pointer); + println(" --------------- "); + println(" How much are you betting? "); + println(" ------------------------- "); + println(" "); + + } + + + //ENDING SCREENS + public void playAgainScreen() { + println(" "); + println(" Play Again? "); + println(" ----------- "); + println(" 1: Yes 2: No "); + println(" "); + } + + public void leaveCrapsScreen() { + println(" "); + println(" Good Luck! "); + println(" "); + println(" 0: Return to lobby "); + } + + public void getMoreChips() { + println(" "); + println(" Insufficient Chips "); + println(" "); + println(" Please go get more "); + println(" "); + println(" 0: Return to lobby "); + println(" 1: Enter different bet "); + } +} + + diff --git a/src/main/java/io/zipcoder/casino/Screens/DisplayMainCasinoScreens.java b/src/main/java/io/zipcoder/casino/Screens/DisplayMainCasinoScreens.java new file mode 100644 index 000000000..858d58046 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Screens/DisplayMainCasinoScreens.java @@ -0,0 +1,154 @@ +package io.zipcoder.casino.Screens; + +public class DisplayMainCasinoScreens extends Displays{ + + //MAIN SCREEN + public void welcomeScreen() { + println(" "); + println(" $$ $$ "); + println(" $$$$$$$$$$$$$ "); + println(" $$$$$$$$$$$$$$$ "); + println(" $$$ $$ $$ $$$$ "); + println(" $$$ $$ $$ $$$ "); + println(" $$$ $$ $$ "); + println(" $$$$ $$ $$ "); + println(" $$$$$$$$$$$$$ "); + println(" $$$$$$$$$$$$$ "); + println(" $$ $$ $$$$ "); + println(" $$ $$ $$$ "); + println(" $$$ $$ $$ $$$ "); + println(" $$$$ $$ $$ $$$$ "); + println(" $$$$$$$$$$$$$$$ "); + println(" $$$$$$$$$$$$ "); + println(" $$ $$ "); + println(" "); + println(" Welcome to The ZCW Casino!!! "); + println("------------------------------"); + println(" 00: Enter Casino "); + println(" 99: Leave Casino "); + println(" "); + } + + public void invalidEntryWelcomeScreen() { + println(" "); + println(" Invalid Entry. Try again "); + println("------------------------------"); + println(" 00: Enter Casino "); + println(" 99: Leave Casino "); + println(" "); + } + + public void goodbyeCasinoScreen() { + println(" "); + println(" Have a wonderful day! "); + println(" Come again soon! "); + println(" "); + } + + //CASINO LOBBY + public void casinoLobbyScreen() { + println(" "); + println(" May the odds be "); + println(" ever in your favor! "); + println("------------------------------"); + println(" 1: Teller Window "); + println(" 2: *GoFish Room "); + println(" 3: BlackJack Room "); + println(" 4: Craps Room "); + println(" 5: MOAK Room "); + println(" 00: Leave "); + println(" "); + println(" *Don't need chips to play "); + println(" "); + } + + public void casinoLobbyInvalidScreen() { + println(" "); + println(" Invalid input "); + println(" "); + println("------------------------------"); + println(" 1: Teller Window "); + println(" 2: *GoFish Room "); + println(" 3: BlackJack Room "); + println(" 4: Craps Room "); + println(" 5: Poker Dice Room "); + println(" 00: Leave "); + println(" "); + println(" *Don't need chips to play "); + println(" "); + } + + //TELLER + public void tellerMainScreen() { + println(" "); + println(" How may I help you? "); + println(" ------------------- "); + println(" 1: Exchange money "); + println(" 2: Cash Out "); + println(" "); + } + + public void tellerInvalidMainScreen() { + println(" "); + println(" I don't understand... "); + println(" Please choose an option "); + println(" from the menu below "); + println(" ------------------- "); + println(" 1: Exchange money "); + println(" 2: Cash Out "); + println(" "); + } + + public void tellerMoneyToChipsScreen(int currentChips, int currentWallet) { + println(" "); + println(" Your wallet: %s ", currentWallet); + println(" Your chips: %s ", currentChips); + println(" "); + println(" How much money would "); + println(" you like to exchange? "); + println(" --------------------- "); + println(" $1 = 1 Chip "); + println(" "); + } + + public void tellerChipsToMoneyScreen(int numOfPlayerChips) { + println(" "); + println(" You cashed out: "); + println(" $%s ",numOfPlayerChips); + println(" --------------------- "); + println(" 1: Another transaction "); + println(" 2: Exit "); + } + + public void howManyChipsScreen (int cashIn) { + println(" "); + println(" Your new chip balance: "); + println(" %s ", cashIn); + println(" "); + println(" 00: Casino Lobby "); + println(" "); + } + + public void loginOrCreateNew() { + println(" "); + println(" 1: Login "); + println(" "); + println(" 2: Create User "); + println(" "); + } + + public void enterUserID() { + println(" "); + println(" Enter ID number "); + println(" "); + } + + public void accountMade(int playerId) { + println(" Thanks for joining! "); + println(" Your ID number is: "); + println(" "); + println(" %s ", playerId); + println(" "); + println(" 00: Enter Casino "); + } +} diff --git a/src/main/java/io/zipcoder/casino/Screens/Displays.java b/src/main/java/io/zipcoder/casino/Screens/Displays.java new file mode 100644 index 000000000..55ce6b96f --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Screens/Displays.java @@ -0,0 +1,13 @@ +package io.zipcoder.casino.Screens; + +public class Displays { + + public static void print(String output, Object... args) { + System.out.printf(output, args); + } + + public static void println(String output, Object... args) { + print(output + "\n", args); + } + +} diff --git a/src/main/java/io/zipcoder/casino/Screens/MostOfAKindScreens.java b/src/main/java/io/zipcoder/casino/Screens/MostOfAKindScreens.java new file mode 100644 index 000000000..deff2a8b1 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Screens/MostOfAKindScreens.java @@ -0,0 +1,144 @@ +package io.zipcoder.casino.Screens; + +import java.util.ArrayList; + +public class MostOfAKindScreens extends Displays{ + //WELCOME + public void welcomeMoakScreen() { + println(" "); + println(" Welcome to the MOAK Room! "); + println(" ------------------------- "); + println(" Would you like to play? "); + println(" "); + println(" 1: Yes 2: No "); + println(" "); + } + + public void welcomeInvalidMoakScreen() { + println(" "); + println(" Invalid Input "); + println(" ------------------------- "); + println(" Would you like to play? "); + println(" "); + println(" 1: Yes 2: No "); + println(" "); + } + + public void anteUpScreen() { + println(" "); + println(" Time to ante up! "); + println(" "); + println(" 1: Pays and rolls "); + println(" "); + } + + //FIRST ROLL + public void firstRollScreen(int pot, ArrayList playerDice) { + println(" "); + println(" Current pot: %s ", pot); + println(" "); + println(" Your Dice: "); + println("%s ", playerDice); + println(" "); + println("How much do you want to bet? "); + println(" "); + } + + public void numberToKeepScreen(int pot, ArrayList playerDice) { + println(" "); + println(" Current pot: %s ", pot); + println(" "); + println(" Your Dice: "); + println("%s ", playerDice); + println(" "); + println("Which number do you want to keep?"); + println(" "); + println(" 0: Roll all dice again "); + println(" "); + } + + //SECOND ROLL + public void secondRollScreen(int pot, ArrayList playerDice) { + println(" "); + println(" Current pot: %s ", pot); + println(" "); + println(" Your Dice: "); + println("%s ", playerDice); + println(" "); + println("How much do you want to bet? "); + println(" "); + } + + //FINAL STEP + public void revealHandsPlayerWins(int pot, ArrayList playerDice, ArrayList dealerDice) { + println(" "); + println(" Current pot: %s ", pot); + println(" "); + println(" Your Dice: "); + println("%s ", playerDice); + println(" "); + println(" Dealer's Dice: "); + println("%s ", dealerDice); + println(" "); + println(" YOU WIN! "); + println(" "); + println(" Do you want to play again? "); + println(" "); + println(" 1: Yes 2: No "); + println(" "); + } + + public void revealHandsDealerWins(int pot, ArrayList playerDice, ArrayList dealerDice) { + println(" "); + println(" Current pot: %s ", pot); + println(" "); + println(" Your Dice: "); + println("%s ", playerDice); + println(" "); + println(" Dealer's Dice: "); + println("%s ", dealerDice); + println(" "); + println(" House wins "); + println(" "); + println(" Do you want to play again? "); + println(" "); + println(" 1: Yes 2: No "); + println(" "); + } + + + //PLAY AGAIN + public void playAgainScreen() { + println(" "); + println(" Do you want to play again? "); + println(" "); + println(" Y or N "); + println(" "); + } + + public void goodbyeScreen() { + println(" "); + println(" Good Luck! "); + println(" "); + println(" 0: Return to lobby "); + println(" "); + } + + + public void needMoreChipsScreen() { + println(" "); + println(" You need more chips "); + println(" "); + println(" 0: Go back to lobby "); + println(" "); + } + + public void getMoreChips() { + println(" "); + println(" Insufficient Chips "); + println(" "); + println(" 0: Go back to lobby "); + println(" 1: Enter different bet "); + println(" "); + } +} diff --git a/src/test/java/io/zipcoder/casino/BlackJackTest.java b/src/test/java/io/zipcoder/casino/BlackJackTest.java new file mode 100644 index 000000000..6640300dd --- /dev/null +++ b/src/test/java/io/zipcoder/casino/BlackJackTest.java @@ -0,0 +1,699 @@ +package io.zipcoder.casino; + +import io.zipcoder.casino.CardGames.BlackJack; +import io.zipcoder.casino.CardGames.Card; +import io.zipcoder.casino.Player.Player; +import io.zipcoder.casino.Player.PlayerFactory; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class BlackJackTest { + Player gerg = PlayerFactory.createPlayer("gerg", 5000); + BlackJack bj = new BlackJack(gerg); + + + @Test + public void addToPotTest() { + //Given: + gerg.setChipBalance(3000); + + //When: + int expected = 500; + bj.addToPot(expected); + int actual = bj.sizeOfPot; + + //Then: + assertEquals(expected, actual); + } + + @Test + public void addToPotPlayerBalanceTest() { + //Given: + gerg.setChipBalance(3000); + + //When: + bj.addToPot(500); + int expected = 2500; + int actual = gerg.getChipBalance(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void playerWinPotTest() { + //Given: + gerg.setChipBalance(3000); + + //When: + bj.addToPot(500); + bj.passPot(2); + int expected = 3500; + int actual = gerg.getChipBalance(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void playerWinPotBalanceTest() { + //Given: + gerg.setChipBalance(3000); + + //When: + bj.addToPot(500); + bj.passPot(2); + int expected = 0; + int actual = bj.sizeOfPot; + + //Then: + assertEquals(expected, actual); + } + + @Test + public void playerBlackJackTest() { + //Given: + gerg.setChipBalance(3000); + + //When: + bj.addToPot(500); + bj.passPot(3); + int expected = 4000; + int actual = gerg.getChipBalance(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void playGamePlayerHandTest() { + //Given: + bj.playGame(); + + //When: + int expected = 2; + int actual = bj.playerHand.size(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void playGameDealerHandTest() { + //Given: + bj.playGame(); + + //When: + int expected = 2; + int actual = bj.dealerHand.size(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void playGamePlayerHandValueTest() { + //Given: + bj.playGame(); + + //When: + int actual = bj.playerTotal; + + //Then: + assertTrue(actual > 0); + } + + @Test + public void playGameDealerHandValueTest() { + //Given: + bj.playGame(); + + //When: + int actual = bj.dealerTotal; + + //Then: + assertTrue(actual > 0); + } + + @Test + public void checkWinnerPlayerWinTest() { + //Given: + bj.playerTotal = 18; + bj.dealerTotal = 17; + + //When: + String expected = "Player"; + String actual = bj.checkWinner(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void checkWinnerPlayerBustTest() { + //Given: + bj.playerTotal = 25; + bj.dealerTotal = 17; + + //When: + String expected = "Dealer"; + String actual = bj.checkWinner(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void checkWinnerDealerWinsTest() { + //Given: + bj.playerTotal = 19; + bj.dealerTotal = 20; + + //When: + String expected = "Dealer"; + String actual = bj.checkWinner(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void checkWinnerDealerBustTest() { + //Given: + bj.playerTotal = 16; + bj.dealerTotal = 23; + + //When: + String expected = "Player"; + String actual = bj.checkWinner(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void checkWinnerPlayerBlackJackTest() { + //Given: + bj.playerTotal = 21; + bj.dealerTotal = 21; + + //When: + String expected = "Tie"; + String actual = bj.checkWinner(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void hitMePlayerTest() { + //Given: + bj.playGame(); + + //When: + bj.hitMe(); + bj.hitMe(); + int expected = 4; + int actual = bj.playerHand.size(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void hitMeDealerAndHoldTest() { + //Given: + bj.playGame(); + + //When: + bj.hitMe(); + bj.hold(); + bj.hitMe(); + int expected = 3; + int actual = bj.dealerHand.size(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void playerHandSplitTest() { + //Given: + Card AceOfHearts=new Card("A", "Hearts", 11); + Card AceOfDiamonds=new Card("A", "Diamonds", 11); + bj.makeDeck(); + bj.shuffleDeck(); + bj.playerHand.add(AceOfDiamonds); + bj.playerHand.add(AceOfHearts); + + //When: + bj.playerHandSplit(); + int expected = 2; + int actual = bj.playerHand.size(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void playerHandSplitPlayerValueTest() { + //Given: + Card AceOfHearts=new Card("A", "Hearts", 11); + Card AceOfDiamonds=new Card("A", "Diamonds", 11); + bj.makeDeck(); + bj.shuffleDeck(); + bj.playerHand.add(AceOfDiamonds); + bj.playerTotal += 11; + bj.playerHand.add(AceOfHearts); + bj.playerTotal += 11; + + //When: + bj.playerHandSplit(); + int actual = bj.playerTotal; + + //Then: + assertTrue(actual > 11); + } + + @Test + public void playerHandSplitSecondHandTest() { + //Given: + Card AceOfHearts=new Card("A", "Hearts", 11); + Card AceOfDiamonds=new Card("A", "Diamonds", 11); + bj.makeDeck(); + bj.shuffleDeck(); + bj.playerHand.add(AceOfDiamonds); + bj.playerHand.add(AceOfHearts); + + //When: + bj.playerHandSplit(); + int expected = 2; + int actual = bj.playerSplitHand.size(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void playerHandSplitPlayerSplitValueTest() { + //Given: + Card AceOfHearts=new Card("A", "Hearts", 11); + Card AceOfDiamonds=new Card("A", "Diamonds", 11); + bj.makeDeck(); + bj.shuffleDeck(); + bj.playerHand.add(AceOfDiamonds); + bj.playerTotal += 11; + bj.playerHand.add(AceOfHearts); + bj.playerTotal += 11; + + //When: + bj.playerHandSplit(); + int actual = bj.playerSplitTotal; + + //Then: + assertTrue(actual > 11); + } + + @Test + public void playerHandSplitHitMeTest() { + //Given: + Card AceOfHearts=new Card("A", "Hearts", 11); + Card AceOfDiamonds=new Card("A", "Diamonds", 11); + bj.makeDeck(); + bj.shuffleDeck(); + bj.playerHand.add(AceOfDiamonds); + bj.playerTotal += 11; + bj.playerHand.add(AceOfHearts); + bj.playerTotal += 11; + + //When: + bj.playerHandSplit(); + bj.hitMe(); + bj.hitMe(); + int actual = bj.playerHand.size(); + + //Then: + assertTrue(actual == 4); + } + + @Test + public void playerHandSplitHitMeOnSplitHandTest() { + //Given: + Card AceOfHearts=new Card("A", "Hearts", 11); + Card AceOfDiamonds=new Card("A", "Diamonds", 11); + bj.makeDeck(); + bj.shuffleDeck(); + bj.playerHand.add(AceOfDiamonds); + bj.playerTotal += 11; + bj.playerHand.add(AceOfHearts); + bj.playerTotal += 11; + + //When: + bj.playerHandSplit(); + bj.hitMe(); + bj.hold(); + bj.hitMe(); + bj.hitMe(); + bj.hitMe(); + int actual = bj.playerSplitHand.size(); + + //Then: + assertTrue(actual == 5); + } + + @Test + public void playerHandSplitSizeOfPotTest() { + //Given: + Card AceOfHearts=new Card("A", "Hearts", 11); + Card AceOfDiamonds=new Card("A", "Diamonds", 11); + bj.makeDeck(); + bj.shuffleDeck(); + bj.playerHand.add(AceOfDiamonds); + bj.playerTotal += 11; + bj.playerHand.add(AceOfHearts); + bj.playerTotal += 11; + bj.sizeOfPot = 50; + + //When: + bj.playerHandSplit(); + int actual = bj.sizeOfPot; + + //Then: + assertTrue(actual == 100); + } + + @Test + public void playerHandSplitPlayerChipTest() { + //Given: + Card AceOfHearts=new Card("A", "Hearts", 11); + Card AceOfDiamonds=new Card("A", "Diamonds", 11); + bj.makeDeck(); + bj.shuffleDeck(); + bj.playerHand.add(AceOfDiamonds); + bj.playerTotal += 11; + bj.playerHand.add(AceOfHearts); + bj.playerTotal += 11; + bj.sizeOfPot = 50; + gerg.setChipBalance(5000); + + //When: + bj.playerHandSplit(); + int actual = gerg.getChipBalance(); + + //Then: + assertTrue(actual == 4950); + } + + @Test + public void checkSplitWinnerTrueTest() { + //Given: + bj.playerSplitTotal = 21; + bj.dealerTotal = 20; + + //When: + String expected = "Player"; + String actual = bj.checkWinner(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void checkSplitWinnerFalseTest() { + //Given: + bj.playerSplitTotal = 18; + bj.dealerTotal = 19; + + //When: + String expected = "Dealer"; + String actual = bj.checkWinner(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void checkSplitWinnerTieTest() { + //Given: + bj.playerSplitTotal = 17; + bj.dealerTotal = 17; + + //When: + String expected = "Tie"; + String actual = bj.checkWinner(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void playerHaveBlackJackTrueTest() { + //Given: + Card AceOfSpades=new Card("A", "Spades", 11); + Card TenOfSpades=new Card("10", "Spades", 10); + Card EightOfSpades=new Card("8", "Spades", 8); + bj.playerHand.add(AceOfSpades); + bj.playerHand.add(TenOfSpades); + bj.playerTotal = 21; + bj.dealerTotal = 20; + + //When: + String expected = "Player"; + String actual = bj.blackJackCheck(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void playerHaveBlackJackFalseTest() { + //Given: + Card AceOfSpades=new Card("A", "Spades", 11); + Card TenOfSpades=new Card("10", "Spades", 10); + Card EightOfSpades=new Card("8", "Spades", 8); + bj.playerHand.add(EightOfSpades); + bj.playerHand.add(TenOfSpades); + bj.playerHand.add(AceOfSpades); + bj.playerTotal = 21; + bj.dealerTotal = 20; + + //When: + String expected = "None"; + String actual = bj.blackJackCheck(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void playerSplitHandHaveBlackJackTrueTest() { + //Given: + Card AceOfSpades=new Card("A", "Spades", 11); + Card TenOfSpades=new Card("10", "Spades", 10); + Card EightOfSpades=new Card("8", "Spades", 8); + bj.playerSplitHand.add(TenOfSpades); + bj.playerSplitHand.add(AceOfSpades); + bj.playerSplitTotal = 21; + bj.dealerTotal = 18; + + //When: + String expected = "Player"; + String actual = bj.blackJackCheck(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void playerSplitHandHaveBlackJackFalseTest() { + //Given: + Card AceOfSpades=new Card("A", "Spades", 11); + Card TenOfSpades=new Card("10", "Spades", 10); + Card EightOfSpades=new Card("8", "Spades", 8); + bj.playerSplitHand.add(EightOfSpades); + bj.playerSplitHand.add(TenOfSpades); + bj.playerSplitTotal = 16; + bj.dealerTotal = 18; + + //When: + String expected = "None"; + String actual = bj.blackJackCheck(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void dealerHaveBlackJackTrueTest() { + //Given: + Card AceOfSpades=new Card("A", "Spades", 11); + Card TenOfSpades=new Card("10", "Spades", 10); + bj.dealerHand.add(AceOfSpades); + bj.dealerHand.add(TenOfSpades); + bj.playerTotal = 20; + bj.dealerTotal = 21; + + //When: + boolean expected = true; + boolean actual = bj.dealerHaveBlackJack(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void dealerHaveBlackJackFalseTest() { + //Given: + bj.playerTotal = 20; + bj.dealerTotal = 18; + + //When: + boolean expected = false; + boolean actual = bj.dealerHaveBlackJack(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void playerBustTrueTest() { + //Given: + bj.playerTotal = 23; + bj.dealerTotal = 18; + + //When: + boolean expected = true; + boolean actual = bj.playerBust(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void playerBustFalseTest() { + //Given: + bj.playerTotal = 20; + bj.dealerTotal = 19; + + //When: + boolean expected = false; + boolean actual = bj.playerBust(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void playerSplitHandBustTrueTest() { + //Given: + bj.playerSplitTotal = 24; + bj.dealerTotal = 19; + + //When: + boolean expected = true; + boolean actual = bj.playerSplitHandBust(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void playerSplitHandBustFalseTest() { + //Given: + bj.playerSplitTotal = 15; + bj.dealerTotal = 19; + + //When: + boolean expected = false; + boolean actual = bj.playerSplitHandBust(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void dealerBustTrueTest() { + //Given: + bj.playerSplitTotal = 20; + bj.dealerTotal = 26; + + //When: + boolean expected = true; + boolean actual = bj.dealerBust(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void dealerBustFalseTest() { + //Given: + bj.playerSplitTotal = 20; + bj.dealerTotal = 13; + + //When: + boolean expected = false; + boolean actual = bj.dealerBust(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void tiePotTest() { + //Given: + gerg.setChipBalance(3000); + + //When: + bj.addToPot(500); + bj.passPot(1); + int expected = 3000; + int actual = gerg.getChipBalance(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void checkWinnerTieTest() { + //Given: + bj.playerTotal = 17; + bj.dealerTotal = 17; + + //When: + String expected = "Tie"; + String actual = bj.checkWinner(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void checkGetPot() { + //Given: + bj.sizeOfPot = 500; + + //When: + int expected = 500; + int actual = bj.getPot(); + + //Then: + assertEquals(expected, actual); + } + + @Test + public void checkSplitWinnerDealerTest() { + //Given: + bj.playerTotal = 26; + bj.playerSplitTotal = 19; + bj.dealerTotal = 20; + + //When: + String expected = "Dealer"; + String actual = bj.checkWinner(); + + //Then: + assertEquals(expected, actual); + } +} \ No newline at end of file diff --git a/src/test/java/io/zipcoder/casino/CardTest.java b/src/test/java/io/zipcoder/casino/CardTest.java new file mode 100644 index 000000000..f26ab3cf5 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/CardTest.java @@ -0,0 +1,47 @@ +package io.zipcoder.casino; + +import io.zipcoder.casino.CardGames.Card; +import org.junit.Assert; +import org.junit.Test; + +public class CardTest { + + @Test + public void constructorTest(){ + Card joker= new Card("3", "Hearts", 3); + Assert.assertTrue(joker instanceof Card); + } + + @Test + public void getCardNameTest(){ + Card joker= new Card("3", "Hearts", 3); + String expected = "3"; + String actual = joker.getCardName(); + Assert.assertEquals(expected,actual); + } + + @Test + public void getCardSuitTest(){ + Card joker= new Card("3", "Hearts", 3); + String expected = "Hearts"; + String actual = joker.getCardSuit(); + Assert.assertEquals(expected,actual); + } + + @Test + public void getCardValueTest(){ + Card joker= new Card("3", "Hearts", 3); + Integer expected = 3; + Integer actual = joker.getValue(); + Assert.assertEquals(expected,actual); + } + + @Test + public void setCardValueTest(){ + Card joker= new Card("3", "Hearts", 3); + Integer expected = 7; + joker.setValue(7); + Integer actual = joker.getValue(); + Assert.assertEquals(expected,actual); + } +} 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..440ba662a --- /dev/null +++ b/src/test/java/io/zipcoder/casino/CrapsTest.java @@ -0,0 +1,337 @@ +package io.zipcoder.casino; + +import io.zipcoder.casino.DiceGames.Craps; +import io.zipcoder.casino.Player.Player; +import io.zipcoder.casino.Player.PlayerFactory; +import org.junit.Assert; +import org.junit.Test; + + +public class CrapsTest { + Player gerg = PlayerFactory.createPlayer("gerg", 500); + Craps craps = new Craps(gerg); + + //SuperClass tests + @Test + public void getPot() { + //Given + int expected = 0; + + //When + int actual = craps.getPot(); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void addToPot() { + //Given + int expected = 5; + + //When + craps.addToPot(5); + int actual = craps.getPot(); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void playerBalanceAfterBet() { + //Given + gerg.setChipBalance(50); + int expected = 40; + + //When + craps.addToPot(10); + int actual = gerg.getChipBalance(); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void clearPot() { + //Given + int expected = 0; + craps.addToPot(7); + craps.clearPot(); + + //When + int actual = craps.getPot(); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void rollDice() { + //Given + + //When + int result = craps.rollDice(); + + //Then + Assert.assertTrue(result > 0 && result < 7); + } + + + //Unique to Craps + @Test + public void setGameRound() { + //Given + int expected = 1; + + //When + craps.setGameRound(1); + int actual = craps.getGameRound(); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void setGetPointer() { + //Given + int expected = 8; + + //When + craps.setPointer(8); + int actual = craps.getPointer(); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void setGetBetStatus() { + //Given + String expected = "PASS"; + + //When + craps.setBetStatus("Pass"); + String actual = craps.getBetStatus(); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void betStatusTwo() { + //Given + String expected = "NOT PASS"; + + //When + craps.setBetStatus("NoT paSS"); + String actual = craps.getBetStatus(); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void sumOfDice() { + //Given + + //When + craps.sumOfDice(); + int actual = craps.currentSum; + + + //Then + Assert.assertTrue(actual > 1 && actual < 13); + } + + @Test + public void getCurrentSum() { + //Given + craps.currentSum = 10; + int expected = 10; + + //When + int actual = craps.getCurrentSum(); + + //Then + Assert.assertEquals(expected, actual); + } + + //Round One Pass Outcomes + @Test + public void playerWinsRoundOnePass() { + //Given + int expected = 1; + craps.setBetStatus("Pass"); + + //When + int dieSum = 7; + int actual = craps.checkWinnerRoundOne(dieSum); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void playerLosesRoundOnePass() { + //Given + int expected = 2; + craps.setBetStatus("Pass"); + + //When + int dieSum = 2; + int actual = craps.checkWinnerRoundOne(dieSum); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void playerRollsAgainPass() { + //Given + int expected = 3; + craps.setBetStatus("Pass"); + + //When + int dieSum = 4; + int actual = craps.checkWinnerRoundOne(dieSum); + + //Then + Assert.assertEquals(expected, actual); + } + + //Round One Not Pass Outcomes + @Test + public void playerWinsRoundOneNotPass() { + //Given + int expected = 1; + craps.setBetStatus("Not Pass"); + + //When + int dieSum = 2; + int actual = craps.checkWinnerRoundOne(dieSum); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void playerLosesRoundOneNotPass() { + //Given + int expected = 2; + craps.setBetStatus("Not Pass"); + + //When + int dieSum = 7; + int actual = craps.checkWinnerRoundOne(dieSum); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void playerRollsAgainRoundOneNotPass() { + //Given + int expected = 3; + craps.setBetStatus("Not Pass"); + + //When + int dieSum = 9; + int actual = craps.checkWinnerRoundOne(dieSum); + + //Then + Assert.assertEquals(expected, actual); + } + + //Round Two Pass Outcomes + @Test + public void playerWinsRoundTwoPass() { + //Given + int expected = 1; + craps.setBetStatus("Pass"); + craps.setPointer(10); + + //When + int dieSum = 10; + int actual = craps.checkWinnerRoundTwo(dieSum); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void playerLosesRoundTwoPass() { + //Given + int expected = 2; + craps.setBetStatus("Pass"); + craps.setPointer(10); + + //When + int dieSum = 7; + int actual = craps.checkWinnerRoundTwo(dieSum); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void playerRollsAgainRoundTwoPass() { + //Given + int expected = 3; + craps.setBetStatus("Pass"); + craps.setPointer(10); + + //When + int dieSum = 4; + int actual = craps.checkWinnerRoundTwo(dieSum); + + //Then + Assert.assertEquals(expected, actual); + } + + //Round Two Not Pass Outcomes + @Test + public void playerWinsRoundTwoNotPass() { + //Given + int expected = 1; + craps.setBetStatus("Not Pass"); + craps.setPointer(10); + + //When + int dieSum = 7; + int actual = craps.checkWinnerRoundTwo(dieSum); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void playerLosesRoundTwoNotPass() { + //Given + int expected = 2; + craps.setBetStatus("Not Pass"); + craps.setPointer(10); + + //When + int dieSum = 10; + int actual = craps.checkWinnerRoundTwo(dieSum); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void playerRollsAgainRoundTwoNotPass() { + //Given + int expected = 3; + craps.setBetStatus("Not Pass"); + craps.setPointer(10); + + //When + int dieSum = 11; + int actual = craps.checkWinnerRoundTwo(dieSum); + + //Then + Assert.assertEquals(expected, actual); + } + +} diff --git a/src/test/java/io/zipcoder/casino/GoFishTest.java b/src/test/java/io/zipcoder/casino/GoFishTest.java new file mode 100644 index 000000000..e77b433eb --- /dev/null +++ b/src/test/java/io/zipcoder/casino/GoFishTest.java @@ -0,0 +1,261 @@ +package io.zipcoder.casino; + + +import io.zipcoder.casino.CardGames.Card; +import io.zipcoder.casino.CardGames.GoFish; +import org.junit.Assert; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; + +public class GoFishTest { + + + @Test + public void constructorGameTest(){ + GoFish friendlyGame = new GoFish(); + Assert.assertTrue(friendlyGame instanceof GoFish); + } + + @Test + public void playerHandTest(){ + GoFish friendlyGame=new GoFish(); + friendlyGame.makeDeck(); + ArrayList oswald= new ArrayList<>(); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + Integer actual=friendlyGame.cardsInHand(oswald); + Integer expected = 4; + Assert.assertEquals(actual,expected); + } + + @Test + public void twoHandsTest(){ + GoFish friendlyGame=new GoFish(); + friendlyGame.makeDeck(); + ArrayList oswald= new ArrayList<>(); + ArrayList dealer= new ArrayList<>(); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(dealer); + friendlyGame.dealCards(dealer); + Integer actual=friendlyGame.cardsInHand(dealer); + Integer expected = 2; + Assert.assertEquals(actual,expected); + } + + @Test + public void testShowCard(){ + GoFish friendlyGame=new GoFish(); + ArrayList oswald= new ArrayList<>(); + friendlyGame.makeDeck(); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + String actual=friendlyGame.showCard(oswald, 3); + String expected="4 of Spades"; + Assert.assertEquals(actual,expected); + } + + @Test + public void testSeeHand(){ + GoFish friendlyGame=new GoFish(); + ArrayList oswald= new ArrayList<>(); + friendlyGame.makeDeck(); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + String actual=friendlyGame.seeHand(oswald); + String expected="Your hand is:\nA of Spades\n2 of Spades\n3 of Spades\n4 of Spades\n"; + Assert.assertEquals(actual,expected); + } + + @Test + public void testGotAnyKings1(){ + GoFish friendlyGame=new GoFish(); + friendlyGame.makeDeck(); + ArrayList oswald= new ArrayList<>(); + ArrayList dealer= new ArrayList<>(); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(dealer); + Assert.assertTrue(friendlyGame.gotAnyKings(oswald, "A")); + + } + + @Test + public void testTakeCards(){ + GoFish friendlyGame=new GoFish(); + friendlyGame.makeDeck(); + ArrayList oswald= new ArrayList<>(); + ArrayList dealer= new ArrayList<>(); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(dealer); + friendlyGame.dealCards(dealer); + friendlyGame.dealCards(dealer); + friendlyGame.dealCards(dealer); + friendlyGame.dealCards(dealer); + friendlyGame.dealCards(dealer); + friendlyGame.dealCards(dealer); + friendlyGame.dealCards(dealer); + friendlyGame.dealCards(dealer); + friendlyGame.dealCards(dealer); + + friendlyGame.takeCards(oswald,dealer,"2"); + + Integer actual=friendlyGame.cardsInHand(dealer); + Integer expected = 9; + Assert.assertEquals(actual,expected); + } + + @Test + public void testTakeCards2(){ + GoFish friendlyGame=new GoFish(); + friendlyGame.makeDeck(); + ArrayList oswald= new ArrayList<>(); + ArrayList dealer= new ArrayList<>(); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(dealer); + friendlyGame.dealCards(dealer); + friendlyGame.dealCards(dealer); + friendlyGame.dealCards(dealer); + friendlyGame.dealCards(dealer); + friendlyGame.dealCards(dealer); + friendlyGame.dealCards(dealer); + friendlyGame.dealCards(dealer); + friendlyGame.dealCards(dealer); + friendlyGame.dealCards(dealer); + + friendlyGame.takeCards(oswald,dealer,"4"); + + Integer actual=friendlyGame.cardsInHand(oswald); + Integer expected = 11; + Assert.assertEquals(actual,expected); + } + + @Test + public void testDrawAnyKings(){ + GoFish friendlyGame=new GoFish(); + ArrayList oswald= new ArrayList<>(); + friendlyGame.makeDeck(); + friendlyGame.dealCards(oswald); + Assert.assertTrue(friendlyGame.drawAnyKings(oswald, "A")); + } + + @Test + public void testDrawAnyKings2(){ + GoFish friendlyGame=new GoFish(); + ArrayList oswald= new ArrayList<>(); + friendlyGame.makeDeck(); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + Assert.assertFalse(friendlyGame.drawAnyKings(oswald, "A")); + } + + @Test + public void testDrawAnyKings3(){ + GoFish friendlyGame=new GoFish(); + ArrayList oswald= new ArrayList<>(); + friendlyGame.makeDeck(); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + Assert.assertTrue(friendlyGame.drawAnyKings(oswald, "2")); + } + + @Test + public void testBookClose(){ + GoFish friendlyGame=new GoFish(); + ArrayList oswald= new ArrayList<>(); + friendlyGame.makeDeck(); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + //A + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + //2 + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + //3 + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + //4 + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + //5 + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + //6 + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + //7 + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + //8 + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + //9 + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + //10 + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + //J + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + //Q + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + friendlyGame.dealCards(oswald); + //K + + Assert.assertTrue(friendlyGame.completeSet(oswald, "K")); + } +} diff --git a/src/test/java/io/zipcoder/casino/MostOfAKindTests.java b/src/test/java/io/zipcoder/casino/MostOfAKindTests.java new file mode 100644 index 000000000..1fb785d86 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/MostOfAKindTests.java @@ -0,0 +1,412 @@ +package io.zipcoder.casino; + +import io.zipcoder.casino.DiceGames.MostOfAKindGame; +import io.zipcoder.casino.Player.Player; +import io.zipcoder.casino.Player.PlayerFactory; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; + +public class MostOfAKindTests { + Player gerg = PlayerFactory.createPlayer("gerg", 500); + MostOfAKindGame yahtzee = new MostOfAKindGame(gerg); + + @Test + public void getPot() { + //Given + int expected = 0; + + //When + int actual = yahtzee.getPot(); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void getPotTwo() { + //Given + yahtzee.addToPot(10); + int expected = 10; + + //When + int actual = yahtzee.getPot(); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void addToPot() { + //Given + int expected = 5; + + //When + yahtzee.addToPot(5); + int actual = yahtzee.getPot(); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void clearPot() { + //Given + int expected = 0; + yahtzee.addToPot(7); + yahtzee.clearPot(); + + //When + int actual = yahtzee.getPot(); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void rollDice() { + //Given + + //When + int result = yahtzee.rollDice(); + + //Then + Assert.assertTrue(result > 0 && result < 7); + } + + @Test + public void addToPlayerCount() { + //Given + yahtzee.addToPlayerCount(3); + int expected = 3; + + //When + int actual = yahtzee.getPlayerCount(); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void checkWinnerDealer() { + //Given + yahtzee.addToPlayerCount(3); + yahtzee.addToDealerCount(4); + + //When + boolean actual = yahtzee.checkWinner(); + + //Then + Assert.assertFalse(actual); + } + + @Test + public void checkWinnerPlayer() { + //Given + yahtzee.addToPlayerCount(4); + yahtzee.addToDealerCount(2); + + //When + boolean actual = yahtzee.checkWinner(); + + //Then + Assert.assertTrue(actual); + } + + @Test + public void extensiveCheckWinner() { + ArrayList dealerHand = new ArrayList<>(); + dealerHand.add(5); + dealerHand.add(5); + dealerHand.add(5); + dealerHand.add(5); + dealerHand.add(5); + + ArrayList playerHand = new ArrayList<>(); + playerHand.add(6); + playerHand.add(6); + playerHand.add(6); + playerHand.add(6); + playerHand.add(6); + + //When + yahtzee.exchangePlayerDice(6); + yahtzee.exchangeDealerDice(5); + yahtzee.playerNumOfMatches(playerHand); + yahtzee.dealerNumOfMatches(dealerHand); + + boolean expected = true; + boolean actual = yahtzee.checkWinner(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void winnerBugTest() { + //Given + ArrayList dealerHand = new ArrayList<>(); + dealerHand.add(1); + dealerHand.add(1); + dealerHand.add(3); + dealerHand.add(1); + dealerHand.add(5); + + ArrayList playerHand = new ArrayList<>(); + playerHand.add(3); + playerHand.add(3); + playerHand.add(5); + playerHand.add(6); + playerHand.add(5); + + //When + yahtzee.playerNumOfMatches(playerHand); + yahtzee.dealerNumOfMatches(dealerHand); + boolean result = yahtzee.checkWinner(); + + + //Then + Assert.assertFalse(result); + } + + @Test + public void playerNumberOfMatches() { + //Given + ArrayList playerHand = new ArrayList<>(); + playerHand.add(3); + playerHand.add(3); + playerHand.add(5); + playerHand.add(6); + playerHand.add(5); + + //When + int expected = 2; + yahtzee.playerNumOfMatches(playerHand); + int actual = yahtzee.getPlayerCount(); + + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void dealerNumberOfMatches() { + //Given + ArrayList dealerHand = new ArrayList<>(); + dealerHand.add(1); + dealerHand.add(1); + dealerHand.add(3); + dealerHand.add(1); + dealerHand.add(5); + + //When + int expected = 3; + yahtzee.dealerNumOfMatches(dealerHand); + int actual = yahtzee.getDealerCount(); + + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void makeDealerHand() { + //Given + + //When + yahtzee.makeDealerHand(5); + int actual = yahtzee.getDealerHand().size(); + + //Then + Assert.assertEquals(5, actual); + } + + @Test + public void makePlayerHand() { + //Given + + //When + yahtzee.makePlayerHand(5); + int actual = yahtzee.getPlayerHand().size(); + + //Then + Assert.assertEquals(5, actual); + } + + @Test + public void playerSecondRoll() { + //Given + yahtzee.playerDiceHand.add(5); + yahtzee.playerDiceHand.add(4); + yahtzee.playerDiceHand.add(3); + yahtzee.playerDiceHand.add(5); + yahtzee.playerDiceHand.add(6); + ArrayList old = yahtzee.getPlayerHand(); + + //When + yahtzee.exchangePlayerDice(5); + ArrayList newHand = yahtzee.getPlayerHand(); + + //Then + Assert.assertNotEquals(old, newHand); + } + + @Test + public void dealerSecondRoll() { + yahtzee.dealerHand.add(2); + yahtzee.dealerHand.add(2); + yahtzee.dealerHand.add(1); + yahtzee.dealerHand.add(2); + yahtzee.dealerHand.add(5); + ArrayList oldHand = yahtzee.getDealerHand(); + + //When + yahtzee.exchangeDealerDice(2); + ArrayList newHand = yahtzee.getDealerHand(); + + //Then + Assert.assertNotEquals(oldHand, newHand); + } + + @Test + public void playerSecondRollIrrational() { + //Given + yahtzee.playerDiceHand.add(5); + yahtzee.playerDiceHand.add(4); + yahtzee.playerDiceHand.add(3); + yahtzee.playerDiceHand.add(5); + yahtzee.playerDiceHand.add(6); + ArrayList old = yahtzee.getPlayerHand(); + + //When + yahtzee.exchangePlayerDice(3); + ArrayList newHand = yahtzee.getPlayerHand(); + + //Then + Assert.assertNotEquals(old, newHand); + } + + @Test + public void dealerSecondRollIrrational() { + //Given + yahtzee.dealerHand.add(2); + yahtzee.dealerHand.add(2); + yahtzee.dealerHand.add(1); + yahtzee.dealerHand.add(2); + yahtzee.dealerHand.add(5); + ArrayList oldHand = yahtzee.getDealerHand(); + + //When + yahtzee.exchangeDealerDice(5); + ArrayList newHand = yahtzee.getDealerHand(); + + //Then + Assert.assertNotEquals(oldHand, newHand); + } + + @Test + public void setGetPlayerMatchingNum() { + //Given + yahtzee.setPlayerMatchingNum(5); + int expected = 5; + + //When + int actual = yahtzee.getPlayerMatchingNum(); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void setGetDealerMatchingNum() { + //Given + yahtzee.setDealerMatchingNum(2); + int expected = 2; + + //When + int actual = yahtzee.getDealerMatchingNum(); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void getPlayerNumOfMatches() { + //Given + yahtzee.playerDiceHand.add(5); + yahtzee.playerDiceHand.add(5); + yahtzee.playerDiceHand.add(5); + yahtzee.playerDiceHand.add(3); + yahtzee.playerDiceHand.add(6); + int expected = 3; + + //When + yahtzee.playerNumOfMatches(yahtzee.playerDiceHand); + int actual = yahtzee.getPlayerCount(); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void getDealerNumOfMatches() { + //Given + yahtzee.dealerHand.add(2); + yahtzee.dealerHand.add(2); + yahtzee.dealerHand.add(2); + yahtzee.dealerHand.add(2); + yahtzee.dealerHand.add(5); + int expected = 4; + + //When + yahtzee.dealerNumOfMatches(yahtzee.dealerHand); + int actual = yahtzee.getDealerCount(); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void dealerAI() { + //Given + ArrayList dealerHand = new ArrayList<>(); + dealerHand.add(5); + dealerHand.add(2); + dealerHand.add(5); + dealerHand.add(1); + dealerHand.add(5); + + //When + yahtzee.dealerAINumbersToKeep(dealerHand); + int expectedCount = 3; + int expectedMatch = 5; + int actualCount = yahtzee.getDealerCount(); + int actualMatch = yahtzee.getDealerMatchingNum(); + + //Then + Assert.assertEquals(expectedCount, actualCount); + Assert.assertEquals(expectedMatch, actualMatch); + } + + @Test + public void dealerAITwo() { + //Given + ArrayList dealerHand = new ArrayList<>(); + dealerHand.add(5); + dealerHand.add(5); + dealerHand.add(5); + dealerHand.add(1); + dealerHand.add(5); + + //When + yahtzee.dealerAINumbersToKeep(dealerHand); + int expectedCount = 4; + int expectedMatch = 5; + int actualCount = yahtzee.getDealerCount(); + int actualMatch = yahtzee.getDealerMatchingNum(); + + //Then + Assert.assertEquals(expectedCount, actualCount); + Assert.assertEquals(expectedMatch, actualMatch); + } +} diff --git a/src/test/java/io/zipcoder/casino/PlayerFactoryTest.java b/src/test/java/io/zipcoder/casino/PlayerFactoryTest.java new file mode 100644 index 000000000..d8ab1839d --- /dev/null +++ b/src/test/java/io/zipcoder/casino/PlayerFactoryTest.java @@ -0,0 +1,203 @@ +package io.zipcoder.casino; + +import io.zipcoder.casino.Player.Player; +import io.zipcoder.casino.Player.PlayerFactory; +import org.junit.Assert; +import org.junit.Test; + +public class PlayerFactoryTest { + + @Test + public void createPlayerNameTest() { + //Given: + String name = "GergDon"; + int walletsize = 420; + + //When: + Player gerg = PlayerFactory.createPlayer(name, walletsize); + String actual = gerg.getPlayerName(); + + //Then + Assert.assertEquals(name, actual); + } + + @Test + public void createPlayerWalletTest() { + //Given: + String name = "GergDon"; + int walletsize = 420; + + //When: + Player gerg = PlayerFactory.createPlayer(name, walletsize); + int actual = gerg.getWallet(); + + //Then + Assert.assertEquals(walletsize, actual); + } + + @Test + public void createPlayerIDTest() { + //Given: + String name = "GergDon"; + int walletsize = 420; + + //When: + Player gerg = PlayerFactory.createPlayer(name, walletsize); + int actual = gerg.getPlayerID(); + + //Then: + Assert.assertTrue(actual <= 9999 && actual >= 1000); + } + + @Test + public void setWalletTest() { + //Given: + String name = "GergDon"; + int walletsize = 420; + + //When: + Player gerg = PlayerFactory.createPlayer(name, walletsize); + int expected = 69420; + gerg.setWallet(expected); + int actual = gerg.getWallet(); + + //Then: + Assert.assertEquals(expected, actual); + } + + @Test + public void getChipBalanceTest() { + //Given: + String name = "GergDon"; + int walletsize = 420; + + //When: + Player gerg = PlayerFactory.createPlayer(name, walletsize); + int expected = 0; + int actual = gerg.getChipBalance(); + + //Then: + Assert.assertEquals(expected, actual); + } + + @Test + public void setChipBalanceTest() { + //Given: + String name = "GergDon"; + int walletsize = 420; + + //When: + Player gerg = PlayerFactory.createPlayer(name, walletsize); + int expected = 2570; + gerg.setChipBalance(expected); + int actual = gerg.getChipBalance(); + + //Then: + Assert.assertEquals(expected, actual); + } + + @Test + public void addToWalletTest() { + //Given: + String name = "GergDon"; + int walletsize = 420; + + //When: + Player gerg = PlayerFactory.createPlayer(name, walletsize); + int amountToAdd = 1500; + int expected = 1920; + gerg.addToWallet(amountToAdd); + int actual = gerg.getWallet(); + + //Then: + Assert.assertEquals(expected, actual); + } + + @Test + public void wageMoneyTest() { + //Given: + String name = "GergDon"; + int walletsize = 420; + int betAmount = 500; + + //When: + Player gerg = PlayerFactory.createPlayer(name, walletsize); + gerg.setChipBalance(2500); + int expected = 2000; + gerg.wageMoney(betAmount); + int actual = gerg.getChipBalance(); + + //Then: + Assert.assertEquals(expected, actual); + } + + @Test + public void cashOutTest() { + //Given: + String name = "GergDon"; + int walletsize = 420; + + + //When: + Player gerg = PlayerFactory.createPlayer(name, walletsize); + gerg.setChipBalance(2500); + int expected = 2920; + gerg.cashOut(); + int actual = gerg.getWallet(); + + //Then: + Assert.assertEquals(expected, actual); + } + + @Test + public void getMoreChipsTest() { + //Given: + String name = "GergDon"; + int walletsize = 420; + + //When: + Player gerg = PlayerFactory.createPlayer(name, walletsize); + int expected = 420; + gerg.getMoreChips(expected); + int actual = gerg.getChipBalance(); + + //Then: + Assert.assertEquals(expected, actual); + } + + @Test + public void getMoreChipsWithBalanceTest() { + //Given: + String name = "GergDon"; + int walletsize = 420; + int chipsWanted = 320; + + //When: + Player gerg = PlayerFactory.createPlayer(name, walletsize); + gerg.setChipBalance(600); + int expected = 920; + gerg.getMoreChips(chipsWanted); + int actual = gerg.getChipBalance(); + + //Then: + Assert.assertEquals(expected, actual); + } + + @Test + public void getMoreChipsRemainingWalletTest() { + //Given: + String name = "GergDon"; + int walletsize = 420; + int chipsWanted = 320; + + //When: + Player gerg = PlayerFactory.createPlayer(name, walletsize); + gerg.setChipBalance(600); + int expected = 100; + gerg.getMoreChips(chipsWanted); + int actual = gerg.getWallet(); + + //Then: + Assert.assertEquals(expected, actual); + } +} \ No newline at end of file diff --git a/src/test/java/io/zipcoder/casino/PlayerTest.java b/src/test/java/io/zipcoder/casino/PlayerTest.java new file mode 100644 index 000000000..e944d1826 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/PlayerTest.java @@ -0,0 +1,228 @@ +package io.zipcoder.casino; + +import io.zipcoder.casino.Player.Player; +import org.junit.Assert; +import org.junit.Test; + +public class PlayerTest { + String name = "Gerg"; + int stash = 5000; + + @Test + public void getPlayerNameTest() { + //Given: + Player gamblingAddict = new Player(name, stash); + + //When: + String expected = "Gerg"; + String actual = gamblingAddict.getPlayerName(); + + //Then: + Assert.assertEquals(expected, actual); + } + + @Test + public void setPlayerNameTest() { + //Given: + Player gamblingAddict = new Player(name, stash); + + //When: + String expected = "Don"; + gamblingAddict.setPlayerName(expected); + String actual = gamblingAddict.getPlayerName(); + + //Then: + Assert.assertEquals(expected, actual); + } + + @Test + public void getPlayerIDTest() { + //Given: + Player gamblingAddict = new Player(name, stash); + + //When: + int actual = gamblingAddict.getPlayerID(); + + //Then: + Assert.assertTrue(actual <= 9999 && actual >= 1000); + } + + @Test + public void getWalletTest() { + //Given: + Player gamblingAddict = new Player(name, stash); + + //When: + int expected = 5000; + int actual = gamblingAddict.getWallet(); + + //Then: + Assert.assertEquals(expected, actual); + } + + @Test + public void setWalletTest() { + //Given: + Player gamblingAddict = new Player(name, stash); + + //When: + int expected = 69420; + gamblingAddict.setWallet(expected); + int actual = gamblingAddict.getWallet(); + + //Then: + Assert.assertEquals(expected, actual); + } + + @Test + public void getChipBalanceTest() { + //Given: + Player gamblingAddict = new Player(name, stash); + + //When: + int expected = 0; + int actual = gamblingAddict.getChipBalance(); + + //Then: + Assert.assertEquals(expected, actual); + } + + @Test + public void setChipBalanceTest() { + //Given: + Player gamblingAddict = new Player(name, stash); + + //When: + int expected = 2570; + gamblingAddict.setChipBalance(expected); + int actual = gamblingAddict.getChipBalance(); + + //Then: + Assert.assertEquals(expected, actual); + } + + @Test + public void addToWalletTest() { + //Given: + Player gamblingAddict = new Player(name, stash); + + //When: + int amountToAdd = 1500; + int expected = 6500; + gamblingAddict.addToWallet(amountToAdd); + int actual = gamblingAddict.getWallet(); + + //Then: + Assert.assertEquals(expected, actual); + } + + @Test + public void wageMoneyTest() { + //Given: + Player gamblingAddict = new Player(name, stash); + gamblingAddict.setChipBalance(2500); + int betAmount = 500; + + //When: + int expected = 2000; + gamblingAddict.wageMoney(betAmount); + int actual = gamblingAddict.getChipBalance(); + + //Then: + Assert.assertEquals(expected, actual); + } + + @Test + public void wageMoneyNegativeTest() { + //Given: + Player gamblingAddict = new Player(name, stash); + gamblingAddict.setChipBalance(2500); + int betAmount = -500; + + //When: + int expected = 2500; + gamblingAddict.wageMoney(betAmount); + int actual = gamblingAddict.getChipBalance(); + + //Then: + Assert.assertEquals(expected, actual); + } + + @Test + public void cashOutTest() { + //Given: + Player gamblingAddict = new Player(name, stash); + gamblingAddict.setChipBalance(2500); + + //When: + int expected = 7500; + gamblingAddict.cashOut(); + int actual = gamblingAddict.getWallet(); + + //Then: + Assert.assertEquals(expected, actual); + } + + @Test + public void getMoreChipsTest() { + //Given: + Player gamblingAddict = new Player(name, stash); + + //When: + int expected = 4000; + gamblingAddict.getMoreChips(expected); + int actual = gamblingAddict.getChipBalance(); + + //Then: + Assert.assertEquals(expected, actual); + } + + @Test + public void getMoreChipsWithBalanceTest() { + //Given: + Player gamblingAddict = new Player(name, stash); + gamblingAddict.setChipBalance(5000); + int chipsWanted = 3000; + + //When: + int expected = 8000; + gamblingAddict.getMoreChips(chipsWanted); + int actual = gamblingAddict.getChipBalance(); + + //Then: + Assert.assertEquals(expected, actual); + } + + @Test + public void getMoreChipsRemainingWalletTest() { + //Given: + Player gamblingAddict = new Player(name, stash); + gamblingAddict.setChipBalance(5000); + int chipsWanted = 3000; + + //When: + int expected = 2000; + gamblingAddict.getMoreChips(chipsWanted); + int actual = gamblingAddict.getWallet(); + + //Then: + Assert.assertEquals(expected, actual); + } + + @Test + public void winChipsTest() { + //Given: + Player gamblingAddict = new Player(name, stash); + gamblingAddict.setChipBalance(5000); + int chipsWon = 167; + + //When: + int expected = 5167; + gamblingAddict.winChips(chipsWon); + int actual = gamblingAddict.getChipBalance(); + + //Then: + Assert.assertEquals(expected, actual); + } + +} \ No newline at end of file diff --git a/src/test/java/io/zipcoder/casino/PlayerWarehouseTest.java b/src/test/java/io/zipcoder/casino/PlayerWarehouseTest.java new file mode 100644 index 000000000..d24c83c5f --- /dev/null +++ b/src/test/java/io/zipcoder/casino/PlayerWarehouseTest.java @@ -0,0 +1,86 @@ +package io.zipcoder.casino; + +import io.zipcoder.casino.Player.Player; +import io.zipcoder.casino.Player.PlayerFactory; +import io.zipcoder.casino.Player.PlayerWarehouse; +import org.junit.Assert; +import org.junit.Test; + +public class PlayerWarehouseTest { + + @Test + public void addPlayer() { + //Given: + Player gerg = PlayerFactory.createPlayer("gerg", 500); + int playerID = gerg.getPlayerID(); + + //When: + PlayerWarehouse.removeAllPlayers(); + PlayerWarehouse.addPlayer(playerID, gerg); + + //Then: + Assert.assertEquals(1, (int) PlayerWarehouse.getNumberOfCurrentPlayers()); + } + + @Test + public void removePlayer() { + //Given: + Player gerg = PlayerFactory.createPlayer("gerg", 500); + Player eab = PlayerFactory.createPlayer("eab", 500); + Player nixog = PlayerFactory.createPlayer("nixog", 500); + int gergPlayerID = gerg.getPlayerID(); + int eabPlayerID = eab.getPlayerID(); + int nixogPlayerID = nixog.getPlayerID(); + PlayerWarehouse.removeAllPlayers(); + PlayerWarehouse.addPlayer(gergPlayerID, gerg); + PlayerWarehouse.addPlayer(eabPlayerID, eab); + PlayerWarehouse.addPlayer(nixogPlayerID, nixog); + + //When: + PlayerWarehouse.removePlayer(gergPlayerID); + + //Then: + Assert.assertEquals(2, (int) PlayerWarehouse.getNumberOfCurrentPlayers()); + } + + @Test + public void getNumberOfCurrentPlayers() { + //Given: + Player gerg = PlayerFactory.createPlayer("gerg", 500); + Player eab = PlayerFactory.createPlayer("eab", 500); + Player nixog = PlayerFactory.createPlayer("nixog", 500); + int gergPlayerID = gerg.getPlayerID(); + int eabPlayerID = eab.getPlayerID(); + int nixogPlayerID = nixog.getPlayerID(); + PlayerWarehouse.removeAllPlayers(); + PlayerWarehouse.addPlayer(gergPlayerID, gerg); + PlayerWarehouse.addPlayer(eabPlayerID, eab); + PlayerWarehouse.addPlayer(nixogPlayerID, nixog); + + //When: + PlayerWarehouse.removePlayer(gergPlayerID); + + //Then: + Assert.assertEquals(2, (int) PlayerWarehouse.getNumberOfCurrentPlayers()); + } + + @Test + public void removeAllPlayers() { + //Given: + Player gerg = PlayerFactory.createPlayer("gerg", 500); + Player eab = PlayerFactory.createPlayer("eab", 500); + Player nixog = PlayerFactory.createPlayer("nixog", 500); + int gergPlayerID = gerg.getPlayerID(); + int eabPlayerID = eab.getPlayerID(); + int nixogPlayerID = nixog.getPlayerID(); + PlayerWarehouse.addPlayer(gergPlayerID, gerg); + PlayerWarehouse.addPlayer(eabPlayerID, eab); + PlayerWarehouse.addPlayer(nixogPlayerID, nixog); + + //When: + PlayerWarehouse.removeAllPlayers(); + + //Then: + Assert.assertEquals(0, (int) PlayerWarehouse.getNumberOfCurrentPlayers()); + } +} \ No newline at end of file