diff --git a/README.md b/README.md index d2512752a..3305b41c6 100644 --- a/README.md +++ b/README.md @@ -73,3 +73,8 @@ * from the browser, navigate to the _forked_ project from **your** github account. * click the `Pull Requests` tab. * select `New Pull Request` + + + + +## Adding a line to the readMe for git hub example diff --git a/accounts.csv b/accounts.csv new file mode 100644 index 000000000..0f44d2b7a --- /dev/null +++ b/accounts.csv @@ -0,0 +1,2 @@ +1 +Bjork,beeyork,400,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 diff --git a/src/main/java/com/github/zipcodewilmington/Casino.java b/src/main/java/com/github/zipcodewilmington/Casino.java index 5eae9ac0c..89810f271 100644 --- a/src/main/java/com/github/zipcodewilmington/Casino.java +++ b/src/main/java/com/github/zipcodewilmington/Casino.java @@ -1,73 +1,111 @@ package com.github.zipcodewilmington; -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.casino.*; +import com.github.zipcodewilmington.casino.games.Beetle.BeetleGame; +import com.github.zipcodewilmington.casino.games.blackjack.BlackJackGame; +import com.github.zipcodewilmington.casino.games.keno.KenoGameRE; import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessGame; -import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessPlayer; +import com.github.zipcodewilmington.casino.games.plinko.REPlinko; import com.github.zipcodewilmington.casino.games.slots.SlotsGame; -import com.github.zipcodewilmington.casino.games.slots.SlotsPlayer; import com.github.zipcodewilmington.utils.AnsiColor; +import com.github.zipcodewilmington.utils.CSVUtils; import com.github.zipcodewilmington.utils.IOConsole; +import java.io.IOException; + /** * Created by leon on 7/21/2020. */ public class Casino implements Runnable { private final IOConsole console = new IOConsole(AnsiColor.BLUE); - + private CasinoAccount casinoAccount; + private PlayerInterface player; @Override public void run() { - String arcadeDashBoardInput; + Integer arcadeDashBoardInput; CasinoAccountManager casinoAccountManager = new CasinoAccountManager(); do { arcadeDashBoardInput = getArcadeDashboardInput(); - if ("select-game".equals(arcadeDashBoardInput)) { + if (arcadeDashBoardInput.equals(2)) { String accountName = console.getStringInput("Enter your account name:"); 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 { - // TODO - implement better exception handling - String errorMessage = "[ %s ] is an invalid game selection"; - throw new RuntimeException(String.format(errorMessage, gameSelectionInput)); - } + Integer gameSelectionInput = getGameSelectionInput(); + processGameSelection(gameSelectionInput); } else { // TODO - implement better exception handling String errorMessage = "No account found with name of [ %s ] and password of [ %s ]"; - throw new RuntimeException(String.format(errorMessage, accountPassword, accountName)); + //throw new RuntimeException(String.format(errorMessage, accountPassword, accountName)); } - } else if ("create-account".equals(arcadeDashBoardInput)) { + } else if (arcadeDashBoardInput.equals(1)) { 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); casinoAccountManager.registerAccount(newAccount); + this.casinoAccount = newAccount; + casinoAccount.alterAccountBalance(500); + this.player = new Player(accountName, casinoAccount); + this.player.setArcadeAccount(casinoAccount); + } else if(arcadeDashBoardInput.equals(4)){ + try { + CSVUtils.csvFileSaver(this.player.getArcadeAccount()); + } catch (IOException e) { + e.printStackTrace(); + console.println("Save unsuccessful, refer to error message above for more information"); + } + } else if(arcadeDashBoardInput.equals(3)){ + this.casinoAccount = CSVUtils.loadData(); + this.player = new Player(this.casinoAccount.getAccountName(), this.casinoAccount); + casinoAccountManager.registerAccount(this.casinoAccount); + } else if(arcadeDashBoardInput.equals(5)){ + console.print(this.casinoAccount.getScoreboard().printAllScores()); } - } while (!"logout".equals(arcadeDashBoardInput)); + + } while (!arcadeDashBoardInput.equals(6)); } - 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 ]") - .toString()); + private Integer getArcadeDashboardInput() { + return console.getIntegerInput("Welcome to the Arcade Dashboard!\n" + + "From here, you can select any of the following options:\n" + + "\t[ 1. create-account ] [ 2. select-game ] [ 3. load-saved-account ] [ 4. save-account ] [ 5.scoreboard ] [ 6. logout ]"); } - 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 ]") - .toString()); + private Integer getGameSelectionInput() { + return console.getIntegerInput("Welcome to the Game Selection Dashboard!\n" + + "From here, you can select any of the following options:\n" + + "[ 1.SLOTS ] [ 2.NUMBERGUESS ] [ 3.PLINKO ] [ 4.BEETLE ] [ 5.BLACKJACK ] [ 6.KENO ]"); + } + + private void processGameSelection(Integer input){ + //input = input.toLowerCase(Locale.ROOT); + GameInterface gameObject; + switch(input){ + case 4: + gameObject = new BeetleGame(); + break; + case 1: + gameObject = new SlotsGame(); + break; + case 5: + gameObject = new BlackJackGame(); + break; + case 2: + gameObject = new NumberGuessGame(); + break; + case 3: + gameObject = new REPlinko(); + break; + case 6: + gameObject = new KenoGameRE(); + break; + default: + gameObject = new BeetleGame(); + } + + play(gameObject, player); } private void play(Object gameObject, Object playerObject) { @@ -76,4 +114,6 @@ private void play(Object gameObject, Object playerObject) { game.add(player); game.run(); } + + } diff --git a/src/main/java/com/github/zipcodewilmington/MainApplication.java b/src/main/java/com/github/zipcodewilmington/MainApplication.java index 508787a85..efa70a2a4 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.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; + 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..fb7039b57 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java @@ -1,9 +1,49 @@ package com.github.zipcodewilmington.casino; +import com.github.zipcodewilmington.Casino; +import com.github.zipcodewilmington.utils.Scoreboard; + +import java.util.ArrayList; +import java.util.List; + /** * Created by leon on 7/21/2020. * `ArcadeAccount` is registered for each user of the `Arcade`. * The `ArcadeAccount` is used to log into the system to select a `Game` to play. */ public class CasinoAccount { + private String password; + private String accountName; + private Integer accountBalance = 0; + private Scoreboard scoreboard; + + public CasinoAccount(String accountName, String accountPassword){ + this.accountName = accountName; + this.password = accountPassword; + this.scoreboard = new Scoreboard(); + } + + public CasinoAccount(String accountName, String accountPassword, Scoreboard scoreboard){ + this.accountName = accountName; + this.password = accountPassword; + this.scoreboard = scoreboard; + } + + public String getPassword() { + return password; + } + + public String getAccountName() { + return accountName; + } + + public Integer getAccountBalance() { + return accountBalance; + } + + public void alterAccountBalance(Integer value) { + this.accountBalance += value; + } + + public Scoreboard getScoreboard(){ return scoreboard; } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java index 2d09ec2a0..b0d3e036a 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java @@ -1,46 +1,42 @@ package com.github.zipcodewilmington.casino; +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 { + 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)); + for(int i = 0; i < accountList.size(); i++){ + CasinoAccount currentAccount = accountList.get(i); + String pass = currentAccount.getPassword(); + String name = currentAccount.getAccountName(); + if(name.equals(accountName)) + if(pass.equals(accountPassword)){ + return currentAccount; + } + } + System.out.println("Account Name or Password does not match. Are you really you?"); + return null; } - /** - * logs & creates a new `ArcadeAccount` - * - * @param accountName name of account to be created - * @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)); + CasinoAccount myAccount = new CasinoAccount(accountName, accountPassword); + return myAccount; } - /** - * logs & registers a new `ArcadeAccount` to `this.getArcadeAccountList()` - * - * @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)); + this.accountList.add(casinoAccount); } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java b/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java index 9873f1ed9..1b29cf63c 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java +++ b/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java @@ -1,7 +1,8 @@ package com.github.zipcodewilmington.casino; /** - * Created by leon on 7/21/2020. + * Author: Nathan + * Date: 7/12/21 */ public interface GameInterface extends Runnable { /** @@ -20,4 +21,23 @@ public interface GameInterface extends Runnable { * specifies how the game will run */ void run(); + + /** + * Calculate player's winning payout amount of bet x multiplier + * @return (double) amount of money winnings + */ + Integer calculateWinnings(Integer multiplier, Integer betAmount); + + /** + * Subtract the bet amount from player's balance + */ + void subtractBetFromBalance(Integer betAmount); + + /** + * Add winnings amount to player's balance + */ + void addMoneyToBalance(PlayerInterface Player, Integer winnings); + + + } diff --git a/src/main/java/com/github/zipcodewilmington/casino/GameScoreboardInterface.java b/src/main/java/com/github/zipcodewilmington/casino/GameScoreboardInterface.java new file mode 100644 index 000000000..1d3e89836 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/GameScoreboardInterface.java @@ -0,0 +1,15 @@ +package com.github.zipcodewilmington.casino; + + +import com.github.zipcodewilmington.utils.GameScoreBoard; + +public interface GameScoreboardInterface { + Integer getLifetimeBets(); + Integer getLifetimeWinnings(); + Integer getLifetimeLosses(); + void addToLifetimeWinnings(Integer winnings); + void addToLifetimeLosses(Integer losses); + void addToLifetimeBets(Integer bets); + String getGameName(); + String printScores(); +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/Player.java b/src/main/java/com/github/zipcodewilmington/casino/Player.java new file mode 100644 index 000000000..e84c87027 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/Player.java @@ -0,0 +1,51 @@ +package com.github.zipcodewilmington.casino; + + +public class Player implements PlayerInterface{ + + private String name; + private Integer balance = 0; + private Integer currentBet = 0; + private CasinoAccount arcadeAccount; + + public Player(String name, CasinoAccount account) { + this.name = name; + this.arcadeAccount = account; + } + + public String getName() { + return name; + } + + + public Integer getBalance() { + return balance; + } + + public void setCurrentBet(Integer currentBet) { + this.currentBet = currentBet; + } + + public void setBalance(Integer deposit) { + this.balance = balance + deposit; + } + + + public Integer makeBet(Integer betAmount) { + currentBet = betAmount; + balance = balance - currentBet; + return currentBet; + } + + public Integer getCurrentBet() { + return currentBet; + } + + public CasinoAccount getArcadeAccount(){ + return this.arcadeAccount; + } + + public void setArcadeAccount(CasinoAccount arcadeAccount) { + this.arcadeAccount = arcadeAccount; + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/PlayerInterface.java b/src/main/java/com/github/zipcodewilmington/casino/PlayerInterface.java index c50b5113b..7fd3978b8 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/PlayerInterface.java +++ b/src/main/java/com/github/zipcodewilmington/casino/PlayerInterface.java @@ -11,11 +11,13 @@ public interface PlayerInterface { * @return the `ArcadeAccount` used to log into the `Arcade` system to play this game */ CasinoAccount getArcadeAccount(); - + void setArcadeAccount(CasinoAccount casinoAccount); /** * Defines how a specific implementation of `PlayerInterface` plays their respective game. * @param specify any return type you would like here * @return whatever return value you would like */ - SomeReturnType play(); + + + // SomeReturnType play(); } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java new file mode 100644 index 000000000..178af02eb --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java @@ -0,0 +1,110 @@ +package com.github.zipcodewilmington.casino.games.Beetle; + +import com.github.zipcodewilmington.casino.models.Dice; + +public class Beetle{ + private Dice dice = new Dice(1); + private Integer currentPlayer = 0; + private Integer[][] playerBeetles; + private Integer[] scoreboard; + private Integer numPlayers; + private Integer lastDiceRolls[] = {0, 0}; + + + public Beetle(Integer numPlayers){ + this.numPlayers = numPlayers; + this.playerBeetles = new Integer[numPlayers][6]; + this.scoreboard = new Integer[numPlayers]; + this.initializeBeetleCards(); + this.initializeScoreboards(); + } + + public void initializeBeetleCards(){ + for(int i = 0; i < numPlayers; i++){ + for(int j = 0; j < 6; j++){ + this.playerBeetles[i][j] = 0; + } + } + } + + public void initializeScoreboards(){ + for(int i = 0; i < numPlayers; i++){ + this.scoreboard[i] = 0; + } + } + + public Dice getDice() { + return dice; + } + + public Integer getCurrentPlayer() { + return currentPlayer; + } + + public Integer[][] getPlayerBeetles() { + return playerBeetles; + } + + public Integer getNumPlayers() { + return numPlayers; + } + + public Integer[] getPlayerCard(Integer playerNumber){ + return this.getPlayerBeetles()[playerNumber]; + } + + public void setCurrentPlayer(Integer currentPlayer) { + this.currentPlayer = currentPlayer; + } + + public void setPlayerBeetles(Integer player, Integer diceRoll) { + this.playerBeetles[player][diceRoll - dice.getNumDice()]++; + this.lastDiceRolls[player] = diceRoll; + } + + public void nextPlayer(){ + this.currentPlayer = (this.currentPlayer + 1) % this.numPlayers; + } + + public String printBeetle(Integer player){ + Integer[] currentBeetle = this.getPlayerBeetles()[player]; + String output = "\u001B[36mBody:"; + output += (currentBeetle[0].equals(0)) ? "0 " : "X "; + output += "Head:"; + output += (currentBeetle[1].equals(0)) ? "0 " : "X "; + output += "Legs:"; + output += (currentBeetle[2].equals(0)) ? "0 " : "X "; + output += "Eyes:"; + output += (currentBeetle[3].equals(0)) ? "0 " : "X "; + output += "Antenna:"; + output += (currentBeetle[4].equals(0)) ? "0 " : "X "; + output += "Tail:"; + output += (currentBeetle[5].equals(0)) ? "0 " : "X "; + + return output; + } + + public Boolean checkWinner(Integer player){ + if(this.beetleIsComplete(player)){ + return true; + } + return false; + } + + public Boolean beetleIsComplete(Integer player){ + Integer[] playerBeetle = getPlayerCard(player); + for(int i = 0; i < 6; i++){ + if(playerBeetle[i] == 0) + return false; + } + return true; + } + + public Integer getLastDiceRoll(Integer index){ + return this.lastDiceRolls[index]; + } + + public Integer getScore(Integer player){ + return this.scoreboard[player]; + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java new file mode 100644 index 000000000..b3bb3134c --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java @@ -0,0 +1,200 @@ +package com.github.zipcodewilmington.casino.games.Beetle; + +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.ArrayList; + +public class BeetleGame implements GameInterface { + private Beetle game; + private Boolean isRunning = false; + private PlayerInterface player; + private IOConsole console = new IOConsole(); + private Integer betAmt; + private Boolean isDemo = false; + + public BeetleGame(){ + this.game = new Beetle(2); + } + + public void add(PlayerInterface player){ + this.player = player; + } + + /** + * removes a player from the game + * @param player the player to be removed from the game + */ + public void remove(PlayerInterface player){ + this.player = null; + } + + /** + * specifies how the game will run + */ + public void run(){ + if(isDemo) return; + this.initGame(); + while(this.isRunning){ + this.nextPlayer(); + this.executeTurn(); + this.isGameOver(this.game.checkWinner(this.game.getCurrentPlayer())); + } + this.determinePayout(); + console.println(this.printEndingGameMessage()); + } + + public void initGame(){ + console.println(printWelcome()); + console.newLine(); + printBalanceAndBetText(); + Integer betAmt = console.getIntegerInput("\u001B[34m How much do you want to bet?"); + this.setBetAmt(betAmt); + console.newLine(); + game.setCurrentPlayer(-1); + this.isRunning = true; + } + + public String printBeetleCards(){ + String output = ""; + output += "\u001B[32mYour last dice roll: " + game.getLastDiceRoll(0) + + " Your Beetle: \n"; + output += game.printBeetle(0) +"\n"; + output += "\u001B[32mDealer's last dice roll: " + game.getLastDiceRoll(1) + + " Dealer's Beetle: \n"; + output += game.printBeetle(1); + return output; + } + + public void isGameOver(boolean playerWon){ + if(playerWon){ + isRunning = false; + } + } + public void nextPlayer(){ + game.nextPlayer(); + } + + public void executeTurn(){ + Integer currentPlayer = game.getCurrentPlayer(); + if(game.getCurrentPlayer() == 0){ + console.println(printNextTurnMessage()); + this.console.pressEnterToProceed(); + } + game.setPlayerBeetles(currentPlayer, game.getDice().tossAndSum()); + } + + public String printNextTurnMessage(){ + String output = this.printBeetleCards() + "\nPress enter to roll next dice"; + return output; + } + + public Integer determinePayout(){ + Integer payout = (int)(this.betAmt * 1.1); + if(this.game.getCurrentPlayer() == 0){ + this.player.getArcadeAccount().alterAccountBalance(payout); + player.getArcadeAccount().getScoreboard().getBeetleScores().addToLifetimeWinnings(payout); + return payout; + } + return 0; + } + /** + * Calculate player's winning payout amount of bet x multiplier + * @return (double) amount of money winnings + */ + public Integer calculateWinnings(Integer multiplier, Integer betAmount){ + return multiplier * betAmount; + } + + /** + * Subtract the bet amount from player's balance + */ + public void subtractBetFromBalance(Integer betAmount){ + player.getArcadeAccount().alterAccountBalance(betAmount * -1); + } + + + /** + * Add winnings amount to player's balance + */ + public void addMoneyToBalance(PlayerInterface Player, Integer winnings){ + Player.getArcadeAccount().alterAccountBalance(winnings); + } + + + + public String printWelcome() { + return + "\u001B[33m***********************************\n" + + "*** ***\n" + + "****** WELCOME TO BEETLE ******\n" + + "*** ***\n" + + "***********************************"; + } + + + public String printBalanceAndBetText(){ + console.newLine(); + console.println("\u001B[35m Current account balance: " + this.player.getArcadeAccount().getAccountBalance()); + console.newLine(); + return "\u001B[35m Current account balance: " + this.player.getArcadeAccount().getAccountBalance(); + } + + public String printWinnerMessage(){ + if(this.game.getCurrentPlayer() == 0){ + this.determinePayout(); + return "You win!"; + } else { + this.player.getArcadeAccount().getScoreboard().getBeetleScores() + .addToLifetimeLosses(this.betAmt); + return "Dealer wins..."; + } + } + + public String printEndingGameMessage(){ + String output = "\nFinal Beetle results: \n" + + this.printBeetleCards() + "\n"; + output += this.printWinnerMessage() + printWinnerMessage(); + + return output; + } + + public Beetle getGame() { + return game; + } + + public Boolean getDemo() { + return isDemo; + } + + public void setDemo(Boolean demo) { + isDemo = demo; + } + + public PlayerInterface getPlayer() { + return player; + } + + public Boolean getIsRunning(){ + return this.isRunning; + } + + public Integer getBetAmt() { + return betAmt; + } + + public void setBetAmt(Integer betAmt) { + this.betAmt = betAmt; + this.player.getArcadeAccount() + .getScoreboard() + .getBeetleScores() + .addToLifetimeBets(betAmt); + } + + public void setRunning(boolean running){ + this.isRunning = running; + } +} + diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java new file mode 100644 index 000000000..ac12cb40b --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java @@ -0,0 +1,25 @@ +package com.github.zipcodewilmington.casino.games.Beetle; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.PlayerInterface; + +public class BeetlePlayer implements PlayerInterface { + private PlayerInterface player; + + public BeetlePlayer(PlayerInterface player){ + this.player = player; + } + + + public CasinoAccount getArcadeAccount() { + return player.getArcadeAccount(); + } + + public void setArcadeAccount(CasinoAccount casinoAccount) { + this.player.setArcadeAccount(casinoAccount); + } + + public PlayerInterface getPlayer() { + return player; + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java new file mode 100644 index 000000000..68211d354 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java @@ -0,0 +1,108 @@ +package com.github.zipcodewilmington.casino.games.blackjack; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.models.Card; + +import java.util.*; + +public class BlackJack { + List playersHand; + List playersHandOnSplit; + List dealersHand; + Deque deckOfCards; + Integer betAmount; // Equal to user input + + public BlackJack() { + this.playersHand = new ArrayList<>(); + this.playersHandOnSplit = new ArrayList<>(); + this.dealersHand = new ArrayList<>(); + this.deckOfCards = new ArrayDeque<>(generateNewDeck()); + } + + public List generateNewDeck() { + Card card = new Card(); + card.polishDeck(); + card.shuffleDeck(); + return card.getCardPool(); + } + + public List givePlayerCard() { + Integer valueOfCard = deckOfCards.pop(); + this.playersHand.add(valueOfCard); + return this.playersHand; + } + + public List givePlayerCardOnSplit() { + Integer valueOfCard = deckOfCards.pop(); + this.playersHandOnSplit.add(valueOfCard); + return this.playersHandOnSplit; + } + + public List giveDealerCard() { + Integer valueOfCard = deckOfCards.pop(); + this.dealersHand.add(valueOfCard); + return this.dealersHand; + } + + public Integer splitPlayersCurrentValue () { + Integer sum = 0; + for (int i = 0; i < this.playersHandOnSplit.size(); i++) { + sum += this.playersHandOnSplit.get(i); + } + return sum; + } + + public Integer playersCurrentValue() { + Integer sum = 0; + for (int i = 0; i < this.playersHand.size(); i++) { + sum += this.playersHand.get(i); + } + return sum; + } + + public Integer dealersCurrentValue() { + Integer sum = 0; + for (int i = 0; i < this.dealersHand.size(); i++) { + sum += this.dealersHand.get(i); + } + return sum; + } + + + + public boolean playerBreaks21() { + if (playersCurrentValue() > 21) { + return true; + } else { + return false; + } + } + + + + public List getPlayersHand() { + return playersHand; + } + + public void setPlayersHand(List playersHand) { + this.playersHand = playersHand; + } + + public List getDealersHand() { + return dealersHand; + } + + public void setDealersHand(List dealersHand) { + this.dealersHand = dealersHand; + } + + public List getPlayersHandOnSplit() { + return playersHandOnSplit; + } + + public void setPlayersHandOnSplit(List playersHandOnSplit) { + this.playersHandOnSplit = playersHandOnSplit; + } +} \ No newline at end of file diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java new file mode 100644 index 000000000..14a5fba8d --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java @@ -0,0 +1,367 @@ +package com.github.zipcodewilmington.casino.games.blackjack; + +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; + + +public class BlackJackGame implements GameInterface { + private Boolean isRunning = false; + private PlayerInterface playerInt; + private Boolean isDemo = false; + Integer userBet; + Integer splitBet; + IOConsole input = new IOConsole(); + IOConsole blue = new IOConsole(AnsiColor.BLUE); + IOConsole red = new IOConsole(AnsiColor.RED); + IOConsole cyan = new IOConsole(AnsiColor.CYAN); + IOConsole green = new IOConsole(AnsiColor.GREEN); + IOConsole purple = new IOConsole(AnsiColor.PURPLE); + Integer winnings = 0; + Integer splitWinnings = 0; + BlackJack bj; + + + /* + reorder the 'helper' methods for more clarity + * need formatting on splitHand + * need refinement on formatting the beginning + * make it flashy + */ + + public BlackJackGame () { + } + + public void run() { + printWelcome(); + while(!isRunning) { + // include betting range + playerInt.getArcadeAccount().alterAccountBalance(splitWinnings); + playerInt.getArcadeAccount().alterAccountBalance(winnings); + cyan.println("Your current balance is... " + playerInt.getArcadeAccount().getAccountBalance() + "\n"); + Integer userInput = input.getIntegerInput("\u001B[32m1. Start A Hand" + "\n" + "\u001B[31m2. Quit" + "\n"); + switch (userInput) { + case 1: + BlackJack freshHand = new BlackJack(); + bj = freshHand; + userBet = (input.getIntegerInput("\u001B[32mHow much would you like to bet?" + "\n")); + userBetCondition(); + playerInt.getArcadeAccount().alterAccountBalance(userBet * (-1)); + startGame(); + break; + case 2: + isRunning = true; + } + } + } + + public void printWelcome () { + blue.println("============================================================" + "\n" + + "===== =====" + "\n" + + "===== WELCOME =====" + "\n" + + "===== TO =====" + "\n" + + "===== B L A C K =====" + "\n" + + "===== J A C K =====" + "\n" + + "===== =====" + "\n" + + "============================================================"); + } + + public void startGame () { + bj.givePlayerCard(); + cyan.println("\n" + "Your starting card : " + bj.playersCurrentValue() + "\n"); + cyan.println("Your second next card : " + bj.givePlayerCard() + "\n"); + cyan.println("Hand value : " + bj.playersCurrentValue() + "\n"); + if (twoCardBlackJack()) { + green.println("BLACK JACK!!!" + "\n"); + calculateWinnings(3, userBet); + } else if(isDemo){ + return; + } else if (bj.playersHand.get(0).equals(bj.playersHand.get(1))) { // include conditional on starting blackjack! + splitPlayer(); + + } else { + standardGame(); + } + } + + public boolean twoCardBlackJack () { + if ((bj.playersHand.get(0) + bj.playersHand.get(1)) == 21) { + calculateWinnings(3, userBet); + return true; + } + return false; + } + + public void standardGame () { + boolean isWinner = false; + while (!isWinner) { + cyan.println("With the value of " + bj.playersCurrentValue() + "..." + "\n"); + Integer userChoice = input.getIntegerInput("1. Hit" + "\n" + "2. Stay"); + switch (userChoice) { + case 1: + bj.givePlayerCard(); + if (checkStandardWinner()) { + isWinner = true; + } + break; + case 2: + bj.giveDealerCard(); + red.println("The dealers first card : " + bj.dealersCurrentValue()); + bj.giveDealerCard(); + dealersGame(); + isWinner = true; + break; + } + } + } + + public void splitPlayer () { + Integer choice = input.getIntegerInput("1. Split" + "\n" + "2. No, I'll play this hand"); + if (choice.equals(2)) { + standardGame(); + } else { // include another betting portion for this hand + splitHandRound(); + } + } + + + public CasinoAccount getArcadeAccount() { + return null; + } + + + public Integer calculateWinnings(Integer multiplier, Integer userBet) { + winnings = multiplier * userBet; + return winnings; + } + + public Integer calculateWinningsSplitHand(Integer multiplier, Integer splitBet) { + splitWinnings = multiplier * splitBet; + return splitWinnings; + } + + + private void splitPlayerHitsBlackJack(Integer splitBet) { + green.println("BLACK JACK!!"); + calculateWinningsSplitHand(3, splitBet); + standardGame(); + } + + private void splitPlayerBust(Integer splitBet) { + red.println("Sorry bud, you got " + bj.splitPlayersCurrentValue() + + ", you still have one more hand!"); + calculateWinningsSplitHand(0, splitBet); + standardGame(); + } + + private boolean checkStandardWinner() { + boolean playerWon; + cyan.println("Current hand value " + bj.playersCurrentValue() + "\n"); + if(bj.playersCurrentValue() > 21) { + playerBustButHasAces(); + if (bj.playersCurrentValue() > 21) { + red.println("Sorry bud, you got " + bj.playersCurrentValue() + + ", better luck next time" + "\n"); + calculateWinnings(0, userBet); + playerWon = true; + } else { + playerWon = false; + } + } else if (playerHitsBlackJack()) { + green.println("BLACK JACK!!" + "\n"); + calculateWinnings(3, userBet); + playerWon = true; + } else { + playerWon = false; + } + return playerWon; + } + + + private Integer secondHandBet() { + Integer splitValue = bj.playersHand.get(1); + bj.playersHandOnSplit.add(splitValue); + bj.playersHand.set(1, 0); + Integer splitBet = input.getIntegerInput("\u001B[32mPlease place your bet for the second hand" + "\n"); + if (splitBet > playerInt.getArcadeAccount().getAccountBalance()) { + splitHandBetConditions(); + } + playerInt.getArcadeAccount().alterAccountBalance(splitBet * (-1)); + cyan.println("Your hand has been split! Current value " + bj.splitPlayersCurrentValue() + "\n" + "\n"); + return splitBet; + } + + private void splitHandRound() { + boolean isWinnerSecondHand = false; + Integer splitBet = secondHandBet(); + while (!isWinnerSecondHand) { + Integer userInput = input.getIntegerInput("1. Hit" + "\n" + "2. Stay" + "\n"); + switch (userInput) { + case 1: + bj.givePlayerCardOnSplit(); + cyan.println("Current hand value " + bj.splitPlayersCurrentValue()); + if (bj.splitPlayersCurrentValue() > 21) { + splitHandBustHasAces(); + if (bj.splitPlayersCurrentValue() > 21) { + splitPlayerBust(splitBet); + isWinnerSecondHand = true; + } else { + isWinnerSecondHand = false; + } + } else if (splitPlayerHitsBlackJack()) { + splitPlayerHitsBlackJack(splitBet); + isWinnerSecondHand = true; + } + break; + case 2: + standardGame(); + } + } + } + public void dealersGame() { + boolean gameEnd = false; + while (!gameEnd) { + red.println("The dealer has : " + bj.dealersCurrentValue()); + if (bj.dealersCurrentValue() > 21) { + green.println("You win!" + "\n"); + calculateWinnings(2, userBet); + gameEnd = true; + } else if (bj.dealersCurrentValue() == 21) { + red.println("The dealer has won!" + "\n"); + calculateWinnings(0, userBet); + gameEnd = true; + } else if (bj.dealersCurrentValue() > bj.playersCurrentValue()) { + red.println("The dealer has won!" + "\n"); + calculateWinnings(0, userBet); + gameEnd = true; + } else { + bj.giveDealerCard(); + } + } + } + + public void playerBustButHasAces () { + for (int i = 0; i < bj.playersHand.size(); i++) { + if (bj.playersHand.get(i).equals(11)) { + bj.playersHand.set(i, 1); + purple.println("***You had an Ace - we reduced that 11 to a 1! Keep going!***" + "\n" ); + break; + } + } + } + + public void dealerBustButHasAces () { + for (int i = 0; i < bj.dealersHand.size(); i++) { + if (bj.dealersHand.get(i).equals(11)) { + bj.dealersHand.set(i, 1); + break; + } + } + } + + public void splitHandBustHasAces () { + for (int i = 0; i < bj.playersHandOnSplit.size(); i++) { + if (bj.playersHandOnSplit.get(i).equals(11)) { + bj.playersHandOnSplit.set(i, 1); + purple.println("***You had an Ace - we reduced that 11 to a 1! Keep going!***" + "\n" ); + break; + } + } + } + + public boolean splitPlayerHitsBlackJack () { + if (bj.splitPlayersCurrentValue() == 21) { + calculateWinningsSplitHand(3, splitBet); + return true; + } else { + return false; + } + } + + public boolean playerHitsBlackJack() { + if (bj.playersCurrentValue() == 21) { + calculateWinnings(3, userBet); + return true; + } else { + return false; + } + } + + public void userBetCondition () { + while (userBet > playerInt.getArcadeAccount().getAccountBalance()) { + red.println("Oh no! You're trying to place a bet with more money than you have..."); + userBet = (input.getIntegerInput("\u001B[32mHow much would you like to bet?" + "\n")); + } + } + + public void splitHandBetConditions () { + while (splitBet > playerInt.getArcadeAccount().getAccountBalance()) { + red.println("You don't have enough money for that, Silly!" + "\n"); + splitBet = (input.getIntegerInput("\u001B[32mPlease place your bet for the second hand" + "\n")); + } + } + + public void subtractBetFromBalance(Integer betAmount) { + this.getPlayer().getArcadeAccount().alterAccountBalance(betAmount * -1); + } + + + public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + Player.getArcadeAccount().alterAccountBalance(winnings); + } + + public void add(PlayerInterface player) { + this.playerInt = player; + } + + + public void remove(PlayerInterface player) { + this.playerInt = null; + } + + public Boolean getRunning() { + return isRunning; + } + + public void setRunning(Boolean running) { + isRunning = running; + } + + public Integer getUserBet() { + return userBet; + } + + public void setUserBet(Integer userBet) { + this.userBet = userBet; + } + + public PlayerInterface getPlayer() { + return playerInt; + } + + public Boolean getDemo() { + return isDemo; + } + + public void setDemo(Boolean demo) { + isDemo = demo; + } + + public BlackJack getGame() { + return bj; + } + + public void setGame(){ + bj = new BlackJack(); + } + + public Integer getSplitBet() { + return splitBet; + } + + public void setSplitBet(Integer splitBet) { + this.splitBet = splitBet; + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackPlayer.java new file mode 100644 index 000000000..ef586091e --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackPlayer.java @@ -0,0 +1,27 @@ +package com.github.zipcodewilmington.casino.games.blackjack; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; + +public class BlackJackPlayer implements PlayerInterface { + private PlayerInterface player; + + public BlackJackPlayer(PlayerInterface player) { + this.player = player; + } + + @Override + public CasinoAccount getArcadeAccount() { + return player.getArcadeAccount(); + } + + @Override + public void setArcadeAccount(CasinoAccount casinoAccount) { + + } + + public PlayerInterface getPlayer() { + return player; + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGameRE.java b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGameRE.java new file mode 100644 index 000000000..e1a387611 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGameRE.java @@ -0,0 +1,235 @@ +package com.github.zipcodewilmington.casino.games.keno; + +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.HashSet; + +public class KenoGameRE implements GameInterface { + private final IOConsole Red = new IOConsole(AnsiColor.RED); + private final IOConsole Green = new IOConsole(AnsiColor.GREEN); + private final IOConsole Yellow = new IOConsole(AnsiColor.YELLOW); + private final IOConsole Blue = new IOConsole(AnsiColor.BLUE); + private final IOConsole Purple = new IOConsole(AnsiColor.PURPLE); + private final IOConsole Cyan = new IOConsole(AnsiColor.CYAN); + private IOConsole console = new IOConsole(AnsiColor.BLUE); + private PlayerInterface currentPlayer; + private Integer userBet; + private Integer currentUserChoice; + private HashSet tenChoices; + private HashSet twentyOneRandom; + private HashSet matches; + private Integer multiplier; + private Integer winnings; + + //--------------------------------------------------------------------- + + public KenoGameRE(){ + } + + @Override + public void run() { + //Display welcome + Yellow.println(printWelcome()); + //Display instruction + console.setWait(1000); + Blue.println(displayInstruction()); + Boolean quit = false; + while(!quit) { + //Print user current balance + console.setWait(1000); + Green.println("Your Current Balance: " + getPlayerBalance()); + //Ask user for bet amount + console.setWait(1000); + userBet = Purple.getIntegerInput("How much do you want to bet?"); + //Subtract bet amount from user's balance + subtractBetFromBalance(userBet); + //Ask user to pick 10 numbers between 1-80 and add to array + getUserChoices(); + //Display user's picks + console.setWait(1000); + Purple.println("Your chose: " + tenChoices); + //Generate 21 random numbers and add to array + setTwentyOneRandom(twentyOneRandomNum()); + //Display the 21 random numbers + console.setWait(1000); + console.println("Game chose:" + twentyOneRandom); + //Find matches b/w user choice and random 21 + setMatches(findMatches()); + //Print matched array + console.setWait(1000); + Yellow.println("Matches: " + matches); + //Calculate multiplier then set multiplier + Integer multiply = calculateMultiplier(); + setMultiplier(multiply); + //Calculate winnings and set it + Integer win = calculateWinnings(multiplier, userBet); + setWinnings(win); + //Print winnings + console.setWait(1000); + Green.println("You won: $" + winnings); + //Add winnings to player's account balance + addMoneyToBalance(currentPlayer, winnings); + //Print user current balance + console.setWait(1000); + Green.println("Your Current Balance: $" + getPlayerBalance()); + //Ask user to play again + quit = playAgain(); + } + } + + @Override + public void add(PlayerInterface player) { + this.currentPlayer = player; + } + @Override + public void remove(PlayerInterface player) { + this.currentPlayer = null; + } + @Override + public Integer calculateWinnings(Integer multiplier, Integer betAmount) { + return multiplier * betAmount; + } + @Override + public void subtractBetFromBalance(Integer betAmount) { + currentPlayer.getArcadeAccount().alterAccountBalance(betAmount * (-1)); + } + @Override + public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + Player.getArcadeAccount().alterAccountBalance(winnings); + } + + //-------------------------- Getters and Setters ----------------------- + + public PlayerInterface getCurrentPlayer() { + return currentPlayer; + } + + public void setUserBet(Integer userBet) { + this.userBet = userBet; + } + + public void setTwentyOneRandom(HashSet twentyOneRandom) { + this.twentyOneRandom = twentyOneRandom; + } + + public HashSet getTwentyOneRandom() { + return twentyOneRandom; + } + + public HashSet getMatches() { + return matches; + } + + public void setMatches(HashSet matches) { + this.matches = matches; + } + + public HashSet getTenChoices() { + return tenChoices; + } + + public void setTenChoices(HashSet tenChoices) { + this.tenChoices = tenChoices; + } + + public Integer getMultiplier() { + return multiplier; + } + + public void setMultiplier(Integer multiplier) { + this.multiplier = multiplier; + } + + public Integer getWinnings() { + return winnings; + } + + public void setWinnings(Integer winnings) { + this.winnings = winnings; + } + + //-------------------------- My own methods ---------------------------- + + public String printWelcome() { + return "***********************************\n" + + "*** ***\n" + + "****** WELCOME TO KENO ******\n" + + "*** ***\n" + + "***********************************"; + + } + + public String displayInstruction(){ + return "Pick 10 numbers between 1 and 80!\n" + + "The more numbers matched the more you win!"; + } + + public Integer getPlayerBalance(){ + return currentPlayer.getArcadeAccount().getAccountBalance(); + } + + public void getUserChoices(){ + HashSet choices = new HashSet(); + Integer count = 0; + while(choices.size() < 10){ + currentUserChoice = Cyan.getIntegerInput("Choose your #" + (count+1) +" number"); + if(choices.contains(currentUserChoice)){ + Cyan.println("You already chose that number! Try again!"); + } else { + choiceCondition(); + choices.add(currentUserChoice); + count++; + } + } + this.tenChoices = choices; + } + + public void choiceCondition(){ + while(currentUserChoice < 1 || currentUserChoice > 80){ + currentUserChoice = Blue.getIntegerInput("Please choose number between 1 - 80"); + } + } + + public HashSet twentyOneRandomNum(){ + HashSet twentyOne = new HashSet(); + while(twentyOne.size() < 21){ + Integer input = (int) ((Math.random() * (81 - 1)) + 1); + twentyOne.add(input); + } + return twentyOne; + } + + public HashSet findMatches(){ + HashSet matched = new HashSet<>(); + for(Integer element: tenChoices){ + if(twentyOneRandom.contains(element)){ + matched.add((element)); + } + } + return matched; + } + + public Integer calculateMultiplier(){ + return multiplier = matches.size(); + } + + public Boolean playAgain(){ + if(getPlayerBalance() == 0) { + console.setWait(1000); + Red.println("Oh No! You've ran out of money. Goodbye"); + return true; + } else { + //Continue game? + console.setWait(1000); + Integer userInput = Cyan.getIntegerInput("Would you like to play again?\n" + + "1. Yes 2. No"); + if(userInput.equals(2)){ + return true; + } + } + return false; + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoPlayer.java new file mode 100644 index 000000000..24b0daed1 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoPlayer.java @@ -0,0 +1,28 @@ +package com.github.zipcodewilmington.casino.games.keno; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.PlayerInterface; + +public class KenoPlayer implements PlayerInterface { + private PlayerInterface player; + + public KenoPlayer(PlayerInterface player){ + this.player = player; + } + + @Override + public CasinoAccount getArcadeAccount() { + return player.getArcadeAccount(); + } + + @Override + public void setArcadeAccount(CasinoAccount casinoAccount) { + this.player.setArcadeAccount(casinoAccount); + } + + public PlayerInterface getPlayer() { + return this.player; + } +} + + 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 index 795709488..a71ef1cab 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java @@ -1,7 +1,234 @@ package com.github.zipcodewilmington.casino.games.numberguess; +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.Scanner; + /** - * Created by leon on 7/21/2020. + * Created by Nathan on 7/14/2021 */ -public class NumberGuessGame { + +public class NumberGuessGame implements GameInterface { + private final IOConsole Red = new IOConsole(AnsiColor.RED); + private final IOConsole Green = new IOConsole(AnsiColor.GREEN); + private final IOConsole Yellow = new IOConsole(AnsiColor.YELLOW); + private final IOConsole Blue = new IOConsole(AnsiColor.BLUE); + private final IOConsole Purple = new IOConsole(AnsiColor.PURPLE); + private final IOConsole Cyan = new IOConsole(AnsiColor.CYAN); + private Integer maxNumber = 20; + private PlayerInterface currentPlayer; + private Integer betAmount; + private Integer multiplier; + private Integer guessNumber; + private int randomNumber; + private Scanner scanner = new Scanner(System.in); + private Integer[] potentialEarnings = new Integer[4]; + + public NumberGuessGame(){ + } + + @Override + public void run() { + Yellow.println(printWelcome()); + Boolean quitGame = false; + while(!quitGame) { + //print instruction for game + printInstructions(); + //print player's current account balance + Green.println("Your current account balance is: $" + this.currentPlayer.getArcadeAccount().getAccountBalance() + "\n"); + //ask for a bet amount + takeBet(); + //subtract bet amount from player's account + subtractBetFromBalance(betAmount); + calcPotentialEarnings(); + Red.println("You bet: $"+betAmount+ "\n\nBut WAIT!\nFeeling lucky??\nIncrease the difficulty and increase your earnings!\n"); + //print difficulty levels and ask user to choose + setDifficultyLevel(); + setMultiplier(maxNumber); + //ask player to chose number from 0 to difficulty lvl + takeGuess(); + //generate actual number + pickRandomNumber(); + //compare difference + Integer guessRange = getGuessRange(guessNumber, randomNumber); + printGuessVsActual(); + //calculate amount player won + Integer payout = calculatePayout(multiplier, guessRange, betAmount); + //print winnings + Red.println("You won: $"+payout); + //add winnings to player's account + addMoneyToBalance(currentPlayer,payout); + //ask if player wants to play again + Integer input = Cyan.getIntegerInput("Would you like to play again?\n" + + "1. Yes 2. No"); + if(input == 2){ + quitGame = true; + } + } + } + + private void printGuessVsActual() { + Green.println("Lets compare results!"); + Yellow.println("You guessed: " + guessNumber); + Yellow.println("Actual Number: " + randomNumber); + } + + public void printInstructions() { + Blue.println("Guess a number between 0 and 20.\n" + + "Guess close enough and win a prize!\n" + + "Pick the right number to double your bets!\n"); + } + + public Integer calculatePayout(Integer multiplier, Integer guessRange,Integer betAmount) { + Integer payout; + Double percent = 0.0; + Double multiplierAsDouble = multiplier.doubleValue(); + if (guessRange.equals(0)){ + percent = multiplierAsDouble * 1; + } else if(guessRange <= 10){ + percent = multiplierAsDouble * 0.8; + } else if(guessRange <= 25){ + percent = multiplierAsDouble * 0.6; + } else if(guessRange <= 35){ + percent = multiplierAsDouble * 0.4; + } else if(guessRange >= 36){ + percent = multiplierAsDouble * 0.0; + } + Double payoutAsDouble = percent * betAmount; + payout = payoutAsDouble.intValue(); + return payout; + } + + public void pickRandomNumber() { + Integer random = (int) ((Math.random() * (maxNumber - 0)) + 0); + this.randomNumber = random; + + } + + private void takeGuess() { + Purple.println("Pick a number between 0 and " + maxNumber); + this.guessNumber = scanner.nextInt(); + } + + private void takeBet() { + this.betAmount = Blue.getIntegerInput("How much do you want to bet?"); + } + + public String printWelcome() { + return + "************************************\n" + + "*** ***\n" + + "****** !! WELCOME TO !! ******\n" + + "****** !!! GUESS NUMBER !!! ******\n" + + "*** ***\n" + + "************************************\n"; + } + + public void calcPotentialEarnings(){ + Integer[] calcPotentialEarnings = new Integer[4]; + for (int i = 0; i < 4; i++) { + calcPotentialEarnings[i] = betAmount * (i + 2); + } + this.potentialEarnings = calcPotentialEarnings; + } + + private void setDifficultyLevel() { + Integer input = Cyan.getIntegerInput("1. Start max at 20 and win up to " + potentialEarnings[0] + "!\n" + + "2. Change max to 30 and Triple your winnings up to " + potentialEarnings[1] + "!\n"+ + "3. Change max to 40 and QUADRUPLE your winnings up to " + potentialEarnings[2] + "!\n"+ + "4. Change max to 50! SEND IT TO THE MOON AND WIN UP TO " + potentialEarnings[3] + "!\n"); + switch (input){ + case 1: + setMaxNumber(20); + break; + case 2: + setMaxNumber(30); + break; + case 3: + setMaxNumber(40); + break; + case 4: + setMaxNumber(50); + break; + } + } + + public Integer getGuessRange(Integer guessedNumber, Integer actualNumber){ + return guessRangePercentage(Math.abs(guessedNumber - actualNumber)); + } + + public Integer guessRangePercentage(Integer range){ + Double percent = ((range.doubleValue() / this.maxNumber) * 100); + return percent.intValue(); + } + + public Integer getMaxNumber() { + return maxNumber; + } + + public void setMaxNumber(Integer max){ + this.maxNumber = max; + } + + public void setMultiplier(Integer difficultyLvl) { + switch(difficultyLvl){ + case 20: + this.multiplier = 2; + break; + case 30: + this.multiplier = 3; + break; + case 40: + this.multiplier = 4; + break; + case 50: + this.multiplier = 5; + break; + } + } + + public void setBetAmount(Integer betAmount) { + this.betAmount = betAmount; + } + + public Integer[] getPotentialEarnings() { + return potentialEarnings; + } + + public Integer getMultiplier() { + return multiplier; + } + + public int getRandomNumber() { + return randomNumber; + } + + @Override + public void add(PlayerInterface player) { + this.currentPlayer = player; + } + + @Override + public void remove(PlayerInterface player) { + + } + + @Override + public Integer calculateWinnings(Integer multiplier, Integer betAmount) { + return null; + } + + @Override + public void subtractBetFromBalance(Integer betAmount) { + this.currentPlayer.getArcadeAccount().alterAccountBalance((betAmount * -1)); + } + + @Override + public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + Player.getArcadeAccount().alterAccountBalance(winnings); + } + } \ 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 index aa5cce2e7..268616852 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessPlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessPlayer.java @@ -1,7 +1,29 @@ package com.github.zipcodewilmington.casino.games.numberguess; +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.PlayerInterface; + /** - * Created by leon on 7/21/2020. + * Created by Nathan 7/12/2021 */ -public class NumberGuessPlayer { +public class NumberGuessPlayer implements PlayerInterface { + private PlayerInterface player; + + public NumberGuessPlayer(PlayerInterface player){ + this.player = player; + } + + @Override + public CasinoAccount getArcadeAccount() { + return player.getArcadeAccount(); + } + + @Override + public void setArcadeAccount(CasinoAccount casinoAccount) { + this.player.setArcadeAccount(casinoAccount); + } + + public PlayerInterface getPlayer() { + return this.player; + } } \ No newline at end of file diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoPlayer.java new file mode 100644 index 000000000..d1a324fd0 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoPlayer.java @@ -0,0 +1,19 @@ +package com.github.zipcodewilmington.casino.games.plinko; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.PlayerInterface; + +public class PlinkoPlayer implements PlayerInterface { + private PlayerInterface player; + + public PlinkoPlayer(PlayerInterface player){this.player=player;} + @Override + public CasinoAccount getArcadeAccount() { + return player.getArcadeAccount(); + } + + @Override + public void setArcadeAccount(CasinoAccount casinoAccount) { + this.player.setArcadeAccount(casinoAccount); + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/REPlinko.java b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/REPlinko.java new file mode 100644 index 000000000..37fe888f8 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/REPlinko.java @@ -0,0 +1,138 @@ +package com.github.zipcodewilmington.casino.games.plinko; + +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.ArrayList; +import java.util.Collections; +import java.util.List; + +public class REPlinko implements GameInterface { + private PlayerInterface playerInt; + private Boolean isRunning = false; + public List winningValues; + Integer userBet; + Integer userInput; + Integer actualWinnings = 0; + IOConsole input = new IOConsole(); + IOConsole green = new IOConsole(AnsiColor.GREEN); + IOConsole red = new IOConsole(AnsiColor.RED); + IOConsole cyan = new IOConsole(AnsiColor.CYAN); + + public void run() { + printWelcome(); + while(!isRunning) { + playerInt.getArcadeAccount().alterAccountBalance(actualWinnings); + green.println("Your current account balance is " + playerInt.getArcadeAccount().getAccountBalance() + "\n"); + userInput = cyan.getIntegerInput("Wanna play?" + "\n" + "1. Yes" + "\n" + "2. No" + "\n"); + switch (userInput) { + case 1: + askForBet(); + userBetCondition(); + playerInt.getArcadeAccount().alterAccountBalance(userBet * (-1)); + startGame(); + break; + case 2: + isRunning = true; + } + } + } + + public void startGame() { + createBoard(); + shuffleBoard(); + calculateWinnings(checkWin(), userBet); + printWinnings(); + } + + public Integer checkWin () { + return winningValues.get(0); + } + + public void createBoard () { + winningValues = new ArrayList<>(); + winningValues.add(0); + winningValues.add(0); + winningValues.add(0); + winningValues.add(0); + winningValues.add(0); + winningValues.add(1); + winningValues.add(1); + winningValues.add(2); + winningValues.add(3); + winningValues.add(5); + } + + public void shuffleBoard () { + Collections.shuffle(winningValues); + } + + private void userBetCondition() { + while (userBet > playerInt.getArcadeAccount().getAccountBalance()) { + red.println("Oh no! You're trying to place a bet with more money than you have..." + "\n"); + askForBet(); + } + } + + private void printWelcome() { + input.println("Welcome!"); + } + + public void askForBet () { + userBet = (green.getIntegerInput("How much would you like to bet?" + "\n")); + } + + public void printWinnings () { + if (actualWinnings > 0) { + green.println("You've won " + actualWinnings + "!!" + "\n"); + } else { + red.println("Ahhh, better luck next time! You lost... " + "\n"); + } + } + + public void add(PlayerInterface player) { + this.playerInt = player; + } + + public void remove(PlayerInterface player) { + this.playerInt = null; + } + + public Integer calculateWinnings(Integer multiplier, Integer userBet) { + actualWinnings = multiplier * userBet; + return actualWinnings; + } + + public void subtractBetFromBalance(Integer betAmount) { + playerInt.getArcadeAccount().alterAccountBalance(betAmount * (-1)); + } + + public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + Player.getArcadeAccount().alterAccountBalance(winnings); + } + + public PlayerInterface getPlayerInt() { + return playerInt; + } + + public Boolean getRunning() { + return isRunning; + } + + public void setRunning(Boolean running) { + isRunning = running; + } + + public Integer getUserBet() { + return userBet; + } + + public void setUserBet(Integer amt){ + this.userBet = amt; + } + + public List getWinningValues() { + return winningValues; + } +} \ No newline at end of file diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java new file mode 100644 index 000000000..81ff40c0e --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java @@ -0,0 +1,109 @@ +package com.github.zipcodewilmington.casino.games.slots; +import com.github.zipcodewilmington.utils.AnsiColor; +import com.github.zipcodewilmington.utils.IOConsole; + +import java.util.HashMap; + +/** + * Created by Nathan on 7/12/21 + */ + +public class Slots { + private static final String[] slotItems = {" Peach ", " Cherry", "Diamond", " Plum ", " Seven ", " Nine "}; + private String[][] slots = new String[3][3]; + private HashMap winningLines = new HashMap<>(); + private final IOConsole consoleB = new IOConsole(AnsiColor.BLUE); + + public Slots(String[][] slots) { + this.slots = slots; + initializeWinningLines(); + } + + public Slots(){ + this.slots = new String[][] { + {"Peach", "Cherry", "Diamond"}, + {"Diamond", "Plum", "Nine"}, + {"Seven", "Peach", "Diamond"}}; + initializeWinningLines(); + } + + private void initializeWinningLines(){ + for (int i = 1; i < 9; i++) { + winningLines.put(i, "LOSE"); + } + } + + public String[][] getSlots() { + return slots; + } + + public void setSlots(String[][] slots) { + this.slots = slots; + } + + public HashMap getWinningLines() { + return winningLines; + } + + public void spinSlots(){ + String[][] newSlot = new String[3][3]; + for (int a = 0; a < 3; a++) { + newSlot[a][0] = ramdomSlotItem(); + newSlot[a][1] = ramdomSlotItem(); + newSlot[a][2] = ramdomSlotItem(); + } + setSlots(newSlot); + } + + public static String ramdomSlotItem(){ + int input = (int) ((Math.random() * (7 - 1)) + 1); + String result; + result = slotItems[input -1]; + return result; + } + + public void setWinningLines(){ + String[][] currentSlots = this.getSlots(); + HashMap newWinningLines = new HashMap<>(); + for (int i = 0; i < 3; i++) { + //setting horizontally + if(currentSlots[i][0].equals(currentSlots[i][1]) && currentSlots[i][1].equals(currentSlots[i][2])){ + newWinningLines.put((i+1),"WIN"); + } + //setting vertically + if(currentSlots[0][i].equals(currentSlots[1][i]) && currentSlots[1][i].equals(currentSlots[2][i])){ + newWinningLines.put((i+4),"WIN"); + } + } + //setting diagonally + if(currentSlots[0][0].equals(currentSlots[1][1]) && currentSlots[0][0].equals(currentSlots[2][2])){ + newWinningLines.put(7,"WIN"); + } + if(currentSlots[2][2].equals(currentSlots[1][1]) && currentSlots[2][2].equals(currentSlots[0][0])){ + newWinningLines.put(8,"WIN"); + } + this.winningLines = newWinningLines; + } + + //Take an int[] of numbered lines to be on. + public String[] compareBetVsWinningLines(Integer[] bets){ + String[] result = new String[bets.length]; + for (int i = 0; i < bets.length; i++) { + result[i] = winningLines.get(bets[i]); + } + //return a string[] of "WIN" or "LOSE" + return result; + } + + public void displaySlots(){ + consoleB.println( + " -------------------------------\n" + + " "+ slots[0][0] +" | "+slots[0][1] + " | " +slots[0][2]+" \n" + + " -------------------------------\n" + + " "+ slots[1][0] +" | "+slots[1][1] + " | " +slots[1][2]+ " \n"+ + " -------------------------------\n" + + " "+ slots[2][0] +" | "+slots[2][1] + " | " +slots[2][2]+" \n" + + " -------------------------------\n"); + } + +} 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 index 8cb20c787..12f9b4645 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java @@ -1,7 +1,196 @@ package com.github.zipcodewilmington.casino.games.slots; +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.Scanner; + /** - * Created by leon on 7/21/2020. + * Created by Nathan on 7/12/21 */ -public class SlotsGame { +public class SlotsGame implements GameInterface{ + private final IOConsole Red = new IOConsole(AnsiColor.RED); + private final IOConsole Green = new IOConsole(AnsiColor.GREEN); + private final IOConsole Yellow = new IOConsole(AnsiColor.YELLOW); + private final IOConsole Blue = new IOConsole(AnsiColor.BLUE); + private final IOConsole Purple = new IOConsole(AnsiColor.PURPLE); + private final IOConsole Cyan = new IOConsole(AnsiColor.CYAN); + private IOConsole input = new IOConsole(); + private Integer playerBetAmount; + private Integer betTotal; + private Integer loseMultiplier; + private Integer winMultiplier; + private PlayerInterface currentPlayer; + private Integer numberOfLines; + + public SlotsGame(){ + } + + @Override + public void add(PlayerInterface player) { + this.currentPlayer = player; + } + + @Override + public void remove(PlayerInterface player) { + this.currentPlayer = null; + } + + public Integer getLoseMultiplier() { + return loseMultiplier; + } + + public Integer getWinMultiplier() { + return winMultiplier; + } + + @Override + public void run() { + Scanner scanner = new Scanner(System.in); + Yellow.println(printWelcome()); + Slots slotMachine = new Slots(); + slotMachine.spinSlots(); + //Display first slots + slotMachine.displaySlots(); + + boolean quitGame = false; + while(!quitGame) { + + //print initial account balance + Green.println("Current account balance: $" + getPlayerBalance() + "\n"); + + getBetAmount(); + calculateTotalCost(); + userBetCondition(); + //take money from player account + subtractBetFromBalance(betTotal); + Integer[] selectedBets = getBetSelections(); + + slotMachine.spinSlots(); + slotMachine.displaySlots(); + slotMachine.setWinningLines(); + String[] betResults = slotMachine.compareBetVsWinningLines(selectedBets); + this.calculateMultiplier(betResults); + Integer winnings = calculateWinnings(this.winMultiplier, playerBetAmount); + Red.println("You won: " + winnings + " dollars!\n"); + //add winnings to player object + addMoneyToBalance(currentPlayer, winnings); + //show current balance + Green.println("Current Account Balance: $" + getPlayerBalance()); + if(getPlayerBalance() == 0) { + Red.println("Oh No! You've ran out of money. Goodbye"); + quitGame = true; + } else { + //Continue game? + Integer userInput = input.getIntegerInput("Would you like to play again?\n" + + "1. Yes 2. No"); + if(userInput.equals(2)){ + quitGame = true; + } + } + } + } + + public String printWelcome() { + return "***********************************\n" + + "*** ***\n" + + "****** WELCOME TO SLOTS ******\n" + + "*** ***\n" + + "***********************************"; + + } + + public Integer getPlayerBalance(){ + return currentPlayer.getArcadeAccount().getAccountBalance(); + } + public void getBetAmount() { + playerBetAmount = Purple.getIntegerInput("How much you do want to bet?"); + } + + public void calculateTotalCost(){ + numberOfLines = Blue.getIntegerInput("How many lines do you want to bet on?"); + betTotal = playerBetAmount * numberOfLines; + Red.println("Total cost to play: " + betTotal); + } + + public Integer[] getBetSelections() { + Cyan.println(lineChoices()); + int count = 0; + Integer[] selectedLines = new Integer[numberOfLines]; + while (count < numberOfLines){ + Integer userInput; + userInput = Blue.getIntegerInput("Select your line #" + (count + 1)); + while(userInput <= (0) && userInput > 8){ + userInput = Red.getIntegerInput("Select a number between 1 and 8!"); + } + selectedLines[count] = userInput; + count++; + } + return selectedLines; + } + + public void calculateMultiplier(String[] betResults) { + int countWin = 0; + int countLose = 0; + for(String outcome: betResults){ + if(outcome == "WIN"){ + countWin++; + } else { + countLose++; + } + } + this.winMultiplier = countWin; + this.loseMultiplier = countLose; + } + + public Integer calculateReturnTotal(Integer winnings, Integer losings){ + return this.betTotal + winnings - losings; + } + + public String lineChoices(){ + return "************************************************************************\n" + + "** Select the lines you want to bet on! **\n" + + "** 1. Top Horizontal 2. Middle Horizontal 3. Bottom Horizontal **\n" + + "** 4. Left Vertical 5. Middle Vertical 6. Right Vertical **\n" + + "** 7. Down Diagonal 8. Up Diagonal **\n" + + "************************************************************************"; + } + + @Override + public Integer calculateWinnings(Integer multiplier, Integer betAmount) { + return multiplier * betAmount; + } + + @Override + public void subtractBetFromBalance(Integer losings) { + currentPlayer.getArcadeAccount().alterAccountBalance(losings * (-1)); + } + + @Override + public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + Player.getArcadeAccount().alterAccountBalance(winnings); + } + + public Integer getBetTotal() { + return betTotal; + } + + public void setBetTotal(Integer betTotal) { + this.betTotal = betTotal; + } + + + public PlayerInterface getCurrentPlayer() { + return currentPlayer; + } + + public void userBetCondition () { + while (betTotal > currentPlayer.getArcadeAccount().getAccountBalance()) { + Red.println("Oh no! You're trying to place a bet with more money than you have..."); + betTotal = Green.getIntegerInput("How much would you like to bet?\n"); + } + } + } 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 index f89ebd7f5..9d19c9cd9 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java @@ -1,7 +1,28 @@ package com.github.zipcodewilmington.casino.games.slots; +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.PlayerInterface; /** - * Created by leon on 7/21/2020. + * Created by Nathan on 7/14/2021. */ -public class SlotsPlayer { +public class SlotsPlayer implements PlayerInterface { + private PlayerInterface player; + + public SlotsPlayer(PlayerInterface player){ + this.player = player; + } + + @Override + public CasinoAccount getArcadeAccount() { + return player.getArcadeAccount(); + } + + @Override + public void setArcadeAccount(CasinoAccount casinoAccount) { + this.player.setArcadeAccount(casinoAccount); + } + + public PlayerInterface getPlayer() { + return this.player; + } } \ No newline at end of file diff --git a/src/main/java/com/github/zipcodewilmington/casino/models/Card.java b/src/main/java/com/github/zipcodewilmington/casino/models/Card.java new file mode 100644 index 000000000..ad640218f --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/models/Card.java @@ -0,0 +1,44 @@ +package com.github.zipcodewilmington.casino.models; + +import java.util.*; + +public class Card { + List cardPool; + + + public Card() { + this.cardPool = new ArrayList<>(); + this.createDeck(); + this.polishDeck(); + this.shuffleDeck(); + } + + // Alter the loop to provide the correct amount of 10's + // Jack/Queen/King + // Should have 16 - 10 values in a 52 deck + + public void createDeck() { + for (int i = 0; i < 4; i++) { + for (int j = 2; j < 15; j++) { + this.cardPool.add(j); + } + } + } + + public void polishDeck() { + for (int i = 0; i < this.cardPool.size(); i++) { + if (this.cardPool.get(i) > 11) { + this.cardPool.set(i, 10); + } + } + } + + public void shuffleDeck() { + Collections.shuffle(this.cardPool); + } + + public List getCardPool() { + return cardPool; + } + +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/models/Dice.java b/src/main/java/com/github/zipcodewilmington/casino/models/Dice.java new file mode 100644 index 000000000..d4e7e6d2d --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/models/Dice.java @@ -0,0 +1,65 @@ +package com.github.zipcodewilmington.casino.models; + +public class Dice { + private Integer numDice; + private Integer maxRoll; + private Integer maxBinIndex; + private Integer[] rollValues; + private Integer[] bins; + + public Dice(Integer numberOfDice){ + this.numDice = numberOfDice; + this.maxRoll = numberOfDice * 6; + this.maxBinIndex = numberOfDice * 6 - numberOfDice; + this.rollValues = new Integer[this.numDice]; + this.bins = new Integer[numberOfDice * 6 - (numberOfDice - 1)] ; + this.initializeDiceList(); + this.initializeBins(); + } + + public Integer getNumDice(){ + return this.numDice; + } + + public Integer[] getRollValues(){ + return this.rollValues; + } + + public Integer[] getBins(){ + return this.bins; + } + + public Integer getBin(Integer binNumber){ + return this.bins[binNumber - numDice]; + } + + public Integer getMaxBinIndex() { return this.maxBinIndex; } + + public Integer getMaxRoll(){ return this.maxRoll;} + + public void incrementBin(Integer binNumber){ + this.bins[binNumber - numDice]++; + } + + public void initializeDiceList(){ + for(int i = 0; i < numDice; i++){ + this.rollValues[i] = 0; + } + } + + public void initializeBins(){ + for(int i = 0; i <= maxBinIndex; i++){ + this.bins[i] = 0; + } + } + + public Integer tossAndSum(){ + int sum = 0; + for(int i = 0; i < numDice; i++){ + sum += (Math.random() * 6) + 1; + } + this.incrementBin(sum); + return sum; + } + +} diff --git a/src/main/java/com/github/zipcodewilmington/utils/CSVUtils.java b/src/main/java/com/github/zipcodewilmington/utils/CSVUtils.java new file mode 100644 index 000000000..0ae8fb35a --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/utils/CSVUtils.java @@ -0,0 +1,91 @@ +package com.github.zipcodewilmington.utils; + +import com.github.zipcodewilmington.Casino; +import com.github.zipcodewilmington.casino.CasinoAccount; + +import java.io.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class CSVUtils { + private static final char DEFAULT_SEPARATOR = ','; // (1) + + // (2) + public static void writeLine(Writer w, List values) throws IOException { + boolean first = true; + + StringBuilder sb = new StringBuilder(); + + // (3) + for (String value : values) { + if (!first) { + sb.append(DEFAULT_SEPARATOR); + } + sb.append(value); + first = false; + } + sb.append("\n"); + + w.append(sb.toString()); // (4) + } + + public static void csvFileSaver(CasinoAccount account) throws IOException { + String csvFile = "accounts.csv"; + FileWriter writer = new FileWriter(csvFile); + Integer nextId = 1; + CSVUtils.writeLine(writer, new ArrayList(Arrays.asList(String.valueOf(nextId)))); + Integer[] boards = account.getScoreboard().createCSVArray(); + List list = new ArrayList<>(); + list.add(account.getAccountName()); + list.add(account.getPassword()); + list.add(String.valueOf(account.getAccountBalance())); + //list.add(String.valueOf(account.getScoreboard())); + + for(int i = 0; i < boards.length; i++){ + list.add(String.valueOf(boards[i])); + } + CSVUtils.writeLine(writer, list); + + + writer.flush(); + writer.close(); + } + + public static CasinoAccount loadData(){ + // (1) + String csvFile = "accounts.csv"; + String line = ""; + String csvSplitBy = ","; + Integer nextId = 1; + // (2) + try (BufferedReader br = new BufferedReader(new FileReader(csvFile))) { + nextId = Integer.parseInt(br.readLine()); // (3) + + while ((line = br.readLine()) != null) { + // split line with comma + String[] account = line.split(csvSplitBy); + + String accountName = account[0]; + String password = account[1]; + String accountBalance = account[2]; + Scoreboard scoreboard = new Scoreboard(); + Integer count = 3; + for(int i = 0; i < 5; i++){ + scoreboard.getBoards()[i].addToLifetimeBets(Integer.parseInt(account[count])); + scoreboard.getBoards()[i].addToLifetimeWinnings(Integer.parseInt(account[count + 1])); + scoreboard.getBoards()[i].addToLifetimeLosses(Integer.parseInt(account[count + 2])); + count += 3; + } + // (5) + //inventory.add(new Sneaker(id, name, brand, sport, size, qty, price)); + CasinoAccount loadedAccount = new CasinoAccount(accountName, password, scoreboard); + loadedAccount.alterAccountBalance(Integer.parseInt(accountBalance)); + return loadedAccount; + } + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } +} diff --git a/src/main/java/com/github/zipcodewilmington/utils/GameScoreBoard.java b/src/main/java/com/github/zipcodewilmington/utils/GameScoreBoard.java new file mode 100644 index 000000000..04b54a3e0 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/utils/GameScoreBoard.java @@ -0,0 +1,51 @@ +package com.github.zipcodewilmington.utils; + +import com.github.zipcodewilmington.casino.GameScoreboardInterface; + +public class GameScoreBoard implements GameScoreboardInterface { + private Integer lifetimeBets = 0; + private Integer lifetimeWinnings = 0; + private Integer lifetimeLosses = 0; + private String gameName; + + public GameScoreBoard(String name){ + this.gameName = name; + } + + public Integer getLifetimeBets() { + return lifetimeBets; + } + + + public void addToLifetimeBets(Integer betAmt) { + this.lifetimeBets += betAmt; + } + + public Integer getLifetimeWinnings() { + return lifetimeWinnings; + } + + public void addToLifetimeWinnings(Integer winnings) { + this.lifetimeWinnings += winnings; + } + + public Integer getLifetimeLosses() { + return lifetimeLosses; + } + + public void addToLifetimeLosses(Integer losses) { + this.lifetimeLosses += losses; + } + + public String getGameName(){ return this.gameName; } + + public String printScores(){ + String output = ""; + output += this.getGameName(); + output += "\nBet :$" + this.getLifetimeBets(); + output += "\nWon :$" + this.getLifetimeWinnings(); + output += "\nLost :$" + this.getLifetimeLosses(); + + return output; + } +} diff --git a/src/main/java/com/github/zipcodewilmington/utils/IOConsole.java b/src/main/java/com/github/zipcodewilmington/utils/IOConsole.java index c7afc01da..32330c400 100644 --- a/src/main/java/com/github/zipcodewilmington/utils/IOConsole.java +++ b/src/main/java/com/github/zipcodewilmington/utils/IOConsole.java @@ -3,6 +3,7 @@ import java.io.InputStream; import java.io.PrintStream; import java.util.Scanner; +import java.util.concurrent.TimeUnit; /** * @author leonhunter @@ -36,6 +37,15 @@ public void println(String val, Object... vals) { print(val + "\n", vals); } + public void setWait(int milliseconds){ + try { + TimeUnit.MILLISECONDS.sleep(milliseconds); + } catch (InterruptedException e) { + e.printStackTrace(); + this.println("Wait unsuccessful, refer to error message"); + } + } + public String getStringInput(String prompt, Object... args) { println(prompt, args); return input.nextLine(); @@ -66,6 +76,16 @@ public Long getLongInput(String prompt, Object... args) { } public Integer getIntegerInput(String prompt, Object... args) { - return getLongInput(prompt, args).intValue(); + Integer input = getLongInput(prompt, args).intValue(); + //this.newLine(); + return input; + } + + public void newLine(){ + this.output.println(); + } + + public void pressEnterToProceed(){ + this.input.nextLine(); } } \ No newline at end of file diff --git a/src/main/java/com/github/zipcodewilmington/utils/Scoreboard.java b/src/main/java/com/github/zipcodewilmington/utils/Scoreboard.java new file mode 100644 index 000000000..a3f2e706d --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/utils/Scoreboard.java @@ -0,0 +1,110 @@ +package com.github.zipcodewilmington.utils; + + +import com.github.zipcodewilmington.casino.GameScoreboardInterface; + +import java.util.ArrayList; +import java.util.List; + +public class Scoreboard { + private GameScoreBoard blackjackScores = new GameScoreBoard("Blackjack"); + private GameScoreBoard beetleScores = new GameScoreBoard("Beetle"); + private GameScoreBoard numberGuessScores = new GameScoreBoard("Number Guess"); + private GameScoreBoard kenoScores = new GameScoreBoard("Keno"); + private GameScoreBoard plinkoScores = new GameScoreBoard("Plinko"); + private GameScoreboardInterface[] boards = new GameScoreboardInterface[5]; + + public Scoreboard(){ + this.boards[0] = beetleScores; + this.boards[1] = blackjackScores; + this.boards[2] = kenoScores; + this.boards[3] = numberGuessScores; + this.boards[4] = plinkoScores; + } + + + public GameScoreBoard getBlackJackScores() { + return blackjackScores; + } + + public GameScoreBoard getBeetleScores() { + return beetleScores; + } + + public GameScoreBoard getNumberGuessScores() { + return numberGuessScores; + } + + public GameScoreBoard getKenoScores() { + return kenoScores; + } + + public GameScoreBoard getPlinkoScores() { + return plinkoScores; + } + + public Integer lifetimeBets(){ + Integer totalBets = 0; + totalBets += this.getPlinkoScores().getLifetimeBets(); + totalBets += this.getBeetleScores().getLifetimeBets(); + totalBets += this.getKenoScores().getLifetimeBets(); + totalBets += this.getBlackJackScores().getLifetimeBets(); + totalBets += this.getNumberGuessScores().getLifetimeBets(); + return totalBets; + } + + public Integer lifetimeWinnings(){ + Integer totalBets = 0; + totalBets += this.getPlinkoScores().getLifetimeWinnings(); + totalBets += this.getBeetleScores().getLifetimeWinnings(); + totalBets += this.getKenoScores().getLifetimeWinnings(); + totalBets += this.getBlackJackScores().getLifetimeWinnings(); + totalBets += this.getNumberGuessScores().getLifetimeWinnings(); + return totalBets; + } + + public Integer lifetimeLosses(){ + Integer totalBets = 0; + totalBets += this.getPlinkoScores().getLifetimeLosses(); + totalBets += this.getBeetleScores().getLifetimeLosses(); + totalBets += this.getKenoScores().getLifetimeLosses(); + totalBets += this.getBlackJackScores().getLifetimeLosses(); + totalBets += this.getNumberGuessScores().getLifetimeLosses(); + return totalBets; + } + + public Integer[] createCSVArray(){ + List results = new ArrayList<>(); + + for(int i = 0; i < boards.length; i++){ + results.add(boards[i].getLifetimeBets()); + results.add(boards[i].getLifetimeWinnings()); + results.add(boards[i].getLifetimeLosses()); + } + return results.toArray(new Integer[0]); + } + + public GameScoreboardInterface[] getBoards() { + return boards; + } + + public String lifetimeStats(){ + String output = "Lifetime Stats"; + output += "\nBet :$" + this.lifetimeBets(); + output += "\nWon :$" + this.lifetimeWinnings(); + output += "\nLoss :$" + this.lifetimeLosses(); + + return output; + } + + public String printAllScores(){ + String output = this.lifetimeStats() + "\n\n"; + + for(int i = 0; i < this.boards.length; i++){ + output += boards[i].printScores() + "\n\n"; + } + + return output; + } + +} diff --git a/src/test/java/com/github/zipcodewilmington/ApplicationRunnerTest.java b/src/test/java/com/github/zipcodewilmington/ApplicationRunnerTest.java index a9af8209a..4b9fc35dc 100644 --- a/src/test/java/com/github/zipcodewilmington/ApplicationRunnerTest.java +++ b/src/test/java/com/github/zipcodewilmington/ApplicationRunnerTest.java @@ -13,7 +13,7 @@ public void test() { // TODO - replace boiler-plate logic with business logic Runnable runnable = new Casino(); // when - runnable.run(); + // then Assert.assertNotNull(runnable.toString()); diff --git a/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java b/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java new file mode 100644 index 000000000..b8ab068be --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java @@ -0,0 +1,267 @@ +package com.github.zipcodewilmington; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.Beetle.Beetle; +import com.github.zipcodewilmington.casino.games.Beetle.BeetleGame; +import com.github.zipcodewilmington.casino.games.Beetle.BeetlePlayer; +import org.junit.Assert; +import org.junit.Test; + +public class BeetleGameTest { + @Test + public void constructorTest(){ + BeetleGame beetleGame = new BeetleGame(); + Beetle game = beetleGame.getGame(); + Boolean actual = game instanceof Beetle; + + Assert.assertTrue(actual); + + } + + @Test + public void addTest(){ + BeetleGame beetleGame = new BeetleGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + + beetleGame.add(player); + Boolean expected = true; + Boolean actual = beetleGame.getPlayer() != null; + + Assert.assertEquals(expected, actual); + } + + @Test + public void removeTest(){ + BeetleGame beetleGame = new BeetleGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + + beetleGame.add(player); + beetleGame.remove(player); + Boolean expected = false; + Boolean actual = beetleGame.getPlayer() != null; + + Assert.assertEquals(expected, actual); + + } + + @Test + public void isGameOverTest1(){ + BeetleGame beetleGame = new BeetleGame(); + beetleGame.setRunning(true); + beetleGame.isGameOver(false); + Boolean actual = beetleGame.getIsRunning(); + + Assert.assertTrue(actual); + } + + @Test + public void isGameOverTest2(){ + BeetleGame beetleGame = new BeetleGame(); + beetleGame.setRunning(true); + beetleGame.isGameOver(true); + Boolean actual = beetleGame.getIsRunning(); + + Assert.assertFalse(actual); + } + + @Test + public void determinePayout1(){ + BeetleGame beetleGame = new BeetleGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + beetleGame.add(player); + player.getArcadeAccount().alterAccountBalance(500); + beetleGame.setBetAmt(200); + beetleGame.getGame().setCurrentPlayer(0); + beetleGame.determinePayout(); + Boolean actual = player.getArcadeAccount().getAccountBalance() > 500; + + Assert.assertTrue(actual); + } + + @Test + public void determinePayout2(){ + BeetleGame beetleGame = new BeetleGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + beetleGame.add(player); + player.getArcadeAccount().alterAccountBalance(500); + beetleGame.setBetAmt(200); + beetleGame.getGame().setCurrentPlayer(1); + beetleGame.determinePayout(); + Boolean actual = player.getArcadeAccount().getAccountBalance() == 500; + + Assert.assertTrue(actual); + } + + @Test + public void calculateWinningsTest(){ + BeetleGame beetleGame = new BeetleGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + beetleGame.add(player); + player.getArcadeAccount().alterAccountBalance(500); + beetleGame.setBetAmt(200); + beetleGame.getGame().setCurrentPlayer(0); + + Integer actual = beetleGame.calculateWinnings(2, 200); + Integer expected = 400; + Assert.assertEquals(actual, expected); + } + + @Test + public void subtractTest(){ + BeetleGame beetleGame = new BeetleGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + player.getArcadeAccount().alterAccountBalance(500); + beetleGame.add(player); + beetleGame.subtractBetFromBalance(200); + Integer expected = 300; + Integer actual = player.getArcadeAccount().getAccountBalance(); + Assert.assertEquals(actual, expected); + } + + @Test + public void addMoneyToBalance(){ + BeetleGame beetleGame = new BeetleGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + player.getArcadeAccount().alterAccountBalance(500); + beetleGame.add(player); + beetleGame.addMoneyToBalance(player,200); + Integer expected = 700; + Integer actual = player.getArcadeAccount().getAccountBalance(); + Assert.assertEquals(actual, expected); + } + + @Test + public void printWelcomeTest(){ + BeetleGame beetleGame = new BeetleGame(); + + String actual = beetleGame.printWelcome(); + String expected = "\u001B[33m***********************************\n" + + "*** ***\n" + + "****** WELCOME TO BEETLE ******\n" + + "*** ***\n" + + "***********************************"; + + Assert.assertEquals(actual, expected); + } + + @Test + public void getDemoTest(){ + BeetleGame beetleGame = new BeetleGame(); + + Boolean actual = beetleGame.getDemo(); + + Assert.assertFalse(actual); + } + + @Test + public void printEndingGameMessage(){ + BeetleGame beetleGame = new BeetleGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + player.getArcadeAccount().alterAccountBalance(500); + beetleGame.add(player); + beetleGame.setBetAmt(100); + String actual = beetleGame.printEndingGameMessage(); + String expected = "\nFinal Beetle results: \n" + + "\u001B[32mYour last dice roll: 0 Your Beetle: \n" + + "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 \n" + + "\u001B[32mDealer's last dice roll: 0 Dealer's Beetle: \n" + + "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 \n" + + "You win!You win!"; + Assert.assertEquals(actual, expected); + } + + @Test + public void printEndingGameMessage2(){ + BeetleGame beetleGame = new BeetleGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + player.getArcadeAccount().alterAccountBalance(500); + beetleGame.add(player); + beetleGame.setBetAmt(100); + beetleGame.getGame().setCurrentPlayer(1); + String actual = beetleGame.printEndingGameMessage(); + String expected = "\nFinal Beetle results: \n" + + "\u001B[32mYour last dice roll: 0 Your Beetle: \n" + + "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 \n" + + "\u001B[32mDealer's last dice roll: 0 Dealer's Beetle: \n" + + "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 \n" + + "Dealer wins...Dealer wins..."; + Assert.assertEquals(actual, expected); + } + + @Test + public void printNextTurnMessage(){ + BeetleGame beetleGame = new BeetleGame(); + + String actual = beetleGame.printNextTurnMessage(); + String expected = + "\u001B[32mYour last dice roll: 0 Your Beetle: \n" + + "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 \n" + + "\u001B[32mDealer's last dice roll: 0 Dealer's Beetle: \n" + + "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 \n" + + "Press enter to roll next dice"; + System.out.println(actual); + Assert.assertEquals(actual, expected); + } + + @Test + public void setDemoTest(){ + BeetleGame beetleGame = new BeetleGame(); + + beetleGame.setDemo(true); + Boolean actual = beetleGame.getDemo(); + + Assert.assertTrue(actual); + } + + @Test + public void getBetTest(){ + BeetleGame game = new BeetleGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + game.add(player); + game.setBetAmt(100); + + Integer expected = 100; + Integer actual = game.getBetAmt(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void printBalanceAndBetTextTest(){ + BeetleGame game = new BeetleGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + game.add(player); + game.setBetAmt(100); + + String actual = game.printBalanceAndBetText(); + String expected = "\u001B[35m Current account balance: " + player.getArcadeAccount().getAccountBalance(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void nextPlayerTest(){ + BeetleGame game = new BeetleGame(); + + game.nextPlayer(); + + Integer expected = 1; + Integer actual = game.getGame().getCurrentPlayer(); + + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/com/github/zipcodewilmington/BeetlePlayerTest.java b/src/test/java/com/github/zipcodewilmington/BeetlePlayerTest.java new file mode 100644 index 000000000..663f8b44a --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/BeetlePlayerTest.java @@ -0,0 +1,49 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.Beetle.BeetlePlayer; +import org.junit.Assert; +import org.junit.Test; + +public class BeetlePlayerTest { + + @Test + public void constructorTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + BeetlePlayer beetlePlayer = new BeetlePlayer(player); + + PlayerInterface expected = player; + PlayerInterface actual = beetlePlayer.getPlayer(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getArcadeAccountTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + BeetlePlayer beetlePlayer = new BeetlePlayer(player); + + CasinoAccount actual = beetlePlayer.getArcadeAccount(); + CasinoAccount expected = account; + + Assert.assertEquals(actual, expected); + } + + @Test + public void setArcadeAccountTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + BeetlePlayer beetlePlayer = new BeetlePlayer(player); + beetlePlayer.setArcadeAccount(account); + + CasinoAccount actual = beetlePlayer.getArcadeAccount(); + CasinoAccount expected = account; + + Assert.assertEquals(actual, expected); + + } +} diff --git a/src/test/java/com/github/zipcodewilmington/BeetleTest.java b/src/test/java/com/github/zipcodewilmington/BeetleTest.java new file mode 100644 index 000000000..bbcc30aa8 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/BeetleTest.java @@ -0,0 +1,160 @@ +package com.github.zipcodewilmington; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.github.zipcodewilmington.casino.games.Beetle.Beetle; +import org.junit.Assert; +import org.junit.Test; + +public class BeetleTest { + @Test + public void constructorTest1(){ + Beetle beetle = new Beetle(3); + Integer expected = 3; + Integer actual = beetle.getPlayerBeetles().length; + + Assert.assertEquals(expected, actual); + } + + @Test + public void constructorTest2(){ + Beetle beetle = new Beetle(2); + Integer expected = 6; + Integer[][] playerCards = beetle.getPlayerBeetles(); + Integer actual = playerCards[0].length; + + Assert.assertEquals(expected, actual); + } + + @Test + public void constructorTest3(){ + Beetle beetle = new Beetle(4); + Integer expected = 0; + Integer[][] playerCards = beetle.getPlayerBeetles(); + Integer actual = playerCards[0][0]; + + Assert.assertEquals(expected, actual); + } + + @Test + public void constructorTest4(){ + Beetle beetle = new Beetle(2); + Integer expected = 0; + Integer actual = beetle.getScore(0); + + Assert.assertEquals(expected, actual); + } + + @Test + public void numPlayersTest(){ + Beetle beetle = new Beetle(2); + Integer expected = 2; + Integer actual = beetle.getNumPlayers(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void setPlayerTest(){ + Beetle beetle = new Beetle(2); + Integer expected = 1; + beetle.setCurrentPlayer(1); + Integer actual = beetle.getCurrentPlayer(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void setPlayerBeetleTest(){ + Beetle beetle = new Beetle(2); + Integer expected = 1; + beetle.setPlayerBeetles(0, beetle.getDice().tossAndSum()); + Integer actual = 0; + Integer[] playerCard = beetle.getPlayerCard(0); + for(int i = 0; i < 6; i++){ + if(playerCard[i] > 0){ + actual++; + } + } + Assert.assertEquals(expected, actual); + } + + @Test + public void beetleIsCompleteTest1(){ + Beetle beetle = new Beetle(2); + Boolean expected = true; + for(int i = 1; i <= 6; i++) { + beetle.setPlayerBeetles(0, i); + } + Boolean actual = beetle.beetleIsComplete(0); + + Assert.assertEquals(expected, actual); + } + + @Test + public void beetleIsCompleteTest2(){ + Beetle beetle = new Beetle(2); + Boolean expected = false; + Boolean actual = beetle.beetleIsComplete(0); + + Assert.assertEquals(expected, actual); + } + + @Test + public void checkWinnerTest1(){ + Beetle beetle = new Beetle(2); + Boolean actual = false; + for(int j = 1; j <= 6; j++){ + beetle.setPlayerBeetles(0, j); + } + actual = beetle.checkWinner(0); + Assert.assertTrue(actual); + } + + @Test + public void checkWinnerTest2(){ + Beetle beetle = new Beetle(2); + Boolean actual = false; + for(int j = 1; j <= 5; j++){ + beetle.setPlayerBeetles(0, j); + } + actual = beetle.checkWinner(0); + Assert.assertFalse(actual); + } + + @Test + public void nextPlayerTest1(){ + Beetle beetle = new Beetle(2); + beetle.nextPlayer(); + Integer actual = beetle.getCurrentPlayer(); + Integer expected = 1; + Assert.assertEquals(actual, expected); + } + + @Test + public void nextPlayerTest2(){ + Beetle beetle = new Beetle(2); + beetle.nextPlayer(); + beetle.nextPlayer(); + Integer actual = beetle.getCurrentPlayer(); + Integer expected = 0; + Assert.assertEquals(actual, expected); + } + + @Test + public void printBeetleTest1(){ + Beetle beetle = new Beetle(2); + String expected = "\u001B[36mBody:0 Head:0 Legs:0 Eyes:0 Antenna:0 Tail:0 "; + String actual = beetle.printBeetle(0); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getLastDiceRollTest(){ + Beetle beetle = new Beetle(2); + Integer actual = beetle.getLastDiceRoll(0); + Integer expected = 0; + + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java new file mode 100644 index 000000000..da555e3f0 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java @@ -0,0 +1,276 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.Beetle.BeetleGame; +import com.github.zipcodewilmington.casino.games.blackjack.BlackJack; +import com.github.zipcodewilmington.casino.games.blackjack.BlackJackGame; +import com.github.zipcodewilmington.casino.games.blackjack.BlackJackPlayer; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class BlackJackGameTest { + + + public void startGameTest () { + BlackJack bj = new BlackJack(); + BlackJackGame blackJackGame = new BlackJackGame(); + + + Integer choice = 2; + } + + @Test + public void calculateWinningsTest () { + BlackJackGame blackJack = new BlackJackGame(); + Integer expected = 12; + + Integer multiplier = 3; + Integer betAmount = 4; + Integer actual = blackJack.calculateWinnings(multiplier, betAmount); + + Assert.assertEquals(expected,actual); + } + +// @Test +// public void subtractFromBalance () { +// BlackJackGame blackJack = new BlackJackGame(); +// Player player = new Player("Steve", 100); +// Integer expected = 60; +// +// Integer bet = 40; +// blackJack.subtractBetFromBalance(bet); +// Integer actual = player.getBalance(); +// +// Assert.assertEquals(expected, actual); +// } + + @Test + public void subtractTest() { + BlackJackGame bj = new BlackJackGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + player.getArcadeAccount().alterAccountBalance(500); + bj.add(player); + player.getArcadeAccount().alterAccountBalance(200 * -1); + Integer expected = 300; + Integer actual = player.getArcadeAccount().getAccountBalance(); + Assert.assertEquals(expected, actual); + } + + + @Test + public void runTest () { + BlackJackGame bj = new BlackJackGame(); + bj.setRunning(true); + bj.run(); + + Integer actual = bj.getUserBet(); + Integer expected = null; + + Assert.assertEquals(expected, actual); + } + + @Test + public void printWelcomeTest () { + BlackJackGame bj = new BlackJackGame(); + bj.setRunning(true); + bj.run(); + + System.out.println("============================================================" + "\n" + + "===== =====" + "\n" + + "===== WELCOME =====" + "\n" + + "===== TO =====" + "\n" + + "===== B L A C K =====" + "\n" + + "===== J A C K =====" + "\n" + + "===== =====" + "\n" + + "============================================================"); + } + + @Test + public void getRunningTest () { + BlackJackGame bj = new BlackJackGame(); + boolean expected = false; + boolean actual = bj.getRunning(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void removePlayerTest () { + BlackJackGame bj = new BlackJackGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + + bj.add(player); + bj.remove(player); + Boolean expected = false; + Boolean actual = bj.getPlayer() != null; + + Assert.assertEquals(expected, actual); + } + + @Test + public void startGameTest2(){ + BlackJackGame bj = new BlackJackGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + List playersHand = new ArrayList<>(); + playersHand.add(9); + playersHand.add(9); + bj.setGame(); + BlackJack game = bj.getGame(); + game.setPlayersHand(playersHand); + bj.setDemo(true); + bj.startGame(); + + Assert.assertNotNull(bj); + } + + @Test + public void startGameTest3(){ + BlackJackGame bj = new BlackJackGame(); + List playersHand = new ArrayList<>(); + playersHand.add(11); + playersHand.add(10); + bj.setGame(); + BlackJack game = bj.getGame(); + game.setPlayersHand(playersHand); + bj.setUserBet(100); + Boolean actual = bj.twoCardBlackJack(); + + Assert.assertTrue(actual); + } + + @Test + public void getDemoTest(){ + BlackJackGame bj = new BlackJackGame(); + bj.setDemo(true); + Boolean actual = bj.getDemo(); + + Assert.assertTrue(actual); + } + + @Test + public void addMoneyToBalanceTest(){ + BlackJackGame bj = new BlackJackGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + player.setArcadeAccount(account); + + bj.addMoneyToBalance(player, 100); + + Integer expected = 100; + Integer actual = player.getArcadeAccount().getAccountBalance(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void subtractMoneyFromBalanceTest(){ + BlackJackGame bj = new BlackJackGame(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + player.setArcadeAccount(account); + + bj.add(player); + + bj.addMoneyToBalance(player, 100); + bj.subtractBetFromBalance(50); + Integer expected = 50; + Integer actual = player.getArcadeAccount().getAccountBalance(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void playerHitsBlackJackTest(){ + BlackJackGame bj = new BlackJackGame(); + List playersHand = new ArrayList<>(); + playersHand.add(11); + playersHand.add(10); + bj.setGame(); + BlackJack game = bj.getGame(); + game.setPlayersHand(playersHand); + bj.setUserBet(100); + Boolean actual = bj.playerHitsBlackJack(); + + Assert.assertTrue(actual); + } + + @Test + public void playerHitsBlackJackTest2(){ + BlackJackGame bj = new BlackJackGame(); + List playersHand = new ArrayList<>(); + playersHand.add(10); + playersHand.add(10); + bj.setGame(); + BlackJack game = bj.getGame(); + game.setPlayersHand(playersHand); + bj.setUserBet(100); + Boolean actual = bj.playerHitsBlackJack(); + + Assert.assertFalse(actual); + } + + @Test + public void splitPlayerHitsBlackJackTest () { + BlackJackGame bj = new BlackJackGame(); + List playersHand = new ArrayList<>(); + playersHand.add(10); + playersHand.add(10); + bj.setGame(); + BlackJack game = bj.getGame(); + game.setPlayersHand(playersHand); + bj.setUserBet(100); + Boolean actual = bj.splitPlayerHitsBlackJack(); + + Assert.assertFalse(actual); + + } + + @Test + public void splitPlayerHitsBlackJackTest2 () { + BlackJackGame bj = new BlackJackGame(); + List playersHand = new ArrayList<>(); + playersHand.add(11); + playersHand.add(9); + playersHand.add(1); + bj.setGame(); + BlackJack game = bj.getGame(); + game.setPlayersHandOnSplit(playersHand); + game.setPlayersHand(playersHand); + bj.setUserBet(100); + bj.setSplitBet(100); + Boolean actual = bj.splitPlayerHitsBlackJack(); + + Assert.assertTrue(actual); + } + + @Test + public void splitPlayerBustHasAces () { + BlackJackGame bj = new BlackJackGame(); + List playersHand = new ArrayList<>(); + playersHand.add(10); + playersHand.add(10); + playersHand.add(11); + bj.setGame(); + BlackJack game = bj.getGame(); + game.setPlayersHandOnSplit(playersHand); + game.setPlayersHand(playersHand); + bj.setUserBet(100); + bj.setSplitBet(100); + bj.playerBustButHasAces(); + Integer expected = 21; + Integer actual = 0; + for (int i = 0; i < game.getPlayersHandOnSplit().size(); i++) { + actual += game.getPlayersHandOnSplit().get(i); + } + Assert.assertEquals(actual, expected); + } +} diff --git a/src/test/java/com/github/zipcodewilmington/BlackJackPlayerTest.java b/src/test/java/com/github/zipcodewilmington/BlackJackPlayerTest.java new file mode 100644 index 000000000..5893955ef --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/BlackJackPlayerTest.java @@ -0,0 +1,50 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.blackjack.BlackJack; +import com.github.zipcodewilmington.casino.games.blackjack.BlackJackPlayer; +import org.junit.Assert; +import org.junit.Test; + +public class BlackJackPlayerTest { + + @Test + public void constructorTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + BlackJackPlayer bj = new BlackJackPlayer(player); + + PlayerInterface expected = player; + PlayerInterface actual = bj.getPlayer(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getArcadeAccountTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + BlackJackPlayer bj = new BlackJackPlayer(player); + + CasinoAccount actual = bj.getArcadeAccount(); + CasinoAccount expected = account; + + Assert.assertEquals(actual, expected); + } + + @Test + public void setArcadeAccountTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + BlackJackPlayer bj = new BlackJackPlayer(player); + bj.setArcadeAccount(account); + + CasinoAccount actual = bj.getArcadeAccount(); + CasinoAccount expected = account; + + Assert.assertEquals(actual, expected); + + } +} 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..4aca05301 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/BlackJackTest.java @@ -0,0 +1,178 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.games.blackjack.BlackJack; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class BlackJackTest { + @Test + public void generateNewDeckTest() { + BlackJack bj = new BlackJack(); + Integer expected = 52; + + Integer actual1 = bj.generateNewDeck().size(); + List actual = bj.generateNewDeck(); + System.out.println(actual); + + Assert.assertEquals(expected, actual1); + } + + @Test + public void givePlayerCardTest() { + BlackJack bj = new BlackJack(); + Integer expected = 2; + + bj.givePlayerCard(); + bj.givePlayerCard(); + Integer actual = bj.getPlayersHand().size(); + + System.out.println(bj.getPlayersHand()); + Assert.assertEquals(expected, actual); + } + + @Test + public void giveDealerCardTest () { + BlackJack bj = new BlackJack(); + Integer expected = 2; + + bj.giveDealerCard(); + bj.giveDealerCard(); + Integer actual = bj.getDealersHand().size(); + + System.out.println(bj.getDealersHand()); + Assert.assertEquals(expected, actual); + } + + @Test + public void playersCurrentValueTest () { + BlackJack bj = new BlackJack(); + + // Solid stopping point = need to populate array for test + bj.givePlayerCard(); + bj.givePlayerCard(); + System.out.println(bj.playersCurrentValue()); + + List expected = bj.getPlayersHand(); + + bj.playersCurrentValue(); + Integer actual = bj.playersCurrentValue(); + + System.out.println(expected); + System.out.println(actual); + } + + @Test + public void dealersCurrentValueTest () { + BlackJack bj = new BlackJack(); + List expected = bj.getDealersHand(); + + bj.dealersCurrentValue(); + Integer actual = bj.dealersCurrentValue(); + + System.out.println(expected); + System.out.println(actual); + } + + @Test + public void givePlayerCardOnSplitTest () { + BlackJack bj = new BlackJack(); + List expected = bj.getPlayersHandOnSplit(); + + List actual = bj.givePlayerCardOnSplit(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void splitPlayersCurrentValueTest () { + BlackJack bj = new BlackJack(); + Integer expected = 0; + + bj.getPlayersHandOnSplit().add(0); + Integer actual = bj.splitPlayersCurrentValue(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void setPlayersHandTest(){ + BlackJack bj = new BlackJack(); + List playersHand = new ArrayList<>(); + + playersHand.add(10); + bj.setPlayersHand(playersHand); + List actual = bj.getPlayersHand(); + + Assert.assertArrayEquals(playersHand.toArray(new Integer[0]), actual.toArray(new Integer[0])); + } + + @Test + public void setDealersHandTest(){ + BlackJack bj = new BlackJack(); + List playersHand = new ArrayList<>(); + + playersHand.add(10); + bj.setDealersHand(playersHand); + List actual = bj.getDealersHand(); + + Assert.assertArrayEquals(playersHand.toArray(new Integer[0]), actual.toArray(new Integer[0])); + } + + @Test + public void setPlayersHandOnSplitTest(){ + BlackJack bj = new BlackJack(); + List playersHand = new ArrayList<>(); + playersHand.add(11); + playersHand.add(11); + bj.setPlayersHandOnSplit(playersHand); + Integer actual = bj.getPlayersHandOnSplit().size(); + Integer expected = 2; + + Assert.assertEquals(actual, expected); + } + + @Test + public void playerBreaks21Test1(){ + BlackJack bj = new BlackJack(); + List playersHand = new ArrayList<>(); + playersHand.add(11); + playersHand.add(9); + playersHand.add(9); + + bj.setPlayersHand(playersHand); + Boolean actual = bj.playerBreaks21(); + Boolean expected = true; + Assert.assertEquals(expected, actual); + } + + @Test + public void playerBreaks21Test2(){ + BlackJack bj = new BlackJack(); + List playersHand = new ArrayList<>(); + playersHand.add(9); + playersHand.add(9); + + bj.setPlayersHand(playersHand); + Boolean actual = bj.playerBreaks21(); + Boolean expected = false; + Assert.assertEquals(expected, actual); + } + + @Test + public void dealersCurrentValueTest2(){ + BlackJack bj = new BlackJack(); + List dealersHand = new ArrayList<>(); + + dealersHand.add(10); + bj.setDealersHand(dealersHand); + + Integer expected = 10; + Integer actual = bj.dealersCurrentValue(); + + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/com/github/zipcodewilmington/CSVUtilsTest.java b/src/test/java/com/github/zipcodewilmington/CSVUtilsTest.java new file mode 100644 index 000000000..3071a7be9 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/CSVUtilsTest.java @@ -0,0 +1,37 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.utils.CSVUtils; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; + + +public class CSVUtilsTest { + + @Test + public void csvSaveTest(){ + Boolean actual = true; + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + //PlayerInterface player = new Player("Bjork", account); + account.alterAccountBalance(400); + try { + CSVUtils.csvFileSaver(account); + } catch (IOException e) { + actual = false; + } + + Assert.assertTrue(actual); + } + + @Test + public void csvLoadTest(){ + CasinoAccount actual = CSVUtils.loadData(); + + Assert.assertNotNull(actual); + } +} + diff --git a/src/test/java/com/github/zipcodewilmington/CardsTest.java b/src/test/java/com/github/zipcodewilmington/CardsTest.java new file mode 100644 index 000000000..490a5e821 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/CardsTest.java @@ -0,0 +1,59 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.models.Card; +import org.junit.Assert; +import org.junit.Test; + +import java.util.List; + +public class CardsTest { + @Test + public void constructorTest () { + Integer expected = 52; + + Card card = new Card(); + Integer actual = card.getCardPool().size(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void createDeckTest () { + // Given + Integer expected = 52; + + Card card = new Card(); + Integer actual = card.getCardPool().size(); + + Assert.assertEquals(expected, actual); + + } + + @Test + public void polishDeckTest () { + Card card = new Card(); + + card.polishDeck(); + System.out.println(card.getCardPool().size()); + System.out.println(card.getCardPool()); +// System.out.println(result); + } + + @Test + public void shuffleDeckTest () { + Card card = new Card(); + + System.out.println(card.getCardPool().size()); + System.out.println(card.getCardPool()); // Visual test + } + + @Test + public void setCardPoolTest () { + Card card = new Card(); + } + + @Test + public void setNumberOfCardsTest () { + + } +} diff --git a/src/test/java/com/github/zipcodewilmington/CasinoAccountManagerTest.java b/src/test/java/com/github/zipcodewilmington/CasinoAccountManagerTest.java new file mode 100644 index 000000000..30c128d72 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/CasinoAccountManagerTest.java @@ -0,0 +1,37 @@ +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 CasinoAccountManagerTest { + + @Test + public void createAccountTest(){ + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount account = cam.createAccount("zz", "ss"); + + Assert.assertNotNull(account); + } + + @Test + public void registerAndGetAccountTest(){ + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount account = cam.createAccount("zz", "ss"); + cam.registerAccount(account); + + CasinoAccount actual = cam.getAccount("zz", "ss"); + Assert.assertNotNull(actual); + } + + @Test + public void getAccountTest(){ + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount account = cam.createAccount("zz", "ss"); + cam.registerAccount(account); + + CasinoAccount actual = cam.getAccount("z2", "ss"); + Assert.assertNull(actual); + } +} diff --git a/src/test/java/com/github/zipcodewilmington/DiceTest.java b/src/test/java/com/github/zipcodewilmington/DiceTest.java new file mode 100644 index 000000000..8bbd0709b --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/DiceTest.java @@ -0,0 +1,88 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.models.Dice; +import org.junit.Assert; +import org.junit.Test; + +public class DiceTest { + @Test + public void diceConstructorTest1() { + Dice dice = new Dice(2); + Integer actual = dice.getNumDice(); + Integer expected = 2; + + Assert.assertEquals(expected, actual); + } + + @Test + public void diceConstructorTest2() { + Dice dice = new Dice(3); + Integer expected = 18; + Integer actual = dice.getMaxRoll(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void diceConstructorTest3() { + Dice dice = new Dice(3); + Integer expected = 15; + Integer actual = dice.getMaxBinIndex(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void diceConstructorTest4() { + Dice dice = new Dice(3); + Integer expected = 3; + Integer actual = dice.getRollValues().length; + + Assert.assertEquals(expected, actual); + } + + @Test + public void diceConstructorTest5() { + Dice dice = new Dice(2); + Integer expected = 11; + Integer actual = dice.getBins().length; + + Assert.assertEquals(expected, actual); + } + + @Test + public void diceConstructorTest6() { + Dice dice = new Dice(2); + Integer[] expected = {0, 0}; + Integer[] actual = dice.getRollValues(); + + Assert.assertArrayEquals(expected, actual); + } + + @Test + public void diceConstructorTest7(){ + Dice dice = new Dice(2); + Integer[] expected = {0,0,0,0,0,0,0,0,0,0,0}; + Integer[] actual = dice.getBins(); + + Assert.assertArrayEquals(expected, actual); + } + + @Test + public void getBinQuantityTest(){ + Dice dice = new Dice(2); + dice.tossAndSum(); + Integer[] bins = dice.getBins(); + Integer actual = 0; + for(int i = 2; i <= dice.getMaxBinIndex(); i++){ + if(dice.getBin(i) > 0){ + actual = dice.getBin(i); + break; + } + } + Integer expected = 1; + + Assert.assertEquals(expected, actual); + } + +} diff --git a/src/test/java/com/github/zipcodewilmington/GameScoreBoardTest.java b/src/test/java/com/github/zipcodewilmington/GameScoreBoardTest.java new file mode 100644 index 000000000..f835b71b3 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/GameScoreBoardTest.java @@ -0,0 +1,157 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.GameScoreboardInterface; +import com.github.zipcodewilmington.utils.GameScoreBoard; +import com.github.zipcodewilmington.utils.Scoreboard; +import org.junit.Assert; +import org.junit.Test; + +public class GameScoreBoardTest { + + @Test + public void constructorTest(){ + Scoreboard scoreboard = new Scoreboard(); + GameScoreboardInterface[] boards = new GameScoreboardInterface[5]; + boards[0] = scoreboard.getBeetleScores(); + boards[1] = scoreboard.getBlackJackScores(); + boards[2] = scoreboard.getNumberGuessScores(); + boards[3] = scoreboard.getKenoScores(); + boards[4] = scoreboard.getPlinkoScores(); + Boolean isScoreboard = false; + + for(int i = 0; i < boards.length; i++){ + if(boards[i] instanceof GameScoreboardInterface){ + isScoreboard = true; + } else { + isScoreboard = false; + break; + } + } + + Assert.assertTrue(isScoreboard); + } + + @Test + public void lifetimeBetsTest(){ + Scoreboard scoreboard = new Scoreboard(); + scoreboard.getPlinkoScores().addToLifetimeBets(100); + + Integer actual = scoreboard.getPlinkoScores().getLifetimeBets(); + Integer expected = 100; + + Assert.assertEquals(expected, actual); + } + + @Test + public void lifetimeWinningsTest(){ + Scoreboard scoreboard = new Scoreboard(); + scoreboard.getPlinkoScores().addToLifetimeWinnings(400); + + Integer actual = scoreboard.getPlinkoScores().getLifetimeWinnings(); + Integer expected = 400; + + Assert.assertEquals(expected, actual); + } + + @Test + public void lifetimeLossesTest(){ + Scoreboard scoreboard = new Scoreboard(); + scoreboard.getPlinkoScores().addToLifetimeLosses(400); + + Integer actual = scoreboard.getPlinkoScores().getLifetimeLosses(); + Integer expected = 400; + + Assert.assertEquals(expected, actual); + } + + @Test + public void scoreboardLifetimeBets(){ + Scoreboard scoreboard = new Scoreboard(); + scoreboard.getPlinkoScores().addToLifetimeBets(300); + + Integer actual = scoreboard.lifetimeBets(); + Integer expected = 300; + + Assert.assertEquals(expected, actual); + } + + @Test + public void scoreboardLifetimeWinnings(){ + Scoreboard scoreboard = new Scoreboard(); + scoreboard.getPlinkoScores().addToLifetimeWinnings(300); + + Integer actual = scoreboard.lifetimeWinnings(); + Integer expected = 300; + + Assert.assertEquals(expected, actual); + } + + @Test + public void scoreboardLifetimeLosses(){ + Scoreboard scoreboard = new Scoreboard(); + scoreboard.getPlinkoScores().addToLifetimeLosses(300); + + Integer actual = scoreboard.lifetimeLosses(); + Integer expected = 300; + + Assert.assertEquals(expected, actual); + } + + @Test + public void scoreboardCSVArrayTest(){ + Scoreboard scoreboard = new Scoreboard(); + Integer[] expected = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}; + Integer[] actual = scoreboard.createCSVArray(); + + Assert.assertArrayEquals(expected, actual); + } + + @Test + public void getBoardsTest(){ + Scoreboard scoreboard = new Scoreboard(); + + GameScoreboardInterface[] boards = scoreboard.getBoards(); + Boolean actual = boards[0] instanceof GameScoreboardInterface; + + Assert.assertTrue(actual); + } + + @Test + public void printScoreTest(){ + Scoreboard scoreboard = new Scoreboard(); + + String actual = scoreboard.printAllScores(); + String expected = "Lifetime Stats\n" + + "Bet :$0\n" + + "Won :$0\n" + + "Loss :$0\n" + + "\n" + + "Beetle\n" + + "Bet :$0\n" + + "Won :$0\n" + + "Lost :$0\n" + + "\n" + + "Blackjack\n" + + "Bet :$0\n" + + "Won :$0\n" + + "Lost :$0\n" + + "\n" + + "Keno\n" + + "Bet :$0\n" + + "Won :$0\n" + + "Lost :$0\n" + + "\n" + + "Number Guess\n" + + "Bet :$0\n" + + "Won :$0\n" + + "Lost :$0\n" + + "\n" + + "Plinko\n" + + "Bet :$0\n" + + "Won :$0\n" + + "Lost :$0\n\n"; + + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/com/github/zipcodewilmington/KenoGameRETest.java b/src/test/java/com/github/zipcodewilmington/KenoGameRETest.java new file mode 100644 index 000000000..1f12b8573 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/KenoGameRETest.java @@ -0,0 +1,179 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.keno.KenoGameRE; +import org.junit.Assert; +import org.junit.Test; + +import java.util.HashSet; +import java.util.stream.Stream; + +public class KenoGameRETest { + + @Test + public void addPlayerTest(){ + KenoGameRE keno = new KenoGameRE(); + CasinoAccount account = new CasinoAccount("name", "password"); + Player player1 = new Player(null, account); + keno.add(player1); + PlayerInterface retrievedPlayer = keno.getCurrentPlayer(); + Assert.assertEquals(player1,retrievedPlayer ); + } + + @Test + public void removePlayerTest() { + KenoGameRE keno = new KenoGameRE(); + CasinoAccount account = new CasinoAccount("name", "password"); + Player player1 = new Player(null, account); + keno.remove(player1); + Assert.assertNull(keno.getCurrentPlayer()); + } + + @Test + public void printWelcome(){ + KenoGameRE keno = new KenoGameRE(); + String expected = "***********************************\n" + + "*** ***\n" + + "****** WELCOME TO KENO ******\n" + + "*** ***\n" + + "***********************************"; + String actual = keno.printWelcome(); + Assert.assertEquals(expected,actual); + } + + @Test + public void displayInstructions(){ + KenoGameRE keno = new KenoGameRE(); + String expected = "Pick 10 numbers between 1 and 80!\n" + + "The more numbers matched the more you win!"; + String actual = keno.displayInstruction(); + Assert.assertEquals(expected,actual); + } + + @Test + public void getPlayerBalance(){ + KenoGameRE keno = new KenoGameRE(); + CasinoAccount account = new CasinoAccount("name", "password"); + account.alterAccountBalance(100); + Player player1 = new Player(null, account); + keno.add(player1); + keno.setUserBet(20); + keno.subtractBetFromBalance(20); + Integer actual = player1.getArcadeAccount().getAccountBalance(); + Integer exp = 80; + Assert.assertEquals(exp,actual); + } + + @Test + public void twentyOneRandomNum(){ + KenoGameRE keno = new KenoGameRE(); + CasinoAccount account = new CasinoAccount("name", "password"); + account.alterAccountBalance(100); + Player player1 = new Player(null, account); + keno.add(player1); + keno.setTwentyOneRandom(keno.twentyOneRandomNum()); + Integer actual = keno.getTwentyOneRandom().size(); + Integer expected = 21; + Assert.assertEquals(expected,actual); + } + + @Test + public void findMatches(){ + KenoGameRE keno = new KenoGameRE(); + HashSet userChoices = new HashSet<>(); + Stream.of(1,2,3,4,5,6,7,8,9,10).forEach(e -> userChoices.add(e)); + HashSet twentyOne = new HashSet<>(); + Stream.of(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21).forEach(e -> twentyOne.add(e)); + + keno.setTenChoices(userChoices); + keno.setTwentyOneRandom(twentyOne); + keno.setMatches(keno.findMatches()); + + Assert.assertEquals(userChoices,keno.getMatches()); + } + + @Test + public void multiplier(){ + KenoGameRE keno = new KenoGameRE(); + HashSet matches = new HashSet<>(); + Stream.of(1,2,3,4,5,6,7,8,9,10).forEach(e -> matches.add(e)); + keno.setMatches(matches); + Integer actual = keno.calculateMultiplier(); + Integer expected = 10; + Assert.assertEquals(expected,actual); + } + + @Test + public void calculateWinning(){ + KenoGameRE keno = new KenoGameRE(); + Integer actual = keno.calculateWinnings(10, 5); + Integer exp = 50; + Assert.assertEquals(exp,actual); + } + + @Test + public void addMoneyToBalance(){ + KenoGameRE keno = new KenoGameRE(); + CasinoAccount account = new CasinoAccount("name", "password"); + Player player1 = new Player(null, account); + keno.add(player1); + keno.addMoneyToBalance(player1,500); + Integer exp = 500; + Integer act = keno.getPlayerBalance(); + Assert.assertEquals(exp,act); + } + + @Test + public void playAgain(){ + KenoGameRE keno = new KenoGameRE(); + CasinoAccount account = new CasinoAccount("name", "password"); + Player player1 = new Player(null, account); + keno.add(player1); + Boolean quit = keno.playAgain(); + Assert.assertTrue(quit); + } + + @Test + public void getWinningsTest(){ + KenoGameRE keno = new KenoGameRE(); + CasinoAccount account = new CasinoAccount("name", "password"); + Player player1 = new Player(null, account); + keno.add(player1); + keno.setWinnings(100); + Integer actual = keno.getWinnings(); + Integer expected = 100; + + Assert.assertEquals(expected, actual); + } + + @Test + public void setMultiplierTest(){ + KenoGameRE keno = new KenoGameRE(); + CasinoAccount account = new CasinoAccount("name", "password"); + Player player1 = new Player(null, account); + keno.add(player1); + keno.setMultiplier(10); + Integer actual = keno.getMultiplier(); + Integer expected = 10; + + Assert.assertEquals(expected, actual); + } + + @Test + public void getTenChoices(){ + KenoGameRE keno = new KenoGameRE(); + CasinoAccount account = new CasinoAccount("name", "password"); + Player player1 = new Player(null, account); + keno.add(player1); + HashSet expected = new HashSet<>(); + expected.add(1); + keno.setTenChoices(expected); + HashSet actual = keno.getTenChoices(); + + + Assert.assertTrue(expected.equals(actual)); + } + +} diff --git a/src/test/java/com/github/zipcodewilmington/KenoPlayerTest.java b/src/test/java/com/github/zipcodewilmington/KenoPlayerTest.java new file mode 100644 index 000000000..af86661ee --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/KenoPlayerTest.java @@ -0,0 +1,50 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.blackjack.BlackJackPlayer; +import com.github.zipcodewilmington.casino.games.keno.KenoPlayer; +import org.junit.Assert; +import org.junit.Test; + +public class KenoPlayerTest { + @Test + public void constructorTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + KenoPlayer keno = new KenoPlayer(player); + + PlayerInterface expected = player; + PlayerInterface actual = keno.getPlayer(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getArcadeAccountTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + KenoPlayer keno = new KenoPlayer(player); + + CasinoAccount actual = keno.getArcadeAccount(); + CasinoAccount expected = account; + + Assert.assertEquals(actual, expected); + } + + @Test + public void setArcadeAccountTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + KenoPlayer keno = new KenoPlayer(player); + keno.setArcadeAccount(account); + + CasinoAccount actual = keno.getArcadeAccount(); + CasinoAccount expected = account; + + Assert.assertEquals(actual, expected); + + } +} + diff --git a/src/test/java/com/github/zipcodewilmington/NumberGuessGameTests.java b/src/test/java/com/github/zipcodewilmington/NumberGuessGameTests.java new file mode 100644 index 000000000..61ef03bb2 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/NumberGuessGameTests.java @@ -0,0 +1,148 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessGame; +import org.junit.Assert; +import org.junit.Test; + +public class NumberGuessGameTests { + + @Test + public void constructorTest1(){ + NumberGuessGame game = new NumberGuessGame(); + Integer actual = game.getMaxNumber(); + Integer expected = 20; + Assert.assertEquals(actual, expected); + } + + @Test + public void printWelcomeTest(){ + NumberGuessGame game = new NumberGuessGame(); + String expected = "************************************\n" + + "*** ***\n" + + "****** !! WELCOME TO !! ******\n" + + "****** !!! GUESS NUMBER !!! ******\n" + + "*** ***\n" + + "************************************\n"; + String actual = game.printWelcome(); + Assert.assertEquals(expected, actual); + } + + @Test + public void printInstructions(){ + NumberGuessGame game = new NumberGuessGame(); + game.printInstructions(); + //check output + } + + @Test + public void subtractBetFromBalanceTest(){ + //given + CasinoAccount account = new CasinoAccount("name", "password"); + Player player1 = new Player(null, account); + NumberGuessGame game = new NumberGuessGame(); + game.add(player1); + Integer expected = 300; + //when + account.alterAccountBalance(500); + game.subtractBetFromBalance(200); + Integer actual = player1.getArcadeAccount().getAccountBalance(); + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void calcPotentialEarningsTest(){ + //given + CasinoAccount account = new CasinoAccount("name", "password"); + Player player1 = new Player(null, account); + NumberGuessGame game = new NumberGuessGame(); + game.setBetAmount(10); + Integer[] expected = {20,30,40,50}; + //when + game.calcPotentialEarnings(); + Integer[] actual = game.getPotentialEarnings(); + //then + Assert.assertArrayEquals(expected, actual); + } + + @Test + public void setMultiplierTest(){ + //given + NumberGuessGame game = new NumberGuessGame(); + game.setMultiplier(20); + Integer expected = 2; + Integer actual = game.getMultiplier(); + Assert.assertEquals(expected,actual); + } + + @Test + public void pickRandomNumber(){ + //given + NumberGuessGame game = new NumberGuessGame(); + game.pickRandomNumber(); + Integer first = game.getRandomNumber(); + game.pickRandomNumber(); + Integer second = game.getRandomNumber(); + Assert.assertNotEquals(first, second); + } + + @Test + public void getGuessRange(){ + NumberGuessGame game = new NumberGuessGame(); + Integer guessedNumber = 10; + Integer actualNumber = 5; + Integer actual = game.getGuessRange(guessedNumber, actualNumber); + Integer expected = 25; + Assert.assertEquals(actual, expected); + } + + @Test + public void calculatePayoutTest(){ + //given + NumberGuessGame game = new NumberGuessGame(); + Integer expected = 50; + Integer actual = game.calculatePayout(5,0,10); + Assert.assertEquals(expected,actual); + } + + @Test + public void addMoneyToBalance(){ + CasinoAccount account = new CasinoAccount("name", "password"); + Player player1 = new Player(null, account); + NumberGuessGame game = new NumberGuessGame(); + game.add(player1); + game.addMoneyToBalance(player1,10); + + Integer expected = 10; + Integer actual = player1.getArcadeAccount().getAccountBalance(); + Assert.assertEquals(expected,actual); + } + + @Test + public void setMaxNumberTest(){ + NumberGuessGame game = new NumberGuessGame(); + game.setMaxNumber(50); + Integer actual = game.getMaxNumber(); + Integer expected = 50; + + Assert.assertEquals(actual, expected); + } + + + + @Test + public void getGuessPercentage(){ + NumberGuessGame game = new NumberGuessGame(); + Integer guessedNumber = 10; + Integer max = game.getMaxNumber(); + Integer actualNumber = 5; + Integer range = Math.abs(guessedNumber - actualNumber); + Integer actual = game.guessRangePercentage(range); + Integer expected = 25; + + Assert.assertEquals(actual, expected); + } + +} diff --git a/src/test/java/com/github/zipcodewilmington/NumberGuessPlayerTest.java b/src/test/java/com/github/zipcodewilmington/NumberGuessPlayerTest.java new file mode 100644 index 000000000..b8e351275 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/NumberGuessPlayerTest.java @@ -0,0 +1,62 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessPlayer; +import org.junit.Assert; +import org.junit.Test; + +public class NumberGuessPlayerTest { + @Test + public void numberGuessPlayerTest(){ + //given + CasinoAccount account = new CasinoAccount("aaa", "bbb"); + PlayerInterface player = new Player("john",account); + NumberGuessPlayer gp = new NumberGuessPlayer(player); + //when + PlayerInterface expected = player; + PlayerInterface actual = gp.getPlayer(); + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void getArcadeAccountTest(){ + //given + CasinoAccount account = new CasinoAccount("aaa", "bbb"); + PlayerInterface player = new Player("john",account); + NumberGuessPlayer gp = new NumberGuessPlayer(player); + //when + CasinoAccount retrieved = gp.getArcadeAccount(); + //then + Assert.assertEquals(account, retrieved); + + } + + @Test + public void setArcadeAccountTest(){ + //given + CasinoAccount account = new CasinoAccount("aaa", "bbb"); + CasinoAccount account2 = new CasinoAccount("ddd", "eee"); + PlayerInterface player = new Player("john",account); + NumberGuessPlayer gp = new NumberGuessPlayer(player); + //when + gp.setArcadeAccount(account2); + CasinoAccount retrieved = gp.getArcadeAccount(); + //then + Assert.assertEquals(account2, retrieved); + } + + @Test + public void getPlayerTest(){ + //given + CasinoAccount account = new CasinoAccount("aaa", "bbb"); + PlayerInterface player = new Player("john",account); + NumberGuessPlayer gp = new NumberGuessPlayer(player); + //when + PlayerInterface retrieved = gp.getPlayer(); + //then + Assert.assertEquals(player, retrieved); + } +} diff --git a/src/test/java/com/github/zipcodewilmington/PlayerTest.java b/src/test/java/com/github/zipcodewilmington/PlayerTest.java new file mode 100644 index 000000000..fd7200037 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/PlayerTest.java @@ -0,0 +1,68 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.Beetle.BeetlePlayer; +import org.junit.Assert; +import org.junit.Test; + +public class PlayerTest { + + @Test + public void constructorTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + + Assert.assertNotNull(player); + + } + + @Test + public void getNameTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + Player player = new Player("Bjork", account); + + String actual = player.getName(); + String expected = "Bjork"; + + Assert.assertEquals(actual, expected); + } + + @Test + public void setCurrentBetTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + Player player = new Player("Bjork", account); + player.setCurrentBet(200); + + Integer actual = player.getCurrentBet(); + Integer expected = 200; + Assert.assertEquals(actual, expected); + } + + @Test + public void setBalanceTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + Player player = new Player("Bjork", account); + player.setBalance(2000); + + Integer actual = player.getBalance(); + Integer expected = 2000; + + Assert.assertEquals(actual, expected); + } + + @Test + public void makeBetTest(){ + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + Player player = new Player("Bjork", account); + player.setBalance(2000); + + player.makeBet(1000); + + Integer expected = 1000; + Integer actual = player.getCurrentBet(); + + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/com/github/zipcodewilmington/PlinkoPlayerTest.java b/src/test/java/com/github/zipcodewilmington/PlinkoPlayerTest.java new file mode 100644 index 000000000..4a2c1eb49 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/PlinkoPlayerTest.java @@ -0,0 +1,38 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.games.plinko.PlinkoPlayer; +import org.junit.Assert; +import org.junit.Test; + +public class PlinkoPlayerTest { + + @Test + public void constructorTest(){ + CasinoAccount account = new CasinoAccount("zz", "ss"); + Player player = new Player("brep", account); + PlinkoPlayer plinkoPlayer = new PlinkoPlayer(player); + + Assert.assertNotNull(plinkoPlayer); + } + + @Test + public void getArcadeAccountTest(){ + CasinoAccount account = new CasinoAccount("zz", "ss"); + Player player = new Player("brep", account); + PlinkoPlayer plinkoPlayer = new PlinkoPlayer(player); + CasinoAccount playerAccount = plinkoPlayer.getArcadeAccount(); + Assert.assertEquals(account, playerAccount); + } + + @Test + public void setArcadeAccountTest(){ + CasinoAccount account = new CasinoAccount("zz", "ss"); + Player player = new Player("brep", account); + PlinkoPlayer plinkoPlayer = new PlinkoPlayer(player); + plinkoPlayer.setArcadeAccount(account); + CasinoAccount playerAccount = plinkoPlayer.getArcadeAccount(); + Assert.assertEquals(account, playerAccount); + } +} diff --git a/src/test/java/com/github/zipcodewilmington/REPlinkoTest.java b/src/test/java/com/github/zipcodewilmington/REPlinkoTest.java new file mode 100644 index 000000000..80076ba32 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/REPlinkoTest.java @@ -0,0 +1,177 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.plinko.REPlinko; +import org.junit.Assert; +import org.junit.Test; + +public class REPlinkoTest { + + @Test + public void calculateWinningsTest () { + REPlinko game = new REPlinko(); + Integer expected = 12; + + Integer multiplier = 3; + Integer betAmount = 4; + Integer actual = game.calculateWinnings(multiplier, betAmount); + + Assert.assertEquals(expected,actual); + } + + @Test + public void subtractTest() { + REPlinko game = new REPlinko(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + player.getArcadeAccount().alterAccountBalance(500); + game.add(player); + player.getArcadeAccount().alterAccountBalance(200 * -1); + Integer expected = 300; + Integer actual = player.getArcadeAccount().getAccountBalance(); + Assert.assertEquals(expected, actual); + } + + @Test + public void runTest () { + REPlinko game = new REPlinko(); + game.setRunning(true); + game.run(); + + Integer actual = game.getUserBet(); + Integer expected = null; + + Assert.assertEquals(expected, actual); + } + + @Test + public void getRunningTest () { + REPlinko game = new REPlinko(); + boolean expected = false; + boolean actual = game.getRunning(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void removePlayerTest () { + REPlinko game = new REPlinko(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + + game.add(player); + game.remove(player); + Boolean expected = false; + Boolean actual = game.getPlayerInt() != null; + + Assert.assertEquals(expected, actual); + } + + @Test + public void addPlayerTest () { + REPlinko game = new REPlinko(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + + game.add(player); + Boolean expected = true; + Boolean actual = game.getPlayerInt() != null; + + Assert.assertEquals(expected, actual); + } + + @Test + public void createBoardTest () { + REPlinko game = new REPlinko(); + Integer expected = 10; + + game.createBoard(); + Integer actual = game.winningValues.size(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void checkWinTest () { + REPlinko game = new REPlinko(); + Integer expected = 0; + + game.createBoard(); + Integer actual = game.checkWin(); + + Assert.assertEquals(expected, actual); + } + +// @Test +// public void startGameTest () { +// REPlinko game = new REPlinko(); +// Integer expected = 0; +// +// game.startGame(); +// Integer actual = game.calculateWinnings(game.checkWin(), 100); +// +// Assert.assertEquals(expected, actual); +// } + + @Test + public void shuffleTest () { + REPlinko game = new REPlinko(); + Boolean runner = false; + Integer actual = 5; + + game.createBoard(); + + while (!runner) { + game.shuffleBoard(); + Integer expected = game.winningValues.get(0); + if (expected == actual) { + runner = true; + } + } + Assert.assertTrue(runner); + } + + @Test + public void subtractMoneyTest () { + REPlinko game = new REPlinko(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + player.getArcadeAccount().alterAccountBalance(500); + game.add(player); + game.subtractBetFromBalance(200); + Integer expected = 300; + Integer actual = player.getArcadeAccount().getAccountBalance(); + Assert.assertEquals(actual, expected); + } + + @Test + public void addingMoneyTest () { + REPlinko game = new REPlinko(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + player.getArcadeAccount().alterAccountBalance(500); + game.add(player); + game.addMoneyToBalance(player,200); + Integer expected = 700; + Integer actual = player.getArcadeAccount().getAccountBalance(); + Assert.assertEquals(actual, expected); + } + + @Test + public void startGameTest(){ + REPlinko game = new REPlinko(); + CasinoAccount account = new CasinoAccount("Bjork", "beeyork"); + PlayerInterface player = new Player("Bjork", account); + player.getArcadeAccount().alterAccountBalance(500); + game.setUserBet(100); + game.add(player); + game.startGame(); + + Integer expected = 10; + Integer actual = game.getWinningValues().size(); + + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/com/github/zipcodewilmington/SlotsGameTest.java b/src/test/java/com/github/zipcodewilmington/SlotsGameTest.java new file mode 100644 index 000000000..1f3617319 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/SlotsGameTest.java @@ -0,0 +1,222 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.slots.SlotsGame; +import org.junit.Assert; +import org.junit.Test; + +public class SlotsGameTest { + + @Test + public void slotsConstructorTest(){ + //when + SlotsGame newGame = new SlotsGame(); + Assert.assertTrue(newGame instanceof SlotsGame); + } + + @Test + public void addPlayerTest(){ + //given + SlotsGame newGame = new SlotsGame(); + CasinoAccount account = new CasinoAccount("name", "password"); + Player player1 = new Player(null, account); + //when + newGame.add(player1); + //then + PlayerInterface retrievedPlayer = newGame.getCurrentPlayer(); + Assert.assertEquals(player1,retrievedPlayer ); + } + + @Test + public void removePlayerTest(){ + //given + SlotsGame newGame = new SlotsGame(); + CasinoAccount account = new CasinoAccount("name", "password"); + Player player1 = new Player(null, account); + //when + newGame.add(player1); + newGame.remove(newGame.getCurrentPlayer()); + //then + PlayerInterface retrievedPlayer = newGame.getCurrentPlayer(); + Assert.assertNull(retrievedPlayer); + } + + @Test + public void calculateMultiplierTest(){ + //given + SlotsGame newSlotsGame = new SlotsGame(); + String[] betResults = {"WIN", "WIN", "LOSE", "LOSE"}; + Integer expectedWin = 2; + Integer expectedLose = 2; + //when + newSlotsGame.calculateMultiplier(betResults); + Integer retrievedWin = newSlotsGame.getWinMultiplier(); + Integer retrievedLose = newSlotsGame.getLoseMultiplier(); + //then + Assert.assertEquals(expectedWin, retrievedWin); + Assert.assertEquals(expectedLose, retrievedLose); + + } + + @Test + public void calculateWinningsTest(){ + //given + SlotsGame newGame = new SlotsGame(); + Integer expected = 10; + //when + Integer actual = newGame.calculateWinnings(2, 5); + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void calculateReturnTotal(){ + //given + SlotsGame newGame = new SlotsGame(); + newGame.setBetTotal(80); + Integer expected = 100; + //when + Integer actual = newGame.calculateReturnTotal(50, 30); + //then + Assert.assertEquals(expected, actual); + + } + + @Test + public void subtractBetFromBalanceTest(){ + //given + SlotsGame slotGame = new SlotsGame(); + CasinoAccount account = new CasinoAccount("name", "password"); + Player player1 = new Player(null, account); + slotGame.add(player1); + //when + slotGame.subtractBetFromBalance(50); + Integer expected = 50 * (-1); + Integer retrieved = player1.getArcadeAccount().getAccountBalance(); + //then + Assert.assertEquals(expected, retrieved); + + } + + @Test + public void addMoneyToBalanceTest(){ + //given + SlotsGame slotGame = new SlotsGame(); + CasinoAccount account = new CasinoAccount("name", "password"); + Player player1 = new Player(null, account); + slotGame.add(player1); + //when + slotGame.addMoneyToBalance(player1, 50); + Integer expected = 50; + Integer retrieved = player1.getArcadeAccount().getAccountBalance(); + //then + Assert.assertEquals(expected, retrieved); + } + + @Test + public void setBetTotal(){ + //given + SlotsGame slotGame = new SlotsGame(); + //when + slotGame.setBetTotal(50); + Integer expected = 50; + Integer retrieved = slotGame.getBetTotal(); + // + Assert.assertEquals(expected, retrieved); + } + + @Test + public void lineChoiceTest(){ + //given + SlotsGame slotGame = new SlotsGame(); + String expected = "************************************************************************\n" + + "** Select the lines you want to bet on! **\n" + + "** 1. Top Horizontal 2. Middle Horizontal 3. Bottom Horizontal **\n" + + "** 4. Left Vertical 5. Middle Vertical 6. Right Vertical **\n" + + "** 7. Down Diagonal 8. Up Diagonal **\n" + + "************************************************************************"; + //when + String actual = slotGame.lineChoices(); + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void printWelcomeTest() { + //given + SlotsGame slotGame = new SlotsGame(); + String expected = + "***********************************\n" + + "*** ***\n" + + "****** WELCOME TO SLOTS ******\n" + + "*** ***\n" + + "***********************************"; + //when + String actual = slotGame.printWelcome(); + //then + Assert.assertEquals(expected,actual); + } + + @Test + public void add() { + } + + @Test + public void remove() { + } + + @Test + public void getLoseMultiplier() { + } + + @Test + public void getWinMultiplier() { + } + + @Test + public void run() { + } + + @Test + public void printWelcome() { + } + + @Test + public void getBetAmount() { + } + + @Test + public void getBetSelections() { + } + + @Test + public void calculateMultiplier() { + } + + @Test + public void lineChoices() { + } + + @Test + public void calculateWinnings() { + } + + @Test + public void subtractBetFromBalance() { + } + + @Test + public void addMoneyToBalance() { + } + + @Test + public void getBetTotal() { + } + + @Test + public void getCurrentPlayer() { + } +} diff --git a/src/test/java/com/github/zipcodewilmington/SlotsPlayerTest.java b/src/test/java/com/github/zipcodewilmington/SlotsPlayerTest.java new file mode 100644 index 000000000..37ba06c7b --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/SlotsPlayerTest.java @@ -0,0 +1,64 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.slots.SlotsPlayer; +import org.junit.Assert; +import org.junit.Test; + +public class SlotsPlayerTest { + + @Test + public void constructorTest(){ + //given + CasinoAccount account = new CasinoAccount("aaa", "bbb"); + PlayerInterface player = new Player("john",account); + SlotsPlayer slotPlayer = new SlotsPlayer(player); + //when + PlayerInterface expected = player; + PlayerInterface actual = slotPlayer.getPlayer(); + //then + Assert.assertEquals(expected, actual); + + } + + @Test + public void getArcadeAccount() { + //given + CasinoAccount account = new CasinoAccount("aaa", "bbb"); + PlayerInterface player = new Player("john",account); + SlotsPlayer slotPlayer = new SlotsPlayer(player); + //when + CasinoAccount retrieved = slotPlayer.getArcadeAccount(); + //then + Assert.assertEquals(account, retrieved); + } + + @Test + public void setArcadeAccount() { + //given + CasinoAccount account = new CasinoAccount("aaa", "bbb"); + CasinoAccount account2 = new CasinoAccount("ddd", "eee"); + PlayerInterface player = new Player("john",account); + SlotsPlayer slotPlayer = new SlotsPlayer(player); + //when + slotPlayer.setArcadeAccount(account2); + CasinoAccount retrieved = slotPlayer.getArcadeAccount(); + //then + Assert.assertEquals(account2, retrieved); + + } + + @Test + public void getPlayer() { + //given + CasinoAccount account = new CasinoAccount("aaa", "bbb"); + PlayerInterface player = new Player("john",account); + SlotsPlayer slotPlayer = new SlotsPlayer(player); + //when + PlayerInterface retrieved = slotPlayer.getPlayer(); + //then + Assert.assertEquals(player, retrieved); + } +} diff --git a/src/test/java/com/github/zipcodewilmington/SlotsTest.java b/src/test/java/com/github/zipcodewilmington/SlotsTest.java new file mode 100644 index 000000000..005b7e429 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/SlotsTest.java @@ -0,0 +1,141 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.games.slots.Slots; +import org.junit.Assert; +import org.junit.Test; + +import java.util.HashMap; + +public class SlotsTest { + + @Test + public void slotConstructorTest(){ + //given + String[][] expected = { + {"Peach", "Cherry", "Diamond"}, + {"Diamond", "Plum", "Nine"}, + {"Seven", "Peach", "Diamond"}}; + //when + Slots slot = new Slots(); + String[][] retrieved = slot.getSlots(); + //then + Assert.assertEquals(expected, retrieved); + } + + @Test + public void setSlotTest(){ + //given + Slots slot = new Slots(); + String[][] given = { + {"Cherry", "Cherry", "Cherry"}, + {"Diamond", "Plum", "Nine"}, + {"Seven", "Peach", "Diamond"}}; + //when + slot.setSlots(given); + String[][] retrieved = slot.getSlots(); + //then + Assert.assertEquals(given,retrieved); + } + + @Test + public void getSlotTest(){ + //given + String[][] expected = { + {"Peach", "Cherry", "Diamond"}, + {"Diamond", "Plum", "Nine"}, + {"Seven", "Peach", "Diamond"}}; + //when + Slots slot = new Slots(); + String[][] retrieved = slot.getSlots(); + //then + Assert.assertEquals(expected, retrieved); + } + + @Test + public void randomItemTest(){ + //given + String[] given = {"Peach", "Cherry", "Diamond"}; + String[] retrieved = {"Peach", "Cherry", "Diamond"}; + //when + for (int i = 0; i < retrieved.length; i++) { + retrieved[i] = Slots.ramdomSlotItem(); + } + //then + Assert.assertFalse(given.equals(retrieved)); + } + + @Test + public void spinSlotsTest(){ + //given + Slots slotMachine = new Slots(); + String[][] given = slotMachine.getSlots(); + //when + slotMachine.spinSlots(); + String[][] retrieved = slotMachine.getSlots(); + //then + Assert.assertFalse(given.equals(retrieved)); + } + + @Test + public void initializeWinningLinesTest(){ + //given + Slots slot = new Slots(); + String[] expected = {"LOSE","LOSE","LOSE","LOSE","LOSE","LOSE","LOSE","LOSE",}; + HashMap initialWinningLines = slot.getWinningLines(); + String[] returned = new String[8]; + for (int i = 0; i < initialWinningLines.size(); i++) { + returned[i] = (String) initialWinningLines.get(i + 1); + } + //then + Assert.assertEquals(expected, returned); + + } + + @Test + public void setWinningLinesTest(){ + //given + String[][] given = { + {"Peach", "Peach", "Peach"}, + {"Peach", "Peach", "Peach"}, + {"Peach", "Peach", "Peach"}}; + Slots slot = new Slots(given); + String[] expected = {"WIN","WIN","WIN","WIN","WIN","WIN","WIN","WIN"}; + //when + slot.setWinningLines(); + HashMap winningLines = slot.getWinningLines(); + String[] returned = new String[8]; + for (int i = 0; i < winningLines.size(); i++) { + returned[i] = (String) winningLines.get(i + 1); + } + //then + Assert.assertEquals(expected,returned); + + } + + @Test + public void compareBetVsWinningLinesTest(){ + //given + String[][] given = { + {"Peach", "Peach", "Peach"}, + {"Peach", "Peach", "Peach"}, + {"Peach", "Peach", "Peach"}}; + Slots slot = new Slots(given); + slot.setWinningLines(); + String[] expected = {"WIN","WIN","WIN","WIN","WIN","WIN","WIN","WIN"}; + Integer [] bets = {1,2,3,4,5,6,7,8}; + //when + String[] returned = slot.compareBetVsWinningLines(bets); + //then + Assert.assertEquals(expected, returned); + } + + @Test + public void displaySlotsTest(){ + //given + Slots slot = new Slots(); + //when + slot.displaySlots(); + //then - check output + } + +}