diff --git a/README.md b/README.md index 8cb02ff0..fdd5c057 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ ## Specs * This repo contains a [UML](https://github.com/Zipcoder/CR-MacroLabs-OOP-Casino/blob/master/UML.pdf) to help get you started. * The project should include some concept of - * `Player` class - * `Player` objects should be created upon input from a user. + * `io.zipcoder.casino.Player` class + * `io.zipcoder.casino.Player` objects should be created upon input from a user. * `Game` interface * Contract which ensures that a class enforces some aspect of _playing_. * `Gamble` interface @@ -22,8 +22,8 @@ ## Developmental Notes * Go fish is a friendly game and should not involve gambling. -* `BlackJack` and `GoFish` are both Card Games and should therefore inherit from a common `CardGame`. -* Any common logic or fields between the games should live CardGame class, **not** BlackJack **nor** GoFish. +* `BlackJack` and `io.zipcoder.casino.Game.Game.cardGame.GoFIsh.GoFish` are both Card Games and should therefore inherit from a common `io.zipcoder.casino.Game.Game.cardGame.CardGame`. +* Any common logic or fields between the games should live io.zipcoder.casino.Game.Game.cardGame.CardGame class, **not** BlackJack **nor** io.zipcoder.casino.Game.Game.cardGame.GoFIsh.GoFish. * The UML provided is missing classes, properties, and definitions required to complete this project. * You must have a completed and approved UML diagram before you proceed to do any development * You can either work by yourself , or in a group no bigger than 3. diff --git a/Updated UML b/Updated UML new file mode 100644 index 00000000..8e94fba7 Binary files /dev/null and b/Updated UML differ diff --git a/pom.xml b/pom.xml index c6ec0cc8..1437fecd 100644 --- a/pom.xml +++ b/pom.xml @@ -7,13 +7,25 @@ io.zipcoder casino 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.7 + 1.7 + + + + junit junit 4.12 - test + io.zipcoder.casinotest.test diff --git a/src/main/java/io/zipcoder/casino/Casino.java b/src/main/java/io/zipcoder/casino/Casino.java index 74dfdd8c..30e6b0f5 100644 --- a/src/main/java/io/zipcoder/casino/Casino.java +++ b/src/main/java/io/zipcoder/casino/Casino.java @@ -1,5 +1,7 @@ package io.zipcoder.casino; - public class Casino { + public static void main(String[] args) { + House.INSTANCE.startCasino(); + } } diff --git a/src/main/java/io/zipcoder/casino/CasinoUtilities/Console.java b/src/main/java/io/zipcoder/casino/CasinoUtilities/Console.java new file mode 100644 index 00000000..fcbeec42 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/CasinoUtilities/Console.java @@ -0,0 +1,50 @@ +package io.zipcoder.casino.CasinoUtilities; + +import io.zipcoder.casino.Player; + +import java.util.Scanner; + +public class Console { + + private static Scanner casinoScanner = new Scanner(System.in); + public static Player currentPlayer; + + public static String getString() { + return casinoScanner.nextLine(); + } + + public static Double getDouble() { + Double input; + try { + input = Double.valueOf(casinoScanner.nextLine()); + return input; + } + catch(NumberFormatException e){ + Console.print("Invalid input: please enter a numerical value"); + return -0.001; + } + + } + + public static int getInt() { + + return getDouble().intValue(); + } + + //TODO: implement later once rules are operational + /*public static void readFile() { + + }*/ + + + public static void print(String output) { + /*System.out.println("============================================"); + System.out.println("Current Player: " + currentPlayer.getProfile().getName()); + System.out.println("Current Balance: " + currentPlayer.getProfile().getAccountBalance()); + System.out.println("============================================");*/ + + System.out.println(output); + } + + +} diff --git a/src/main/java/io/zipcoder/casino/Escrow.java b/src/main/java/io/zipcoder/casino/Escrow.java new file mode 100644 index 00000000..e20fa199 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Escrow.java @@ -0,0 +1,16 @@ +package io.zipcoder.casino; + +import java.util.HashMap; + +public class Escrow { + private HashMap escrow; + + public Escrow(){ + this.escrow = new HashMap<>(0); + } + + public HashMap getEscrow(){ + return this.escrow; + } + +} diff --git a/src/main/java/io/zipcoder/casino/Gambler.java b/src/main/java/io/zipcoder/casino/Gambler.java new file mode 100644 index 00000000..57344ac9 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Gambler.java @@ -0,0 +1,11 @@ +package io.zipcoder.casino; + +public interface Gambler{ + + boolean bet(TypeOfBet betType, double amount); + void win(TypeOfBet betType, double payoutMultiplier); + void lose(TypeOfBet betType); + void setEscrow(TypeOfBet typeOfBet, double incomingBet); + double getEscrowBet(TypeOfBet typeOfBet); + public boolean escrowContains(TypeOfBet typeOfBet); +} diff --git a/src/main/java/io/zipcoder/casino/Game/Game.java b/src/main/java/io/zipcoder/casino/Game/Game.java new file mode 100644 index 00000000..8a953195 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Game/Game.java @@ -0,0 +1,12 @@ +package io.zipcoder.casino.Game; + +import io.zipcoder.casino.Player; + +public interface Game { + + public void addPlayer(Player player); + public void removePlayer (Player player); + public void startGame(); + public void endGame(); + public String getRules(); +} diff --git a/src/main/java/io/zipcoder/casino/Game/cardGame/BLackJack/BlackJackBet.java b/src/main/java/io/zipcoder/casino/Game/cardGame/BLackJack/BlackJackBet.java new file mode 100644 index 00000000..b46718f3 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Game/cardGame/BLackJack/BlackJackBet.java @@ -0,0 +1,9 @@ +package io.zipcoder.casino.Game.cardGame.BLackJack; + +import io.zipcoder.casino.TypeOfBet; + +public enum BlackJackBet implements TypeOfBet { + INTIAL_BET, + EVEN_BET, + DOUBLE_DOWN; +} diff --git a/src/main/java/io/zipcoder/casino/Game/cardGame/BLackJack/BlackJackGame.java b/src/main/java/io/zipcoder/casino/Game/cardGame/BLackJack/BlackJackGame.java new file mode 100644 index 00000000..941c7419 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Game/cardGame/BLackJack/BlackJackGame.java @@ -0,0 +1,435 @@ +package io.zipcoder.casino.Game.cardGame.BLackJack; + +import io.zipcoder.casino.CasinoUtilities.Console; +import io.zipcoder.casino.Game.cardGame.CardGame; +import io.zipcoder.casino.Game.cardGame.utilities.Card; +import io.zipcoder.casino.Game.cardGame.utilities.CardRank; +import io.zipcoder.casino.Game.cardGame.utilities.Hand; + +import io.zipcoder.casino.House; +import io.zipcoder.casino.Player; +import io.zipcoder.casino.Profile; +import io.zipcoder.casino.TypeOfBet; + +public class BlackJackGame extends CardGame { + private BlackJackPlayer player; + private BlackJackPlayer dealer; + private boolean playAnotherGame; + + public BlackJackGame(Profile profile) { + player = new BlackJackPlayer(profile); + dealer = new BlackJackPlayer(null); + player.setIsBusted(false); + dealer.setIsBusted(false); + playAnotherGame = true; + } + + @Override + public void startGame() { + Console.print("Welcome to BlackJack!" + " " + player.getProfile().getName().toString()); + + playBlackJack(); + endGame(); + } + + //TODO test this method + public void playBlackJack() { + + while (playAnotherGame == true) { + reset(); + String printThis; + while (placeInitialBet(player) == false) { + placeInitialBet(player); + } + printThis = round(player, dealer); + Console.print(printThis); + + Console.print(player.getProfile().getName().toString() + " Play Again: Enter [Yes] : [NO] to end game"); + + if (Console.getString().equalsIgnoreCase("YES")) { + continue; + } else if (Console.getString().equalsIgnoreCase("NO")) { + playAnotherGame = false; + } else { + Console.print("Invalid entry"); + } + } + } + + /** + * changes + * when intial is blackJack needs to be auto win + * when hitting need to print hand + * need to print blackJack if blackJack occurs + * need to print bust if bust occurs + * isBust is not working properly loop should break if busted and should settle bets + * need to reset all values before each round + * need to handle if dealer gets black jack at start + * + * @param thePlayer + * @param theDealer + * @return + */ + //TODO test this method + public String round(BlackJackPlayer thePlayer, BlackJackPlayer theDealer) { + String result = ""; + deal(thePlayer); + /*check to see if player or dealer has blackjack upon first dealing if so round ends by return result.*/ + + if (isBlackJack(thePlayer) == true) { + result = settlesIfBlackJAck(thePlayer, theDealer); + return result; + } + /*player plays turn if player has blackjack or busts then round will end by returning result.*/ + result = turn(thePlayer); + if (result != null) { + return result; + }/*dealer deals to self: ends round if dealer has blackJack or busts.*/ + result = dealerBehavior(thePlayer, theDealer); + if (result != null) { + return result; + }/*determines winner and settles all the bets accordingly*/ + result = settleBets(thePlayer, theDealer); + return result; + } + + //TODO test this method; + public String settlesIfBlackJAck(BlackJackPlayer thePlayer, BlackJackPlayer theDealer) { + if (isBlackJack(thePlayer) == true) { + return settleBets(thePlayer, theDealer); + } else if (isBlackJack(theDealer)) { + return settleBets(thePlayer, theDealer); + } + return null; + } + + //TODO test this method + + /** + * player takes turn by perfoming game actions until either Bust,BlackJack or Stands. + * + * @param currentPlayer + * @return + */ + public String turn(BlackJackPlayer currentPlayer) { + String aResult = null; + // currentPlayer.setCurrentPlayer(true); + while (currentPlayer.getIsBusted() == false | currentPlayer.getHasStood() == false) { + if (currentPlayer.getScore() > 21) { + currentPlayer.setIsBusted(true); + Console.print(currentPlayer.getProfile().getName() + "You BUSTED!!!!"); + aResult = settleBets(currentPlayer, dealer); + break; + } + else if (isBlackJack(currentPlayer) == true) { + Console.print("BLACKJACK!!!!!!!!"); + aResult = settlesIfBlackJAck(currentPlayer, dealer); + break; + } + showListOfPlayerActions(); + String input = Console.getString(); + if (input.equalsIgnoreCase("Hit") & currentPlayer.getScore() < 21) { + hit(currentPlayer); + Console.print(currentPlayer.getProfile().getName() + " " + currentPlayer.getHand().showHand()); + } else if (input.equalsIgnoreCase("Stand")) { + stand(currentPlayer); + break; + } else { + Console.print("Invalid input enter one of the following actions"); + } + + } + //currentPlayer.setCurrentPlayer(false); + return aResult; + } + + + public static void main(String[] args) { + Profile someProfile = new Profile("Commander", 100.0, 1); + BlackJackGame game = new BlackJackGame(someProfile); + game.startGame(); + } + + + // need to change deal to accomodate multiple players not just given players + //Multiple players would loop through list of players at table and deal to each player + public void deal(BlackJackPlayer player1) { + Card temp; + for (int i = 0; i < 2; i++) { + temp = deck.getCard(); + player1.getHand().addCard(deck.getCard()); + updateScore(temp, player1); + + temp = deck.getCard(); + dealer.getHand().addCard(temp); + updateScore(temp, dealer); + } + + Console.print(player.getHand().showHand()); + Console.print("Dealer Face Card: " + showDealersFaceCard()); + } + + //bets are placed be for the dealer deals + //need to change list of players to cardPlayers + public boolean placeInitialBet(BlackJackPlayer thePlayer) { + return placeBet(BlackJackBet.INTIAL_BET, thePlayer); + } + + public String hit(BlackJackPlayer thePlayer) { + String currentScore = String.valueOf(dealACard(thePlayer)); + return currentScore; + } + + /** + * @param thePlayer + * @return + */ + public boolean stand(BlackJackPlayer thePlayer) { + thePlayer.setHasStood(true); + return thePlayer.getHasStood(); + } + /** + * updates the current Score + * + * @param cardToScore + * @param thePlayer + * @return + */ + //makes changes to include aces + // players hand has more than one ace add ace score as score plus 1 + public int updateScore(Card cardToScore, BlackJackPlayer thePlayer) { + int cardValue; + int updateScore; + + if ((cardToScore.getRank() == CardRank.ACE ) & (countAcesInHand(thePlayer) > 1)) { + cardValue = 1; + } else { + cardValue = cardToScore.getRank().getCardValue(); + } + updateScore = thePlayer.getScore() + cardValue; + thePlayer.setScore(updateScore); + return updateScore; + } + + + /** + * @param currentPlayer + * @return + */ + public int countAcesInHand(BlackJackPlayer currentPlayer) { + int numberOfAces = 0; + for (Card ace : currentPlayer.getHand().getCards()) { + if (ace.getRank() == CardRank.ACE) { + numberOfAces++; + } + } + return numberOfAces; + } + + public String dealerBehavior(BlackJackPlayer thePlayer, BlackJackPlayer theDealer) { + String result = ""; + // TODO consider When dealer has a soft 17 + while (theDealer.getScore() < 17) { + dealACard(theDealer); + Console.print("Dealers Hand: " + theDealer.getHand().showHand()); + } + if (isBusted(theDealer) | isBlackJack(theDealer)) { + result = settleBets(thePlayer, theDealer); + Console.print("Dealer Busts"); + return result; + } + return null; + } + + public int dealACard(BlackJackPlayer cardPlayer) { + Card temp = deck.getCard(); + cardPlayer.getHand().addCard(temp); + return updateScore(temp, cardPlayer); + + } + + public String showDealersFaceCard() { + Hand hand = dealer.getHand(); + Card faceCard = hand.getCards().get(0); + + // /Console.print(faceCard.toString()); + return faceCard.toString(); + } + + public String showListOfPlayerActions() { + String playerActions = "Choose Action: [Bet], [Hit], [Stand]"; + + Console.print(playerActions); + + return playerActions; + } + + + public boolean placeBet(TypeOfBet betType, BlackJackPlayer currentPlayer) { + Double betAmount; + boolean keepRunning = true; + do { + // Console.print(bar); + Console.print("Your current balance is: $" + currentPlayer.getProfile().getAccountBalance()); + Console.print("How much would you like to bet?"); + betAmount = Console.getDouble(); + if (betAmount >= 0 && betAmount < 0.01) { + Console.print("Cannot bet fractions of a cent. Please enter a valid bet"); + } else if (betAmount >= 0) { + keepRunning = false; + } else if (betAmount == -0.001) { + continue; + } else if (betAmount < 0) { + Console.print("Cannot bet negative values. Please enter a valid bet"); + } + } + while (keepRunning); + boolean wasBetPlaced = currentPlayer.bet(betType, betAmount); + //Console.print(bar); + //Console.print(); + return wasBetPlaced; + } + + + //TODO test this + + /** + * Only time this method should be called is when both players have not busted + * + * @param thePlayer + * @param theDealer + * @return + */ + public String settleBets(BlackJackPlayer thePlayer, BlackJackPlayer theDealer) { + int payout = 0; + String theResult = ""; + //settle winning bets; + if ((isBlackJack(thePlayer) == true) | (theDealer.getIsBusted() == true )| (decideWinner(thePlayer, theDealer) == thePlayer)) { + payout = 1; + settlingBets(thePlayer, payout); + theResult = winnerAsString(thePlayer); + }//settle loosing bets + else if ((thePlayer.getIsBusted() == true) | (decideWinner(thePlayer, theDealer) == theDealer)){ + payout = 2; + settlingBets(thePlayer, payout); + theResult = looserAsString(thePlayer); + } else if (decideWinner(thePlayer, theDealer) == null) { + payout = 3; + settlingBets(thePlayer, payout); + theResult = playPushAsString(thePlayer); + } + return theResult; + } + + + //TODO test this + public String winnerAsString(BlackJackPlayer thePlayer) { + String winner = thePlayer.getProfile().getName() + " YOU WIN" + "\n" + + "Your New Balance: " + thePlayer.getProfile().getAccountBalance(); + return winner; + } + + public String playPushAsString(BlackJackPlayer thePlayer) { + String push = thePlayer.getProfile().getName() + " YOU PUSH" + "\n" + + "Your New Balance: " + thePlayer.getProfile().getAccountBalance(); + return push; + } + + public String looserAsString(BlackJackPlayer thePlayer) { + String looser = thePlayer.getProfile().getName() + "You Loose!!" + "\n" + + "Your New Balance: " + thePlayer.getProfile().getAccountBalance(); + return looser; + } + + +//TODO test this + + /** + * @param thePlayer + */ + public void settlingBets(BlackJackPlayer thePlayer, int payout) { + for (TypeOfBet key : thePlayer.getAllBets().keySet()) { + if (payout == 1) { + settleBetsPlayerWins(thePlayer, key); + } else if (payout == 2) { + settleBetsPlayerLooses(thePlayer, key); + } else { + settleBetsPlayerPushes(thePlayer, key); + } + } + } + + //TODO test this + public void settleBetsPlayerLooses(BlackJackPlayer thePlayer, TypeOfBet key) { + thePlayer.lose(key); + thePlayer.setIsBusted(false); + } + + //TODO test this + + public void settleBetsPlayerWins(BlackJackPlayer thePlayer, TypeOfBet key) { + if (key == BlackJackBet.INTIAL_BET) { + thePlayer.win(key, 3 / 2); + } else if (key == BlackJackBet.DOUBLE_DOWN) { + thePlayer.win(key, 2); + } + } + + //TODO test this + public void settleBetsPlayerPushes(BlackJackPlayer thePlayer, TypeOfBet key) { + thePlayer.win(key, 0); + } + + //TODO test this + public Player decideWinner(BlackJackPlayer thePlayer, BlackJackPlayer theDealer) { + int playerScore = thePlayer.getScore(); + int dealerScore = theDealer.getScore(); + + if ((playerScore <= 21 & dealerScore <= 21) & (playerScore < dealerScore)) { + return theDealer; + } + // score is equal game is a push no player wins or looses + else if ((playerScore <= 21 & dealerScore <= 21) & (playerScore > dealerScore)) { + return thePlayer; + } + return null; + } + + public boolean isBusted(BlackJackPlayer thePlayer) { + if (thePlayer.getScore() > 21) { + thePlayer.setIsBusted(true); + } + return thePlayer.getIsBusted(); + } + + + public boolean isBlackJack(BlackJackPlayer currentPlayer) { + boolean blackJack = false; + if (currentPlayer.getScore() == 21) { + blackJack = true; + } + return blackJack; + } + + //TODO test this + public void reset() { + player.setIsBusted(false); + dealer.setIsBusted(false); + player.setHasStood(false); + dealer.setHasStood(false); + player.getHand().clear(); + dealer.getHand().clear(); + player.setScore(0); + dealer.setScore(0); + } + + + public void endGame() { + House.INSTANCE.gameSelection(); + } + + public String getRules() { + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/io/zipcoder/casino/Game/cardGame/BLackJack/BlackJackPlayer.java b/src/main/java/io/zipcoder/casino/Game/cardGame/BLackJack/BlackJackPlayer.java new file mode 100644 index 00000000..6ccedaba --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Game/cardGame/BLackJack/BlackJackPlayer.java @@ -0,0 +1,102 @@ +package io.zipcoder.casino.Game.cardGame.BLackJack; + +import io.zipcoder.casino.*; +import io.zipcoder.casino.CasinoUtilities.Console; +import io.zipcoder.casino.Game.cardGame.CardPlayer; + +import java.util.HashMap; + +public class BlackJackPlayer extends CardPlayer implements Gambler { + + private boolean hasStood; + private boolean isBusted; + private Escrow playerEscrow; + + public BlackJackPlayer(Profile someProfile) { + super(someProfile); + this.playerEscrow = new Escrow(); + } + + public boolean getHasStood() { + return hasStood; + } + + public void setHasStood(boolean stoodStatus) { + this.hasStood = stoodStatus; + } + + public boolean getIsBusted() { + return isBusted; + } + + public void setIsBusted(boolean isBusted) { + this.isBusted = isBusted; + } + + public boolean bet(TypeOfBet typeOfBet, double amount) { + double accountBalance = this.getProfile().getAccountBalance(); + + if (accountBalance < amount) { + Console.print("Insufficient funds : cannot place bet"); + return false; + } + else if (this.escrowContains(typeOfBet)) { + double escrowBalance = this.getEscrowBet(typeOfBet); + this.getProfile().setAccountBalance(accountBalance - amount); + this.setEscrow(typeOfBet, amount + escrowBalance); + return true; + } + else { + this.getProfile().setAccountBalance(accountBalance - amount); + this.setEscrow(typeOfBet, amount); + return true; + } + + } + + public void win(TypeOfBet typeOfBet, double payoutMultiplier) { + double accountBalance = this.getProfile().getAccountBalance(); + double escrow = this.getEscrowBet(typeOfBet); + double winnings = escrow + (escrow * payoutMultiplier); + this.getProfile().setAccountBalance(accountBalance+ winnings); + this.setEscrow(typeOfBet,0); + } + + public void lose(TypeOfBet typeOfBet) { + this.setEscrow(typeOfBet, 0); + } + + public void setEscrow(TypeOfBet typeOfBet, double incomingBet){ + this.playerEscrow.getEscrow().put(typeOfBet, incomingBet); + } + + + public double getEscrowBet(TypeOfBet typeOfBet){ + return this.playerEscrow.getEscrow().get(typeOfBet); + } + + + public boolean escrowContains(TypeOfBet typeOfBet){ + return playerEscrow.getEscrow().containsKey(typeOfBet) ; + } + + public HashMap getAllBets(){ + return playerEscrow.getEscrow(); + } + +// public void buyInsurance() { +// +// } +// +// public io.zipcoder.casino.Game.cardGame.utilities.Hand split(io.zipcoder.casino.Game.cardGame.utilities.Hand currentHand) { +// +// return additionalHand; +// +// } +// +// public void doubleDown() { +// +// } + + +} diff --git a/src/main/java/io/zipcoder/casino/Game/cardGame/CardGame.java b/src/main/java/io/zipcoder/casino/Game/cardGame/CardGame.java new file mode 100644 index 00000000..cb2b37be --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Game/cardGame/CardGame.java @@ -0,0 +1,67 @@ +package io.zipcoder.casino.Game.cardGame; + +import io.zipcoder.casino.CasinoUtilities.Console; +import io.zipcoder.casino.Game.Game; +import io.zipcoder.casino.Game.cardGame.utilities.Deck; +import io.zipcoder.casino.Player; + +import java.util.ArrayList; + +abstract public class CardGame implements Game { + + protected Deck deck; + protected ArrayList players; + //private Player winner; + + public CardGame() { + deck = new Deck(); + players = new ArrayList<>(); + } + + public Deck getDeck() { + + return deck; + } + + public int calculateScore() { + return 0; + } + + public Player decideWinner(Player player1, Player player2) { + + return null; + } + + public void addPlayer(Player aPlayer){ + if(players.contains(aPlayer)){ + Console.print("Error: Player already added to game - cannot add duplicate players"); + } + else{ + players.add(aPlayer); + } + + } + public void removePlayer (Player aPlayer){ + if(!players.contains(aPlayer)){ + Console.print("Error: Player not in game - cannot remove nonexistent player"); + } + else{ + players.remove(aPlayer); + } + + } + + public void startGame() { + + } + + public void endGame() { + + } + + public String getRules() { + + return null; + } + +} diff --git a/src/main/java/io/zipcoder/casino/Game/cardGame/CardPlayer.java b/src/main/java/io/zipcoder/casino/Game/cardGame/CardPlayer.java new file mode 100644 index 00000000..83ff1de6 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Game/cardGame/CardPlayer.java @@ -0,0 +1,55 @@ +package io.zipcoder.casino.Game.cardGame; + +import io.zipcoder.casino.Game.cardGame.utilities.Hand; +import io.zipcoder.casino.Player; +import io.zipcoder.casino.Profile; + +public abstract class CardPlayer extends Player { + + + protected boolean isCurrentPlayer; + protected Hand cardPlayerHand; + protected int score; + + public CardPlayer(Profile someProfile) { + super(someProfile); + cardPlayerHand = new Hand(); + setHand(cardPlayerHand); + this.isCurrentPlayer = isCurrentPlayer; + } + + public void setScore(int newScore) { + + this.score = newScore; + } + + public int getScore() { + + return this.score; + } + + + public void setHand(Hand aHand) { + this.cardPlayerHand = aHand; + } + + public Hand getHand() { + return cardPlayerHand; + } + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("Score=" + score); + return sb.toString(); + } + + public boolean isCurrentPlayer() { + return isCurrentPlayer; + } + + public void setCurrentPlayer(boolean currentPlayer) { + isCurrentPlayer = currentPlayer; + } +} diff --git a/src/main/java/io/zipcoder/casino/Game/cardGame/GoFIsh/GoFish.java b/src/main/java/io/zipcoder/casino/Game/cardGame/GoFIsh/GoFish.java new file mode 100644 index 00000000..2b7c9ac9 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Game/cardGame/GoFIsh/GoFish.java @@ -0,0 +1,283 @@ +package io.zipcoder.casino.Game.cardGame.GoFIsh; + +import io.zipcoder.casino.CasinoUtilities.Console; +import io.zipcoder.casino.Game.cardGame.CardGame; +import io.zipcoder.casino.Game.cardGame.utilities.Card; +import io.zipcoder.casino.Game.cardGame.utilities.CardRank; +import io.zipcoder.casino.House; +import io.zipcoder.casino.Profile; + +import java.util.ArrayList; + + +public class GoFish extends CardGame { + + private GoFishPlayer user; + private GoFishPlayer dealer; + boolean isTurn; + + + public GoFish(Profile userProfile) { + + super(); + user = new GoFishPlayer(userProfile); + dealer = new GoFishPlayer(House.HOUSE_PROFILE); + addPlayer(user); + addPlayer(dealer); + } + + public void deal() { + + for (int i = 0; i < 7; i++) { + user.getHand().addCard(deck.getCard()); + dealer.getHand().addCard(deck.getCard()); + } + } + + public void startGame() { + GoFish newGame = new GoFish(user.getProfile()); + Console.print("Lets play Go Fish! Shuffle up and deal..."); + deal(); + + } + + public void playGame() { + startGame(); + + do { + playUserTurn(); + playDealerTurn(); + } while (getDeck().countRemainingCards() > 0 ); + + decideWinner(); + + endGame(); + + } + + public void endGame() { + boolean keepPlaying = true; + Console.print("Would you like to play again? ('Yes' or 'No')"); + do { + String choice = Console.getString(); + if (choice.equalsIgnoreCase("no")) { + Console.print("Thanks for playing!"); + keepPlaying = false; + House.INSTANCE.gameSelection(); + } else if (choice.equalsIgnoreCase("yes")) { + keepPlaying = false; + playGame(); + } else { + Console.print("Invalid response: please enter your selection again."); + } + } while (keepPlaying); + + } + + public void playUserTurn() { + + Console.print("_ _ _ _ _ _ _ _ _ _ _ _ _ _ _"); + if (user.getHand().getCards().size() == 0) { + Console.print("Your hand is empty. You have to fish."); + fish(user); + isTurn = false; + } + do { +// dealer.getHand().orderCards(); +// Console.print(dealer.getHand().showHand()); + user.getHand().orderCards(); + Console.print(user.getHand().showHand()); + Console.print("Which card value would you like to ask for?"); + CardRank requestedRank = convertStringToRank(Console.getString()); + playerAsk(requestedRank, dealer, user); + } while (isTurn); + + } + + public void playDealerTurn() { + + Console.print("_ _ _ _ _ _ _ _ _ _ _ _ _ _ _"); + + Console.print("Now its my turn!"); + + + if (dealer.getHand().getCards().size() == 0) { + Console.print("My hand is empty. I have to fish."); + fish(dealer); + isTurn = false; + } + + do { + int dealerHandSize = dealer.getHand().getCards().size(); + int randomSelector = (int) Math.floor(Math.random() * dealerHandSize); + CardRank aCardRank = dealer.getHand().getCards().get(randomSelector).getRank(); + Console.print("Do you have any " + aCardRank + "s?"); + dealerAsk(aCardRank); + } while (!isTurn); + + } + + public void playerAsk(CardRank aCardRank, GoFishPlayer playerBeingAsked, GoFishPlayer askingPlayer) { + + isTurn = true; + + if (countMatchesInHand(askingPlayer, aCardRank) < 1) { + Console.print("You cannot ask for a card that you do not have. Try again."); + + } else if (countMatchesInHand(playerBeingAsked, aCardRank) < 1) { + Console.print("Go fish."); + Console.print("You fished: " + getDeck().peek().toString()); + aCardRank = getDeck().peek().getRank(); + fish(askingPlayer); + + + if (getHandForBook(askingPlayer, aCardRank) > 0) { + askingPlayer.getHand().orderCards(); + Console.print(askingPlayer.getHand().showHand()); + Console.print("You made a book!!"); + askingPlayer.buildBooks(askingPlayer, aCardRank); + removeFromHand(askingPlayer, aCardRank); +// Console.print(askingPlayer.getHand().showHand()); + } + isTurn = false; + + } else { + transfer(aCardRank, playerBeingAsked, askingPlayer); + Console.print("Good guess! Here you go!"); + if (getHandForBook(askingPlayer, aCardRank) > 0) { + Console.print("You made a book!!"); + askingPlayer.buildBooks(askingPlayer, aCardRank); + removeFromHand(askingPlayer, aCardRank); + askingPlayer.getHand().orderCards(); +// Console.print(askingPlayer.getHand().showHand()); + } + } + } + + public void dealerAsk(CardRank aCardRank) { + + isTurn = false; + + if (countMatchesInHand(user, aCardRank) < 1) { + Console.print("Darn. I'm fishing. Your turn now."); + fish(dealer); +// if (getHandForBook(dealer, aCardRank) > 0) { +// Console.print("I made a book!!"); +// dealer.buildBooks(dealer, aCardRank); +// removeFromHand(dealer, aCardRank); +// } + + isTurn = true; + + } else { + transfer(aCardRank, user, dealer); + Console.print("Thanks! Now I guess again!"); +// if (getHandForBook(dealer, aCardRank) > 0) { +// Console.print("I made a book!!"); +// dealer.buildBooks(dealer, aCardRank); +// removeFromHand(dealer, aCardRank); +// } + } + + } + + public int getHandForBook(GoFishPlayer aPlayer, CardRank aCardRank) { + int books = 0; + int count = 0; + for (int i = 0; i < aPlayer.getHand().getCards().size(); i++) { + if (aCardRank == aPlayer.getHand().getCards().get(i).getRank()) { + count++; + } + if (count == 4) { + books++; + } + } + return books; + } + + public void removeFromHand(GoFishPlayer aPlayer, CardRank aCardRank) { + + + + for (int i = aPlayer.getHand().getCards().size() - 1; i >= 0; i--) { + if (aPlayer.getHand().getCards().get(i).getRank() == aCardRank) { + //aPlayer.buildBooks(aPlayer, aCardRank); + aPlayer.getHand().getCards().remove(aPlayer.getHand().getCards().get(i)); + } + + } + + } + + public String decideWinner() { + + Console.print("Dealer score is: " + dealer.getScore()); + Console.print("Your score is: " + user.getScore()); + + if (user.getScores() > dealer.getScores()) { + return "The winner is: " + user.getProfile().getName(); + } else if (dealer.getScores() > user.getScore()) { + return "The winner is: " + dealer.getProfile().getName(); + } else { + return "It is a tie."; + } + } + + public void fish(GoFishPlayer askingPlayer) { + askingPlayer.getHand().addCard(getDeck().getCard()); + } + + public int countMatchesInHand(GoFishPlayer goFishPlayer, CardRank someCardRank) { + + int countOfCard = 0; + ArrayList cardsBeingChecked = goFishPlayer.getHand().getCards(); + + for (int i = 0; i < cardsBeingChecked.size(); i++) { + if (cardsBeingChecked.get(i).getRank() == (someCardRank)) { + countOfCard++; + } + } + + return countOfCard; + } + + public void transfer(CardRank someCardRank, GoFishPlayer fromPlayer, GoFishPlayer toPlayer) { + + for (int i = 0; i < fromPlayer.getHand().getCards().size(); i++) { + + if (fromPlayer.getHand().getCards().get(i).getRank() == someCardRank) { + toPlayer.getHand().addCard(fromPlayer.getHand().getCards().get(i)); + } + } + + ArrayList tempHand = new ArrayList<>(); + + for (int i = 0; i < fromPlayer.getHand().getCards().size(); i++) { + if (fromPlayer.getHand().getCards().get(i).getRank() != someCardRank) { + tempHand.add(fromPlayer.getHand().getCards().get(i)); + } + } + + fromPlayer.getHand().setCards(tempHand); + + } + + public GoFishPlayer getUser() { + return user; + } + + public GoFishPlayer getDealer() { + return dealer; + } + + public CardRank convertStringToRank(String aString) { + + try { + return CardRank.valueOf(aString.toUpperCase()); + } catch (IllegalArgumentException iae) { + Console.print("Invalid entry."); + return null; + } + } + +} diff --git a/src/main/java/io/zipcoder/casino/Game/cardGame/GoFIsh/GoFishPlayer.java b/src/main/java/io/zipcoder/casino/Game/cardGame/GoFIsh/GoFishPlayer.java new file mode 100644 index 00000000..cfe7138d --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Game/cardGame/GoFIsh/GoFishPlayer.java @@ -0,0 +1,46 @@ +package io.zipcoder.casino.Game.cardGame.GoFIsh; + +import io.zipcoder.casino.Game.cardGame.CardPlayer; +import io.zipcoder.casino.Game.cardGame.utilities.Card; +import io.zipcoder.casino.Game.cardGame.utilities.CardRank; +import io.zipcoder.casino.Profile; + +import java.util.ArrayList; +import java.util.HashMap; + + +public class GoFishPlayer extends CardPlayer { + + //private HashMapbooks; +// private Hand gfHand; +ArrayListbooks = new ArrayList<>(); + + public GoFishPlayer(Profile playerProfile){ + super(playerProfile); +// gfHand = new Hand(); + } + +// +// public Hand getHand() { +// super.getHand(); +// return this.gfHand; +// +// } + + + public void buildBooks(GoFishPlayer aPlayer, CardRank aCardRank){ + for(int i = aPlayer.getHand().getCards().size() - 1; i >= 0; i--){ + if(aPlayer.getHand().getCards().get(i).getRank()==aCardRank){ + books.add(aPlayer.getHand().getCards().get(i)); + } + } + } + public ArrayList getBook(){ + return this.books; + } + public int getScores(){ + return this.books.size()/4; + } + + +} diff --git a/src/main/java/io/zipcoder/casino/Game/cardGame/utilities/Card.java b/src/main/java/io/zipcoder/casino/Game/cardGame/utilities/Card.java new file mode 100644 index 00000000..057b1485 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Game/cardGame/utilities/Card.java @@ -0,0 +1,54 @@ +package io.zipcoder.casino.Game.cardGame.utilities; + +public class Card implements Comparable { + private CardSuit suit; + private CardRank rank; + + public Card(CardSuit suit, CardRank rank) { + this.suit = suit; + this.rank = rank; + } + + public CardSuit getSuit() { + return suit; + } + + public CardRank getRank() { + return rank; + } + + public void setSuit(CardSuit suit) { + this.suit = suit; + } + + public void setRank(CardRank rank) { + this.rank = rank; + } + + @Override + public String toString() { + StringBuilder card = new StringBuilder(); + card.append(suit.getSuitSymbols() + " " + rank + " " + suit.getSuitSymbols()); + + return card.toString(); + } + + + @Override + public int compareTo(Card anyCard) { + + if (getRank().compareTo(anyCard.getRank()) > 0) { + return 1; + } else if (getRank().compareTo(anyCard.getRank()) < 0) { + return -1; + } else { + return getSuit().compareTo(anyCard.getSuit()); + } + } +} + + + + + + diff --git a/src/main/java/io/zipcoder/casino/Game/cardGame/utilities/CardRank.java b/src/main/java/io/zipcoder/casino/Game/cardGame/utilities/CardRank.java new file mode 100644 index 00000000..a3400197 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Game/cardGame/utilities/CardRank.java @@ -0,0 +1,30 @@ +package io.zipcoder.casino.Game.cardGame.utilities; + +public enum CardRank { + + TWO(2), + THREE(3), + FOUR(4), + FIVE(5), + SIX(6), + SEVEN(7), + EIGHT(8), + NINE(9), + TEN(10), + JACK(10), + QUEEN(10), + KING(10), + ACE(11); + + private int cardValue; + + CardRank(int value) { + this.cardValue = value; + } + + public int getCardValue() { + return cardValue; + } + + +} diff --git a/src/main/java/io/zipcoder/casino/Game/cardGame/utilities/CardSuit.java b/src/main/java/io/zipcoder/casino/Game/cardGame/utilities/CardSuit.java new file mode 100644 index 00000000..25935d57 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Game/cardGame/utilities/CardSuit.java @@ -0,0 +1,23 @@ +package io.zipcoder.casino.Game.cardGame.utilities; + +public enum CardSuit { + +// DIAMONDS, +// HEARTS, +// SPADES, +// CLUBS + + + CLUBS("♧"), DIAMONDS("♢"), HEARTS("♡"), SPADES("♤"); + + private final String suitSymbols; + + CardSuit(String symbol){ + this.suitSymbols = symbol; + } + + public String getSuitSymbols() { + return suitSymbols; + } + +} diff --git a/src/main/java/io/zipcoder/casino/Game/cardGame/utilities/Deck.java b/src/main/java/io/zipcoder/casino/Game/cardGame/utilities/Deck.java new file mode 100644 index 00000000..650cb1ae --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Game/cardGame/utilities/Deck.java @@ -0,0 +1,46 @@ +package io.zipcoder.casino.Game.cardGame.utilities; + +import java.util.Collections; +import java.util.Stack; + + +public class Deck { + + private Stack deckOfCards = new Stack<>(); + + public Deck() { + fillDeck(); + shuffle(); + } + + public void fillDeck() { + + for (CardSuit aSuit : CardSuit.values()) { + for (CardRank aRank : CardRank.values()) { + Card tempCard = new Card(aSuit, aRank); + deckOfCards.push(tempCard); + } + } + } + + public Card getCard() { + return deckOfCards.pop(); + } + + public int countRemainingCards() { + return deckOfCards.size(); + } + + public void addCard(Card card) { + deckOfCards.push(card); + } + + public Card peek() { + return deckOfCards.peek(); + } + + public void shuffle() { + Collections.shuffle(deckOfCards); + } + +} diff --git a/src/main/java/io/zipcoder/casino/Game/cardGame/utilities/Hand.java b/src/main/java/io/zipcoder/casino/Game/cardGame/utilities/Hand.java new file mode 100644 index 00000000..49e858d4 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Game/cardGame/utilities/Hand.java @@ -0,0 +1,62 @@ +package io.zipcoder.casino.Game.cardGame.utilities; + + +import io.zipcoder.casino.CasinoUtilities.Console; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; + +public class Hand { + + private ArrayListcards; + + public Hand() { + cards = new ArrayList<>(); + } + + public void addCard(Card card){ + cards.add(card); + + } + public void removeCard(Card card){ + cards.remove(card); + } + + public void clear(){ + cards.clear(); + } + + public boolean hasCard(Card thisCard) { + + if (cards.contains(thisCard)) { + return true; + } + return false; + } + + public ArrayList getCards() { + return cards; + } + + public ArrayList orderCards() { + Collections.sort(cards); + + return cards; + } + + public void setCards (ArrayList someCards) { + this.cards = someCards; + } + + + public String showHand() { + StringBuilder cards = new StringBuilder(); + cards.append("Your Cards: "); + for(Card aCard: getCards()){ + cards.append(aCard.toString() + ", "); + } + return cards.toString(); + + } +} \ No newline at end of file diff --git a/src/main/java/io/zipcoder/casino/Game/diceGame/Craps/CrapsBet.java b/src/main/java/io/zipcoder/casino/Game/diceGame/Craps/CrapsBet.java new file mode 100644 index 00000000..af0c7fa4 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Game/diceGame/Craps/CrapsBet.java @@ -0,0 +1,57 @@ +package io.zipcoder.casino.Game.diceGame.Craps; + +import io.zipcoder.casino.TypeOfBet; + +public enum CrapsBet implements TypeOfBet { + + ///////Craps Bets///////// + PASS_LINE, + DO_NOT_PASS, + COME, + DO_NOT_COME, + ODDS, + PLACE_WIN, + PLACE_LOSE, + BIG_SIX, + BIG_EIGHT, + HARD_FOUR, + HARD_SIX, + HARD_EIGHT, + HARD_TEN, + FIELD, + ANY_SEVEN, + YO_ELEVEN, + ANY_CRAPS, + ACE_DEUCE, + ACES, + BOXCAR, + PASS_LINE_ODDS, + DO_NOT_PASS_ODDS, + COME_FOUR, + COME_FIVE, + COME_SIX, + COME_EIGHT, + COME_NINE, + COME_TEN, + DO_NOT_COME_FOUR, + DO_NOT_COME_FIVE, + DO_NOT_COME_SIX, + DO_NOT_COME_EIGHT, + DO_NOT_COME_NINE, + DO_NOT_COME_TEN, + HORN + + + +/* + public String toString(){ + return name().replaceAll("_", " "); + }*/ + + + + + + + +} diff --git a/src/main/java/io/zipcoder/casino/Game/diceGame/Craps/CrapsGame.java b/src/main/java/io/zipcoder/casino/Game/diceGame/Craps/CrapsGame.java new file mode 100644 index 00000000..7846ed00 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Game/diceGame/Craps/CrapsGame.java @@ -0,0 +1,1269 @@ +package io.zipcoder.casino.Game.diceGame.Craps; + + +import io.zipcoder.casino.CasinoUtilities.Console; +import io.zipcoder.casino.Game.diceGame.DiceGame; +import io.zipcoder.casino.House; +import io.zipcoder.casino.Profile; +import io.zipcoder.casino.TypeOfBet; + +import java.util.Arrays; + +public class CrapsGame extends DiceGame { + private int point; + boolean isComeOutPhase = true; + private CrapsPlayer currentPlayer; + private boolean newRound = true; + private boolean hardRoll = false; + + + public CrapsGame(Profile profile) { + this.currentPlayer = new CrapsPlayer(profile); + players.add(currentPlayer); + } + + public void comeOutPhase() { + Console.print(bar); + Console.print("The game is in the Come Out phase"); + this.printComePoints(); + this.printDontComePoints(); + int roll = this.getRollValue(); + if (isNatural(roll)) { + Console.print("You rolled a Natural"); + if(roll == 7){ + this.comeOutSevenPayouts(roll); + } + this.oneRollBetPayouts(roll); + this.rollIsNaturalPayout(); + this.newRound = true; + this.hardRoll = false; + this.turn(); + } else if (isCraps(roll)) { + Console.print("You rolled Craps"); + this.oneRollBetPayouts(roll); + this.rollIsCrapsPayout(roll); + this.newRound = true; + this.hardRoll = false; + this.turn(); + } else { + this.point = roll; + this.comeOutPointSetPayouts(roll); + Console.print("The game is entering the Point phase"); + Console.print("The point is set to: [" + this.point +"]"); + this.isComeOutPhase = false; + this.hardRoll = false; + this.turn(); + } + } + + public void pointPhase() { + Console.print(bar); + Console.print("The game is in the Point phase"); + Console.print("The Point is set to: [" + this.point + "]"); + this.printComePoints(); + this.printDontComePoints(); + int roll = this.getRollValue(); + if (roll == this.point) { + this.pointPhasePointMadePayouts(roll); + this.newRound = true; + Console.print("The game is entering the Come Out Phase"); + this.isComeOutPhase = true; + this.hardRoll = false; + this.turn(); + } else if (roll == 7) { + this.pointPhaseSevenPayouts(roll); + + this.newRound = true; + Console.print("The game is entering the Come Out Phase"); + this.isComeOutPhase = true; + this.hardRoll = false; + this.turn(); + } + else if(!isCraps(roll) && roll != 11){ + this.pointPhaseNotCrapsAndNotElevenPayouts(roll); + this.hardRoll = false; + this.turn(); + } + else { + this.pointPhaseRemainingPayouts(roll); + this.hardRoll = false; + this.turn(); + } + } + + public void turn() { + + String rollOrBet; + do { + Console.print(bar); + Console.print("Would you like to [roll] [bet] or [leave]?"); + rollOrBet = Console.getString(); + if (rollOrBet.equalsIgnoreCase("roll") && newRound) { + Console.print("You must make a Pass Line or Do Not Pass bet before starting a new round"); + this.turn(); + } else if (rollOrBet.equalsIgnoreCase("roll")) { + if (isComeOutPhase) { + this.comeOutPhase(); + } else { + this.pointPhase(); + } + } else if (rollOrBet.equalsIgnoreCase("bet")) { + Console.print(bar); + this.selectBet(); + } + else if(rollOrBet.equalsIgnoreCase("leave")){ + this.endGame(); + } + else { + Console.print(invalidInput); + } + } + while (!rollOrBet.equalsIgnoreCase("roll")); + } + + public void selectBet() { + boolean keepRunning = true; + do { + Console.print(this.printBettingMenu()); + Console.print("What type of bet would you like to place?"); + Console.print("Enter [stop] to finish betting"); + String textBet = Console.getString(); + keepRunning = this.chooseBet(textBet); + + } + while (keepRunning == true); + + } + + public boolean chooseBet(String textBet) { + boolean validBet; + TypeOfBet betType; + textBet = textBet.toLowerCase(); + switch (textBet) { + + case "stop": + return false; + + case "pass line": + if (!newRound && isInvalidBet(!currentPlayer.isPassLine() || !this.isComeOutPhase)) { + break; + } + betType = CrapsBet.PASS_LINE; + validBet = this.placeBet(betType); + if (validBet) { + currentPlayer.setPassLine(true); + newRound = false; + } + break; + + case "do not pass": + if (!newRound && isInvalidBet(currentPlayer.isPassLine() || !this.isComeOutPhase)) { + break; + } + betType = CrapsBet.DO_NOT_PASS; + validBet = this.placeBet(betType); + if (validBet) { + currentPlayer.setPassLine(false); + newRound = false; + } + break; + + case "pass line odds": + if (isInvalidBet(!currentPlayer.isPassLine() || this.isComeOutPhase)) { + break; + } + betType = CrapsBet.PASS_LINE_ODDS; + validBet = this.placeBet(betType); + if (validBet) { + currentPlayer.setOdds(true); + } + break; + + case "do not pass odds": + if (isInvalidBet(currentPlayer.isPassLine() || this.isComeOutPhase)) { + break; + } + betType = CrapsBet.DO_NOT_PASS_ODDS; + validBet = this.placeBet(betType); + if (validBet) { + currentPlayer.setOdds(true); + } + break; + + case "come": + if(isInvalidBet(currentPlayer.isDontCome() || this.isComeOutPhase)){ + break; + } + betType = CrapsBet.COME; + validBet = this.placeBet(betType); + if(validBet){ + currentPlayer.setCome(true); + } + break; + + case "do not come": + if(isInvalidBet(currentPlayer.isCome() || this.isComeOutPhase)){ + break; + } + betType = CrapsBet.DO_NOT_COME; + validBet = this.placeBet(betType); + if(validBet){ + currentPlayer.setDontCome(true); + } + break; + + case "big six": + betType = CrapsBet.BIG_SIX; + validBet = this.placeBet(betType); + if(validBet){ + currentPlayer.setBigSix(true); + } + break; + + case "big eight": + betType = CrapsBet.BIG_EIGHT; + validBet = this.placeBet(betType); + if(validBet){ + currentPlayer.setBigEight(true); + } + break; + + case "field": + betType = CrapsBet.FIELD; + validBet = this.placeBet(betType); + if(validBet){ + currentPlayer.setField(true); + } + break; + + case "hard four": + betType = CrapsBet.HARD_FOUR; + validBet = this.placeBet(betType); + if(validBet){ + currentPlayer.setHardFour(true); + } + break; + + case "hard six": + betType = CrapsBet.HARD_SIX; + validBet = this.placeBet(betType); + if(validBet){ + currentPlayer.setHardSix(true); + } + break; + + case "hard eight": + betType = CrapsBet.HARD_EIGHT; + validBet = this.placeBet(betType); + if(validBet){ + currentPlayer.setHardEight(true); + } + break; + + case "hard ten": + betType = CrapsBet.HARD_TEN; + validBet = this.placeBet(betType); + if(validBet){ + currentPlayer.setHardTen(true); + } + break; + + case "aces": + betType = CrapsBet.ACES; + validBet = this.placeBet(betType); + if(validBet){ + currentPlayer.setAces(true); + } + break; + + case "ace deuce": + betType = CrapsBet.ACE_DEUCE; + validBet = this.placeBet(betType); + if(validBet){ + currentPlayer.setAceDeuce(true); + } + break; + + case "yo eleven": + betType = CrapsBet.YO_ELEVEN; + validBet = this.placeBet(betType); + if(validBet){ + currentPlayer.setYoEleven(true); + } + break; + + case "boxcar": + betType = CrapsBet.BOXCAR; + validBet = this.placeBet(betType); + if(validBet){ + currentPlayer.setBoxcar(true); + } + break; + + case "horn": + betType = CrapsBet.HORN; + validBet = this.placeBet(betType); + if(validBet){ + currentPlayer.setHorn(true); + } + break; + + case "any seven": + betType = CrapsBet.ANY_SEVEN; + validBet = this.placeBet(betType); + if(validBet){ + currentPlayer.setAnySeven(true); + } + break; + + case "any craps": + betType = CrapsBet.ANY_CRAPS; + validBet = this.placeBet(betType); + if(validBet){ + currentPlayer.setAnyCraps(true); + } + break; + + default: + Console.print(invalidInput); + Console.print(bar); + } + return true; + } + + public boolean isInvalidBet(boolean betCondition) { + if (betCondition) { + Console.print("You cannot place that type of bet at this time"); + Console.print(bar); + return true; + } + return false; + } + + + public String printBettingMenu() { + StringBuilder bettingMenu = new StringBuilder("Here are the types of bets you can make: \n"); + if ((newRound || currentPlayer.isPassLine()) && this.isComeOutPhase) { + bettingMenu.append("[Pass Line] \n"); + } + if ((newRound || !currentPlayer.isPassLine()) && this.isComeOutPhase) { + bettingMenu.append("[Do Not Pass]\n"); + } + if ((newRound || currentPlayer.isPassLine()) && !this.isComeOutPhase) { + bettingMenu.append("[Pass Line Odds] \n"); + } + if ((newRound || !currentPlayer.isPassLine()) && !this.isComeOutPhase) { + bettingMenu.append("[Do Not Pass Odds]\n"); + } + if(!this.isComeOutPhase && !currentPlayer.isDontCome()){ + bettingMenu.append("[Come]\n"); + } + if(!this.isComeOutPhase && !currentPlayer.isCome()){ + bettingMenu.append("[Do Not Come]\n"); + } + bettingMenu.append("[Field]\n"); + bettingMenu.append("[Big Six]\n"); + bettingMenu.append("[Big Eight]\n"); + bettingMenu.append("[Hard Four]\n"); + bettingMenu.append("[Hard Six]\n"); + bettingMenu.append("[Hard Eight]\n"); + bettingMenu.append("[Hard Ten]\n"); + bettingMenu.append("[Aces]\n"); + bettingMenu.append("[Ace Deuce]\n"); + bettingMenu.append("[Yo Eleven]\n"); + bettingMenu.append("[Boxcar]\n"); + bettingMenu.append("[Horn]\n"); + bettingMenu.append("[Any Seven]\n"); + bettingMenu.append("[Any Craps]\n"); + return bettingMenu.toString(); + } + + public boolean placeBet(TypeOfBet betType) { + Double betAmount; + boolean keepRunning = true; + do { + Console.print(bar); + Console.print("Your current balance is: $" + currentPlayer.getProfile().getAccountBalance()); + Console.print("How much would you like to bet?"); + betAmount = Console.getDouble(); + if(betAmount >=0 && betAmount<0.01){ + Console.print("Cannot bet fractions of a cent. Please enter a valid bet"); + } + else if(betAmount >=0){ + keepRunning = false; + } + else if(betAmount == -0.001){ + continue; + } + else if(betAmount <0){ + Console.print("Cannot bet negative values. Please enter a valid bet"); + } + } + while(keepRunning); + boolean wasBetPlaced = currentPlayer.bet(betType, betAmount); + Console.print(bar); + Console.print(newBalance()); + return wasBetPlaced; + } + + public void rollIsNaturalPayout() { + if (currentPlayer.isPassLine()) { + Console.print("Your Pass Line bet pays even money!"); + currentPlayer.win(CrapsBet.PASS_LINE, 1); + Console.print(newBalance()); + } else if (!currentPlayer.isPassLine()) { + Console.print("Your Do Not Pass bet loses"); + currentPlayer.lose(CrapsBet.DO_NOT_PASS); + Console.print(newBalance()); + } + } + + public void rollIsCrapsPayout(int roll) { + if (currentPlayer.isPassLine()) { + Console.print("You Crapped Out"); + Console.print("Your Pass Line bet loses"); + currentPlayer.lose(CrapsBet.PASS_LINE); + Console.print(newBalance()); + } else if (!currentPlayer.isPassLine() && roll == 12) { + Console.print("Your Do Not Pass bet breaks even"); + currentPlayer.win(CrapsBet.DO_NOT_PASS, 0); + Console.print(newBalance()); + } else if (!currentPlayer.isPassLine()) { + Console.print("Your Do Not Pass bet pays even money!"); + currentPlayer.win(CrapsBet.DO_NOT_PASS, 1); + Console.print(newBalance()); + } + } + + public void passLinePayout() { + if (currentPlayer.isPassLine()) { + Console.print("Your made your Point!"); + Console.print("Your Pass Line bet pays even money!"); + currentPlayer.win(CrapsBet.PASS_LINE, 1); + Console.print(newBalance()); + } else if (!currentPlayer.isPassLine()) { + Console.print("The Point came before a 7"); + Console.print("Your Do Not Pass bet loses"); + currentPlayer.lose(CrapsBet.DO_NOT_PASS); + Console.print(newBalance()); + } + } + + public void doNotPassPayout() { + if (currentPlayer.isPassLine()) { + Console.print("A 7 came before the Point"); + Console.print("You Sevened Out"); + Console.print("Your Pass Line bet loses"); + currentPlayer.lose(CrapsBet.PASS_LINE); + Console.print(newBalance()); + } else if (!currentPlayer.isPassLine()) { + Console.print("A 7 came before the Point!"); + Console.print("Your Do Not Pass bet pays even money!"); + currentPlayer.win(CrapsBet.DO_NOT_PASS, 1); + Console.print(newBalance()); + } + + } + + public void passLineOddsPayout(int roll){ + if(roll == 4 || roll == 10){ + Console.print("Your Pass Line Odds bet pays 2:1!"); + currentPlayer.win(CrapsBet.PASS_LINE_ODDS, 2); + Console.print(newBalance()); + } + else if(roll == 5 || roll == 9){ + Console.print("Your Pass Line Odds bet pays 3:2!"); + currentPlayer.win(CrapsBet.PASS_LINE_ODDS, 1.5); + Console.print(newBalance()); + } + else if(roll == 6 || roll == 8){ + Console.print("Your Pass Line Odds bet pays 6:5!"); + currentPlayer.win(CrapsBet.PASS_LINE_ODDS, 1.2); + Console.print(newBalance()); + } + else{ + Console.print("Your Pass Line Odds bet loses"); + currentPlayer.lose(CrapsBet.PASS_LINE_ODDS); + Console.print(newBalance()); + } + } + + public void doNotPassOddsPayout(int point){ + if(point == 4 || point == 10){ + Console.print("Your Do Not Pass Odds bet pays 1:2!"); + currentPlayer.win(CrapsBet.DO_NOT_PASS_ODDS, .5); + Console.print(newBalance()); + } + else if(point == 5 || point == 9){ + Console.print("Your Do Not Pass Odds bet pays 2:3!"); + currentPlayer.win(CrapsBet.DO_NOT_PASS_ODDS, .66); + Console.print(newBalance()); + } + else if(point == 6 || point == 8){ + Console.print("Your Do Not Pass Odds bet pays 5:6!"); + currentPlayer.win(CrapsBet.DO_NOT_PASS_ODDS, .83); + Console.print(newBalance()); + } + else{ + Console.print("Your Do Not Pass Odds bet loses"); + currentPlayer.lose(CrapsBet.DO_NOT_PASS_ODDS); + Console.print(newBalance()); + } + + } + + public void comeNaturalPayout(int roll){ + if(currentPlayer.isCome() && isNatural(roll)){ + Console.print("Your Come bet pays even money!"); + currentPlayer.win(CrapsBet.COME,1); + Console.print(newBalance()); + currentPlayer.setCome(false); + } + else if(currentPlayer.isDontCome() && isNatural(roll)){ + Console.print("Your Do Not Come bet loses"); + currentPlayer.lose(CrapsBet.DO_NOT_COME); + Console.print(newBalance()); + currentPlayer.setDontCome(false); + } + + } + + public void doNotComeCrapsPayout(int roll){ + if(currentPlayer.isDontCome() && (roll == 2 || roll == 3)){ + Console.print("Your Do Not Come bet wins even money!"); + currentPlayer.win(CrapsBet.DO_NOT_COME, 1); + Console.print(newBalance()); + currentPlayer.setDontCome(false); + } + else if(currentPlayer.isDontCome() && roll == 12){ + Console.print("Your Do Not Come bet breaks even"); + currentPlayer.win(CrapsBet.DO_NOT_COME, 0); + Console.print(newBalance()); + currentPlayer.setDontCome(false); + } + else if(currentPlayer.isCome() && isCraps(roll)){ + Console.print("Your Come bet loses"); + currentPlayer.lose(CrapsBet.COME); + Console.print(newBalance()); + currentPlayer.setCome(false); + } + + } + + public void changeComeBet(int roll){ + double betValue; + switch(roll){ + + case 4: + betValue = currentPlayer.getEscrowBet(CrapsBet.COME); + currentPlayer.setEscrow(CrapsBet.COME,0); + currentPlayer.setEscrow(CrapsBet.COME_FOUR, betValue); + break; + + case 5: + betValue = currentPlayer.getEscrowBet(CrapsBet.COME); + currentPlayer.setEscrow(CrapsBet.COME,0); + currentPlayer.setEscrow(CrapsBet.COME_FIVE, betValue); + break; + + case 6: + betValue = currentPlayer.getEscrowBet(CrapsBet.COME); + currentPlayer.setEscrow(CrapsBet.COME,0); + currentPlayer.setEscrow(CrapsBet.COME_SIX, betValue); + break; + + case 8: + betValue = currentPlayer.getEscrowBet(CrapsBet.COME); + currentPlayer.setEscrow(CrapsBet.COME,0); + currentPlayer.setEscrow(CrapsBet.COME_EIGHT, betValue); + break; + + case 9: + betValue = currentPlayer.getEscrowBet(CrapsBet.COME); + currentPlayer.setEscrow(CrapsBet.COME,0); + currentPlayer.setEscrow(CrapsBet.COME_NINE, betValue); + break; + + case 10: + betValue = currentPlayer.getEscrowBet(CrapsBet.COME); + currentPlayer.setEscrow(CrapsBet.COME,0); + currentPlayer.setEscrow(CrapsBet.COME_TEN, betValue); + break; + + } + + } + + public void setComePoint(int roll){ + currentPlayer.getComePoints().add(roll); + } + + public void changeDontComeBet(int roll){ + double betValue; + switch(roll){ + + case 4: + betValue = currentPlayer.getEscrowBet(CrapsBet.DO_NOT_COME); + currentPlayer.setEscrow(CrapsBet.DO_NOT_COME,0); + currentPlayer.setEscrow(CrapsBet.DO_NOT_COME_FOUR, betValue); + break; + + case 5: + betValue = currentPlayer.getEscrowBet(CrapsBet.DO_NOT_COME); + currentPlayer.setEscrow(CrapsBet.DO_NOT_COME,0); + currentPlayer.setEscrow(CrapsBet.DO_NOT_COME_FIVE, betValue); + break; + + case 6: + betValue = currentPlayer.getEscrowBet(CrapsBet.DO_NOT_COME); + currentPlayer.setEscrow(CrapsBet.DO_NOT_COME,0); + currentPlayer.setEscrow(CrapsBet.DO_NOT_COME_SIX, betValue); + break; + + case 8: + betValue = currentPlayer.getEscrowBet(CrapsBet.DO_NOT_COME); + currentPlayer.setEscrow(CrapsBet.DO_NOT_COME,0); + currentPlayer.setEscrow(CrapsBet.DO_NOT_COME_EIGHT, betValue); + break; + + case 9: + betValue = currentPlayer.getEscrowBet(CrapsBet.DO_NOT_COME); + currentPlayer.setEscrow(CrapsBet.DO_NOT_COME,0); + currentPlayer.setEscrow(CrapsBet.DO_NOT_COME_NINE, betValue); + break; + + case 10: + betValue = currentPlayer.getEscrowBet(CrapsBet.DO_NOT_COME); + currentPlayer.setEscrow(CrapsBet.DO_NOT_COME,0); + currentPlayer.setEscrow(CrapsBet.DO_NOT_COME_TEN, betValue); + break; + + } + + } + + public void setDontComePoint(int roll){ + currentPlayer.getDontComePoints().add(roll); + } + + public void newComePoint(int roll){ + if(currentPlayer.isCome()){ + this.changeComeBet(roll); + this.setComePoint(roll); + currentPlayer.setCome(false); + Console.print("You have a new Come Point: [" + roll +"]"); + } + } + + public void newDontComePoint(int roll){ + if(currentPlayer.isDontCome()){ + this.changeDontComeBet(roll); + this.setDontComePoint(roll); + currentPlayer.setDontCome(false); + Console.print("You have a new Do Not Come Point: [" + roll +"]"); + } + } + + public void comePointPayout(int roll){ + if(currentPlayer.hasComePoints()){ + if(currentPlayer.getComePoints().contains(roll)){ + Console.print("You made your Come Point before a 7 was rolled!"); + Console.print("Your Come bet on [" + roll + "] pays even money!"); + currentPlayer.win(intToComePoint(roll), 1); + currentPlayer.removeComePoint(roll); + Console.print(newBalance()); + } + else if(roll == 7){ + Console.print("A 7 came before your Come Point"); + for(int i = 0; i>"); + if(rawRoll[0] == rawRoll[1]){ + this.hardRoll = true; + } + return sum; + } + + public void setHardRoll(boolean input){ + this.hardRoll = input; + } + + public static boolean isCraps(int rollValue) { + if (rollValue == 2 || rollValue == 3 || rollValue == 12) { + return true; + } else { + return false; + } + } + + public static boolean isNatural(int rollValue) { + if (rollValue == 7 || rollValue == 11) { + return true; + } else { + return false; + } + + } + + public int getPoint() { + return this.point; + } + + @Override + public void startGame() { + this.createDie(6, 2); + this.point = 0; + Console.print(bar); + Console.print("Welcome to Craps " + currentPlayer.getProfile().getName()); + Console.print("You currently have $" + currentPlayer.getProfile().getAccountBalance() +" to gamble with"); + Console.print("Your private game of Craps is starting now!"); + this.turn(); + } + + @Override + public void endGame(){ + boolean keepRunning = true; + Console.print("Are you sure you want to leave Craps?"); + Console.print("[Yes] [No]"); + Console.print("Any outstanding bets will be lost"); + do { + String choice = Console.getString(); + if (choice.equalsIgnoreCase("yes")) { + Console.print("Thanks for playing Craps at Casino Royale With Cheese!"); + Console.print(bar); + keepRunning = false; + House.INSTANCE.gameSelection(); + } else if (choice.equalsIgnoreCase("no")) { + keepRunning = false; + this.turn(); + } else { + Console.print("Invalid response: please enter your answer again"); + } + } + while(keepRunning); + + } + + public CrapsPlayer getCurrentPlayer() { + return this.currentPlayer; + } + + + private String invalidInput = "Invalid input: please enter your choice again"; + private String bar = "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"; + + public String newBalance() { + return "Your new balance is: $" + currentPlayer.getProfile().getAccountBalance(); + } +} diff --git a/src/main/java/io/zipcoder/casino/Game/diceGame/Craps/CrapsPlayer.java b/src/main/java/io/zipcoder/casino/Game/diceGame/Craps/CrapsPlayer.java new file mode 100644 index 00000000..e11a29ee --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Game/diceGame/Craps/CrapsPlayer.java @@ -0,0 +1,278 @@ +package io.zipcoder.casino.Game.diceGame.Craps; + + +import io.zipcoder.casino.*; +import io.zipcoder.casino.CasinoUtilities.Console; + +import java.util.ArrayList; + +public class CrapsPlayer extends Player implements Gambler { + + private boolean passLine; + private boolean odds; + private boolean come; + private boolean dontCome; + private boolean bigSix; + private boolean bigEight; + private boolean field; + private boolean hardFour; + private boolean hardSix; + private boolean hardEight; + private boolean hardTen; + private boolean aces; + private boolean aceDeuce; + private boolean yoEleven; + private boolean boxcar; + private boolean horn; + private boolean anySeven; + private boolean anyCraps; + private ArrayList comePoints; + private ArrayList dontComePoints; + + private Escrow playerEscrow; + + + + public CrapsPlayer(Profile someProfile) { + + super(someProfile); + this.playerEscrow = new Escrow(); + this.comePoints = new ArrayList(0); + this.dontComePoints = new ArrayList(0); + + } + + + public boolean bet(TypeOfBet typeOfBet, double amount) { + double accountBalance = this.getProfile().getAccountBalance(); + + if (accountBalance < amount) { + Console.print("Insufficient funds : cannot place bet"); + return false; + } + else if (this.escrowContains(typeOfBet)) { + double escrowBalance = this.getEscrowBet(typeOfBet); + this.getProfile().setAccountBalance(accountBalance - amount); + this.setEscrow(typeOfBet, amount + escrowBalance); + return true; + } + else { + this.getProfile().setAccountBalance(accountBalance - amount); + this.setEscrow(typeOfBet, amount); + return true; + } + + } + + public void win(TypeOfBet typeOfBet, double payoutMultiplier) { + double accountBalance = this.getProfile().getAccountBalance(); + double escrow = this.getEscrowBet(typeOfBet); + double winnings = escrow + (escrow * payoutMultiplier); + + this.getProfile().setAccountBalance(accountBalance+ winnings); + this.setEscrow(typeOfBet,0); + } + + public void lose(TypeOfBet typeOfBet) { + this.setEscrow(typeOfBet, 0); + } + + public void setEscrow(TypeOfBet typeOfBet, double incomingBet){ + this.playerEscrow.getEscrow().put(typeOfBet, incomingBet); + } + + + public double getEscrowBet(TypeOfBet typeOfBet){ + return this.playerEscrow.getEscrow().get(typeOfBet); + } + + public boolean escrowContains(TypeOfBet typeOfBet){ + return playerEscrow.getEscrow().containsKey(typeOfBet) ; + } + + public boolean isPassLine() { + return this.passLine; + } + + public void setPassLine(boolean input) { + this.passLine = input; + + } + + public void setOdds(boolean input){ + this.odds = input; + } + + public boolean hasOdds(){ + return this.odds; + } + public void setCome(boolean input){ + this.come = input; + } + public boolean isCome(){ + return this.come; + } + + public void setDontCome(boolean input){ + this.dontCome=input; + } + + public boolean isDontCome(){ + return this.dontCome; + } + + public ArrayList getComePoints(){ + return this.comePoints; + } + + public ArrayList getDontComePoints(){ + return this.dontComePoints; + } + + public void addComePoint(Integer point){ + this.comePoints.add(point); + } + + public void removeComePoint(Integer point){ + this.comePoints.remove(point); + } + + public void addDontComePoint(Integer point){ + this.dontComePoints.add(point); + } + + public void removeDontComePoint(Integer point){ + this.dontComePoints.remove(point); + } + + public boolean hasComePoints(){ + if (this.comePoints.size()>0){ + return true; + } + else{ + return false; + } + } + + public boolean hasDontComePoints(){ + if (this.dontComePoints.size()>0){ + return true; + } + else{ + return false; + } + } + + public void setBigSix(boolean input){ + this.bigSix = input; + } + + public boolean isBigSix(){ + return this.bigSix; + } + + public void setBigEight(boolean input){ + this.bigEight = input; + } + + public boolean isBigEight(){ + return this.bigEight; + } + + public void setField(boolean input){ + this.field = input; + } + + public boolean isField(){ + return this.field; + } + + public void setHardFour(boolean input){ + this.hardFour = input; + } + + public boolean isHardFour(){ + return this.hardFour; + } + public void setHardSix(boolean input){ + this.hardSix = input; + } + + public boolean isHardSix(){ + return this.hardSix; + } + + public void setHardEight(boolean input){ + this.hardEight = input; + } + + public boolean isHardEight(){ + return this.hardEight; + } + + public void setHardTen(boolean input){ + this.hardTen = input; + } + + public boolean isHardTen(){ + return this.hardTen; + } + + public void setAces(boolean input){ + this.aces = input; + } + + public boolean isAces(){ + return this.aces; + } + + public void setAceDeuce(boolean input){ + this.aceDeuce = input; + } + + public boolean isAceDeuce(){ + return this.aceDeuce; + } + + public void setYoEleven(boolean input){ + this.yoEleven = input; + } + + public boolean isYoEleven(){ + return this.yoEleven; + } + + public void setBoxcar(boolean input){ + this.boxcar = input; + } + + public boolean isBoxcar(){ + return this.boxcar; + } + + public void setHorn(boolean input){ + this.horn = input; + } + + public boolean isHorn(){ + return this.horn; + } + + public void setAnySeven(boolean input){ + this.anySeven = input; + } + + public boolean isAnySeven(){ + return this.anySeven; + } + + public void setAnyCraps(boolean input){ + this.anyCraps = input; + } + + public boolean isAnyCraps(){ + return this.anyCraps; + } + + +} diff --git a/src/main/java/io/zipcoder/casino/Game/diceGame/DiceGame.java b/src/main/java/io/zipcoder/casino/Game/diceGame/DiceGame.java new file mode 100644 index 00000000..d0f6d018 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Game/diceGame/DiceGame.java @@ -0,0 +1,75 @@ +package io.zipcoder.casino.Game.diceGame; + + +import io.zipcoder.casino.CasinoUtilities.Console; +import io.zipcoder.casino.Game.Game; +import io.zipcoder.casino.Player; + +import java.util.ArrayList; + + +abstract public class DiceGame implements Game { + protected Die[] dice; + protected ArrayList players; + + + + public DiceGame() { + players = new ArrayList(); + } + + public void createDie(int faces, int number){ + Die[] diceToCreate = new Die[number]; + for (int i = 0; i< number; i++){ + diceToCreate[i] = new Die(faces); + } + this.dice = diceToCreate; + } + + public Die[] getDice(){ + return this.dice; + } + + public int[] rollDice(){ + int [] rollResult = new int[dice.length]; + for(int i = 0; i < dice.length; i++){ + rollResult[i] = dice[i].rollDie(); + } + return rollResult; + } + + public void addPlayer(Player player){ + if(players.contains(player)){ + Console.print("Error: Player already added to game - cannot add duplicate players"); + } + else{ + players.add(player); + } + + } + public void removePlayer (Player player){ + if(!players.contains(player)){ + Console.print("Error: Player not in game - cannot remove nonexistent player"); + } + else{ + players.remove(player); + } + + } + + public ArrayList getPlayers() { + return this.players; + } + + //TODO: implement methods later once functionality is better understood + public void startGame(){ + + } + public void endGame(){ + + } + public String getRules(){ + return null; + } + +} diff --git a/src/main/java/io/zipcoder/casino/Game/diceGame/Die.java b/src/main/java/io/zipcoder/casino/Game/diceGame/Die.java new file mode 100644 index 00000000..0643c931 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Game/diceGame/Die.java @@ -0,0 +1,21 @@ +package io.zipcoder.casino.Game.diceGame; + +import java.util.Random; + +public class Die { + private int numberOfFaces; + private Random roller = new Random(); + + public Die(int numberOfFaces) { + this.numberOfFaces = numberOfFaces; + } + + public int getNumberOfFaces() { + return this.numberOfFaces; + } + + public int rollDie(){ + return roller.nextInt(numberOfFaces) +1; + } + +} diff --git a/src/main/java/io/zipcoder/casino/House.java b/src/main/java/io/zipcoder/casino/House.java new file mode 100644 index 00000000..7108fbbf --- /dev/null +++ b/src/main/java/io/zipcoder/casino/House.java @@ -0,0 +1,157 @@ +package io.zipcoder.casino; + +import io.zipcoder.casino.CasinoUtilities.Console; +import io.zipcoder.casino.Game.Game; +import io.zipcoder.casino.Game.cardGame.BLackJack.BlackJackGame; +import io.zipcoder.casino.Game.cardGame.BLackJack.BlackJackPlayer; +import io.zipcoder.casino.Game.cardGame.CardGame; +import io.zipcoder.casino.Game.cardGame.GoFIsh.GoFish; +import io.zipcoder.casino.Game.diceGame.Craps.CrapsGame; +import io.zipcoder.casino.Game.diceGame.DiceGame; + +import java.util.ArrayList; +import java.util.HashMap; + +public class House implements MainMenu { + public static final House INSTANCE = new House(); + public static final Profile HOUSE_PROFILE = new Profile("Dealer", 0, 1); + private Profile profile; + private ArrayList profiles; + private Profile currentPlayer; + private double initialBalance; + + public House() { + profiles = new ArrayList<>(); + } + + public Profile getProfileById(int id) { + for (Profile profile : profiles) { + if (profile.getId() == id) { + return profile; + } + } + return null; + } + + + + public void createProfile(String name) { + createProfile(name, 0, profiles.size() + 1); + } + + public void createProfile(String name, double balance) { + createProfile(name, balance, profiles.size() + 1); + } + + + public void createProfile(String name, double balance, int id) { + profile = new Profile(name, balance, id); + createProfile(profile); + } + + public void createProfile(Profile profile) { + Console.print("Registering a new profile..."); + profiles.add(profile); + Console.print(""); + } + + public Profile selectExistingProfile(String name) { + for (Profile profile : profiles) { + if (profile.getName().equals(name)) { + return profile; + } + } + return null; + } + + public void removeProfile(int id) { + profiles.remove(id); + Console.print("Profle was removed"); + } + + public void startCasino(){ + Console.print("Welcome to Casino Royale With Cheese!"); + Console.print("What is your name?"); + String profileName = Console.getString(); + Console.print("How much money do you want to deposit with the house?"); + Console.print("The minimum deposit is $100"); + Double accountBalance = this.intakeBalance(); + initialBalance = accountBalance; + createProfile(profileName,accountBalance); + currentPlayer = getProfileById(profiles.size()); + this.gameSelection(); + } + + public void gameSelection(){ + Console.print("Hello " + currentPlayer.getName()); + Console.print("You have $" + currentPlayer.getAccountBalance() + " to gamble with"); + Console.print("What game would you like to play?"); + Console.print("[Craps]"); + Console.print("[Black Jack]"); + Console.print("[Go Fish]"); + Console.print("Enter [leave] to cash out and go home"); + boolean keepRunning = true; + do{ + String userInput = Console.getString(); + if(userInput.equalsIgnoreCase("craps")){ + CrapsGame newGame = new CrapsGame(currentPlayer); + newGame.startGame(); + break; + } + else if(userInput.equalsIgnoreCase("black jack")){ + BlackJackGame newGame = new BlackJackGame(currentPlayer); + newGame.startGame(); + break; + } + else if(userInput.equalsIgnoreCase("go fish")){ + GoFish newGame = new GoFish(currentPlayer); + newGame.playGame(); + break; + } + else if(userInput.equalsIgnoreCase("leave")){ + Console.print("Goodbye " + currentPlayer.getName()); + Console.print("You're leaving our casino with $" + currentPlayer.getAccountBalance()); + if(currentPlayer.getAccountBalance()>initialBalance){ + Console.print("That's $" + (currentPlayer.getAccountBalance()-initialBalance) + " more than you came here with!"); + Console.print("Great job! Come again soon!"); + System.exit(0); + } + else if (currentPlayer.getAccountBalance()= 0 && accountBalance < 100) { + Console.print("Cannot deposit less than the minimum. Please enter a valid deposit"); + } else if (accountBalance >= 100) { + return accountBalance; + } else if (accountBalance == -0.001) { + continue; + + } else if (accountBalance < 0) { + Console.print("Cannot deposit negative values. Please enter a valid deposit"); + } + } + while (keepRunning == true); + + return 0d; + } + +} diff --git a/src/main/java/io/zipcoder/casino/MainMenu.java b/src/main/java/io/zipcoder/casino/MainMenu.java new file mode 100644 index 00000000..00ee8c59 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/MainMenu.java @@ -0,0 +1,12 @@ +package io.zipcoder.casino; + +import io.zipcoder.casino.Game.cardGame.CardGame; +import io.zipcoder.casino.Game.diceGame.DiceGame; + +public interface MainMenu { + public void createProfile(String name, double balance); + public Profile selectExistingProfile(String nameOfPlayer); + public void removeProfile(int id); + public void startCasino(); + public void gameSelection(); +} diff --git a/src/main/java/io/zipcoder/casino/Player.java b/src/main/java/io/zipcoder/casino/Player.java new file mode 100644 index 00000000..95cc5368 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Player.java @@ -0,0 +1,23 @@ +package io.zipcoder.casino; + +public class Player { + + private Profile playerProfile; + + public Player(Profile someProfile) { + this.playerProfile = someProfile; + } + + public Player() { + + } + + public void setProfile(Profile someProfile) { + this.playerProfile = someProfile; + } + + // method mostly used for testing purposes + public Profile getProfile() { + return playerProfile; + } +} diff --git a/src/main/java/io/zipcoder/casino/Profile.java b/src/main/java/io/zipcoder/casino/Profile.java new file mode 100644 index 00000000..a8e6174e --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Profile.java @@ -0,0 +1,49 @@ +package io.zipcoder.casino; + + +import java.util.HashMap; + +public class Profile { + private String name; + private double accountBalance; + private int id; + + + public Profile(String name, double accountBalance, int id) { + this.name = name; + this.accountBalance = accountBalance; + this.id = id; + } + + public String getName() { + return name; + } + + public double getAccountBalance() { + return accountBalance; + } + + + public void setName(String name) { + this.name = name; + } + + public void setAccountBalance(double accountBalance) { + this.accountBalance = accountBalance; + } + + public void setId(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(" " + name +" " + "Your Account Balance is: $ " +accountBalance); + return sb.toString(); + } +} diff --git a/src/test/java/io/zipcoder/casino/CasinoTest.java b/src/main/java/io/zipcoder/casino/TypeOfBet.java similarity index 51% rename from src/test/java/io/zipcoder/casino/CasinoTest.java rename to src/main/java/io/zipcoder/casino/TypeOfBet.java index e9286523..86fd22ea 100644 --- a/src/test/java/io/zipcoder/casino/CasinoTest.java +++ b/src/main/java/io/zipcoder/casino/TypeOfBet.java @@ -1,5 +1,4 @@ package io.zipcoder.casino; - -public class CasinoTest { +public interface TypeOfBet { } diff --git a/src/test/java/io/zipcoder/casinotest/test/GameTest/cardGameTest/BlackJackTest/BlackJackGameTest.java b/src/test/java/io/zipcoder/casinotest/test/GameTest/cardGameTest/BlackJackTest/BlackJackGameTest.java new file mode 100644 index 00000000..c9926968 --- /dev/null +++ b/src/test/java/io/zipcoder/casinotest/test/GameTest/cardGameTest/BlackJackTest/BlackJackGameTest.java @@ -0,0 +1,198 @@ +package io.zipcoder.casinotest.test.GameTest.cardGameTest.BlackJackTest; + +import io.zipcoder.casino.Game.cardGame.BLackJack.BlackJackBet; +import io.zipcoder.casino.Game.cardGame.BLackJack.BlackJackGame; +import io.zipcoder.casino.Game.cardGame.BLackJack.BlackJackPlayer; +import io.zipcoder.casino.Game.cardGame.utilities.Card; +import io.zipcoder.casino.Game.cardGame.utilities.CardRank; +import io.zipcoder.casino.Game.cardGame.utilities.Deck; +import io.zipcoder.casino.Game.cardGame.utilities.Hand; +import io.zipcoder.casino.Profile; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class BlackJackGameTest { + private Deck testDeck; + private Hand testHand; + private Profile testPlayerProfile; + private BlackJackPlayer testPlayer; + private BlackJackPlayer testDealer; + private BlackJackGame testBlackJackGAme; + + @Before + public void setUp() throws Exception { + testDeck = new Deck(); + testHand = new Hand(); + + testPlayerProfile = new Profile("name", 1000.0, 1); + testBlackJackGAme = new BlackJackGame(testPlayerProfile); + testPlayer = new BlackJackPlayer(testPlayerProfile); + testDealer = new BlackJackPlayer(null); + testDeck = testBlackJackGAme.getDeck(); + } + + @Test + public void dealTest() { + testBlackJackGAme.deal(testPlayer); + int expected = 46; + int actual = testBlackJackGAme.getDeck().countRemainingCards(); + Assert.assertEquals(expected, actual); + } + + //How can I write this test to not have if else statements? + //create a cleaner method retrieve cardValues; + @Test + public void countAcesInHandTest(){ + Card card1 = testDeck.getCard(); + Card card2 = testDeck.getCard(); + testPlayer.getHand().addCard(card1); + testPlayer.getHand().addCard(card2); + int expected = 0; + if(card1.getRank() == CardRank.ACE){ + expected++; + } + else if(card2.getRank() == CardRank.ACE){ + expected++; + } + int actual = testBlackJackGAme.countAcesInHand(testPlayer); + + Assert.assertEquals(expected, actual); + } + + @Test + public void turnChoice1Test() { + testPlayer.bet(BlackJackBet.INTIAL_BET, 500); + double expectecd = 500; + double actual = testPlayer.getProfile().getAccountBalance(); + + Assert.assertEquals(expectecd, actual, .001); + } + + + @Test + public void hitTest() { + testBlackJackGAme.hit(testPlayer); + int expected = 1; + int actual = testPlayer.getHand().getCards().size(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void currentScoreTest() { + Card cardToScore = testDeck.getCard(); + Card card1 = testDeck.getCard(); + testPlayer.getHand().addCard(card1); + + //updates score of first card addeded + testBlackJackGAme.updateScore(card1, testPlayer); + // adds another card to hand + testPlayer.getHand().addCard(cardToScore); + + + int expected = card1.getRank().getCardValue() + cardToScore.getRank().getCardValue(); + // updates score to reflect second card added + int actual = Integer.valueOf(testBlackJackGAme.updateScore(cardToScore, testPlayer)); + + Assert.assertEquals(expected, actual); + } + + @Test + public void standTest() { + //isStood changes to true; + //currentPlayer changes to dealer + boolean expected = true; + boolean actual = testBlackJackGAme.stand(testPlayer); + + Assert.assertEquals(expected, actual); + } + + @Test + public void splitTest() { + // if both cards delt are same then player can choose to split + // + } + + @Test + public void bustedTest() { + testBlackJackGAme.dealACard(testPlayer); + testBlackJackGAme.dealACard(testPlayer); + testBlackJackGAme.dealACard(testPlayer); + boolean expected; + if (testPlayer.getScore() > 21) { + expected = true; + } else { + expected = false; + } + boolean actual = testBlackJackGAme.isBusted(testPlayer); + + Assert.assertEquals(expected, actual); + } + + @Test + public void dealACardTest() { + int actual = testBlackJackGAme.dealACard(testPlayer); + int expected = testPlayer.getScore(); + Assert.assertEquals(expected, actual); + } + +/* + @Test + public void roundTest() { + + }*/ +/* + @Test + public void dealerBehaviorTest() { + // if dealer score is less than 17 a dealer must be dealt a card + Card cardToScore = testDeck.getCard(); + Card card1 = testDeck.getCard(); + testDealer.getHand().addCard(card1); + //updates score of first card addeded + testBlackJackGAme.updateScore(card1, testDealer); + testBlackJackGAme.updateScore(cardToScore, testDealer); + + boolean expected = true; + //boolean actual = testBlackJackGAme.dealerBehavior(); + + //Assert.assertEquals(expected, actual); + }*/ + + + + // need to get find way to fill expected String + /*@Test + public void showDealerTopCardTEst() { + testBlackJackGAme.deal(testPlayer); + + + String expected = ""; + String actual = testBlackJackGAme.showDealersFaceCard(); + + Assert.assertEquals(expected, actual); + }*/ + + @Test + public void showListOfPlayerActionsTest() { + String expected = "Choose Action: [Bet], [Hit], [Stand]"; + String actual = testBlackJackGAme.showListOfPlayerActions(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void isBlackJackIntialHandTest(){ + testBlackJackGAme.dealACard(testPlayer); + testBlackJackGAme.dealACard(testPlayer); + boolean expected = false; + if(testPlayer.getScore() == 21){ + expected = true; + } + boolean actual = testBlackJackGAme.isBlackJack(testPlayer); + + Assert.assertEquals(expected, actual); + } + + +} diff --git a/src/test/java/io/zipcoder/casinotest/test/GameTest/cardGameTest/BlackJackTest/BlackJackPlayerTest.java b/src/test/java/io/zipcoder/casinotest/test/GameTest/cardGameTest/BlackJackTest/BlackJackPlayerTest.java new file mode 100644 index 00000000..283e04ae --- /dev/null +++ b/src/test/java/io/zipcoder/casinotest/test/GameTest/cardGameTest/BlackJackTest/BlackJackPlayerTest.java @@ -0,0 +1,87 @@ +package io.zipcoder.casinotest.test.GameTest.cardGameTest.BlackJackTest; + + +import io.zipcoder.casino.Game.cardGame.BLackJack.BlackJackBet; +import io.zipcoder.casino.Game.cardGame.BLackJack.BlackJackPlayer; +import io.zipcoder.casino.Profile; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class BlackJackPlayerTest { + + Profile testProfile; + BlackJackPlayer testBlackJackPlayer; + + + @Before + public void setup() { + testProfile = new Profile("Lucky", 100000, 0); + testBlackJackPlayer = new BlackJackPlayer(testProfile); + } + + @Test + public void getHasStoodTest1() { + boolean actual = testBlackJackPlayer.getHasStood(); + Assert.assertFalse(actual); + } + + @Test + public void getHasStoodTest2() { + boolean stoodStatus = true; + testBlackJackPlayer.setHasStood(stoodStatus); + boolean actual = testBlackJackPlayer.getHasStood(); + Assert.assertTrue(actual); + } + + @Test + public void getIsBustedTest1() { + boolean actual = testBlackJackPlayer.getIsBusted(); + Assert.assertFalse(actual); + } + + @Test + public void getIsBustedTest2() { + boolean bustedStatus = true; + testBlackJackPlayer.setIsBusted(bustedStatus); + boolean actual = testBlackJackPlayer.getIsBusted(); + Assert.assertTrue(actual); + } + + @Test + public void betTest1() { + double betAmount = 100; + testBlackJackPlayer.bet(BlackJackBet.EVEN_BET,betAmount); + double expected = 99900; + double actual = testProfile.getAccountBalance(); + } + + @Test + public void betTest2() { + double betAmount = 500; + + + } + + @Test + public void winTest1() { + + } + + @Test + public void winTest2() { + + } + + @Test + public void loseTest1() { + + } + + @Test + public void loseTest2() { + + } + + +} diff --git a/src/test/java/io/zipcoder/casinotest/test/GameTest/cardGameTest/GoFishTest/GoFishPlayerTest.java b/src/test/java/io/zipcoder/casinotest/test/GameTest/cardGameTest/GoFishTest/GoFishPlayerTest.java new file mode 100644 index 00000000..2b6e29be --- /dev/null +++ b/src/test/java/io/zipcoder/casinotest/test/GameTest/cardGameTest/GoFishTest/GoFishPlayerTest.java @@ -0,0 +1,108 @@ +package io.zipcoder.casinotest.test.GameTest.cardGameTest.GoFishTest; + +import io.zipcoder.casino.Game.cardGame.GoFIsh.GoFishPlayer; +import io.zipcoder.casino.Game.cardGame.utilities.Card; +import io.zipcoder.casino.Game.cardGame.utilities.CardRank; +import io.zipcoder.casino.Game.cardGame.utilities.CardSuit; +import io.zipcoder.casino.Game.cardGame.utilities.Hand; +import io.zipcoder.casino.Profile; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class GoFishPlayerTest { + + Profile testProfile; + GoFishPlayer testGoFishPlayer; + + @Before + public void setUp() { + testProfile = new Profile("Kibret",5000, 0); + testGoFishPlayer = new GoFishPlayer(testProfile); + } + + + @Test + public void testBuildBook1(){ + Hand aHand = new Hand(); + testGoFishPlayer.setHand(aHand); + Card firstCard = new Card(CardSuit.HEARTS, CardRank.JACK); + Card secondCard = new Card(CardSuit.DIAMONDS,CardRank.TWO); + Card thirdCard = new Card(CardSuit.SPADES,CardRank.JACK); + testGoFishPlayer.getHand().getCards().add(firstCard); + testGoFishPlayer.getHand().getCards().add(secondCard); + testGoFishPlayer.getHand().getCards().add(thirdCard); + + int expected = 2; + testGoFishPlayer.buildBooks(testGoFishPlayer,CardRank.JACK); + int actual=testGoFishPlayer.getBook().size(); + + Assert.assertEquals(expected,actual); + + + } + + @Test + public void testBuildBook2(){ + Hand aHand = new Hand(); + Hand hand2=new Hand(); + Profile profile2 = new Profile("aaa",1000,100); + GoFishPlayer testGoFishPlayer2 = new GoFishPlayer(profile2); + testGoFishPlayer2.setHand(hand2); + + testGoFishPlayer.setHand(aHand); + Card firstCard = new Card(CardSuit.HEARTS, CardRank.JACK); + Card secondCard = new Card(CardSuit.DIAMONDS,CardRank.TWO); + Card thirdCard = new Card(CardSuit.SPADES,CardRank.JACK); + + testGoFishPlayer.getHand().getCards().add(firstCard); + testGoFishPlayer.getHand().getCards().add(secondCard); + testGoFishPlayer.getHand().getCards().add(thirdCard); + + + System.out.println(testGoFishPlayer.getHand().showHand()); + testGoFishPlayer2.buildBooks(testGoFishPlayer,CardRank.JACK); + for(Card card:testGoFishPlayer2.getBook()){ + testGoFishPlayer2.getHand().addCard(card); + } + System.out.println(testGoFishPlayer2.getHand().showHand()); + + } + + @Test + public void setScoreTest(){ + int expected = 10; + testGoFishPlayer.setScore(10); + int actual = testGoFishPlayer.getScore(); + Assert.assertEquals(expected, actual); + } + + + @Test + public void getScoreTest(){ + int expected = 25; + testGoFishPlayer.setScore(15); + int actual = testGoFishPlayer.getScore(); + Assert.assertNotEquals(expected, actual); + } + + @Test + public void setHandTest() { + Profile anotherProfile = new Profile("card player", 500, 5); + GoFishPlayer anotherCardPlayer = new GoFishPlayer(anotherProfile); + Hand cardPlayerHand = new Hand(); + anotherCardPlayer.setHand(cardPlayerHand); + Hand expected = cardPlayerHand; + Hand actual = anotherCardPlayer.getHand(); + Assert.assertEquals(expected, actual); + } + + @Test + public void getHandTest() { + Assert.assertNotNull(testGoFishPlayer.getHand()); + + } + + + +} \ No newline at end of file diff --git a/src/test/java/io/zipcoder/casinotest/test/GameTest/cardGameTest/GoFishTest/GoFishTest.java b/src/test/java/io/zipcoder/casinotest/test/GameTest/cardGameTest/GoFishTest/GoFishTest.java new file mode 100644 index 00000000..d9e2f1ec --- /dev/null +++ b/src/test/java/io/zipcoder/casinotest/test/GameTest/cardGameTest/GoFishTest/GoFishTest.java @@ -0,0 +1,214 @@ +package io.zipcoder.casinotest.test.GameTest.cardGameTest.GoFishTest; + +import io.zipcoder.casino.Game.cardGame.GoFIsh.GoFish; + +import io.zipcoder.casino.Game.cardGame.utilities.Card; +import io.zipcoder.casino.Game.cardGame.utilities.CardRank; +import io.zipcoder.casino.Game.cardGame.utilities.CardSuit; +import io.zipcoder.casino.Profile; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +public class GoFishTest { + + private Profile testUserProfile; + private GoFish testGame; + + + @Before + public void setup() { + testUserProfile = new Profile("Kibret", 100000, 2); + testGame = new GoFish(testUserProfile); + } + + @Test + public void dealTest1() { + testGame.deal(); + int expected = 38; + int actual = testGame.getDeck().countRemainingCards(); + Assert.assertEquals(expected, actual); + } + + @Test + public void countMatchesInHandTest1() { + Card newCard = testGame.getDeck().getCard(); + testGame.getUser().getHand().addCard(newCard); + CardRank testCardRank = newCard.getRank(); + int expected = 1; + int actual = testGame.countMatchesInHand(testGame.getUser(), testCardRank); + Assert.assertEquals(expected, actual); + } + + @Test + public void countMatchesInHandTest2() { + Card newCard = testGame.getDeck().getCard(); + testGame.getUser().getHand().addCard(newCard); + CardRank testCardRank = newCard.getRank(); + Card anotherCard = new Card(CardSuit.SPADES, newCard.getRank()); + testGame.getUser().getHand().addCard(anotherCard); + int expected = 2; + int actual = testGame.countMatchesInHand(testGame.getUser(), testCardRank); + Assert.assertEquals(expected, actual); + } + + @Test + public void countMatchesInHandTest3() { + Card newCard = new Card(CardSuit.HEARTS, CardRank.JACK); + testGame.getUser().getHand().addCard(newCard); + Card secondCard = new Card(CardSuit.DIAMONDS, CardRank.JACK); + testGame.getUser().getHand().addCard(secondCard); + Card thirdCard = new Card(CardSuit.DIAMONDS, CardRank.EIGHT); + testGame.getUser().getHand().addCard(thirdCard); + + CardRank newCardRank = newCard.getRank(); + int expected = 2; + int actual = testGame.countMatchesInHand(testGame.getUser(), newCardRank); + Assert.assertEquals(expected, actual); + } + + + @Test + public void fishTest1() { + testGame.fish(testGame.getUser()); + int expected = 1; + int actual = testGame.getUser().getHand().getCards().size(); + Assert.assertEquals(expected, actual); + } + + @Test + public void fishTest2() { + Card expected = testGame.getDeck().peek(); + testGame.fish(testGame.getUser()); + Card actual = testGame.getUser().getHand().getCards().get(0); + Assert.assertEquals(expected, actual); + } + + @Test + public void transferCardTest1() { + Card newCard = new Card(CardSuit.HEARTS, CardRank.JACK); + testGame.getUser().getHand().addCard(newCard); + Card secondCard = new Card(CardSuit.DIAMONDS, CardRank.FIVE); + testGame.getUser().getHand().addCard(secondCard); + + CardRank newCardRank = newCard.getRank(); + testGame.transfer(newCardRank, testGame.getUser(), testGame.getDealer()); + + Assert.assertTrue(testGame.getDealer().getHand().hasCard(newCard)); + } + + @Test + public void transferCardTest2() { + Card newCard = new Card(CardSuit.HEARTS, CardRank.FIVE); + testGame.getUser().getHand().addCard(newCard); + Card secondCard = new Card(CardSuit.DIAMONDS, CardRank.FIVE); + testGame.getUser().getHand().addCard(secondCard); + + CardRank newCardRank = newCard.getRank(); + testGame.transfer(newCardRank, testGame.getUser(), testGame.getDealer()); + + int expected = 2; + int actual = testGame.getDealer().getHand().getCards().size(); + Assert.assertEquals(expected, actual); + } + + @Test + public void askTest1() { + Card newCard = new Card(CardSuit.SPADES, CardRank.THREE); + Card anotherCard = new Card(CardSuit.HEARTS, CardRank.QUEEN); + testGame.getUser().getHand().addCard(newCard); + testGame.getDealer().getHand().addCard(anotherCard); + testGame.playerAsk(CardRank.QUEEN, testGame.getDealer(), testGame.getUser()); + + Card expected = anotherCard; + Card actual = testGame.getDealer().getHand().getCards().get(0); + Assert.assertEquals(expected, actual); + } + + @Test + public void askTest2() { + Card newCard = new Card(CardSuit.SPADES, CardRank.THREE); + Card anotherCard = new Card(CardSuit.HEARTS, CardRank.QUEEN); + testGame.getUser().getHand().addCard(newCard); + testGame.getDealer().getHand().addCard(anotherCard); + testGame.playerAsk(anotherCard.getRank(), testGame.getUser(), testGame.getDealer()); + int expected = 2; + int actual = testGame.getDealer().getHand().getCards().size(); + Assert.assertEquals(expected, actual); + } + + @Test + public void askTest3() { + Card newCard = new Card(CardSuit.SPADES, CardRank.QUEEN); + Card anotherCard = new Card(CardSuit.HEARTS, CardRank.QUEEN); + testGame.getUser().getHand().addCard(newCard); + testGame.getDealer().getHand().addCard(anotherCard); + testGame.playerAsk(anotherCard.getRank(), testGame.getUser(), testGame.getDealer()); + Assert.assertTrue(testGame.getDealer().getHand().hasCard(newCard)); + } + + @Test + public void askTest4() { + Card newCard = new Card(CardSuit.SPADES, CardRank.JACK); + Card anotherCard = new Card(CardSuit.HEARTS, CardRank.JACK); + Card aThirdCard = new Card(CardSuit.CLUBS, CardRank.JACK); + testGame.getUser().getHand().addCard(newCard); + testGame.getDealer().getHand().addCard(anotherCard); + testGame.getDealer().getHand().addCard(aThirdCard); + testGame.playerAsk(anotherCard.getRank(), testGame.getDealer(), testGame.getUser()); + int expected = 3; + int actual = testGame.getUser().getHand().getCards().size(); + Assert.assertEquals(expected, actual); + } + + + +// @Test +// public void testGetDeck(){ +// +// +// } +// +// @Test +// public void calculateScore(){ +// +// +// } +// +// @Test +// public void testDecideWinner( ){ +// +// +// } +// +// @Test +// public void testAddPlayer() { +// +// } +// +// @Test +// public void testRemovePlayer() { +// +// } +// +// @Test +// public void testStartGame() { +// +// } +// +// @Test +// public void testEndGame() { +// +// } +// +// @Test +// public void testGetRules() { +// +// +// } + + +} + + diff --git a/src/test/java/io/zipcoder/casinotest/test/GameTest/cardGameTest/utilitiesTest/CardTest.java b/src/test/java/io/zipcoder/casinotest/test/GameTest/cardGameTest/utilitiesTest/CardTest.java new file mode 100644 index 00000000..49ebbee7 --- /dev/null +++ b/src/test/java/io/zipcoder/casinotest/test/GameTest/cardGameTest/utilitiesTest/CardTest.java @@ -0,0 +1,46 @@ +package io.zipcoder.casinotest.test.GameTest.cardGameTest.utilitiesTest; + +import io.zipcoder.casino.Game.cardGame.utilities.Card; +import io.zipcoder.casino.Game.cardGame.utilities.CardRank; +import io.zipcoder.casino.Game.cardGame.utilities.CardSuit; +import org.junit.Assert; +import org.junit.Test; + +public class CardTest { + + Card testCard; + + @Test + public void getSuitTest1() { + testCard = new Card(CardSuit.CLUBS, CardRank.FOUR); + CardSuit expected = CardSuit.CLUBS; + CardSuit actual = testCard.getSuit(); + Assert.assertEquals(expected, actual); + } + + @Test + public void getSuitTest2() { + testCard = new Card(CardSuit.DIAMONDS, CardRank.JACK); + CardSuit expected = CardSuit.DIAMONDS; + CardSuit actual = testCard.getSuit(); + Assert.assertEquals(expected, actual); + } + + @Test + public void getRankTest1() { + testCard = new Card(CardSuit.HEARTS, CardRank.ACE); + CardRank expected = CardRank.ACE; + CardRank actual = testCard.getRank(); + Assert.assertEquals(expected, actual); + } + + @Test + public void getRankTest2() { + testCard = new Card(CardSuit.SPADES, CardRank.NINE); + CardRank expected = CardRank.NINE; + CardRank actual = testCard.getRank(); + Assert.assertEquals(expected, actual); + } + + +} diff --git a/src/test/java/io/zipcoder/casinotest/test/GameTest/cardGameTest/utilitiesTest/DeckTest.java b/src/test/java/io/zipcoder/casinotest/test/GameTest/cardGameTest/utilitiesTest/DeckTest.java new file mode 100644 index 00000000..aac7c312 --- /dev/null +++ b/src/test/java/io/zipcoder/casinotest/test/GameTest/cardGameTest/utilitiesTest/DeckTest.java @@ -0,0 +1,103 @@ +package io.zipcoder.casinotest.test.GameTest.cardGameTest.utilitiesTest; + +import io.zipcoder.casino.Game.cardGame.utilities.Card; +import io.zipcoder.casino.Game.cardGame.utilities.CardRank; +import io.zipcoder.casino.Game.cardGame.utilities.CardSuit; +import io.zipcoder.casino.Game.cardGame.utilities.Deck; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +public class DeckTest { + + Deck testDeck; + + @Before + public void setup () { + testDeck = new Deck(); + } + + @Test + public void fillDeckTest() { + int expected = 52; + int actual = testDeck.countRemainingCards(); + Assert.assertEquals(expected, actual); + } + + @Test + public void getCardTest1() { + Card card = testDeck.getCard(); + Assert.assertNotNull(card); + } + + @Test + public void getCardTest2() { + testDeck.getCard(); + int expected = 51; + int actual = testDeck.countRemainingCards(); + Assert.assertEquals(expected, actual); + } + + @Test + public void countRemainingCardsTest1() { + testDeck.getCard(); + testDeck.getCard(); + testDeck.getCard(); + int expected = 49; + int actual = testDeck.countRemainingCards(); + Assert.assertEquals(expected, actual); + } + + @Test + public void countRemainingCardsTest2() { + Card card = testDeck.getCard(); + testDeck.addCard(card); + int expected = 52; + int actual = testDeck.countRemainingCards(); + Assert.assertEquals(expected, actual); + } + + @Test + public void addCardTest1() { + Card card = new Card(CardSuit.HEARTS, CardRank.NINE); + testDeck.addCard(card); + int expected = 53; + int actual = testDeck.countRemainingCards(); + Assert.assertEquals(expected, actual); + } + + @Test + public void addCardTest2() { + Card card = new Card(CardSuit.DIAMONDS, CardRank.KING); + testDeck.addCard(card); + Card expected = card; + Card actual = testDeck.peek(); + Assert.assertEquals(expected, actual); + } + + @Test + public void peekTest1() { + Assert.assertNotNull(testDeck.peek()); + } + + @Test + public void peekTest2() { + Card card = new Card(CardSuit.HEARTS, CardRank.SEVEN); + testDeck.addCard(card); + Card expected = card; + Card actual = testDeck.peek(); + Assert.assertEquals(expected, actual); + } + + @Test + public void shuffleTest1() { + Card expected = new Card(CardSuit.SPADES, CardRank.QUEEN); + testDeck.addCard(expected); + testDeck.shuffle(); + Card actual = testDeck.getCard(); + Assert.assertNotEquals(expected, actual); + } + + +} diff --git a/src/test/java/io/zipcoder/casinotest/test/GameTest/cardGameTest/utilitiesTest/HandTest.java b/src/test/java/io/zipcoder/casinotest/test/GameTest/cardGameTest/utilitiesTest/HandTest.java new file mode 100644 index 00000000..40848b20 --- /dev/null +++ b/src/test/java/io/zipcoder/casinotest/test/GameTest/cardGameTest/utilitiesTest/HandTest.java @@ -0,0 +1,114 @@ +package io.zipcoder.casinotest.test.GameTest.cardGameTest.utilitiesTest; + +import io.zipcoder.casino.Game.cardGame.utilities.*; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class HandTest { + + Hand testHand; + Deck testDeck; + + + @Before + public void setup() { + testDeck = new Deck(); + testHand = new Hand(); + } + + @Test + public void addCardTest1() { + Card trueCard = new Card(CardSuit.HEARTS, CardRank.JACK); + Card falseCard = new Card(CardSuit.CLUBS, CardRank.FOUR); + testHand.addCard(trueCard); + Assert.assertFalse(testHand.hasCard(falseCard)); + } + + @Test + public void addCardTest2() { + Card trueCard = new Card(CardSuit.HEARTS, CardRank.JACK); + testHand.addCard(trueCard); + Assert.assertTrue(testHand.hasCard(trueCard)); + } + + @Test + public void removeCardTest1() { + Card card1 = testDeck.getCard(); + testHand.addCard(card1); + Card card2 = testDeck.getCard(); + testHand.addCard(card2); + Card card3 = testDeck.getCard(); + testHand.addCard(card3); + testHand.removeCard(card2); + Assert.assertFalse(testHand.hasCard(card2)); + } + + @Test + public void removeCardTest2() { + Card card1 = testDeck.getCard(); + testHand.addCard(card1); + Card card2 = testDeck.getCard(); + testHand.addCard(card2); + testHand.removeCard(card2); + Assert.assertTrue(testHand.hasCard(card1)); + } + + @Test + public void clearTest1() { + Card card1 = testDeck.getCard(); + testHand.addCard(card1); + Card card2 = testDeck.getCard(); + testHand.addCard(card2); + Card card3 = testDeck.getCard(); + testHand.addCard(card3); + testHand.clear(); + int expected = 0; + int actual = testHand.getCards().size(); + Assert.assertEquals(expected, actual); + } + + @Test + public void clearTest2() { + Card card1 = testDeck.getCard(); + testHand.addCard(card1); + Card card2 = testDeck.getCard(); + testHand.addCard(card2); + testHand.clear(); + Card card3 = testDeck.getCard(); + testHand.addCard(card3); + int expected = 1; + int actual = testHand.getCards().size(); + Assert.assertEquals(expected, actual); + } + + @Test + public void showCardTest1() { + Card card1 = testDeck.getCard(); + Card card2 = testDeck.getCard(); + testHand.addCard(card1); + testHand.addCard(card2); + String expected = "Your Cards: " + card1.toString() + ", " + card2.toString() +", "; + String actual = testHand.showHand(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void orderCardsTest1() { + Card card1 = new Card(CardSuit.HEARTS, CardRank.FOUR); + Card card2 = new Card(CardSuit.CLUBS, CardRank.JACK); + Card card4 = new Card(CardSuit.DIAMONDS, CardRank.FOUR); + Card card3 = new Card(CardSuit.DIAMONDS, CardRank.EIGHT); + testHand.addCard(card1); + testHand.addCard(card2); + testHand.addCard(card3); + testHand.addCard(card4); + testHand.orderCards(); + Card expected = card4; + Card actual = testHand.getCards().get(0); + Assert.assertEquals(expected, actual); + } + + +} diff --git a/src/test/java/io/zipcoder/casinotest/test/GameTest/diceGameTest/CrapsTest/CrapsGameTest.java b/src/test/java/io/zipcoder/casinotest/test/GameTest/diceGameTest/CrapsTest/CrapsGameTest.java new file mode 100644 index 00000000..c83cc9a8 --- /dev/null +++ b/src/test/java/io/zipcoder/casinotest/test/GameTest/diceGameTest/CrapsTest/CrapsGameTest.java @@ -0,0 +1,1233 @@ +package io.zipcoder.casinotest.test.GameTest.diceGameTest.CrapsTest; + +import io.zipcoder.casino.Game.diceGame.Craps.CrapsBet; +import io.zipcoder.casino.Game.diceGame.Craps.CrapsGame; +import io.zipcoder.casino.Player; +import io.zipcoder.casino.Profile; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class CrapsGameTest { + + CrapsGame testGame; + Profile stinkyProfile = new Profile("Stinky Pete", 100, 1); + Player stinkyPete = new Player(stinkyProfile); + + + @Before + public void setup(){ + testGame = new CrapsGame(stinkyProfile); + testGame.createDie(6,2); + + } + + + @Test + public void chooseBetStopTest(){ + //Given + //testGame + String textBet = "stop"; + + //When + boolean expected = false; + boolean actual = testGame.chooseBet(textBet); + + //Then + Assert.assertEquals(expected,actual); + } + + @Test + public void rollIsNaturalPayoutWinTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.PASS_LINE, 50); + testGame.getCurrentPlayer().setPassLine(true); + + //When + testGame.rollIsNaturalPayout(); + double expected = 150; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + } + + @Test + public void rollIsNaturalPayoutLoseTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.DO_NOT_PASS, 50); + testGame.getCurrentPlayer().setPassLine(false); + + //When + testGame.rollIsNaturalPayout(); + double expected = 50; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + } + + @Test + public void rollIsCrapsPayoutWinTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.DO_NOT_PASS, 50); + testGame.getCurrentPlayer().setPassLine(false); + + //When + testGame.rollIsCrapsPayout(2); + double expected = 150; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + } + + @Test + public void rollIsCrapsPayoutPushTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.DO_NOT_PASS, 50); + testGame.getCurrentPlayer().setPassLine(false); + + //When + testGame.rollIsCrapsPayout(12); + double expected = 100; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + } + + @Test + public void rollIsCrapsPayoutLoseTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.PASS_LINE, 50); + testGame.getCurrentPlayer().setPassLine(true); + + //When + testGame.rollIsCrapsPayout(3); + double expected = 50; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertTrue(expected == actual && + testGame.getCurrentPlayer().getEscrowBet(CrapsBet.PASS_LINE) == 0); + } + + @Test + public void passLinePayoutWinTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.PASS_LINE, 50); + testGame.getCurrentPlayer().setPassLine(true); + + //When + testGame.passLinePayout(); + double expected = 150; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + + } + + @Test + public void passLinePayoutLoseTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.DO_NOT_PASS, 50); + testGame.getCurrentPlayer().setPassLine(false); + + //When + testGame.passLinePayout(); + double expected = 50; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertTrue(expected == actual && + testGame.getCurrentPlayer().getEscrowBet(CrapsBet.DO_NOT_PASS) == 0); + + } + + @Test + public void passLineOddsPayoutLoseTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.PASS_LINE_ODDS, 50); + testGame.getCurrentPlayer().setPassLine(true); + + //When + testGame.passLineOddsPayout(3); + double expected = 50; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertTrue(expected == actual && + testGame.getCurrentPlayer().getEscrowBet(CrapsBet.PASS_LINE_ODDS) == 0); + + } + + @Test + public void passLineOddsPayoutWin4Test(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.PASS_LINE_ODDS, 50); + testGame.getCurrentPlayer().setPassLine(true); + + //When + testGame.passLineOddsPayout(4); + double expected = 200; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + + } + + @Test + public void passLineOddsPayoutWin5Test(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.PASS_LINE_ODDS, 50); + testGame.getCurrentPlayer().setPassLine(true); + + //When + testGame.passLineOddsPayout(5); + double expected = 175; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + + } + + @Test + public void passLineOddsPayoutWin6Test(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.PASS_LINE_ODDS, 50); + testGame.getCurrentPlayer().setPassLine(true); + + //When + testGame.passLineOddsPayout(6); + double expected = 160; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + + } + + @Test + public void doNotPassOddsPayoutLoseTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.DO_NOT_PASS_ODDS, 50); + testGame.getCurrentPlayer().setPassLine(false); + + //When + testGame.doNotPassOddsPayout(3); + double expected = 50; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertTrue(expected == actual && + testGame.getCurrentPlayer().getEscrowBet(CrapsBet.DO_NOT_PASS_ODDS) == 0); + + } + + @Test + public void doNotPassOddsPayoutWin4Test(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.DO_NOT_PASS_ODDS, 50); + testGame.getCurrentPlayer().setPassLine(false); + + //When + testGame.doNotPassOddsPayout(4); + double expected = 125; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + + } + + @Test + public void doNotPassOddsPayoutWin5Test(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.DO_NOT_PASS_ODDS, 50); + testGame.getCurrentPlayer().setPassLine(false); + + //When + testGame.doNotPassOddsPayout(5); + double expected = 133; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + + } + + @Test + public void doNotPassOddsPayoutWin6Test(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.DO_NOT_PASS_ODDS, 50); + testGame.getCurrentPlayer().setPassLine(false); + + //When + testGame.doNotPassOddsPayout(6); + double expected = 141.5; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + + } + + + @Test + public void doNotPassPayoutWinTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.DO_NOT_PASS, 50); + testGame.getCurrentPlayer().setPassLine(false); + + //When + testGame.doNotPassPayout(); + double expected = 150; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + + } + + @Test + public void doNotPassPayoutLoseTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.PASS_LINE, 50); + testGame.getCurrentPlayer().setPassLine(true); + + //When + testGame.doNotPassPayout(); + double expected = 50; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertTrue(expected == actual && + testGame.getCurrentPlayer().getEscrowBet(CrapsBet.PASS_LINE) == 0); + + } + + @Test + public void comeNaturalPayoutWinTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.COME, 50); + testGame.getCurrentPlayer().setCome(true); + + //When + testGame.comeNaturalPayout(7); + double expected = 150; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + } + + @Test + public void comeNaturalPayoutLoseTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.DO_NOT_COME, 50); + testGame.getCurrentPlayer().setDontCome(true); + + //When + testGame.comeNaturalPayout(7); + double expected = 50; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertTrue(expected == actual && + testGame.getCurrentPlayer().getEscrowBet(CrapsBet.DO_NOT_COME) == 0); + + } + + @Test + public void doNotComeCrapsPayoutWinTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.DO_NOT_COME, 50); + testGame.getCurrentPlayer().setDontCome(true); + + //When + testGame.doNotComeCrapsPayout(3); + double expected = 150; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + } + + @Test + public void doNotComeCrapsPayoutLoseTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.COME, 50); + testGame.getCurrentPlayer().setCome(true); + + //When + testGame.doNotComeCrapsPayout(2); + double expected = 50; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertTrue(expected == actual && + testGame.getCurrentPlayer().getEscrowBet(CrapsBet.COME) == 0); + + } + + @Test + public void doNotComeCrapsPayoutPushTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.DO_NOT_COME, 50); + testGame.getCurrentPlayer().setDontCome(true); + + //When + testGame.doNotComeCrapsPayout(12); + double expected = 100; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertTrue(expected == actual && + testGame.getCurrentPlayer().getEscrowBet(CrapsBet.DO_NOT_COME) == 0); + + } + + @Test + public void changeComeBetTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.COME, 50); + testGame.getCurrentPlayer().setCome(true); + + //When + int roll = 4; + double expected = 50; + testGame.changeComeBet(roll); + double actual = testGame.getCurrentPlayer().getEscrowBet(CrapsBet.COME_FOUR); + + //Then + Assert.assertEquals(expected,actual,0.01); + + } + + @Test + public void changeComeBetTest2(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.COME, 50); + testGame.getCurrentPlayer().setCome(true); + + //When + int roll = 8; + double expected = 50; + testGame.changeComeBet(roll); + double actual = testGame.getCurrentPlayer().getEscrowBet(CrapsBet.COME_EIGHT); + + //Then + Assert.assertEquals(expected,actual,0.01); + + } + + @Test + public void setComePointTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.COME, 50); + testGame.getCurrentPlayer().setCome(true); + + //When + int roll = 4; + testGame.setComePoint(roll); + int expected = 4; + boolean actual = testGame.getCurrentPlayer().getComePoints().contains(expected); + + //Then + Assert.assertTrue(actual); + } + + @Test + public void changeDontComeBetTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.DO_NOT_COME, 50); + testGame.getCurrentPlayer().setDontCome(true); + + //When + int roll = 4; + double expected = 50; + testGame.changeDontComeBet(roll); + double actual = testGame.getCurrentPlayer().getEscrowBet(CrapsBet.DO_NOT_COME_FOUR); + + //Then + Assert.assertEquals(expected,actual,0.01); + + } + + @Test + public void changeDontComeBetTest2(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.DO_NOT_COME, 50); + testGame.getCurrentPlayer().setDontCome(true); + + //When + int roll = 8; + double expected = 50; + testGame.changeDontComeBet(roll); + double actual = testGame.getCurrentPlayer().getEscrowBet(CrapsBet.DO_NOT_COME_EIGHT); + + //Then + Assert.assertEquals(expected,actual,0.01); + + } + + @Test + public void setDontComePointTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.DO_NOT_COME, 50); + testGame.getCurrentPlayer().setDontCome(true); + + //When + int roll = 4; + testGame.setDontComePoint(roll); + int expected = 4; + boolean actual = testGame.getCurrentPlayer().getDontComePoints().contains(expected); + + //Then + Assert.assertTrue(actual); + } + + @Test + public void comePointPayoutWinTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.COME, 50); + testGame.getCurrentPlayer().setCome(true); + testGame.newComePoint(5); + + //When + double expected = 150; + testGame.comePointPayout(5); + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + } + + @Test + public void comePointPayoutLoseTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.COME, 50); + testGame.getCurrentPlayer().setCome(true); + testGame.newComePoint(5); + testGame.getCurrentPlayer().bet(CrapsBet.COME, 50); + testGame.getCurrentPlayer().setCome(true); + testGame.newComePoint(10); + + //When + double expected = 0; + testGame.comePointPayout(7); + double actual1 = testGame.getCurrentPlayer().getEscrowBet(CrapsBet.COME_FIVE); + double actual2 = testGame.getCurrentPlayer().getEscrowBet(CrapsBet.COME_TEN); + double actual3 = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + double actual4 = testGame.getCurrentPlayer().getComePoints().size(); + + //Then + Assert.assertTrue(expected == actual1 && expected == actual2 && expected == actual3 && expected == actual4); + } + + @Test + public void dontComePointPayoutWinTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.DO_NOT_COME, 50); + testGame.getCurrentPlayer().setDontCome(true); + testGame.newDontComePoint(6); + testGame.getCurrentPlayer().bet(CrapsBet.DO_NOT_COME, 50); + testGame.getCurrentPlayer().setDontCome(true); + testGame.newDontComePoint(8); + + //When + double expected = 200; + testGame.dontComePointPayout(7); + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + } + + @Test + public void dontComePointPayoutLoseTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.DO_NOT_COME, 100); + testGame.getCurrentPlayer().setDontCome(true); + testGame.newDontComePoint(6); + + //When + double expected = 0; + testGame.dontComePointPayout(6); + double actual1 = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + double actual2 = testGame.getCurrentPlayer().getEscrowBet(CrapsBet.DO_NOT_COME_SIX); + + //Then + Assert.assertTrue(expected == actual1 && expected == actual2); + + } + + @Test + public void bigSixPayoutWinTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.BIG_SIX, 50); + testGame.getCurrentPlayer().setBigSix(true); + + //When + double expected = 150; + testGame.bigSixPayout(6); + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + + } + + @Test + public void bigSixPayoutLoseTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.BIG_SIX, 50); + testGame.getCurrentPlayer().setBigSix(true); + + //When + double expected = 50; + testGame.bigSixPayout(7); + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertTrue(expected == actual && testGame.getCurrentPlayer().getEscrowBet(CrapsBet.BIG_SIX) == 0); + + } + + @Test + public void bigEightPayoutWinTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.BIG_EIGHT, 50); + testGame.getCurrentPlayer().setBigEight(true); + + //When + double expected = 150; + testGame.bigEightPayout(8); + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + + } + + @Test + public void bigEightPayoutLoseTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.BIG_EIGHT, 50); + testGame.getCurrentPlayer().setBigEight(true); + + //When + double expected = 50; + testGame.bigEightPayout(7); + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertTrue(expected == actual && testGame.getCurrentPlayer().getEscrowBet(CrapsBet.BIG_EIGHT) == 0); + + } + + @Test + public void fieldPayoutWin2Test(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.FIELD, 50); + testGame.getCurrentPlayer().setField(true); + + //When + double expected = 200; + testGame.fieldPayout(2); + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + } + + @Test + public void fieldPayoutWin3Test(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.FIELD, 50); + testGame.getCurrentPlayer().setField(true); + + //When + double expected = 150; + testGame.fieldPayout(3); + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + } + + @Test + public void fieldPayoutWin12Test(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.FIELD, 50); + testGame.getCurrentPlayer().setField(true); + + //When + double expected = 250; + testGame.fieldPayout(12); + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + } + + @Test + public void fieldPayoutLoseTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.FIELD, 50); + testGame.getCurrentPlayer().setField(true); + + //When + double expected = 50; + testGame.fieldPayout(7); + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertTrue(expected == actual && testGame.getCurrentPlayer().getEscrowBet(CrapsBet.FIELD)==0); + } + + @Test + public void hardFourPayoutWinTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.HARD_FOUR,50); + testGame.getCurrentPlayer().setHardFour(true); + + //When + testGame.setHardRoll(true); + testGame.hardFourPayout(4); + double expected = 450; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + } + + @Test + public void hardFourPayoutLoseTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.HARD_FOUR,50); + testGame.getCurrentPlayer().setHardFour(true); + + //When + testGame.setHardRoll(false); + testGame.hardFourPayout(4); + double expected = 50; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertTrue(expected == actual && testGame.getCurrentPlayer().getEscrowBet(CrapsBet.HARD_FOUR) == 0); + } + + @Test + public void hardSixPayoutWinTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.HARD_SIX,50); + testGame.getCurrentPlayer().setHardSix(true); + + //When + testGame.setHardRoll(true); + testGame.hardSixPayout(6); + double expected = 550; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + } + + @Test + public void hardSixPayoutLoseTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.HARD_SIX,50); + testGame.getCurrentPlayer().setHardSix(true); + + //When + testGame.setHardRoll(false); + testGame.hardSixPayout(7); + double expected = 50; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertTrue(expected == actual && testGame.getCurrentPlayer().getEscrowBet(CrapsBet.HARD_SIX) == 0); + } + + @Test + public void hardEightPayoutWinTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.HARD_EIGHT,50); + testGame.getCurrentPlayer().setHardEight(true); + + //When + testGame.setHardRoll(true); + testGame.hardEightPayout(8); + double expected = 550; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + } + + @Test + public void hardEightPayoutLoseTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.HARD_EIGHT,50); + testGame.getCurrentPlayer().setHardEight(true); + + //When + testGame.setHardRoll(false); + testGame.hardEightPayout(8); + double expected = 50; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertTrue(expected == actual && testGame.getCurrentPlayer().getEscrowBet(CrapsBet.HARD_EIGHT) == 0); + } + + @Test + public void hardTenPayoutWinTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.HARD_TEN,50); + testGame.getCurrentPlayer().setHardTen(true); + + //When + testGame.setHardRoll(true); + testGame.hardTenPayout(10); + double expected = 450; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + } + + @Test + public void hardTenPayoutLoseTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.HARD_TEN,50); + testGame.getCurrentPlayer().setHardTen(true); + + //When + testGame.setHardRoll(false); + testGame.hardTenPayout(7); + double expected = 50; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertTrue(expected == actual && testGame.getCurrentPlayer().getEscrowBet(CrapsBet.HARD_TEN) == 0); + } + + @Test + public void acesPayoutWinTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.ACES,50); + testGame.getCurrentPlayer().setAces(true); + + //When + testGame.acesPayout(2); + double expected = 1600; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual, 0.01); + } + + @Test + public void acesPayoutLoseTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.ACES,50); + testGame.getCurrentPlayer().setAces(true); + + //When + testGame.acesPayout(7); + double expected = 50; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertTrue(expected == actual && testGame.getCurrentPlayer().getEscrowBet(CrapsBet.ACES) == 0); + } + + @Test + public void aceDeucePayoutWinTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.ACE_DEUCE,50); + testGame.getCurrentPlayer().setAceDeuce(true); + + //When + testGame.aceDeucePayout(3); + double expected = 850; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual, 0.01); + } + + @Test + public void aceDeucePayoutLoseTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.ACE_DEUCE,50); + testGame.getCurrentPlayer().setAceDeuce(true); + + //When + testGame.aceDeucePayout(7); + double expected = 50; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertTrue(expected == actual && testGame.getCurrentPlayer().getEscrowBet(CrapsBet.ACE_DEUCE) == 0); + } + + @Test + public void yoElevenPayoutWinTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.YO_ELEVEN,50); + testGame.getCurrentPlayer().setYoEleven(true); + + //When + testGame.yoElevenPayout(11); + double expected = 850; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual, 0.01); + } + + @Test + public void yoElevenPayoutLoseTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.YO_ELEVEN,50); + testGame.getCurrentPlayer().setYoEleven(true); + + //When + testGame.yoElevenPayout(7); + double expected = 50; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertTrue(expected == actual && testGame.getCurrentPlayer().getEscrowBet(CrapsBet.YO_ELEVEN) == 0); + } + + @Test + public void boxcarPayoutWinTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.BOXCAR,50); + testGame.getCurrentPlayer().setBoxcar(true); + + //When + testGame.boxcarPayout(12); + double expected = 1600; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual, 0.01); + } + + @Test + public void boxcarPayoutLoseTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.BOXCAR,50); + testGame.getCurrentPlayer().setBoxcar(true); + + //When + testGame.boxcarPayout(7); + double expected = 50; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertTrue(expected == actual && testGame.getCurrentPlayer().getEscrowBet(CrapsBet.BOXCAR) == 0); + } + + @Test + public void hornPayoutWinTest2(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.HORN,50); + testGame.getCurrentPlayer().setHorn(true); + + //When + testGame.hornPayout(2); + double expected = 437.5; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual, 0.01); + } + + @Test + public void hornPayoutWinTest11(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.HORN,50); + testGame.getCurrentPlayer().setHorn(true); + + //When + testGame.hornPayout(11); + double expected = 250; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual, 0.01); + } + + @Test + public void hornPayoutLoseTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.HORN,50); + testGame.getCurrentPlayer().setHorn(true); + + //When + testGame.hornPayout(7); + double expected = 50; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertTrue(expected == actual && testGame.getCurrentPlayer().getEscrowBet(CrapsBet.HORN) == 0); + } + + @Test + public void anySevenPayoutWinTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.ANY_SEVEN,50); + testGame.getCurrentPlayer().setAnySeven(true); + + //When + testGame.anySevenPayout(7); + double expected = 300; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual, 0.01); + } + + @Test + public void anySevenPayoutLoseTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.ANY_SEVEN,50); + testGame.getCurrentPlayer().setAnySeven(true); + + //When + testGame.anySevenPayout(3); + double expected = 50; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertTrue(expected == actual && testGame.getCurrentPlayer().getEscrowBet(CrapsBet.ANY_SEVEN) == 0); + } + + @Test + public void anyCrapsPayoutWinTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.ANY_CRAPS,50); + testGame.getCurrentPlayer().setAnyCraps(true); + + //When + testGame.anyCrapsPayout(2); + double expected = 450; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual, 0.01); + } + + @Test + public void anyCrapsPayoutLoseTest(){ + //Given + //testGame + testGame.getCurrentPlayer().bet(CrapsBet.ANY_CRAPS,50); + testGame.getCurrentPlayer().setAnyCraps(true); + + //When + testGame.anyCrapsPayout(5); + double expected = 50; + double actual = testGame.getCurrentPlayer().getProfile().getAccountBalance(); + + //Then + Assert.assertTrue(expected == actual && testGame.getCurrentPlayer().getEscrowBet(CrapsBet.ANY_CRAPS) == 0); + } + + @Test + public void intToComePointTest(){ + //Given + //testGame + + //When + CrapsBet expected = CrapsBet.COME_EIGHT; + CrapsBet actual = testGame.intToComePoint(8); + + //Then + Assert.assertEquals(expected,actual); + } + + @Test + public void intToDontComePointTest(){ + //Given + //testGame + + //When + CrapsBet expected = CrapsBet.DO_NOT_COME_TEN; + CrapsBet actual = testGame.intToDontComePoint(10); + + //Then + Assert.assertEquals(expected,actual); + } + + + + + + @Test + public void invalidBetTest(){ + //Given + boolean betCondition = true; + + //When + boolean expected = true; + boolean actual = testGame.isInvalidBet(betCondition); + + //Then + Assert.assertEquals(expected,actual); + + + } + + @Test + public void getRollValueTest(){ + //Given + //testGame + + //When + int lowerExpectedBound = 2; + int upperExpectedBound = 12; + boolean actual = isRollOutOfBounds(lowerExpectedBound,upperExpectedBound); + + //Then + Assert.assertFalse(actual); + + } + + @Test + public void isCrapsTestTrue(){ + //Given + int rollValue = 12; + + //When + boolean expected = true; + boolean actual = CrapsGame.isCraps(rollValue); + + //Then + Assert.assertEquals(expected,actual); + } + + @Test + public void isCrapsTestFalse(){ + //Given + int rollValue = 7; + + //When + boolean expected = false; + boolean actual = CrapsGame.isCraps(rollValue); + + //Then + Assert.assertEquals(expected,actual); + } + + @Test + public void isNaturalTestTrue(){ + //Given + int rollValue = 11; + + //When + boolean expected = true; + boolean actual = CrapsGame.isNatural(rollValue); + + //Then + Assert.assertEquals(expected,actual); + } + + @Test + public void isNaturalTestFalse(){ + //Given + int rollValue = 4; + + //When + boolean expected = false; + boolean actual = CrapsGame.isNatural(rollValue); + + //Then + Assert.assertEquals(expected,actual); + } + + private boolean isRollOutOfBounds(int expectedLowerBound, int expectedUpperBound) { + for (int i = 0; i < 100000; i++) { + int roll = testGame.getRollValue(); + //System.out.println(roll); + if (roll < expectedLowerBound || roll > expectedUpperBound) { + return true; + } + } + return false; + } + + +} diff --git a/src/test/java/io/zipcoder/casinotest/test/GameTest/diceGameTest/CrapsTest/CrapsPlayerTest.java b/src/test/java/io/zipcoder/casinotest/test/GameTest/diceGameTest/CrapsTest/CrapsPlayerTest.java new file mode 100644 index 00000000..bd73af73 --- /dev/null +++ b/src/test/java/io/zipcoder/casinotest/test/GameTest/diceGameTest/CrapsTest/CrapsPlayerTest.java @@ -0,0 +1,298 @@ +package io.zipcoder.casinotest.test.GameTest.diceGameTest.CrapsTest; + +import io.zipcoder.casino.Game.diceGame.Craps.CrapsBet; +import io.zipcoder.casino.Game.diceGame.Craps.CrapsPlayer; +import io.zipcoder.casino.Profile; +import org.junit.Assert; +import org.junit.Test; + +public class CrapsPlayerTest { + + Profile stinkyProfile = new Profile("Stinky Pete", 100, 1); + CrapsPlayer stinkyPete = new CrapsPlayer(stinkyProfile); + + @Test + public void betAccountBalanceTest(){ + //Given + //CrapsPlayer stinkyPete + + //When + stinkyPete.bet(CrapsBet.PASS_LINE, 50); + double expectedAccountBalance = 50; + double actualAccountBalance = stinkyPete.getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expectedAccountBalance, actualAccountBalance, 0.01); + } + + @Test + public void betEscrowTest(){ + //Given + //CrapsPlayer stinkyPete + + //When + stinkyPete.bet(CrapsBet.PASS_LINE,75); + double expectedEscrowBalance = 75; + double actualEscrowBalance = stinkyPete.getEscrowBet(CrapsBet.PASS_LINE); + + //Then + Assert.assertEquals(expectedEscrowBalance, actualEscrowBalance, 0.01); + } + + @Test + public void multipleBetEscrowTest(){ + //Given + //CrapsPlayer stinkyPete + + //When + stinkyPete.bet(CrapsBet.PASS_LINE, 25); + stinkyPete.bet(CrapsBet.HARD_EIGHT, 10); + double expectedPL = 25; + double expectedHE = 10; + double actualPL = stinkyPete.getEscrowBet(CrapsBet.PASS_LINE); + double actualHE = stinkyPete.getEscrowBet(CrapsBet.HARD_EIGHT); + + //Then + Assert.assertTrue(expectedPL == actualPL && expectedHE == actualHE); + } + + @Test + public void multipleBetAccountDebitTest(){ + //Given + //CrapsPlayer stinkyPete + + //When + stinkyPete.bet(CrapsBet.PASS_LINE, 25); + stinkyPete.bet(CrapsBet.HARD_EIGHT, 10); + double expected = 65; + double actual = stinkyPete.getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + + } + + @Test + public void addToExistingBetTest(){ + //Given + //CrapsPlayer stinkyPete + + //When + stinkyPete.bet(CrapsBet.PASS_LINE, 25); + stinkyPete.bet(CrapsBet.PASS_LINE, 75); + double expected = 100; + double actual = stinkyPete.getEscrowBet(CrapsBet.PASS_LINE); + + //Then + Assert.assertEquals(expected,actual,0.01); + } + + @Test + public void placeBetWithoutMoneyTest(){ + //Given + //CrapsPlayer stinkyPete + + //When + stinkyPete.bet(CrapsBet.PASS_LINE, 25); + stinkyPete.bet(CrapsBet.PASS_LINE, 125); + double expectedBalance = 75; + double actualBalance = stinkyPete.getProfile().getAccountBalance(); + double expectedEscrow = 25; + double actualEscrow = stinkyPete.getEscrowBet(CrapsBet.PASS_LINE); + + //Then + Assert.assertTrue(expectedBalance == actualBalance && expectedEscrow == actualEscrow); + + } + + + + @Test + public void winTestOneToOnePayout(){ + //Given + //CrapsPlayer stinkyPete + stinkyPete.bet(CrapsBet.PASS_LINE, 50); + + //When + double payoutMultiplier = 1; + stinkyPete.win(CrapsBet.PASS_LINE, payoutMultiplier); + double expectedAccountBalance = 150; + double actualAccountBalance = stinkyPete.getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expectedAccountBalance,actualAccountBalance,0.01); + } + + @Test + public void winTestTwoPointFivePayout(){ + //Given + //CrapsPlayer stinkyPete + stinkyPete.bet(CrapsBet.ODDS, 50); + + //When + double payoutMultiplier = 2.5; + stinkyPete.win(CrapsBet.ODDS, payoutMultiplier); + double expectedAccountBalance = 225; + double actualAccountBalance = stinkyPete.getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expectedAccountBalance,actualAccountBalance,0.01); + } + + @Test + public void pushTest(){ + //Given + //CrapsPlayer stinkyPete + stinkyPete.bet(CrapsBet.DO_NOT_PASS, 50); + + //When + double payoutMultiplier = 0; + stinkyPete.win(CrapsBet.DO_NOT_PASS, payoutMultiplier); + double expected = 100; + double actual = stinkyPete.getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + + + } + + @Test + public void multipleBetWinTest(){ + //Given + //CrapsPlayer stinkyPete + + //When + stinkyPete.bet(CrapsBet.PASS_LINE, 25); + stinkyPete.bet(CrapsBet.HARD_EIGHT, 25); + stinkyPete.win(CrapsBet.PASS_LINE, 1); + stinkyPete.win(CrapsBet.HARD_EIGHT, 9); + double expected = 350; + double actual = stinkyPete.getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + } + + @Test + public void multipleBetSplitWinLossTest(){ + //Given + //CrapsPlayer stinkyPete + + //When + stinkyPete.bet(CrapsBet.PASS_LINE, 25); + stinkyPete.bet(CrapsBet.HARD_EIGHT, 25); + stinkyPete.win(CrapsBet.PASS_LINE, 1); + stinkyPete.lose(CrapsBet.HARD_EIGHT); + double expected = 100; + double actual = stinkyPete.getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + + } + + @Test + public void winTestEmptyEscrowAfter(){ + //Given + //CrapsPlayer stinkyPete + stinkyPete.bet(CrapsBet.PASS_LINE, 50); + + //When + stinkyPete.win(CrapsBet.PASS_LINE,1); + double expectedEscrow = 0; + double actualEscrow = stinkyPete.getEscrowBet(CrapsBet.PASS_LINE); + + //Then + Assert.assertEquals(expectedEscrow,actualEscrow, 0.01); + + } + + @Test + public void LoseTestMissingFromAccount(){ + //Given + //CrapsPlayer stinkyPete + stinkyPete.bet(CrapsBet.PASS_LINE, 50); + + //When + stinkyPete.lose(CrapsBet.PASS_LINE); + double expected = 50; + double actual = stinkyPete.getProfile().getAccountBalance(); + + //Then + Assert.assertEquals(expected,actual,0.01); + } + + @Test + public void LoseTestEmptyEscrow(){ + //Given + //CrapsPlayer stinkyPete + stinkyPete.bet(CrapsBet.PASS_LINE, 50); + + //When + stinkyPete.lose(CrapsBet.PASS_LINE); + double expected = 0; + double actual = stinkyPete.getEscrowBet(CrapsBet.PASS_LINE); + + //Then + Assert.assertEquals(expected,actual,0.01); + } + + + @Test + public void passLineTest(){ + //Given + stinkyPete.setPassLine(false); + + //When + boolean expected = false; + boolean actual = stinkyPete.isPassLine(); + + //Then + Assert.assertEquals(expected,actual); + } + + @Test + public void passLineTest2() { + //Given + stinkyPete.setPassLine(true); + + //When + boolean expected = true; + boolean actual = stinkyPete.isPassLine(); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void hasComePointsTest(){ + //Given + stinkyPete.addComePoint(4); + stinkyPete.addComePoint(5); + + //When + stinkyPete.removeComePoint(4); + stinkyPete.removeComePoint(5); + boolean expected = false; + boolean actual = stinkyPete.hasComePoints(); + + //Then + Assert.assertEquals(expected,actual); + } + + @Test + public void hasDontComePointsTest(){ + //Given + stinkyPete.addDontComePoint(9); + + //When + boolean expected = true; + boolean actual = stinkyPete.hasDontComePoints(); + + //Then + Assert.assertEquals(expected,actual); + } + + +} diff --git a/src/test/java/io/zipcoder/casinotest/test/GameTest/diceGameTest/DiceGameTest.java b/src/test/java/io/zipcoder/casinotest/test/GameTest/diceGameTest/DiceGameTest.java new file mode 100644 index 00000000..c85f35ed --- /dev/null +++ b/src/test/java/io/zipcoder/casinotest/test/GameTest/diceGameTest/DiceGameTest.java @@ -0,0 +1,178 @@ +package io.zipcoder.casinotest.test.GameTest.diceGameTest; + +import io.zipcoder.casino.Game.diceGame.Craps.CrapsGame; +import io.zipcoder.casino.Game.diceGame.Craps.CrapsPlayer; +import io.zipcoder.casino.Game.diceGame.DiceGame; +import io.zipcoder.casino.Game.diceGame.Die; +import io.zipcoder.casino.Player; +import io.zipcoder.casino.Profile; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; + +import static org.junit.Assert.assertEquals; + +public class DiceGameTest { + + DiceGame testGame; + Player stinkyPete; + Player smellyPeter; + Profile stinkyProfile; + + + @Before + public void setup(){ + stinkyPete = new Player(); + smellyPeter = new Player(); + testGame = new CrapsGame(stinkyProfile); + + } + + @Test + public void createDieTest1(){ + //Given + int faces = 6; + int number = 2; + + //When + int[] expected = {6,6}; + testGame.createDie(faces,number); + Die[] actualDice = testGame.getDice(); + int[] actual = {actualDice[0].getNumberOfFaces(), actualDice[1].getNumberOfFaces()}; + + //Then + Assert.assertTrue(Arrays.equals(expected,actual)); + } + + @Test + public void createDieTest2(){ + //Given + int faces = 20; + int number = 5; + + //When + int[] expected = {20,20,20,20,20}; + testGame.createDie(faces,number); + Die[] actualDice = testGame.getDice(); + int[] actual = {actualDice[0].getNumberOfFaces(), actualDice[1].getNumberOfFaces(), actualDice[2].getNumberOfFaces(), + actualDice[3].getNumberOfFaces(), actualDice[4].getNumberOfFaces()}; + + //Then + Assert.assertTrue(Arrays.equals(expected,actual)); + } + + @Test + public void rollDiceTest1(){ + //Given + + testGame.createDie(6,2); + + + //When + int expectedlowerBound = 1; + int expectedupperBound = 6; + boolean actual = areOutOfBounds(expectedlowerBound, expectedupperBound); + + //Then + Assert.assertFalse(actual); + + + } + + @Test + public void rollDiceTest2(){ + //Given + testGame.createDie(20,5); + + //When + int expectedlowerBound = 1; + int expectedupperBound = 20; + boolean actual = areOutOfBounds(expectedlowerBound, expectedupperBound); + + //Then + Assert.assertFalse(actual); + } + + @Test + public void addPlayerTest(){ + //Given + //DiceGame testGame + + //When + Player expected = stinkyPete; + testGame.addPlayer(stinkyPete); + ArrayList actual = testGame.getPlayers(); + + //Then + Assert.assertTrue(actual.contains(expected)); + } + + @Test + public void addPlayerTwiceTest(){ + //Given + //DiceGame testGame + + //When + Player expected2 = smellyPeter; + testGame.addPlayer(smellyPeter); + testGame.addPlayer(smellyPeter); + testGame.addPlayer(smellyPeter); + ArrayList actual = testGame.getPlayers(); + System.out.println(actual.size()); + + //Then + Assert.assertTrue(actual.contains(expected2) && actual.size() == 2); + } + + @Test + public void removePlayerTest(){ + //Given + //DiceGame testGame + testGame.addPlayer(smellyPeter); + + //When + + Player notExpected = smellyPeter; + testGame.removePlayer(smellyPeter); + ArrayList actual = testGame.getPlayers(); + + //Then + Assert.assertFalse(actual.contains(notExpected)); + } + + @Test + public void removeNonExistentPlayerTest(){ + //Given + //DiceGame testGame + testGame.addPlayer(smellyPeter); + + //When + Player notExpected = smellyPeter; + testGame.removePlayer(smellyPeter); + testGame.removePlayer(smellyPeter); + ArrayList actual = testGame.getPlayers(); + + + //Then + Assert.assertFalse(actual.contains(notExpected)); + } + + + + private boolean areOutOfBounds(int expectedLowerBound, int expectedUpperBound) { + for(int i = 0; i< 100000; i++){ + int[] testRolls = testGame.rollDice(); + //System.out.println(Arrays.toString(testRolls)); + for (int roll : testRolls) { + if (roll < expectedLowerBound || roll > expectedUpperBound) { + return true; + } + } + } + return false; + } + +} diff --git a/src/test/java/io/zipcoder/casinotest/test/GameTest/diceGameTest/DieTest.java b/src/test/java/io/zipcoder/casinotest/test/GameTest/diceGameTest/DieTest.java new file mode 100644 index 00000000..aacdf181 --- /dev/null +++ b/src/test/java/io/zipcoder/casinotest/test/GameTest/diceGameTest/DieTest.java @@ -0,0 +1,78 @@ +package io.zipcoder.casinotest.test.GameTest.diceGameTest; + +import io.zipcoder.casino.Game.diceGame.Die; +import org.junit.Assert; +import org.junit.Test; + +public class DieTest { + + @Test + public void getNumberOfFacesTest(){ + //Given + Die testDie = new Die (6); + + //When + int expected = 6; + int actual = testDie.getNumberOfFaces(); + + //Then + Assert.assertEquals(expected, actual); + + } + + @Test + public void getNumberOfFacesTest2(){ + //Given + Die testDie = new Die (20); + + //When + int expected = 20; + int actual = testDie.getNumberOfFaces(); + + //Then + Assert.assertEquals(expected, actual); + + } + + @Test + public void rollDieTest(){ + //Given + Die testDie = new Die(6); + + //When + int expectedLowerBound = 1; + int expectedUpperBound = 6; + boolean actual = isOutOfBounds(testDie, expectedLowerBound, expectedUpperBound); + + //Then + Assert.assertFalse(actual); + + } + + @Test + public void rollDieTest2(){ + //Given + Die testDie = new Die(20); + + //When + int expectedLowerBound = 1; + int expectedUpperBound = 20; + boolean actual = isOutOfBounds(testDie, expectedLowerBound, expectedUpperBound); + + //Then + Assert.assertFalse(actual); + + } + + private boolean isOutOfBounds(Die testDie, int expectedLowerBound, int expectedUpperBound) { + for(int i = 0; i< 100000; i++){ + int actual = testDie.rollDie(); + if(actual < expectedLowerBound || actual > expectedUpperBound){ + return true; + } + } + return false; + } + + +} diff --git a/src/test/java/io/zipcoder/casinotest/test/HouseTest.java b/src/test/java/io/zipcoder/casinotest/test/HouseTest.java new file mode 100644 index 00000000..bc359f84 --- /dev/null +++ b/src/test/java/io/zipcoder/casinotest/test/HouseTest.java @@ -0,0 +1,124 @@ +package io.zipcoder.casinotest.test; + +import io.zipcoder.casino.Game.Game; +import io.zipcoder.casino.Game.cardGame.BLackJack.BlackJackGame; +import io.zipcoder.casino.Game.cardGame.BLackJack.BlackJackPlayer; +import io.zipcoder.casino.Game.cardGame.CardGame; +import io.zipcoder.casino.Game.diceGame.DiceGame; +import io.zipcoder.casino.House; +import io.zipcoder.casino.Player; +import io.zipcoder.casino.Profile; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; + +import static org.junit.Assert.*; + +public class HouseTest { + + + private double intialBalance1; + private String playerName1; + private String playerName2; + + private CardGame game1; + private DiceGame game2; + private House casino; + + @Before + + public void setUp() throws Exception { + intialBalance1 = 1000.0; + playerName1 = "John"; + playerName2 = "Stella"; + + casino = new House(); + + } + + + @Test + public void getProfileTest() { + + Profile expected = new Profile(playerName1, intialBalance1, -8); + casino.createProfile(expected); + Profile actual = casino.getProfileById(-8); + + assertEquals(expected, actual); + } + +//fix test +// @Test +// public void chooseBlackJackCardGameTest() { +// Profile player = new Profile(playerName1, intialBalance1, 5); +// String cardGame = "Black Jack"; +// casino.createProfile(player); +// +// Profile profile = casino.getProfileById(player.getId()); +// BlackJackPlayer blackJackPlayer = new BlackJackPlayer(profile); +// +// CardGame expected = new BlackJackGame(blackJackPlayer); +// CardGame actual = casino.chooseCardGame(cardGame, player.getId()); +// +// Assert.assertEquals(true, expected.equals(actual)); +// } + + //fix test +// @Test +// public void chooseGoldFishCardGameTest() { +// Profile player = new Profile(playerName1, intialBalance1, 5); +// String cardGame = "Gold Fish"; +// casino.createProfile(player); +// +// Profile profile = casino.getProfileById(player.getId()); +// +// CardGame expected = new BlackJackGame(blackJackPlayer); +// CardGame actual = casino.chooseCardGame(cardGame, player.getId()); +// +// Assert.assertEquals(true, expected.equals(actual)); +// } +// +// @Test +// public void chooseDiceGame() { +// +// } + + @Test + public void createProfileTest() { + + Profile expexted = new Profile(playerName2, intialBalance1, 1); + casino.createProfile(expexted); + Profile actual = casino.getProfileById(1); + Assert.assertEquals(expexted, actual); + } + + + + @Test + public void selectExistingProfile() { + String playerName = "Sue"; + Profile expected = new Profile(playerName, 100.0, 2); + casino.createProfile(expected); + Profile actual = casino.selectExistingProfile(playerName); + + assertEquals(true,expected.equals(actual)); + } + + @Test + public void removeProfileTest() { + Profile player = new Profile("Tim", 100.0, 1); + Profile testProfile = new Profile("Tim", 100.0, 2); + + casino.createProfile(testProfile); + casino.createProfile(player); + casino.removeProfile(player.getId()); + Profile expected = null; + Profile actual = casino.getProfileById(player.getId()); + + Assert.assertEquals(expected, actual); + + } + +} \ No newline at end of file diff --git a/src/test/java/io/zipcoder/casinotest/test/PlayerTest.java b/src/test/java/io/zipcoder/casinotest/test/PlayerTest.java new file mode 100644 index 00000000..9206f504 --- /dev/null +++ b/src/test/java/io/zipcoder/casinotest/test/PlayerTest.java @@ -0,0 +1,49 @@ +package io.zipcoder.casinotest.test; + +import io.zipcoder.casino.House; +import io.zipcoder.casino.Player; +import io.zipcoder.casino.Profile; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class PlayerTest { + private String name1; + private String name2; + private double intialBalance1; + private double intialBalance2; + private Profile profile1; + private Profile profile2; + private Player player1; + + @Before + public void setUp() throws Exception { + name1 = "Sally"; + name2 = "Rachel"; + intialBalance1 = 100.0; + intialBalance2 = 5.00; + profile1 = new Profile(name1, intialBalance1, 0); + profile2 = new Profile(name2, intialBalance2, 0); + + player1 = new Player(profile1); + } + + @Test + public void setPlayerTest(){ + player1.setProfile(profile2); + Profile expexted = profile2; + Profile actual = player1.getProfile(); + + Assert.assertEquals(expexted, actual); + } + @Test + public void setPlayer1Test(){ + player1.setProfile(profile2); + Profile expexted = profile2; + Profile actual = player1.getProfile(); + + Assert.assertEquals(expexted, actual); + } + + +} diff --git a/src/test/java/io/zipcoder/casinotest/test/ProfileTest.java b/src/test/java/io/zipcoder/casinotest/test/ProfileTest.java new file mode 100644 index 00000000..36224189 --- /dev/null +++ b/src/test/java/io/zipcoder/casinotest/test/ProfileTest.java @@ -0,0 +1,99 @@ +package io.zipcoder.casinotest.test; + +import io.zipcoder.casino.Game.diceGame.Craps.CrapsBet; +import io.zipcoder.casino.Game.diceGame.Craps.CrapsPlayer; +import io.zipcoder.casino.Profile; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class ProfileTest { + private final static double ROUND_NUMBER =.001; + private String name1; + private String name2; + private double intialBalance1; + private double intialBalance2; + private Profile profile1; + private Profile profile2; + + @Before + public void setUp() throws Exception { + name1 ="Tim"; + name2 = "Sonja"; + intialBalance1 = 100.0; + intialBalance2 = 50.0; + profile1 = new Profile(name1, intialBalance1, 1); + profile2 = new Profile(name2, intialBalance2, 2); + } + + @Test + public void setNameTest(){ + profile1.setName(name2); + String expexted = name2; + String actual = profile1.getName(); + Assert.assertEquals(expexted, actual); + } + @Test + public void setName2Test(){ + profile2.setName(name1); + String expexted = name1; + String actual = profile2.getName(); + Assert.assertEquals(expexted, actual); + } + + @Test + public void setAccountBalanceTest(){ + profile1.setAccountBalance(intialBalance2); + double expexted = intialBalance2; + double actual = profile1.getAccountBalance(); + Assert.assertEquals(expexted, actual,ROUND_NUMBER ); + } + @Test + public void setAccountBalance2Test(){ + profile2.setAccountBalance(intialBalance1); + double expexted = intialBalance1; + double actual = profile2.getAccountBalance(); + Assert.assertEquals(expexted, actual,ROUND_NUMBER ); + } + @Test + public void setIdTest() { + profile1.setId(5); + int expected = 5; + int actual = profile1.getId(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void EscrowTest1(){ + //Given + //profile1 + CrapsPlayer testPlayer = new CrapsPlayer(profile1); + + //When + testPlayer.setEscrow(CrapsBet.PASS_LINE,100); + double expected = 100; + double actual = testPlayer.getEscrowBet(CrapsBet.PASS_LINE); + + //Then + Assert.assertEquals(expected,actual, 0.01); + } + + @Test + public void EscrowTest2(){ + //Given + //profile1 + + //When + CrapsPlayer testPlayer = new CrapsPlayer(profile1); + testPlayer.setEscrow(CrapsBet.PASS_LINE,10000.54); + double expected = 10000.54; + double actual = testPlayer.getEscrowBet(CrapsBet.PASS_LINE); + + //Then + Assert.assertEquals(expected,actual, 0.01); + } + + + +} diff --git a/src/test/java/io/zipcoder/casinotest/test/TestSuite.java b/src/test/java/io/zipcoder/casinotest/test/TestSuite.java new file mode 100644 index 00000000..b4c0db76 --- /dev/null +++ b/src/test/java/io/zipcoder/casinotest/test/TestSuite.java @@ -0,0 +1,38 @@ +package io.zipcoder.casinotest.test; + +import io.zipcoder.casinotest.test.GameTest.cardGameTest.BlackJackTest.BlackJackGameTest; +import io.zipcoder.casinotest.test.GameTest.cardGameTest.BlackJackTest.BlackJackPlayerTest; +import io.zipcoder.casinotest.test.GameTest.cardGameTest.GoFishTest.GoFishPlayerTest; +import io.zipcoder.casinotest.test.GameTest.cardGameTest.GoFishTest.GoFishTest; +import io.zipcoder.casinotest.test.GameTest.cardGameTest.utilitiesTest.CardTest; +import io.zipcoder.casinotest.test.GameTest.cardGameTest.utilitiesTest.DeckTest; +import io.zipcoder.casinotest.test.GameTest.cardGameTest.utilitiesTest.HandTest; +import io.zipcoder.casinotest.test.GameTest.diceGameTest.CrapsTest.CrapsGameTest; +import io.zipcoder.casinotest.test.GameTest.diceGameTest.CrapsTest.CrapsPlayerTest; +import io.zipcoder.casinotest.test.GameTest.diceGameTest.DiceGameTest; +import io.zipcoder.casinotest.test.GameTest.diceGameTest.DieTest; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) + + +@Suite.SuiteClasses({ + BlackJackGameTest.class, + BlackJackPlayerTest.class, + GoFishPlayerTest.class, + GoFishTest.class, + CardTest.class, + DeckTest.class, + HandTest.class, + CrapsGameTest.class, + CrapsPlayerTest.class, + DiceGameTest.class, + DieTest.class, + HouseTest.class, + PlayerTest.class, + ProfileTest.class, + +}) +public class TestSuite { +}