diff --git a/README.md b/README.md index 48e04792b..445513eee 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ # Casino Simulation +Jacob Branch + * **Objective** - To create an casino simulation * **Purpose** - To gain familiarity with general object orientation and design principles diff --git a/src/main/java/com/github/zipcodewilmington/Casino.java b/src/main/java/com/github/zipcodewilmington/Casino.java index 5eae9ac0c..85dc97baa 100644 --- a/src/main/java/com/github/zipcodewilmington/Casino.java +++ b/src/main/java/com/github/zipcodewilmington/Casino.java @@ -4,10 +4,12 @@ import com.github.zipcodewilmington.casino.CasinoAccountManager; import com.github.zipcodewilmington.casino.GameInterface; import com.github.zipcodewilmington.casino.PlayerInterface; -import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessGame; -import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessPlayer; -import com.github.zipcodewilmington.casino.games.slots.SlotsGame; -import com.github.zipcodewilmington.casino.games.slots.SlotsPlayer; +import com.github.zipcodewilmington.casino.games.cardGames.BlackJack; +import com.github.zipcodewilmington.casino.games.cardGames.BlackJackPlayer; +import com.github.zipcodewilmington.casino.games.cardGames.War; +import com.github.zipcodewilmington.casino.games.cardGames.WarPlayer; +import com.github.zipcodewilmington.casino.games.roulette.RouletteGame; +import com.github.zipcodewilmington.casino.games.roulette.RoulettePlayer; import com.github.zipcodewilmington.utils.AnsiColor; import com.github.zipcodewilmington.utils.IOConsole; @@ -17,6 +19,7 @@ public class Casino implements Runnable { private final IOConsole console = new IOConsole(AnsiColor.BLUE); + @Override public void run() { String arcadeDashBoardInput; @@ -28,13 +31,19 @@ public void run() { String accountPassword = console.getStringInput("Enter your account password:"); CasinoAccount casinoAccount = casinoAccountManager.getAccount(accountName, accountPassword); boolean isValidLogin = casinoAccount != null; + if (isValidLogin) { String gameSelectionInput = getGameSelectionInput().toUpperCase(); - if (gameSelectionInput.equals("SLOTS")) { - play(new SlotsGame(), new SlotsPlayer()); - } else if (gameSelectionInput.equals("NUMBERGUESS")) { - play(new NumberGuessGame(), new NumberGuessPlayer()); - } else { + + if (gameSelectionInput.equalsIgnoreCase("WAR")) { + play(new War(casinoAccount), new WarPlayer(casinoAccount)); + } + else if (gameSelectionInput.equalsIgnoreCase("BLACKJACK")) { + play(new BlackJack(casinoAccount), new BlackJackPlayer(casinoAccount)); + } + else if (gameSelectionInput.equalsIgnoreCase("ROULETTE")) { + play(new RouletteGame(casinoAccount), new RoulettePlayer(casinoAccount));} + else { // TODO - implement better exception handling String errorMessage = "[ %s ] is an invalid game selection"; throw new RuntimeException(String.format(errorMessage, gameSelectionInput)); @@ -48,7 +57,8 @@ public void run() { console.println("Welcome to the account-creation screen."); String accountName = console.getStringInput("Enter your account name:"); String accountPassword = console.getStringInput("Enter your account password:"); - CasinoAccount newAccount = casinoAccountManager.createAccount(accountName, accountPassword); + Double accountBalance = console.getDoubleInput("Please make initial deposit:"); + CasinoAccount newAccount = casinoAccountManager.createAccount(accountName, accountPassword, accountBalance); casinoAccountManager.registerAccount(newAccount); } } while (!"logout".equals(arcadeDashBoardInput)); @@ -58,7 +68,7 @@ private String getArcadeDashboardInput() { return console.getStringInput(new StringBuilder() .append("Welcome to the Arcade Dashboard!") .append("\nFrom here, you can select any of the following options:") - .append("\n\t[ create-account ], [ select-game ]") + .append("\n\t[ create-account ], [ select-game ] [ logout ]") .toString()); } @@ -66,7 +76,7 @@ private String getGameSelectionInput() { return console.getStringInput(new StringBuilder() .append("Welcome to the Game Selection Dashboard!") .append("\nFrom here, you can select any of the following options:") - .append("\n\t[ SLOTS ], [ NUMBERGUESS ]") + .append("\n\t[ WAR ], [ BLACKJACK ], [ ROULETTE ]") .toString()); } diff --git a/src/main/java/com/github/zipcodewilmington/MainApplication.java b/src/main/java/com/github/zipcodewilmington/MainApplication.java index 508787a85..fbe1aaa29 100644 --- a/src/main/java/com/github/zipcodewilmington/MainApplication.java +++ b/src/main/java/com/github/zipcodewilmington/MainApplication.java @@ -1,5 +1,11 @@ package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.games.roulette.RouletteGame; + +import java.util.Arrays; + public class MainApplication { public static void main(String[] args) { new Casino().run(); diff --git a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java index 654c749b4..3ae2ef721 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java @@ -6,4 +6,49 @@ * The `ArcadeAccount` is used to log into the system to select a `Game` to play. */ public class CasinoAccount { + + + // todo get acct info from casino.java into here + + + private String username; + private String password; + private Double balance; + + + public CasinoAccount(String username, String password, Double balance) { + this.username = username; + this.password = password; + this.balance = balance; + } + + public String getUsername() { + return username; + } + + + + public String getPassword() { + return password; + } + + + + public Double getBalance() { + return balance; + } + + public void setBalance(Double balance) { + this.balance = balance; + } + +// public void addBalance(Double amountToAdd) { +// this.balance += amountToAdd; +// } +// public void reduceBalance(Double amountToReduce) { +// this.balance -= amountToReduce; +// } + } + + diff --git a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java index 2d09ec2a0..c9dd09154 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java @@ -1,21 +1,40 @@ package com.github.zipcodewilmington.casino; +import com.github.zipcodewilmington.utils.IOConsole; + +import java.util.ArrayList; +import java.util.List; + /** * Created by leon on 7/21/2020. * `ArcadeAccountManager` stores, manages, and retrieves `ArcadeAccount` objects * it is advised that every instruction in this class is logged */ public class CasinoAccountManager { + IOConsole console = new IOConsole(); + + private List accountList = new ArrayList<>(); /** * @param accountName name of account to be returned * @param accountPassword password of account to be returned * @return `ArcadeAccount` with specified `accountName` and `accountPassword` */ public CasinoAccount getAccount(String accountName, String accountPassword) { - String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); - String currentClassName = getClass().getName(); - String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; - throw new RuntimeException(String.format(errorMessage, currentMethodName, currentClassName)); +// String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); +// String currentClassName = getClass().getName(); +// String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; +// throw new RuntimeException(String.format(errorMessage, currentMethodName, currentClassName)); + for (CasinoAccount account: accountList) { + String username = account.getUsername(); + String password = account.getPassword(); + if(username.equals(accountName)){ + if(password.equals(accountPassword)){ + return account; + } + } + } + console.println("Sorry your account doesn't exist"); + return null; } /** @@ -25,11 +44,15 @@ public CasinoAccount getAccount(String accountName, String accountPassword) { * @param accountPassword password of account to be created * @return new instance of `ArcadeAccount` with specified `accountName` and `accountPassword` */ - public CasinoAccount createAccount(String accountName, String accountPassword) { - String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); - String currentClassName = getClass().getName(); - String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; - throw new RuntimeException(String.format(errorMessage, currentMethodName, currentClassName)); + public CasinoAccount createAccount(String accountName, String accountPassword , Double accountBalance) { +// String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); +// String currentClassName = getClass().getName(); +// String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; +// throw new RuntimeException(String.format(errorMessage, currentMethodName, currentClassName)); + + CasinoAccount createAcct = new CasinoAccount(accountName, accountPassword, accountBalance); + + return createAcct; } /** @@ -38,9 +61,12 @@ public CasinoAccount createAccount(String accountName, String accountPassword) { * @param casinoAccount the arcadeAccount to be added to `this.getArcadeAccountList()` */ public void registerAccount(CasinoAccount casinoAccount) { - String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); - String currentClassName = getClass().getName(); - String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; - throw new RuntimeException(String.format(errorMessage, currentMethodName, currentClassName)); +// String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); +// String currentClassName = getClass().getName(); +// String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; +// throw new RuntimeException(String.format(errorMessage, currentMethodName, currentClassName)); + this.accountList.add(casinoAccount); + + } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/cardGames/BlackJack.java b/src/main/java/com/github/zipcodewilmington/casino/games/cardGames/BlackJack.java new file mode 100644 index 000000000..ef8fc7535 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/cardGames/BlackJack.java @@ -0,0 +1,230 @@ +package com.github.zipcodewilmington.casino.games.cardGames; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.utils.AnsiColor; +import com.github.zipcodewilmington.utils.IOConsole; + +import java.util.Collections; + +public class BlackJack implements GameInterface { + private IOConsole input = new IOConsole(AnsiColor.BLUE); + createDeck deck = new createDeck(); + private Cards dealer; + Integer ACEValue = 1; + private Rank dealerRank; + private Integer dealerValue = 0; + Integer totalDealerValue = 0; + private Cards player; + private Rank playerRank; + private Integer playerValue = 0; + Integer totalPlayerValue = 0; + private PlayerInterface blackJackPlayer; + private Double balance; + private Double wager; + private String choice; + + public BlackJack(CasinoAccount casinoAccount) { + blackJackPlayer = new BlackJackPlayer(casinoAccount); + balance = blackJackPlayer.getArcadeAccount().getBalance(); + dealer = deck.cardsStack.pop(); + player = deck.cardsStack.pop(); + } + + public String rules() { + return "Blackjack is played with one or more standard 52-card decks, with each denomination assigned a\n " + + "point value. The cards 2 through 10 are worth their face value. Kings, queens, and jacks are each\n" + + " worth 10, and aces may be used as either 1 or 11. The object for the player is to draw cards\n" + + " totaling closer to 21, without going over, than the dealer's cards.\n"; + } + + public createDeck shuffleDeck(createDeck deck) { + Collections.shuffle(this.deck.cardsStack); + + return deck; + } + + public String dealCards(Cards dealer, Cards player) { + dealer = deck.cardsStack.pop(); + player = deck.cardsStack.pop(); + + System.out.println("\nThe dealer drew a " + dealer + "\n" + "You drew a " + player); + return "The dealer drew a " + dealer + "\n" + "You drew a " + player; + } + + public Integer valueOfACE(String choice) { + if (choice.equals("1")) { + ACEValue = 1; + } else if (choice.equals("11")) { + ACEValue = 11; + } else { + System.out.println("\nPlease choose 1 or 11."); + valueOfACE(choice); + } + + return ACEValue; + } + + public Integer valueChecking(Cards dealer, Cards player, Integer ACEValue) { + dealerRank = dealer.getRank(); + dealerValue = dealerRank.getFirstValue(); + playerRank = player.getRank(); + playerValue = playerRank.getFirstValue(); + Integer value = 0; + + if (dealerRank.equals(Rank.ACE)) { + if ((totalDealerValue + 11) < 17) { + dealerValue = Rank.ACE.getFirstValue(); + value = dealerValue; + } else if ((totalDealerValue + 11) <= 21) { + dealerValue = Rank.ACE.getSecondValue(); + value = dealerValue; + } + } + + if (playerRank.equals(Rank.ACE)) { + if (ACEValue == 1) { + playerValue = Rank.ACE.getFirstValue(); + value = playerValue; + } else if (ACEValue == 11) { + playerValue = Rank.ACE.getSecondValue(); + value = playerValue; + } + } + + if (dealerRank.equals(Rank.JACK) || dealerRank.equals(Rank.QUEEN) || dealerRank.equals(Rank.KING)) { + dealerValue = Rank.TEN.getFirstValue(); + value = dealerValue; + } + + if (playerRank.equals(Rank.JACK) || playerRank.equals(Rank.QUEEN) || playerRank.equals(Rank.KING)) { + playerValue = Rank.TEN.getFirstValue(); + value = playerValue; + } + + return value; + } + + public String userAction(String choice, Cards player, Cards dealer, createDeck deck, Integer ACEValue, Double wager) { + switch (choice.toLowerCase()) { + case "hit": + player = deck.cardsStack.pop(); + valueChecking(dealer, player, ACEValue); + System.out.println("\nYou drew a " + player + "."); + return "You said hit."; + case "stand": + return "You said stand."; + case "double down": + wager = (wager * 2); + System.out.println("\nYour new wager is " + wager + "."); + return "You said double down."; + default: + System.out.println("\nPlease choose a valid option."); + userAction(choice, player, dealer, deck, ACEValue, wager); + } + + return choice; + } + + public String dealerAction(Integer totalDealerValue) { + String action = ""; + + if (totalDealerValue <= 16) { + dealer = deck.cardsStack.pop(); + valueChecking(dealer, player, ACEValue); + System.out.println("\nThe dealer drew a " + dealer + "."); + action = "The dealer drew a " + dealer + "."; + } else { + System.out.println("\nThe dealer has a " + dealer + "."); + action = "The dealer has a " + dealer + "."; + } + + return action; + } + + public String checkWinner(Integer totalDealerValue, Integer totalPlayerValue, Double balance, Double wager) { + String winner = ""; + totalDealerValue += dealerValue; + totalPlayerValue += playerValue; + + if (totalDealerValue > 21 || (totalDealerValue >= 17 && totalPlayerValue > totalDealerValue)) { + totalDealerValue = 0; + totalPlayerValue = 0; + blackJackPlayer.getArcadeAccount().setBalance(balance += wager); + + System.out.println("\nYou are the winner!"); + System.out.println("\nYour new balance is " + balance + ".\n"); + winner = "You are the winner!"; + } else if (totalPlayerValue > 21) { + totalDealerValue = 0; + totalPlayerValue = 0; + blackJackPlayer.getArcadeAccount().setBalance(balance -= wager); + + System.out.println("\nThe dealer won this game."); + System.out.println("\nYour new balance is " + balance + ".\n"); + winner = "The dealer won this game."; + } else { + System.out.println("\nThe total value of your cards is: " + totalPlayerValue); + System.out.println("The total value of the dealer's cards is: " + totalDealerValue); + choice = input.getStringInput("\nWhat do you want to do?\n" + + "[HIT], [STAND], [DOUBLE DOWN]"); + userAction(choice, player, dealer, deck, ACEValue, wager); + dealerAction(totalDealerValue); + checkWinner(totalDealerValue, totalPlayerValue, balance, wager); + } + + return winner; + } + + public boolean continuePlaying(String choice) { + boolean answer = false; + + if (choice.equalsIgnoreCase("yes")) { + answer = true; + } else if (choice.equalsIgnoreCase("no")) { + answer = false; + System.out.println("\nThank you for playing.\n"); + } else { + System.out.println("\nPlease say yes or no."); + continuePlaying(choice); + } + + return answer; + } + + @Override + public void add(PlayerInterface player) { + this.blackJackPlayer = player; + } + + @Override + public void remove(PlayerInterface player) { + this.blackJackPlayer = player; + } + + @Override + public void run() { + BlackJack blackJack = new BlackJack(blackJackPlayer.getArcadeAccount()); + + System.out.println(" ___ _ ___ ___ _ __ _ ___ ___ _ __ \n" + + " | _ ) | | / \\ / __| | |/ / _ | | / \\ / __| | |/ / \n" + + " | _ \\ | |__ | - | | (__ | ' < | || | | - | | (__ | ' < \n" + + " |___/ |____| |_|_| \\___| |_|\\_\\ _\\__/ |_|_| \\___| |_|\\_\\ \n" + + "_|\"\"\"\"\"|_|\"\"\"\"\"|_|\"\"\"\"\"|_|\"\"\"\"\"|_|\"\"\"\"\"|_|\"\"\"\"\"|_|\"\"\"\"\"|_|\"\"\"\"\"|_|\"\"\"\"\"| \n" + + "\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-'\"`-0-0-' "); + + blackJack.rules(); + + do { + wager = input.getDoubleInput("How much would you like to wager: "); + blackJack.shuffleDeck(deck = new createDeck()); + blackJack.dealCards(dealer, player); + choice = input.getStringInput("\nIs the value of your ACE a 1 or an 11: "); + blackJack.valueOfACE(choice); + blackJack.valueChecking(dealer, player, ACEValue); + blackJack.checkWinner(totalDealerValue, totalPlayerValue, balance, wager); + choice = input.getStringInput("\nDo you want to play again: (Yes or No)"); + } while (blackJack.continuePlaying(choice)); + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/cardGames/BlackJackPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/cardGames/BlackJackPlayer.java new file mode 100644 index 000000000..7456cd149 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/cardGames/BlackJackPlayer.java @@ -0,0 +1,21 @@ +package com.github.zipcodewilmington.casino.games.cardGames; +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.PlayerInterface; + +public class BlackJackPlayer implements PlayerInterface { + private CasinoAccount arcadeAccount; + + public BlackJackPlayer( CasinoAccount casinoAccount){ + this.arcadeAccount = casinoAccount; + } + + @Override + public CasinoAccount getArcadeAccount() { + return this.arcadeAccount; + } + + @Override + public SomeReturnType play() { + return null; + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/cardGames/Cards.java b/src/main/java/com/github/zipcodewilmington/casino/games/cardGames/Cards.java new file mode 100644 index 000000000..6b2aff694 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/cardGames/Cards.java @@ -0,0 +1,24 @@ +package com.github.zipcodewilmington.casino.games.cardGames; + +public class Cards { + private final Suit suit; + private final Rank rank; + + public Cards(Suit suit, Rank rank) { + this.suit = suit; + this.rank = rank; + } + + public Rank getRank() { + return rank; + } + + public Integer value() { + return rank.getFirstValue(); + } + + @Override + public String toString() { + return rank + " of " + suit; + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/cardGames/Rank.java b/src/main/java/com/github/zipcodewilmington/casino/games/cardGames/Rank.java new file mode 100644 index 000000000..3dc5adda2 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/cardGames/Rank.java @@ -0,0 +1,39 @@ +package com.github.zipcodewilmington.casino.games.cardGames; + +public enum Rank { + ACE(1, 11), + TWO(2), + THREE(3), + FOUR(4), + FIVE(5), + SIX(6), + SEVEN(7), + EIGHT(8), + NINE(9), + TEN(10), + JACK(11), + QUEEN(12), + KING(13); + + + private final Integer firstValue; + private final Integer secondValue; + + Rank(Integer value) { + this.firstValue = value; + this.secondValue = value; + } + + Rank(Integer firstValue, Integer secondValue) { + this.firstValue = firstValue; + this.secondValue = secondValue; + } + + public Integer getFirstValue() { + return firstValue; + } + + public Integer getSecondValue() { + return secondValue; + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/cardGames/Suit.java b/src/main/java/com/github/zipcodewilmington/casino/games/cardGames/Suit.java new file mode 100644 index 000000000..13b1fe33f --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/cardGames/Suit.java @@ -0,0 +1,14 @@ +package com.github.zipcodewilmington.casino.games.cardGames; + +public enum Suit { + HEARTS("♡"), + CLUBS("♧"), + DIAMONDS("♢"), + SPADES("♤"); + + private final String graphic; + + Suit(String graphic) { + this.graphic = graphic; + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/cardGames/War.java b/src/main/java/com/github/zipcodewilmington/casino/games/cardGames/War.java new file mode 100644 index 000000000..83b76a9c3 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/cardGames/War.java @@ -0,0 +1,214 @@ +package com.github.zipcodewilmington.casino.games.cardGames; + + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.utils.AnsiColor; +import com.github.zipcodewilmington.utils.IOConsole; + +import java.util.Collections; + +public class War implements GameInterface { + + createDeck deck = new createDeck(); + private Double balance; + private Double wager = 0.0; + private PlayerInterface warPlayer; + private IOConsole consoleAuto = new IOConsole(AnsiColor.AUTO); + private String player1Name; + private int player1Score; + private int player2Score; + Cards player1Card; + Cards player2Card; + private Rank player1CardRank; + private Rank player2CardRank; + private String choice; + + + public War(CasinoAccount casinoAccount) { + warPlayer = new WarPlayer(casinoAccount); + balance = warPlayer.getArcadeAccount().getBalance(); + player1Card = deck.cardsStack.pop(); + player2Card = deck.cardsStack.pop(); + } + + // this method states the rules of the game + public String warRules() { + + return ("Welcome to the game of War.\n\nEach player will get dealt a " + + "card. Whoever has the higher \nvalue card wins that round, and gets awarded " + + "one point. In \nthe event of a tie, no points will be rewarded and both " + + "\nplayers will play again. The winner is the first player to \nscore ten points.\n"); + + } + + + // this method takes in and set players names + public String enterNames(String player1) { + + this.player1Name = player1; + + return player1Name; + } + + // this method creates a new deck and shuffles + public createDeck shuffle(createDeck deck) { + + Collections.shuffle(this.deck.cardsStack); + + + return deck; + } + + public Double placeWager(Double balance, Double wager) { + + + consoleAuto.println(player1Name + ", your current balance is " + balance); +// Double amountWagered = Double.parseDouble(choice); // converting choice to a Double called amountWagered + Double amountWagered = wager; + if (amountWagered > balance) { + amountWagered = consoleAuto.getDoubleInput("You do not have enough money for that wager. Please place wager again."); + } else if (amountWagered < 0) { + amountWagered = consoleAuto.getDoubleInput("Sorry, but that is not a valid amount to wager. Please enter a wager more than zero."); + } else if (amountWagered == 0) { + amountWagered = consoleAuto.getDoubleInput("C'mon, that's no fun. Please enter a valid wager amount."); + } else if (amountWagered <= balance) { + wager = amountWagered; // setting amountWagered to global var wager in order to use in other methods + } + + + return wager; + } + + + public String dealCards(String deal) { + + player1Card = deck.cardsStack.pop(); + player2Card = deck.cardsStack.pop(); + consoleAuto.println("Let's flip over our cards."); + consoleAuto.println("\n" + player1Name + " draws a " + player1Card); // print player1card + consoleAuto.println("Computer draws a " + player2Card); // print player2card + + return ""; + } + + // this method determines winner of each individual round + public String determineRoundWinner(Cards player1Card, Cards player2Card, Double wager) { + + String result = ""; + player1CardRank = player1Card.getRank(); + player2CardRank = player2Card.getRank(); + Integer player1Value = player1CardRank.getFirstValue(); + Integer player2Value = player2CardRank.getFirstValue(); + + if (player1Value > player2Value) { + + result = "\n" + player1Name + " has won this round!"; + consoleAuto.println(result); + player1Score++; +// balance = balance + wager; + warPlayer.getArcadeAccount().setBalance(balance = balance + wager); + consoleAuto.println("\n" + player1Name + " now has a balance of " + balance); + consoleAuto.println("\n" + player1Name + " now has won " + player1Score + " rounds.\n"); + + } else if (player1Value < player2Value) { + // if 2 is higher than 1, 2 wins, and one point added to score for player 2 + + result = "\nComputer has won this round!"; + consoleAuto.println(result); + player2Score++; +// balance = balance - wager; + warPlayer.getArcadeAccount().setBalance(balance = balance - wager); + consoleAuto.println("\n" + player1Name + " now has a balance of " + balance); + consoleAuto.println("\nComputer now has won " + player2Score + " rounds.\n"); + + } else if (player1Value == player2Value) { + // this is a tie. neither players gets a point + + result = "\nIt was a tie.\n"; + consoleAuto.println(result); + player1Card = deck.cardsStack.pop(); + player2Card = deck.cardsStack.pop(); + } + return result; + + } + + // this method declares a winner for whoever reached 10 points first + public String determineGameWinner(int player1Score, int player2Score) { + String result = ""; + if (player1Score == 10) { + consoleAuto.println("\n" + player1Name + " has won the game!\n"); + result = "\n" + player1Name + " has won the game!\n"; + player1Score = 0; + player2Score = 0; + } else if (player2Score == 10) { + consoleAuto.println("\nComputer has won the game!\n"); + result = "\nComputer has won the game!\n"; + player2Score = 0; + player1Score = 0; + } + return result; + } + + + @Override + public void add(PlayerInterface player) { + this.warPlayer = player; + } + + @Override + public void remove(PlayerInterface player) { + this.warPlayer = null; + } + + @Override + public void run() { + // where you have game running + + balance = warPlayer.getArcadeAccount().getBalance(); + War war = new War(warPlayer.getArcadeAccount()); + + consoleAuto.println("\n" + + " \n" + + " \n" + + "WWWWWWWW WWWWWWWW AAA RRRRRRRRRRRRRRRRR \n" + + "W::::::W W::::::W A:::A R::::::::::::::::R \n" + + "W::::::W W::::::W A:::::A R::::::RRRRRR:::::R \n" + + "W::::::W W::::::W A:::::::A RR:::::R R:::::R\n" + + " W:::::W WWWWW W:::::W A:::::::::A R::::R R:::::R\n" + + " W:::::W W:::::W W:::::W A:::::A:::::A R::::R R:::::R\n" + + " W:::::W W:::::::W W:::::W A:::::A A:::::A R::::RRRRRR:::::R \n" + + " W:::::W W:::::::::W W:::::W A:::::A A:::::A R:::::::::::::RR \n" + + " W:::::W W:::::W:::::W W:::::W A:::::A A:::::A R::::RRRRRR:::::R \n" + + " W:::::W W:::::W W:::::W W:::::W A:::::AAAAAAAAA:::::A R::::R R:::::R\n" + + " W:::::W:::::W W:::::W:::::W A:::::::::::::::::::::A R::::R R:::::R\n" + + " W:::::::::W W:::::::::W A:::::AAAAAAAAAAAAA:::::A R::::R R:::::R\n" + + " W:::::::W W:::::::W A:::::A A:::::A RR:::::R R:::::R\n" + + " W:::::W W:::::W A:::::A A:::::A R::::::R R:::::R\n" + + " W:::W W:::W A:::::A A:::::A R::::::R R:::::R\n" + + " WWW WWW AAAAAAA AAAAAAARRRRRRRR RRRRRRR\n"); + + + System.out.println(war.warRules()); + + choice = consoleAuto.getStringInput("Player, please enter your name:"); + war.enterNames(choice); + + do { + + war.shuffle(deck= new createDeck()); + + wager = consoleAuto.getDoubleInput("Please enter your wager amount."); + war.placeWager(balance, wager); + war.dealCards(""); + + war.determineRoundWinner(player1Card, player2Card, wager); + war.determineGameWinner(player1Score, player2Score); + + choice = consoleAuto.getStringInput("Would you like to play again? Please press any key to continue, or type [no] to quit."); + + } while (!choice.equalsIgnoreCase("no")); + } +} // class War closing bracket \ No newline at end of file diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/cardGames/WarPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/cardGames/WarPlayer.java new file mode 100644 index 000000000..daf7bb168 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/cardGames/WarPlayer.java @@ -0,0 +1,24 @@ +package com.github.zipcodewilmington.casino.games.cardGames; + +import com.github.zipcodewilmington.Casino; +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.CasinoAccountManager; +import com.github.zipcodewilmington.casino.PlayerInterface; + +public class WarPlayer implements PlayerInterface { + private CasinoAccount arcadeAccount; + + public WarPlayer(CasinoAccount casinoAccount){ + this.arcadeAccount = casinoAccount; + } + + @Override + public CasinoAccount getArcadeAccount() { + return arcadeAccount; + } + + @Override + public SomeReturnType play() { + return null; + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/cardGames/createDeck.java b/src/main/java/com/github/zipcodewilmington/casino/games/cardGames/createDeck.java new file mode 100644 index 000000000..3418d0927 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/cardGames/createDeck.java @@ -0,0 +1,17 @@ +package com.github.zipcodewilmington.casino.games.cardGames; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; +import java.util.Stack; + +public class createDeck { + Stack cardsStack = new Stack<>(); + + public createDeck() { + for (Suit suit : Suit.values()) { + for (Rank rank : Rank.values()) { + cardsStack.add(new Cards(suit, rank)); + } + } + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java deleted file mode 100644 index 795709488..000000000 --- a/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.zipcodewilmington.casino.games.numberguess; - -/** - * Created by leon on 7/21/2020. - */ -public class NumberGuessGame { -} \ No newline at end of file diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessPlayer.java deleted file mode 100644 index aa5cce2e7..000000000 --- a/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessPlayer.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.zipcodewilmington.casino.games.numberguess; - -/** - * Created by leon on 7/21/2020. - */ -public class NumberGuessPlayer { -} \ No newline at end of file diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/roulette/RouletteGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/roulette/RouletteGame.java new file mode 100644 index 000000000..fcbad0ecd --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/roulette/RouletteGame.java @@ -0,0 +1,260 @@ +package com.github.zipcodewilmington.casino.games.roulette; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.CasinoAccountManager; +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.utils.AnsiColor; +import com.github.zipcodewilmington.utils.IOConsole; +import com.sun.org.apache.bcel.internal.generic.ARETURN; +import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; + + +public class RouletteGame implements GameInterface { + private List players = new ArrayList<>(); + private Integer[] red; + private Integer[] black; + private Integer choice; + private Double betAmount; + private String response; + private Integer rouletteNumber; + private PlayerInterface roulettePlayer; + private Double balance; + private String AnsiGreen = "\u001B[32m"; + private String AnsiReset = "\u001B[0m"; + private String AnsiRed = "\u001B[31m"; + private String welcomeMessage = "\n" + + "░█──░█ ░█▀▀▀ ░█─── ░█▀▀█ ░█▀▀▀█ ░█▀▄▀█ ░█▀▀▀   ▀▀█▀▀ ░█▀▀▀█   ░█▀▀█ ░█▀▀▀█ ░█─░█ ░█─── ░█▀▀▀ ▀▀█▀▀ ▀▀█▀▀ ░█▀▀▀ █ █ █ \n" + + "░█░█░█ ░█▀▀▀ ░█─── ░█─── ░█──░█ ░█░█░█ ░█▀▀▀   ─░█── ░█──░█   ░█▄▄▀ ░█──░█ ░█─░█ ░█─── ░█▀▀▀ ─░█── ─░█── ░█▀▀▀ ▀ ▀ ▀ \n" + + "░█▄▀▄█ ░█▄▄▄ ░█▄▄█ ░█▄▄█ ░█▄▄▄█ ░█──░█ ░█▄▄▄   ─░█── ░█▄▄▄█   ░█─░█ ░█▄▄▄█ ─▀▄▄▀ ░█▄▄█ ░█▄▄▄ ─░█── ─░█── ░█▄▄▄ ▄ ▄ ▄"; + private String outOfMoneyMessage = "\n" + + "█░░█ █▀▀█ █░░█   █▀▀█ █▀▀█ █▀▀   █▀▀▄ █▀▀█ █▀▀█ █░█ █▀▀ █ █ █                   \n" + + "█▄▄█ █░░█ █░░█   █▄▄█ █▄▄▀ █▀▀   █▀▀▄ █▄▄▀ █░░█ █▀▄ █▀▀ ▀ ▀ ▀                   \n" + + "▄▄▄█ ▀▀▀▀ ░▀▀▀   ▀░░▀ ▀░▀▀ ▀▀▀   ▀▀▀░ ▀░▀▀ ▀▀▀▀ ▀░▀ ▀▀▀ ▄ ▄ ▄                   \n" + + "\n" + + "█▀▀▀ █▀▀ ▀▀█▀▀   █▀▀█ █░░█ ▀▀█▀▀   █▀▀█ █▀▀   █▀▄▀█ █░░█   █▀▀ █▀▀█ █▀▀ ░▀░ █▀▀▄ █▀▀█ █ █ █ \n" + + "█░▀█ █▀▀ ░░█░░   █░░█ █░░█ ░░█░░   █░░█ █▀▀   █░▀░█ █▄▄█   █░░ █▄▄█ ▀▀█ ▀█▀ █░░█ █░░█ ▀ ▀ ▀ \n" + + "▀▀▀▀ ▀▀▀ ░░▀░░   ▀▀▀▀ ░▀▀▀ ░░▀░░   ▀▀▀▀ ▀░░   ▀░░░▀ ▄▄▄█   ▀▀▀ ▀░░▀ ▀▀▀ ▀▀▀ ▀░░▀ ▀▀▀▀ ▄ ▄ ▄"; + + + private final IOConsole consolePurple = new IOConsole(AnsiColor.PURPLE); + private final IOConsole consoleRed = new IOConsole(AnsiColor.RED); + + public RouletteGame(CasinoAccount casinoAccount) { + roulettePlayer = new RoulettePlayer(casinoAccount); + this.rouletteNumber = null; + this.red = new Integer[]{1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36}; + this.black = new Integer[]{2, 4, 6, 8, 10, 11, 13, 15, 17, 20, 22, 24, 26, 28, 29, 31, 33, 35}; + balance = roulettePlayer.getArcadeAccount().getBalance(); + } + + + public String evenChoice(Integer randomNumber, Double betAmount) { + consolePurple.println("Roulette Number: " + randomNumber); + String result = ""; + + if (randomNumber % 2 == 0) { + roulettePlayer.getArcadeAccount().setBalance(balance += betAmount * 2); + result = (AnsiGreen + "you won $" + betAmount * 2 + AnsiReset); + + } else { + roulettePlayer.getArcadeAccount().setBalance(balance -= betAmount); + result = (AnsiRed + "you lost $" + (betAmount) + AnsiReset); + } + return (result + "\nYour balance is: $" + getBalance()); + } + + + public String oddChoice(Integer randomNumber, Double betAmount) { + consolePurple.println("Roulette Number: " + randomNumber); + String result = ""; + + if (randomNumber % 2 == 1) { + roulettePlayer.getArcadeAccount().setBalance(balance += betAmount * 2); + result = (AnsiGreen + "you won $" + betAmount * 2 + AnsiReset); + + } else { + roulettePlayer.getArcadeAccount().setBalance(balance -= betAmount); + result = (AnsiRed + "you lost $" + (betAmount) + AnsiReset); + } + + return (result + "\nYour balance is: $" + balance); + } + + + public String redChoice(Integer randomNumber, Double betAmount) { + consolePurple.println("Roulette Number: " + randomNumber); + String result = ""; + + if (Arrays.asList(this.red).contains(randomNumber)) { + roulettePlayer.getArcadeAccount().setBalance(balance += betAmount * 2); + result = (AnsiGreen + "you won $" + betAmount * 2 + AnsiReset); + } else { + roulettePlayer.getArcadeAccount().setBalance(balance -= betAmount); + result = (AnsiRed + "you lost $" + (betAmount) + AnsiReset); + } + + return (result + "\nYour balance is: $" + balance); + } + + public String blackChoice(Integer randomNumber, Double betAmount) { + // this.rouletteNumber = ThreadLocalRandom.current().nextInt(1, 36); + String result = ""; + consolePurple.println("Roulette Number: " + randomNumber); + + if (Arrays.asList(this.black).contains(randomNumber)) { + roulettePlayer.getArcadeAccount().setBalance(balance += betAmount * 2); + result = (AnsiGreen + "you won $" + betAmount * 2 + AnsiReset); + + } else { + roulettePlayer.getArcadeAccount().setBalance(balance -= betAmount); + result = (AnsiRed + "you lost $" + (betAmount) + AnsiReset); + + } + + return (result + "\nYour balance is: $" + balance); + } + + public String pickNumberChoice(Integer randomNumber, Double betAmount, Integer pickedNumber) { + String result = ""; + Integer number = pickedNumber; + + if (randomNumber == number) { + roulettePlayer.getArcadeAccount().setBalance(balance += betAmount * 35); + result = (AnsiGreen + "you won $" + betAmount * 35 + AnsiReset); + + } else { + roulettePlayer.getArcadeAccount().setBalance(balance -= betAmount); + result = (AnsiRed + "you lost $" + (betAmount) + AnsiReset); + + } + + return (result + "\nYour balance is: $" + balance); + } + + public String betweenOneAndEighteen(Integer randomNumber, Double betAmount) { + // this.rouletteNumber = ThreadLocalRandom.current().nextInt(1, 36); + String result = ""; + consolePurple.println("Roulette Number: " + randomNumber); + if (randomNumber >= 1 && randomNumber <= 18) { + roulettePlayer.getArcadeAccount().setBalance(balance += betAmount * 2); + result = (AnsiGreen + "you won $" + betAmount * 2 + AnsiReset); + + } else { + roulettePlayer.getArcadeAccount().setBalance(balance -= betAmount); + result = (AnsiRed + "you lost $" + (betAmount) + AnsiReset); + } + + + return (result + "\nYour balance is: $" + balance); + } + + public String betweenNineteenAndThirtySix(Integer randomNumber, Double betAmount) { + // this.rouletteNumber = ThreadLocalRandom.current().nextInt(1, 36); + String result = ""; + consolePurple.println("Roulette Number: " + randomNumber); + + if (randomNumber >= 19 && randomNumber <= 36) { + roulettePlayer.getArcadeAccount().setBalance(balance += betAmount * 2); + result = (AnsiGreen + "you won $" + betAmount * 2 + AnsiReset); + + } else { + roulettePlayer.getArcadeAccount().setBalance(balance -= betAmount); + result = (AnsiRed + "you lost $" + (betAmount) + AnsiReset); + } + + return (result + "\nYour balance is: $" + balance); + } + + + public void rouletteGame() { // GAME ENGINE + + consolePurple.println(welcomeMessage); + + do { + + this.betAmount = consolePurple.getDoubleInput("Please enter amount you would like to bet"); + if (this.betAmount > this.balance) { + consoleRed.println(outOfMoneyMessage); + break; + } + consolePurple.println("PLease choose from the options below"); + choice = consolePurple.getIntegerInput("(1)Red (2)Black (3)Even (4)Odd (5)Pick Number (6)Low 1 to 18 (7)High 19 to 36"); + + while (choice < 0 || choice > 7) { + consolePurple.println("PLease choose from the options below"); + choice = consolePurple.getIntegerInput("(1)Red (2)Black (3)Even (4)Odd (5)Pick Number (6)Low 1 to 18 (7)High 19 to 36"); + } + + if (choice == 1) { + this.rouletteNumber = ThreadLocalRandom.current().nextInt(1, 36); + consolePurple.println(redChoice(this.rouletteNumber, this.betAmount)); + + } else if (choice == 2) { + this.rouletteNumber = ThreadLocalRandom.current().nextInt(1, 36); + consolePurple.println(blackChoice(this.rouletteNumber, this.betAmount)); + + } else if (choice == 3) { + this.rouletteNumber = ThreadLocalRandom.current().nextInt(1, 36); + consolePurple.println(evenChoice(this.rouletteNumber, this.betAmount)); + + } else if (choice == 4) { + this.rouletteNumber = ThreadLocalRandom.current().nextInt(1, 36); + consolePurple.println(oddChoice(this.rouletteNumber, this.betAmount)); + + } else if (choice == 5) { + this.rouletteNumber = ThreadLocalRandom.current().nextInt(1, 36); + //System.out.println(rouletteNumber); //to test if number matches + consolePurple.println(pickNumberChoice(this.rouletteNumber, this.betAmount, consolePurple.getIntegerInput("Place your bet on number(1-36): "))); + + } else if (choice == 6) { + this.rouletteNumber = ThreadLocalRandom.current().nextInt(1, 36); + consolePurple.println(betweenOneAndEighteen(this.rouletteNumber, this.betAmount)); + + } else if (choice == 7) { + this.rouletteNumber = ThreadLocalRandom.current().nextInt(1, 36); + consolePurple.println(betweenNineteenAndThirtySix(this.rouletteNumber, this.betAmount)); + } + + + response = consolePurple.getStringInput("Would you like to play another game? (Y/N) "); + if (response.equals("N") || response.equals("n") || response.equals("NO") || response.equals("no")) { + break; + } + + } while (true); + + consolePurple.println("THANK YOU!!!"); + + } + + + public Double getBalance() { + return balance; + } + + + @Override + public void add(PlayerInterface player) { + this.roulettePlayer = player; + } + + @Override + public void remove(PlayerInterface player) { + this.roulettePlayer = null; + } + + @Override + public void run() { + + RouletteGame rouletteGame = new RouletteGame(roulettePlayer.getArcadeAccount()); + + rouletteGame.rouletteGame(); + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/roulette/RoulettePlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/roulette/RoulettePlayer.java new file mode 100644 index 000000000..bb50ce1a3 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/roulette/RoulettePlayer.java @@ -0,0 +1,26 @@ +package com.github.zipcodewilmington.casino.games.roulette; + +import com.github.zipcodewilmington.Casino; +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.CasinoAccountManager; +import com.github.zipcodewilmington.casino.PlayerInterface; + +public class RoulettePlayer implements PlayerInterface { + private CasinoAccount arcadeAccount; + + + public RoulettePlayer( CasinoAccount casinoAccount){ + this.arcadeAccount = casinoAccount; + + } + + @Override + public CasinoAccount getArcadeAccount() { + return this.arcadeAccount; + } + + @Override + public SomeReturnType play() { + return null; + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java deleted file mode 100644 index 8cb20c787..000000000 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.zipcodewilmington.casino.games.slots; - -/** - * Created by leon on 7/21/2020. - */ -public class SlotsGame { -} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java deleted file mode 100644 index f89ebd7f5..000000000 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.zipcodewilmington.casino.games.slots; - -/** - * Created by leon on 7/21/2020. - */ -public class SlotsPlayer { -} \ No newline at end of file diff --git a/src/main/java/com/github/zipcodewilmington/utils/AnsiColor.java b/src/main/java/com/github/zipcodewilmington/utils/AnsiColor.java index 9a82e8a8e..4cad2abee 100644 --- a/src/main/java/com/github/zipcodewilmington/utils/AnsiColor.java +++ b/src/main/java/com/github/zipcodewilmington/utils/AnsiColor.java @@ -13,7 +13,8 @@ public enum AnsiColor { BLUE("\u001B[34m"), PURPLE("\u001B[35m"), CYAN("\u001B[36m"), - WHITE("\u001B[37m"); + WHITE("\u001B[37m"), + ANSI_BRIGHT_CYAN("\u001B[96m"); private final String color; diff --git a/src/test/java/com/github/zipcodewilmington/ApplicationRunnerTest.java b/src/test/java/com/github/zipcodewilmington/ApplicationRunnerTest.java index a9af8209a..5127e8491 100644 --- a/src/test/java/com/github/zipcodewilmington/ApplicationRunnerTest.java +++ b/src/test/java/com/github/zipcodewilmington/ApplicationRunnerTest.java @@ -7,7 +7,7 @@ * Created by leon on 7/21/2020. */ public class ApplicationRunnerTest { - @Test + @Test public void test() { // TODO - replace boiler-plate logic with business logic // given Runnable runnable = new Casino(); diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackTest.java new file mode 100644 index 000000000..625538a65 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/BlackJackTest.java @@ -0,0 +1,462 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.cardGames.*; +import org.junit.Assert; +import org.junit.Test; + +public class BlackJackTest { + @Test + public void testRules() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + BlackJack blackJack = new BlackJack(casinoAccount); + String expected = "Blackjack is played with one or more standard 52-card decks, with each denomination assigned a\n " + + "point value. The cards 2 through 10 are worth their face value. Kings, queens, and jacks are each\n" + + " worth 10, and aces may be used as either 1 or 11. The object for the player is to draw cards\n" + + " totaling closer to 21, without going over, than the dealer's cards.\n"; + + //when + String actual = blackJack.rules(); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void checkWinnerTest1() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + BlackJack blackJack = new BlackJack(casinoAccount); + Integer totalPlayerValue = 0; + Integer totalDealerValue = 22; + Double balance = 1200.0; + Double wager = 200.0; + String expected = "You are the winner!"; + + //when + String actual = blackJack.checkWinner(totalDealerValue, totalPlayerValue, balance, wager); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void checkWinnerTest2() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + BlackJack blackJack = new BlackJack(casinoAccount); + Integer totalPlayerValue = 22; + Integer totalDealerValue = 0; + Double balance = 1200.0; + Double wager = 200.0; + String expected = "The dealer won this game."; + + //when + String actual = blackJack.checkWinner(totalDealerValue, totalPlayerValue, balance, wager); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void dealerActionTest1() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + BlackJack blackJack = new BlackJack(casinoAccount); + Rank rank = Rank.JACK; + Suit suit = Suit.SPADES; + Cards card = new Cards(suit, rank); + Integer totalDealerValue = 15; + String expected = "The dealer drew a " + card + "."; + + //when + String actual = blackJack.dealerAction(totalDealerValue); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void dealerActionTest2() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + BlackJack blackJack = new BlackJack(casinoAccount); + Rank rank = Rank.KING; + Suit suit = Suit.SPADES; + Cards card = new Cards(suit, rank); + Integer totalDealerValue = 18; + String expected = "The dealer has a " + card + "."; + + //when + String actual = blackJack.dealerAction(totalDealerValue); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void valueChecking1() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + BlackJack blackJack = new BlackJack(casinoAccount); + Rank pRank = Rank.ACE; + Suit pSuit = Suit.SPADES; + Rank dRank = Rank.SIX; + Suit dSuit = Suit.SPADES; + Integer ACEValue = 1; + Cards dealer = new Cards(dSuit, dRank); + Cards player = new Cards(pSuit, pRank); + Integer expected = 1; + + //when + Integer actual = blackJack.valueChecking(dealer, player, ACEValue); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void valueChecking2() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + BlackJack blackJack = new BlackJack(casinoAccount); + Rank pRank = Rank.ACE; + Suit pSuit = Suit.SPADES; + Rank dRank = Rank.SIX; + Suit dSuit = Suit.SPADES; + Integer ACEValue = 11; + Cards dealer = new Cards(dSuit, dRank); + Cards player = new Cards(pSuit, pRank); + Integer expected = 11; + + //when + Integer actual = blackJack.valueChecking(dealer, player, ACEValue); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void valueChecking3() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + BlackJack blackJack = new BlackJack(casinoAccount); + Rank pRank = Rank.JACK; + Suit pSuit = Suit.SPADES; + Rank dRank = Rank.SIX; + Suit dSuit = Suit.SPADES; + Integer ACEValue = 1; + Cards dealer = new Cards(dSuit, dRank); + Cards player = new Cards(pSuit, pRank); + Integer expected = 10; + + //when + Integer actual = blackJack.valueChecking(dealer, player, ACEValue); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void valueChecking4() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + BlackJack blackJack = new BlackJack(casinoAccount); + Rank pRank = Rank.QUEEN; + Suit pSuit = Suit.SPADES; + Rank dRank = Rank.SIX; + Suit dSuit = Suit.SPADES; + Integer ACEValue = 1; + Cards dealer = new Cards(dSuit, dRank); + Cards player = new Cards(pSuit, pRank); + Integer expected = 10; + + //when + Integer actual = blackJack.valueChecking(dealer, player, ACEValue); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void valueChecking5() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + BlackJack blackJack = new BlackJack(casinoAccount); + Rank pRank = Rank.KING; + Suit pSuit = Suit.SPADES; + Rank dRank = Rank.SIX; + Suit dSuit = Suit.SPADES; + Integer ACEValue = 1; + Cards dealer = new Cards(dSuit, dRank); + Cards player = new Cards(pSuit, pRank); + Integer expected = 10; + + //when + Integer actual = blackJack.valueChecking(dealer, player, ACEValue); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void valueChecking6() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + BlackJack blackJack = new BlackJack(casinoAccount); + Rank pRank = Rank.SIX; + Suit pSuit = Suit.SPADES; + Rank dRank = Rank.JACK; + Suit dSuit = Suit.SPADES; + Integer ACEValue = 1; + Cards dealer = new Cards(dSuit, dRank); + Cards player = new Cards(pSuit, pRank); + Integer expected = 10; + + //when + Integer actual = blackJack.valueChecking(dealer, player, ACEValue); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void valueChecking7() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + BlackJack blackJack = new BlackJack(casinoAccount); + Rank pRank = Rank.SIX; + Suit pSuit = Suit.SPADES; + Rank dRank = Rank.QUEEN; + Suit dSuit = Suit.SPADES; + Integer ACEValue = 1; + Cards dealer = new Cards(dSuit, dRank); + Cards player = new Cards(pSuit, pRank); + Integer expected = 10; + + //when + Integer actual = blackJack.valueChecking(dealer, player, ACEValue); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void valueChecking8() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + BlackJack blackJack = new BlackJack(casinoAccount); + Rank pRank = Rank.SIX; + Suit pSuit = Suit.SPADES; + Rank dRank = Rank.KING; + Suit dSuit = Suit.SPADES; + Integer ACEValue = 1; + Cards dealer = new Cards(dSuit, dRank); + Cards player = new Cards(pSuit, pRank); + Integer expected = 10; + + //when + Integer actual = blackJack.valueChecking(dealer, player, ACEValue); + + //then + Assert.assertEquals(expected, actual); + } + +// @Test +// public void dealCardsTest() { +// //given +// CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); +// BlackJack blackJack = new BlackJack(casinoAccount); +// Cards dealer = new Cards(Suit.SPADES, Rank.SIX); +// Cards player = new Cards(Suit.CLUBS, Rank.FIVE); +// String expected = "The dealer drew a " + dealer + "\n" + "You drew a " + player; +// +// //when +// String actual = blackJack.dealCards(dealer, player); +// +// //then +// Assert.assertEquals(expected, actual); +// } + + @Test + public void valueOfACETest1() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + BlackJack blackJack = new BlackJack(casinoAccount); + Integer expected = 1; + String choice = "1"; + + //when + Integer actual = blackJack.valueOfACE(choice); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void valueOfACETest2() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + BlackJack blackJack = new BlackJack(casinoAccount); + Integer expected = 11; + String choice = "11"; + + //when + Integer actual = blackJack.valueOfACE(choice); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void continuePlayingTest1() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + BlackJack blackJack = new BlackJack(casinoAccount); + Boolean expected = true; + String choice = "yes"; + + //when + Boolean actual = blackJack.continuePlaying(choice); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void continuePlayingTest2() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + BlackJack blackJack = new BlackJack(casinoAccount); + Boolean expected = false; + String choice = "no"; + + //when + Boolean actual = blackJack.continuePlaying(choice); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void userActionTest1() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + BlackJack blackJack = new BlackJack(casinoAccount); + createDeck deck = new createDeck(); + Cards dealer = new Cards(Suit.SPADES, Rank.SIX); + Cards player = new Cards(Suit.CLUBS, Rank.FIVE); + Integer ACEValue = 1; + Double wager = 200.0; + String expected = "You said hit."; + String choice = "hit"; + + //when + String actual = blackJack.userAction(choice, player, dealer, deck, ACEValue, wager); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void userActionTest2() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + BlackJack blackJack = new BlackJack(casinoAccount); + createDeck deck = new createDeck(); + Cards dealer = new Cards(Suit.SPADES, Rank.SIX); + Cards player = new Cards(Suit.CLUBS, Rank.FIVE); + Integer ACEValue = 1; + Double wager = 200.0; + String expected = "You said stand."; + String choice = "stand"; + + //when + String actual = blackJack.userAction(choice, player, dealer, deck, ACEValue, wager); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void userActionTest3() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + BlackJack blackJack = new BlackJack(casinoAccount); + createDeck deck = new createDeck(); + Cards dealer = new Cards(Suit.SPADES, Rank.SIX); + Cards player = new Cards(Suit.CLUBS, Rank.FIVE); + Integer ACEValue = 1; + Double wager = 200.0; + String expected = "You said double down."; + String choice = "double down"; + + //when + String actual = blackJack.userAction(choice, player, dealer, deck, ACEValue, wager); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void shuffleDeckTest() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + BlackJack blackJack = new BlackJack(casinoAccount); + createDeck deck = new createDeck(); + createDeck expected = new createDeck(); + + //when + createDeck actual = blackJack.shuffleDeck(deck); + + //then + Assert.assertNotEquals(expected, actual); + } + + @Test + public void rankValueTest() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + BlackJack blackJack = new BlackJack(casinoAccount); + Cards dealer = new Cards(Suit.SPADES, Rank.SIX); + Integer expected = 6; + + //when + Integer actual = dealer.value(); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void addTest() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + BlackJack blackJack = new BlackJack(casinoAccount); + PlayerInterface player = new BlackJackPlayer(casinoAccount); + + //when + blackJack.add(player); + CasinoAccount actual = player.getArcadeAccount(); + + //then + Assert.assertNotNull(actual); + } + + @Test + public void removeTest() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + BlackJack blackJack = new BlackJack(casinoAccount); + PlayerInterface player = new BlackJackPlayer(casinoAccount); + + //when + blackJack.remove(player); + CasinoAccount actual = player.getArcadeAccount(); + + //then + Assert.assertNotNull(actual); + } +} diff --git a/src/test/java/com/github/zipcodewilmington/CasinoManageTest.java b/src/test/java/com/github/zipcodewilmington/CasinoManageTest.java new file mode 100644 index 000000000..062a315f5 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/CasinoManageTest.java @@ -0,0 +1,54 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.CasinoAccountManager; +import org.junit.Assert; +import org.junit.Test; + +public class CasinoManageTest { + @Test + + public void casinoManagerCreateAccountTest(){ + //Given + CasinoAccountManager casinoAccountManager = new CasinoAccountManager(); + //When + CasinoAccount actualAccount = casinoAccountManager.createAccount("Junior", "j", 1500.0); + //Then + Assert.assertNotNull(actualAccount); + + } + + + @Test + public void casinoManagerRegisterAccount(){ + //given + CasinoAccountManager casinoAccountManager = new CasinoAccountManager(); + CasinoAccount casinoAccount = casinoAccountManager.createAccount("Junior", "j", 1500.0); + String expectedUser = "Junior"; + String expectedPassword = "j"; + //when + casinoAccountManager.registerAccount(casinoAccount); + CasinoAccount actual = casinoAccountManager.getAccount(expectedUser, expectedPassword); + + //then + Assert.assertNotNull(actual); + + } +@Test + + public void casinoManagerGetAccountTest(){ + //given + CasinoAccountManager casinoAccountManager = new CasinoAccountManager(); + CasinoAccount casinoAccount = casinoAccountManager.createAccount("Junior", "j", 1500.0); + casinoAccountManager.registerAccount(casinoAccount); + String expectedUser = "Junior"; + String expectedPassword = "j"; + //when + CasinoAccount actual = casinoAccountManager.getAccount(expectedUser, expectedPassword); + //then + Assert.assertNotNull(actual); + +} + + +} diff --git a/src/test/java/com/github/zipcodewilmington/RoulettePlayerTest.java b/src/test/java/com/github/zipcodewilmington/RoulettePlayerTest.java new file mode 100644 index 000000000..085e878ba --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/RoulettePlayerTest.java @@ -0,0 +1,30 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.cardGames.BlackJack; +import com.github.zipcodewilmington.casino.games.cardGames.BlackJackPlayer; +import com.github.zipcodewilmington.casino.games.roulette.RouletteGame; +import com.github.zipcodewilmington.casino.games.roulette.RoulettePlayer; +import org.junit.Assert; +import org.junit.Test; + +public class RoulettePlayerTest { + + @Test + public void implementationTest(){ + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1200.); + RoulettePlayer roulettePlayer = new RoulettePlayer(casinoAccount); + + //when + + //then + Assert.assertTrue(roulettePlayer instanceof PlayerInterface); + } + + + + + +} diff --git a/src/test/java/com/github/zipcodewilmington/RouletteTest.java b/src/test/java/com/github/zipcodewilmington/RouletteTest.java new file mode 100644 index 000000000..add9b71f4 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/RouletteTest.java @@ -0,0 +1,266 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.cardGames.BlackJackPlayer; +import com.github.zipcodewilmington.casino.games.roulette.RouletteGame; +import org.junit.Assert; +import org.junit.Test; + +public class RouletteTest { + private String AnsiGreen = "\u001B[32m"; + private String AnsiReset = "\u001B[0m"; + private String AnsiRed = "\u001B[31m"; + + @Test + public void testBalanceConstructor(){ + //Given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + RouletteGame rouletteGame = new RouletteGame(casinoAccount); + Double expectedBalance = 1500.0; + //When + Double actualBalance = rouletteGame.getBalance(); + //Then + Assert.assertEquals(expectedBalance, actualBalance); + + } + + + + @Test + public void testEvenWin() { + //Given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1000.0); + RouletteGame rouletteGame = new RouletteGame(casinoAccount); + + String expected = AnsiGreen+"you won $200.0"+AnsiReset+"\n" + + "Your balance is: $1200.0"; + + //When + String actual = rouletteGame.evenChoice(2, 100.0); + + //Then + Assert.assertEquals(expected, actual); + } + + + @Test + public void testEvenLoss() { + //Given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1000.0); + RouletteGame rouletteGame = new RouletteGame(casinoAccount); + + String expected = AnsiRed+"you lost $100.0"+AnsiReset+"\n" + + "Your balance is: $900.0"; + //When + String actual = rouletteGame.evenChoice(3, 100.0); + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testOddWin() { + //Given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1000.0); + RouletteGame rouletteGame = new RouletteGame(casinoAccount); + + String expected = AnsiGreen+"you won $400.0"+AnsiReset+"\n" + + "Your balance is: $1400.0"; + + //When + String actual = rouletteGame.oddChoice(9, 200.0); + + //Then + Assert.assertEquals(expected, actual); + + } + + @Test + public void testOddLoss() { + //Given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1000.0); + RouletteGame rouletteGame = new RouletteGame(casinoAccount); + + String expected = AnsiRed+"you lost $200.0"+AnsiReset+"\n" + + "Your balance is: $800.0"; + //When + String actual = rouletteGame.oddChoice(10, 200.0); + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testRedWin() { + //Given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1000.0); + RouletteGame rouletteGame = new RouletteGame(casinoAccount); + + String expected = AnsiGreen+"you won $800.0"+AnsiReset+"\n" + + "Your balance is: $1800.0"; + //When + String actual = rouletteGame.redChoice(14, 400.0); + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testRedLoss() { + //Given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1000.0); + RouletteGame rouletteGame = new RouletteGame(casinoAccount); + + String expected = AnsiRed+"you lost $300.0"+AnsiReset+"\n" + + "Your balance is: $700.0"; + //When + String actual = rouletteGame.redChoice(26, 300.0); + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testBlackWin() { + //Given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1000.0); + RouletteGame rouletteGame = new RouletteGame(casinoAccount); + + String expected = AnsiGreen+"you won $1000.0"+AnsiReset+"\n" + + "Your balance is: $2000.0"; + //When + String actual = rouletteGame.blackChoice(11, 500.0); + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testBlackLoss() { + //Given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1000.0); + RouletteGame rouletteGame = new RouletteGame(casinoAccount); + + String expected = AnsiRed+"you lost $400.0"+AnsiReset+"\n" + + "Your balance is: $600.0"; + //When + String actual = rouletteGame.blackChoice(5, 400.0); + //Then + Assert.assertEquals(expected, actual); + + } + + @Test + public void testPickNumberWin() { + //Given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1000.0); + RouletteGame rouletteGame = new RouletteGame(casinoAccount); + + String expected = AnsiGreen+"you won $3500.0"+AnsiReset+"\n" + + "Your balance is: $4500.0"; + //When + String actual = rouletteGame.pickNumberChoice(5, 100.0, 5); + + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testPickNumberLoss() { + //Given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1000.0); + RouletteGame rouletteGame = new RouletteGame(casinoAccount); + + String expected = AnsiRed+"you lost $500.0"+AnsiReset+"\n" + + "Your balance is: $500.0"; + + //When + String actual = rouletteGame.pickNumberChoice(10, 500.0, 9); + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testLowWin() { + //Given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1000.0); + RouletteGame rouletteGame = new RouletteGame(casinoAccount); + + String expected = AnsiGreen+"you won $800.0"+AnsiReset+"\n" + + "Your balance is: $1800.0"; + + //When + String actual = rouletteGame.betweenOneAndEighteen(5, 400.0); + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testLowLoss() { + //Given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1000.0); + RouletteGame rouletteGame = new RouletteGame(casinoAccount); + + String expected = AnsiRed+"you lost $500.0"+AnsiReset+"\n" + + "Your balance is: $500.0"; + //When + String actual = rouletteGame.betweenOneAndEighteen(19, 500.0); + //Then + Assert.assertEquals(expected, actual); + } + + @Test + public void testHighWin() { + //Given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1000.0); + RouletteGame rouletteGame = new RouletteGame(casinoAccount); + + String expected = AnsiGreen+"you won $800.0"+AnsiReset+"\n" + + "Your balance is: $1800.0"; + //When + String actual = rouletteGame.betweenNineteenAndThirtySix(21, 400.0); + //Then + Assert.assertEquals(expected, actual); + + } + + @Test + public void testHighLoss() { + //Given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1000.0); + RouletteGame rouletteGame = new RouletteGame(casinoAccount); + + String expected = AnsiRed+"you lost $700.0"+AnsiReset+"\n" + + "Your balance is: $300.0"; + //When + String actual = rouletteGame.betweenNineteenAndThirtySix(18, 700.0); + //Then + Assert.assertEquals(expected, actual); + } + @Test + public void addRoulettePlayerTest() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + RouletteGame rouletteGame = new RouletteGame(casinoAccount); + PlayerInterface player = new BlackJackPlayer(casinoAccount); + + //when + rouletteGame.add(player); + CasinoAccount actual = player.getArcadeAccount(); + + //then + Assert.assertNotNull(actual); + } + + @Test + public void removeRoulettePlayerTest() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 1500.0); + RouletteGame rouletteGame = new RouletteGame(casinoAccount); + PlayerInterface player = new BlackJackPlayer(casinoAccount); + + //when + rouletteGame.remove(player); + CasinoAccount actual = player.getArcadeAccount(); + + //then + Assert.assertNotNull(actual); + } + +} diff --git a/src/test/java/com/github/zipcodewilmington/WarTest.java b/src/test/java/com/github/zipcodewilmington/WarTest.java new file mode 100644 index 000000000..651c32986 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/WarTest.java @@ -0,0 +1,189 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.cardGames.*; +import org.junit.Assert; +import org.junit.Test; + +public class WarTest { + + @Test + public void testEnterNamesPlayer() { + // given + CasinoAccount casinoAccount = new CasinoAccount("lance", "dog", 1000.0); + War war = new War(casinoAccount); + String expected = "John"; + String choice = "John"; + + // when + String actual = war.enterNames(choice); + // then + Assert.assertEquals(expected, actual); + } + + @Test + public void testShuffle() { + // given + CasinoAccount casinoAccount = new CasinoAccount("lance", "dog", 1000.0); + War war = new War(casinoAccount); + createDeck deck = new createDeck(); + createDeck expected = new createDeck(); + + // when + createDeck actual = war.shuffle(deck); + // then + Assert.assertNotEquals(expected, actual); + } + + @Test + public void testDealCards() { + //given + CasinoAccount casinoAccount = new CasinoAccount("lance", "dog", 1000.0); + War war = new War(casinoAccount); + String expected = ""; + + //when + String actual = war.dealCards(""); + //then + Assert.assertEquals(expected, actual); + + } + + @Test + public void testRules() { + //given + CasinoAccount casinoAccount = new CasinoAccount("john", "ellis", 1000.0); + War war = new War(casinoAccount); + String expected = "Welcome to the game of War.\n\nEach player will get dealt a " + + "card. Whoever has the higher \nvalue card wins that round, and gets awarded " + + "one point. In \nthe event of a tie, no points will be rewarded and both " + + "\nplayers will play again. The winner is the first player to \nscore ten points.\n"; + + //when + String actual = war.warRules(); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void testDetermineGameWinnerPlayer1() { + //given + int player1Score = 10; + int player2Score = 5; + CasinoAccount casinoAccount = new CasinoAccount("john", "ellis", 1000.0); + War war = new War(casinoAccount); + war.enterNames("John"); + String expected = "\n" + "John" + " has won the game!\n"; + + //when + String actual = war.determineGameWinner(player1Score, player2Score); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void testDetermineGameWinnerPlayer2() { + //given + int player1Score = 5; + int player2Score = 10; + CasinoAccount casinoAccount = new CasinoAccount("john", "ellis", 1000.0); + War war = new War(casinoAccount); + war.enterNames("Computer"); + String expected = "\n" + "Computer" + " has won the game!\n"; + + //when + String actual = war.determineGameWinner(player1Score, player2Score); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void testDetermineRoundWinnerPlayer1() { + //given + CasinoAccount casinoAccount = new CasinoAccount("john", "ellis", 1000.0); + War war = new War(casinoAccount); + Cards player1Card = new Cards(Suit.SPADES, Rank.FIVE); + Cards player2Card = new Cards(Suit.SPADES, Rank.TWO); + Double wager = 4.0; + + war.enterNames("John"); + String expected = "\n" + "John" + " has won this round!"; + + //when + String actual = war.determineRoundWinner(player1Card, player2Card, wager); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void testDetermineRoundWinnerPlayer2() { + //given + CasinoAccount casinoAccount = new CasinoAccount("john", "ellis", 1000.0); + War war = new War(casinoAccount); + Cards player1Card = new Cards(Suit.SPADES, Rank.FIVE); + Cards player2Card = new Cards(Suit.SPADES, Rank.NINE); + Double wager = 4.0; + war.enterNames("John"); + String expected = "\n" + "Computer" + " has won this round!"; + + //when + String actual = war.determineRoundWinner(player1Card, player2Card, wager); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void testDetermineRoundWinnerTie() { + //given + CasinoAccount casinoAccount = new CasinoAccount("john", "ellis", 1000.0); + War war = new War(casinoAccount); + Cards player1Card = new Cards(Suit.SPADES, Rank.FIVE); + Cards player2Card = new Cards(Suit.SPADES, Rank.FIVE); + Double wager = 4.0; + war.enterNames("Computer"); + String expected = "\nIt was a tie.\n"; + + //when + String actual = war.determineRoundWinner(player1Card, player2Card, wager); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void testAdd() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 5000.0); + War war = new War(casinoAccount); + PlayerInterface player = new WarPlayer(casinoAccount); + + //when + war.add(player); + CasinoAccount actual = player.getArcadeAccount(); + + //then + Assert.assertNotNull(actual); + } + + @Test + public void testRemove() { + //given + CasinoAccount casinoAccount = new CasinoAccount("j", "j", 5000.0); + War war = new War(casinoAccount); + PlayerInterface player = new BlackJackPlayer(casinoAccount); + + //when + war.remove(player); + CasinoAccount actual = player.getArcadeAccount(); + + //then + Assert.assertNotNull(actual); + } + +}