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/src/main/java/com/github/zipcodewilmington/Casino.java b/src/main/java/com/github/zipcodewilmington/Casino.java index 5eae9ac0c..ba93e5c4d 100644 --- a/src/main/java/com/github/zipcodewilmington/Casino.java +++ b/src/main/java/com/github/zipcodewilmington/Casino.java @@ -1,22 +1,27 @@ 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.numberguess.NumberGuessGame; import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessPlayer; +import com.github.zipcodewilmington.casino.games.plinko.PlinkoGame; 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; +import java.util.Locale; + /** * 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; @@ -29,20 +34,14 @@ public void run() { 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)); - } + 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)) { console.println("Welcome to the account-creation screen."); @@ -50,6 +49,21 @@ public void run() { 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("save-account".equals(arcadeDashBoardInput)){ + 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("load-saved-account".equals(arcadeDashBoardInput)){ + this.casinoAccount = CSVUtils.loadData(); + this.player = new Player(this.casinoAccount.getAccountName(), this.casinoAccount); + casinoAccountManager.registerAccount(this.casinoAccount); } } while (!"logout".equals(arcadeDashBoardInput)); } @@ -58,7 +72,7 @@ private String getArcadeDashboardInput() { return console.getStringInput(new StringBuilder() .append("Welcome to the Arcade Dashboard!") .append("\nFrom here, you can select any of the following options:") - .append("\n\t[ create-account ], [ select-game ]") + .append("\n\t[ create-account ], [ select-game ], [ load-saved-account ], [ save-account ]") .toString()); } @@ -66,10 +80,34 @@ private String getGameSelectionInput() { return console.getStringInput(new StringBuilder() .append("Welcome to the Game Selection Dashboard!") .append("\nFrom here, you can select any of the following options:") - .append("\n\t[ SLOTS ], [ NUMBERGUESS ]") + .append("\n\t[ SLOTS ], [ NUMBERGUESS ], [ PLINKO ], [ BEETLE ], [ BLACKJACK ]" + + "[ KENO ]") .toString()); } + private void processGameSelection(String input){ + input = input.toLowerCase(Locale.ROOT); + GameInterface gameObject; + switch(input){ + case "beetle": + gameObject = new BeetleGame(); + break; + case "slots": + gameObject = new SlotsGame(); + break; + case "blackjack": + gameObject = new BlackJackGame(); + break; + case "numberguess": + gameObject = new NumberGuessGame(); + break; + default: + gameObject = new BeetleGame(); + } + + play(gameObject, player); + } + private void play(Object gameObject, Object playerObject) { GameInterface game = (GameInterface)gameObject; PlayerInterface player = (PlayerInterface)playerObject; diff --git a/src/main/java/com/github/zipcodewilmington/MainApplication.java b/src/main/java/com/github/zipcodewilmington/MainApplication.java index 508787a85..d6fd77829 100644 --- a/src/main/java/com/github/zipcodewilmington/MainApplication.java +++ b/src/main/java/com/github/zipcodewilmington/MainApplication.java @@ -1,7 +1,12 @@ package com.github.zipcodewilmington; +import com.github.zipcodewilmington.casino.games.slots.SlotsGame; + public class MainApplication { public static void main(String[] args) { new Casino().run(); + +// SlotsGame slotGame = new SlotsGame(); +// slotGame.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..7883d56f3 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java @@ -1,9 +1,38 @@ package com.github.zipcodewilmington.casino; +import com.github.zipcodewilmington.Casino; + +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; + + public CasinoAccount(String accountName, String accountPassword){ + this.accountName = accountName; + this.password = accountPassword; + } + + public String getPassword() { + return password; + } + + public String getAccountName() { + return accountName; + } + + public Integer getAccountBalance() { + return accountBalance; + } + + public void alterAccountBalance(Integer value) { + this.accountBalance += value; + } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java index 2d09ec2a0..0e8b08ef8 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java @@ -1,17 +1,33 @@ 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) { + 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; + } else { + System.out.println("Account Name or Password does not match. Are you really you?"); + return null; + } + } 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"; @@ -26,10 +42,12 @@ public CasinoAccount getAccount(String accountName, String accountPassword) { * @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; + //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)); } /** @@ -38,9 +56,10 @@ public CasinoAccount createAccount(String accountName, String accountPassword) { * @param casinoAccount the arcadeAccount to be added to `this.getArcadeAccountList()` */ public void registerAccount(CasinoAccount casinoAccount) { - String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); - String currentClassName = getClass().getName(); - String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; - throw new RuntimeException(String.format(errorMessage, currentMethodName, currentClassName)); + this.accountList.add(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)); } } 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/Player.java b/src/main/java/com/github/zipcodewilmington/casino/Player.java new file mode 100644 index 000000000..0f5578c68 --- /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{ + + String name; + Integer balance; + Integer currentBet = 0; + 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..9c7f5f4a9 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java @@ -0,0 +1,120 @@ +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[] = new Integer[2]; + + + 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 void refreshBeetle(Integer player){ + this.playerBeetles[player] = new Integer[] {0, 0, 0, 0, 0, 0}; + } + + public String printBeetle(Integer player){ + Integer[] currentBeetle = this.getPlayerBeetles()[player]; + String output = "Body:"; + 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; + //this.scoreboard[player] += 6; + //if(this.getScore(player) == 30){ + //return true; + //} else { + //this.refreshBeetle(player); + //} + } + 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..53ee790f3 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java @@ -0,0 +1,165 @@ +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 ArrayList players = new ArrayList(); + private Beetle game; + private Boolean isRunning = false; + private PlayerInterface player; + private IOConsole console = new IOConsole(); + private Integer betAmt; + + 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){ + players.remove(player); + } + + /** + * specifies how the game will run + */ + public void run(){ + this.initGame(); + while(this.isRunning){ + this.nextPlayer(); + this.executeTurn(); + this.isGameOver(this.game.checkWinner(this.game.getCurrentPlayer())); + } + console.newLine(); + console.println("Final Beetle results: "); + this.printBeetleCards(); + console.newLine(); + this.printWinnerMessage(); + console.println("Your payout is: " + this.determinePayout().toString()); + console.pressEnterToProceed(); + } + + public void initGame(){ + printWelcome(); + console.newLine(); + this.setBetAmt(printBalanceAndBetText()); + Integer turnCount = 0; + game.setCurrentPlayer(-1); + this.isRunning = true; + } + + public void printBeetleCards(){ + console.print("\u001B[32m Your last dice roll: " + game.getLastDiceRoll(0)); + console.print( " Your Beetle: "); + console.println(game.printBeetle(0)); + console.print("\u001B[32m Dealer's last dice roll: " + game.getLastDiceRoll(1)); + console.print(" Dealer's Beetle: "); + console.println(game.printBeetle(1)); + } + + 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){ + this.printBeetleCards(); + console.println("Press enter to roll next dice"); + console.pressEnterToProceed(); + } + game.setPlayerBeetles(currentPlayer, game.getDice().tossAndSum()); + } + + public Integer determinePayout(){ + Integer payout = (int)(this.betAmt * 1.1); + if(this.game.getCurrentPlayer() == 0){ + this.player.getArcadeAccount().alterAccountBalance(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){ + + } + + public void initGame(Integer players){ + this.game = new Beetle(this.players.size()); + this.isRunning = true; + this.run(); + } + + public Boolean getIsRunning(){ + return this.isRunning; + } + + public Integer getBetAmt() { + return betAmt; + } + + public void setBetAmt(Integer betAmt) { + this.betAmt = betAmt; + } + + public void printWelcome() { + console.print( + "\u001B[33m***********************************\n" + + "*** ***\n" + + "****** WELCOME TO BEETLE ******\n" + + "*** ***\n" + + "***********************************"); + } + + + public Integer printBalanceAndBetText(){ + console.newLine(); + console.println("\u001B[35m Current account balance: " + this.player.getArcadeAccount().getAccountBalance()); + console.newLine(); + return console.getIntegerInput("\u001B[34m How much do you want to bet?"); + } + + public void printWinnerMessage(){ + if(this.game.getCurrentPlayer() == 0){ + console.println("You win!"); + } else { + console.println("Dealer wins..."); + } + console.newLine(); + } + +} 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..09b4f79cc --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java @@ -0,0 +1,23 @@ +package com.github.zipcodewilmington.casino.games.Beetle; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; + +public class BeetlePlayer implements PlayerInterface { + private PlayerInterface player; + + public BeetlePlayer(PlayerInterface player){ + this.player = player; + } + + @Override + public CasinoAccount getArcadeAccount() { + return null; + } + + @Override + public void setArcadeAccount(CasinoAccount casinoAccount) { + + } +} 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..bcbccd6dc --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java @@ -0,0 +1,100 @@ +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; + } +} \ 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..7677aa3d5 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java @@ -0,0 +1,302 @@ +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.IOConsole; + + +public class BlackJackGame implements GameInterface { + private Boolean isRunning = false; + private PlayerInterface playerInt; + Integer userBet; + Integer splitBet; + IOConsole input = new IOConsole(); + Integer winnings = 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() { + System.out.println("\u001B[36m============================================================"); + System.out.println("\u001B[36m===== ====="); + System.out.println("\u001B[36m===== WELCOME ====="); + System.out.println("\u001B[36m===== TO ====="); + System.out.println("\u001B[36m===== B L A C K ====="); + System.out.println("\u001B[36m===== J A C K ====="); + System.out.println("\u001B[36m===== ====="); + System.out.println("\u001B[36m============================================================"); + while(!isRunning) { + // include betting range + playerInt.getArcadeAccount().alterAccountBalance(winnings); + System.out.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 startGame () { + bj.givePlayerCard(); + System.out.println("Your starting card : " + bj.playersCurrentValue()); + System.out.println("Your second next card : " + bj.givePlayerCard()); + System.out.println("Hand value : " + bj.playersCurrentValue()); + if (twoCardBlackJack()) { + calculateWinnings(3, userBet); + } 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) { + System.out.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(); + System.out.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; + } + + + private void splitPlayerHitsBlackJack(Integer splitBet) { + System.out.println("BLACK JACK!!"); + calculateWinnings(3, splitBet); + standardGame(); + } + + private void splitPlayerBust(Integer splitBet) { + System.out.println("Sorry bud, you got " + bj.splitPlayersCurrentValue() + + ", you still have one more hand!"); + calculateWinnings(0, splitBet); + standardGame(); + } + + private boolean checkStandardWinner() { + boolean playerWon; + System.out.println("Current hand value " + bj.playersCurrentValue() + "\n"); + if(bj.playersCurrentValue() > 21) { + playerBustButHasAces(); + if (bj.playersCurrentValue() > 21) { + System.out.println("Sorry bud, you got " + bj.playersCurrentValue() + + ", better luck next time" + "\n"); + calculateWinnings(0, userBet); + playerWon = true; + } else { + playerWon = false; + } + } else if (playerHitsBlackJack()) { + System.out.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("Please place your bet for the second hand" + "\n"); + splitHandBetConditions(); + playerInt.getArcadeAccount().alterAccountBalance(splitBet * (-1)); + System.out.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"); + switch (userInput) { + case 1: + bj.givePlayerCardOnSplit(); + System.out.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) { + System.out.println("The dealer has : " + bj.dealersCurrentValue()); + if (bj.dealersCurrentValue() > 21) { + System.out.println("You win!"); + calculateWinnings(2, userBet); + gameEnd = true; + } else if (bj.dealersCurrentValue() == 21) { + System.out.println("The dealer has won!"); + calculateWinnings(0, userBet); + gameEnd = true; + } else if (bj.dealersCurrentValue() > bj.playersCurrentValue()) { + System.out.println("The dealer has won!"); + 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); + System.out.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); + System.out.println("You had an Ace - we reduced that 11 to a 1! Keep going!" + "\n" ); + break; + } + } + } + + public boolean splitPlayerHitsBlackJack () { + if (bj.splitPlayersCurrentValue() == 21) { + calculateWinnings(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()) { + System.out.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 (secondHandBet() > playerInt.getArcadeAccount().getAccountBalance()) { + System.out.println("You don't have enough money for that, Silly!"); + secondHandBet(); + } + } + + public void subtractBetFromBalance(Integer betAmount) { + + } + + + public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + + } + + public void add(PlayerInterface player) { + this.playerInt = player; + } + + + public void remove(PlayerInterface player) { + + } + + +} 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..7aa90e57a --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackPlayer.java @@ -0,0 +1,23 @@ +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) { + + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java new file mode 100644 index 000000000..d9fe981f2 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoGame.java @@ -0,0 +1,313 @@ +package com.github.zipcodewilmington.casino.games.keno; + +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.PlayerInterface; + +import java.util.Random; +import java.util.Scanner; + +public class KenoGame implements GameInterface { + Integer multiplier; + KenoPlayer kenoPlayer; + KenoGame kenoGame; + Integer bet; + int balance; + @Override + public void add(PlayerInterface player) { + + } + + @Override + public void remove(PlayerInterface player) { + + } + + @Override + public void run() { + Scanner input = new Scanner(System.in); + printWelcome(); + balance = 100; //Start the player off with some money + int playerNums[] = new int[15]; + int computerNums[] = new int[20]; + int kenoSpot, kenoCatch; + boolean continueGame = true; + String userInput; + + + System.out.println("\u001B[32mHello, and welcome to the game Keno!"); + System.out.println("\u001B[32mThis is a high stakes game. You can win and lose money quickly!"); + while(continueGame) + { + System.out.println(); + System.out.println("\u001B[32mYou currently have: $" + balance); + System.out.println("\u001B[32mLet's get some numbers to begin."); + System.out.println("\u001B[32mYou may enter up to 15 numbers"); + playerNums = getUserInput(); + bet = (int) getBet(balance); + computerNums = getComputerNums(); + kenoSpot = getSpot(playerNums); + kenoCatch = getCatch(playerNums, computerNums); + System.out.println("\u001B[32mCatch: " + (kenoCatch + 1)); + + System.out.println("\u001B[32mYou have won: $"+payout(kenoSpot,kenoCatch,bet)); + + balance += payout(kenoSpot, kenoCatch, bet); + subtractBetFromBalance(bet); + System.out.println("\u001B[32mYou now have: $" + balance); + if (balance <= 0) + { + continueGame = false; + System.out.println("\u001B[32mSorry, you ran out of money!"); + System.out.println("\u001B[32mBetter luck next time! :)"); + } + else + { + System.out.println("\u001B[32mWould you like to continue(y/n)?"); + userInput = input.nextLine(); + + if ((userInput.equals("y"))) + { + continueGame = true; + } + else + { + continueGame = false; + } + } + } + System.out.println("\u001B[32mThanks for playing!"); + System.out.println("\u001B[32mOverall, you now have: $" + balance); + + } + + private void printWelcome() { + System.out.println( + "\u001B[33m***********************************\n" + + "*** ***\n" + + "****** WELCOME TO KENO ******\n" + + "*** ***\n" + + "***********************************"); + } + + public static int[] getUserInput() + { + Scanner input = new Scanner(System.in); // for input + boolean invalidInput = true; + boolean continuePlayer = true; + int playerNums[] = new int[15]; + int index; + int numberEntered; + String enterString; + for (index = 0; index < playerNums.length; index++ ) + { + playerNums[index] = 0; + } + index = 0; + while(continuePlayer && index < 15) + { + do + { + do + { + System.out.println("\u001B[32mEnter number " + (index+1)); + numberEntered = input.nextInt(); + if ((numberEntered > 0) && (numberEntered < 81)) + { + if(isUnique(numberEntered, playerNums)) + { + invalidInput = false; + playerNums[index] = numberEntered; + } + else + { + System.out.println("\u001B[32mSorry, you already entered that number before!"); + System.out.println("\u001B[32mTry again! "); + invalidInput = true; + } + } + else + { + invalidInput = true; + System.out.println("\u001B[32mSorry, the number you entered is either less than 0 or greater than 79"); + System.out.println("\u001B[32mTry again"); + System.out.println(""); + } + } while(invalidInput); + + if(index < 14) //makes sure program doesn't ask to continue when on the last number + { + System.out.println("\u001B[32mDo you wish to continue? (y/n)"); + input.nextLine(); + enterString = input.nextLine(); + if ((enterString.equals("n")) || (enterString.equals("no"))) + { + invalidInput = false; + continuePlayer = false; + } + else if ((enterString.equals("y")) || (enterString.equals("yes"))) + { + invalidInput = false; + continuePlayer = true; + } + else + { + System.out.println("\u001B[32mSorry, I didn't understand that."); + System.out.println(""); + invalidInput = true; + } + + } + }while(invalidInput); + + index++; + } + return playerNums; + } + + public static boolean isUnique(int number, int[] array) + { + int index; + for (index = 0; index < array.length; index++) + { + if(number == array[index]) + { + return false; + } + } + return true; + } + + public static int[] getComputerNums() + { + int[] computerNums = new int[20]; + Random rand = new Random(); + int index; + int randomNumber = 0; + + for (index = 0; index < computerNums.length; index++) + { + randomNumber = rand.nextInt(80) + 1; + if(isUnique(randomNumber, computerNums)) + { + computerNums[index] = randomNumber; + } + else + { + index--; + } + + } + return computerNums; + } + + public static int getSpot(int[] playerArray) + { + int index; + int spot = 0; + for (index = 0; index < playerArray.length; index++) + { + if(playerArray[index] != 0) + { + spot++; + } + + } + spot -= 1; //Subtract one so it works properly in array + return spot; + } + + public static double getBet(double playerMoney) + { + Scanner input = new Scanner(System.in); + double bet = 0; + boolean invalidInput = true; + while(invalidInput) + { + System.out.print("\u001B[32mEnter the bet amount in whole dollars: $"); + bet = input.nextInt(); + if(bet < 0) + { + System.out.println("\u001B[32mBet amount can't be less than 0!"); + invalidInput = true; + } + else if(bet > playerMoney) + { + System.out.println("\u001B[32mYou don't have enough money to bet that!"); + invalidInput = true; + } + else + { + invalidInput = false; + } + } + return bet; + } + + public static int getCatch(int[] playerArray, int[] computerArray) + { + int playerIndex; + int computerIndex; + int kenoCatch = 0; + for (playerIndex = 0; playerIndex < playerArray.length; playerIndex++) + { + for(computerIndex = 0; computerIndex < computerArray.length; computerIndex++) + { + if(playerArray[playerIndex] == computerArray[computerIndex]) + { + kenoCatch++; + } + } + } + kenoCatch -= 1;//subtact one so it works in array + return kenoCatch; + } + + public double payout(int kenoSpot, int kenoCatch, int betAmount) + { + Integer payoutAmount = 0; + Integer payout[][] = + { + {3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //1 + {1, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //2 + {1, 2, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //3 + {0, 2, 6, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //4 + {0, 1, 3, 15, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//5 + {1, 1, 2, 3, 30, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0},//6 + {2, 0, 1, 6, 12, 36, 100, 0, 0, 0, 0, 0, 0, 0, 0},//7 + {0, 1, 1, 3, 6, 19, 90, 720, 0, 0, 0, 0, 0, 0, 0},//8 + {0, 1, 1, 2, 4, 8, 20, 80, 1200, 0, 0, 0, 0, 0, 0},//9 + {0, 1, 1, 2, 3, 5, 10, 30, 600, 1800, 0, 0, 0, 0, 0},//10 + {0, 0, 1, 1, 2, 6, 15, 25, 180, 1000, 3000, 0, 0, 0, 0},//11 + {0, 0, 0, 1, 2, 4, 24, 72, 250, 500, 2000, 4000, 0, 0, 0},//12 + {0, 0, 0, 1, 3, 4, 5, 20, 80, 240, 500, 3000, 6000, 0, 0},//13 + {0, 0, 0, 0, 2, 3, 5, 12, 50, 150, 500, 1000, 2000, 7500, 0},//14 + {0, 0, 0, 0, 1, 2, 5, 15, 50, 150, 300, 600, 1200, 2500, 10000}//15 + }; + if(kenoCatch < 0) + { + this.multiplier = 0; + } + else + { + multiplier = payout[kenoSpot][kenoCatch]; + payoutAmount = multiplier * betAmount; + } + return payoutAmount; + } + + @Override + public Integer calculateWinnings(Integer multiplier, Integer betAmount) { + return this.multiplier*betAmount; + } + + @Override + public void subtractBetFromBalance(Integer betAmount) { + this.balance-=bet; + } + + @Override + public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + + this.balance+=calculateWinnings(multiplier,bet); + } +} 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..cd10878e8 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/keno/KenoPlayer.java @@ -0,0 +1,22 @@ +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) { + + } + +} + + 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..ef25bb083 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,131 @@ package com.github.zipcodewilmington.casino.games.numberguess; +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.PlayerInterface; + +import java.util.Scanner; + + /** - * Created by leon on 7/21/2020. + * Authors: Zack, Nathan */ -public class NumberGuessGame { + +public class NumberGuessGame implements GameInterface { + private Integer maxNumber; + private PlayerInterface currentPlayer; + private Integer betAmount; + private Integer multiplier; + private Integer guessNumber; + private int randomNumber; + private Scanner scanner = new Scanner(System.in); + + public NumberGuessGame(){ + this.maxNumber = 20; + } + + @Override + public void run() { + Scanner scanner = new Scanner(System.in); + //print welcome + printWelcome(); + //print instruction for game + System.out.println("Guess the right number between 0 and 20 to double your bets!\nFeeling lucky??\n\n Increase the difficulty and increase your earnings!"); + //print difficulty levels and ask user to choose + setDifficultyLevel(); + //print player's current account balance + System.out.println("Your current account balance is: " + this.currentPlayer.getArcadeAccount().getAccountBalance()); + //ask for a bet amount + takeBet(); + //subtract bet amount from player's account + this.currentPlayer.getArcadeAccount().alterAccountBalance(betAmount); + //ask player to chose number from 0 to difficulty lvl + takeGuess(); + //generate actual number + pickRandomNumber(); + //compare difference + + //compute winnings + + //print winnings + + //add winnings to player's account + + } + + private void pickRandomNumber() { + this.randomNumber = (int) ((Math.random() * (maxNumber - 0)) + 0); + } + + private void takeGuess() { + System.out.println("Pick a number between 0 and " + maxNumber); + this.guessNumber = scanner.nextInt(); + + } + + private void takeBet() { + System.out.println("How much do you want to bet?"); + this.betAmount = scanner.nextInt(); + } + + private void printWelcome() { + //TODO + } + + private void setDifficultyLevel() { + System.out.println("1. Start max at 20 and go for double.\n" + + "2. Change max to 30 and Triple your bets!\n" + + "3.Change max to 40 and QUADRUPLE your bets! OH MY!\n" + + "4.Change max to 50! SEND IT! TO THE MOON!"); + setMaxNumber(scanner.nextInt()); + } + + + public Integer getGuessRange(Integer guessedNumber, Integer actualNumber){ + return guessRangePercentage(Math.abs(guessedNumber - actualNumber)); + } + + + //Player can set difficulty level to get high yield + //Take this return - reward if guess is within 10% + //The closer to 0%, the higher reward + //10% = money back, 8% = 1.1 + + 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; + } + + @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) { + + } + + @Override + public void addMoneyToBalance(PlayerInterface Player, Integer 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..6abeb9922 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,25 @@ 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. */ -public class NumberGuessPlayer { +public class NumberGuessPlayer implements PlayerInterface { + private PlayerInterface player; + + public NumberGuessPlayer(PlayerInterface player){ + this.player = player; + } + + @Override + public CasinoAccount getArcadeAccount() { + return null; + } + + @Override + public void setArcadeAccount(CasinoAccount casinoAccount) { + + } } \ No newline at end of file diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java new file mode 100644 index 000000000..0c85ebc31 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java @@ -0,0 +1,200 @@ +package com.github.zipcodewilmington.casino.games.plinko; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.PlayerInterface; + +import java.util.HashMap; +import java.util.Map; +import java.util.Random; +import java.util.Scanner; + +public class PlinkoGame implements GameInterface{ + private Map moneyGenerator=new HashMap(); + + public int initialPosition; + private int bet; + public int multiplier; + public int balance; + + + + @Override + public void add(PlayerInterface player) { + + } + + @Override + public void remove(PlayerInterface player) { + + } + + @Override + public void run() { + Scanner input = new Scanner(System.in); + printWelcome(); + balance = 100; //Start the player off with some money + boolean continueGame=true; + Integer playerNumber; + String userInput; + + System.out.println("\u001B[32mHello, and welcome to the game Plinko!"); + while(continueGame){ + System.out.println("\u001B[32mYou currently have: $" + balance); + System.out.println("\u001B[32mPlease enter a number position of your choice: "); + playerNumber = getUserInput(); + bet = (int) getBet(balance); + int plinkSpot=getPlinkoSpot(); + this.multiplier=plinkSpot; + System.out.println("\u001B[32mAfter playing, now your position is: "+plinkSpot); + balance += payout(plinkSpot); + subtractBetFromBalance(bet); + System.out.println("\u001B[32mYou now have: $" + balance); + if (balance <= 0) + { + continueGame = false; + System.out.println("\u001B[32mSorry, you ran out of money!"); + System.out.println("\u001B[32mBetter luck next time! :)"); + } + else + { + System.out.println("\u001B[32mWould you like to continue(y/n)?"); + userInput = input.nextLine(); + + if ((userInput.equals("y"))) + { + continueGame = true; + } + else + { + continueGame = false; + } + } + } + System.out.println("\u001B[32mThanks for playing!"); + System.out.println("\u001B[32mOverall, you now have: $" + balance); + feature/DipintiTestFiles + } + + + private void printWelcome() { + System.out.println( + "\u001B[33m***********************************\n" + + "*** ***\n" + + "****** WELCOME TO PLINKO ******\n" + + "*** ***\n" + + "***********************************"); + } + + @Override + public Integer calculateWinnings(Integer multiplier, Integer betAmount) { + return this.multiplier*betAmount; + } + + private int payout(int plinkoSpot) { + moneyGenerator.put(1,200); + moneyGenerator.put(2,0); + moneyGenerator.put(3,3000); + moneyGenerator.put(4,30); + moneyGenerator.put(5,0); + moneyGenerator.put(6,0); + moneyGenerator.put(7,1); + moneyGenerator.put(8,750); + moneyGenerator.put(9,0); + Integer moneyWon=0; + + for (Integer pos:moneyGenerator.keySet()) + { + if(pos.equals(plinkoSpot)){ + moneyWon=moneyGenerator.get(pos); + } + } + return moneyWon; + } + + + + public int getPlinkoSpot() { + int max = 9; + int min = 1; + Random rand = new Random(); + return rand.nextInt(max - min + 1) + min; + } + + public static double getBet(double playerMoney) + { + Scanner input = new Scanner(System.in); + double bet = 0; + boolean invalidInput = true; + while(invalidInput) + { + System.out.print("Enter the bet amount in whole dollars: $"); + bet = input.nextInt(); + if(bet < 0) + { + System.out.println("Bet amount can't be less than 0!"); + invalidInput = true; + } + else if(bet > playerMoney) + { + System.out.println("You don't have enough money to bet that!"); + invalidInput = true; + } + else + { + invalidInput = false; + } + } + return bet; + } + + private Integer getUserInput() { + Scanner input = new Scanner(System.in); // for input + boolean invalidInput = true; + boolean continuePlayer = true; + int numberEntered; + int playerNums=0; + String enterString; + + + + while(invalidInput) + { + System.out.println("Enter number :"); + numberEntered = input.nextInt(); + + if ((numberEntered > 0) && (numberEntered < 10)){ + invalidInput = false; + playerNums = numberEntered; + break; + } + else{ + invalidInput = true; + System.out.println("Sorry, the number you entered is either less than 0 or greater than 9"); + System.out.println("Try again"); + System.out.println(""); + } + } + return playerNums; + } + + + + @Override + public void subtractBetFromBalance(Integer betAmount) { + balance-=bet; + } + + @Override + public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + + } + +// @Override +// public CasinoAccount getArcadeAccount() { +// return null; +// } + +} + + 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..d4bd43fa3 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoPlayer.java @@ -0,0 +1,17 @@ +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; + @Override + public CasinoAccount getArcadeAccount() { + return player.getArcadeAccount(); + } + + @Override + public void setArcadeAccount(CasinoAccount casinoAccount) { + + } +} 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..a4f03f2e9 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java @@ -0,0 +1,106 @@ +package com.github.zipcodewilmington.casino.games.slots; + +import java.util.HashMap; + + +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<>(); + + public Slots(String[][] slots) { + //this.winningLines = new HashMap<>(); + this.slots = slots; + initializeWinningLines(); + } + + public Slots(){ + //this.winningLines = new HashMap<>(); + 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][0].equals(currentSlots[i][2])){ + newWinningLines.put((i+1),"WIN"); + } + //setting vertically + if(currentSlots[0][i].equals(currentSlots[1][i]) && currentSlots[2][i].equals(currentSlots[i][2])){ + 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(){ + System.out.println( + "\u001B[34m -------------------------------\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..04fed4b26 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,181 @@ 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 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 Integer playerBetAmount; + private Integer betTotal; + private Integer loseMultiplier; + private Integer winMultiplier; + private PlayerInterface currentPlayer; + private Slots slotMachine; + + public SlotsGame(){ + } + + @Override + public void add(PlayerInterface player) { + this.currentPlayer = player; + } + + @Override + public void remove(PlayerInterface player) { + + } + + public Integer getLoseMultiplier() { + return loseMultiplier; + } + + public Integer getWinMultiplier() { + return winMultiplier; + } + + @Override + public void run() { + Scanner scanner = new Scanner(System.in); + printWelcome(); + Slots newSlotMachine = new Slots(); + slotMachine = newSlotMachine; + slotMachine.spinSlots(); + //Display first slots + slotMachine.displaySlots(); + + Boolean quitGame = false; + while(!quitGame) { + + //print initial account balance + System.out.println("\u001B[35mCurrent account balance: " + currentPlayer.getArcadeAccount().getAccountBalance() + "\n"); + + getBetAmount(); + Integer[] selectedBets = getBetSelections(); + + //take money from player account + currentPlayer.getArcadeAccount().alterAccountBalance(betTotal * (-1)); + + slotMachine.spinSlots(); + slotMachine.displaySlots(); + slotMachine.setWinningLines(); + String[] betResults = slotMachine.compareBetVsWinningLines(selectedBets); + this.calculateMultiplier(betResults); + Integer winnings = calculateWinnings(this.winMultiplier, playerBetAmount); + System.out.println("\u001B[31mYou won: " + winnings + " dollars!\n"); + //add winnings to player object + currentPlayer.getArcadeAccount().alterAccountBalance(winnings); + //Continue game? + System.out.println("\u001B[36mWould you like to play again?\n" + + "1. Yes 2. No"); + Integer input = scanner.nextInt(); + if(input == 2){ + quitGame = true; + } + + } + } + + private void printWelcome() { + System.out.println("\u001B[33m"+ + "***********************************\n" + + "*** ***\n" + + "****** WELCOME TO SLOTS ******\n" + + "*** ***\n" + + "***********************************"); + } + + private void getBetAmount() { + Scanner scanner = new Scanner(System.in); + System.out.println("\u001B[34m"+"How much you do want to bet?"); + Integer input = scanner.nextInt(); + playerBetAmount = input; + } + + public Integer[] getBetSelections() { + Scanner scanner = new Scanner(System.in); + System.out.println("\u001B[35mHow many lines do you want to bet on?"); + Integer numberOfLines = scanner.nextInt(); + Integer totalCost = playerBetAmount * numberOfLines; + System.out.println("\u001B[31mTotal cost to play: " + totalCost); + setBetTotal(totalCost); + + System.out.println( + "\u001B[36m************************************************************************\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" + + "************************************************************************"); + Integer count = 0; + Integer[] selectedLines = new Integer[numberOfLines]; + while (count < numberOfLines){ + System.out.println("\u001B[32mSelect your line #" + (count + 1)); + selectedLines[count] = scanner.nextInt(); + count++; + } + return selectedLines; + } + + public void calculateMultiplier(String[] betResults) { + Integer countWin = 0; + Integer countLose = 0; + Integer[] winVsLose = new Integer[2]; + for(String outcome: betResults){ + if(outcome == "WIN"){ + countWin++; + } else { + countLose++; + } + } + this.winMultiplier = countWin; + this.loseMultiplier = countLose; + } + + public Integer calculateReturnTotal(Integer winnings, Integer losings){ + Integer returnTotal = this.betTotal + winnings - losings; + return returnTotal; + } + + @Override + public Integer calculateWinnings(Integer multiplier, Integer betAmount) { + return multiplier * betAmount; + } + + @Override + public void subtractBetFromBalance(Integer losings) { + } + + @Override + public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + } + + public Integer getPlayerBetAmount() { + return playerBetAmount; + } + + public void setPlayerBetAmount(Integer playerBetAmount) { + this.playerBetAmount = playerBetAmount; + } + + public Integer getBetTotal() { + return betTotal; + } + + public void setBetTotal(Integer betTotal) { + this.betTotal = betTotal; + } + + + public PlayerInterface getCurrentPlayer() { + return currentPlayer; + } + + public void setCurrentPlayer(PlayerInterface currentPlayer) { + this.currentPlayer = (SlotsPlayer) currentPlayer; + } } 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..2e76cef60 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,26 @@ package com.github.zipcodewilmington.casino.games.slots; +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; + /** * Created by leon on 7/21/2020. */ -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) { + + } } \ 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..518262854 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/models/Card.java @@ -0,0 +1,47 @@ +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; + } + + public void setCardPool(List cardPool) { + this.cardPool = 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..f941b0009 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/utils/CSVUtils.java @@ -0,0 +1,81 @@ +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)))); + + List list = new ArrayList<>(); + list.add(account.getAccountName()); + list.add(account.getPassword()); + list.add(String.valueOf(account.getAccountBalance())); + + 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]; + + + // (5) + //inventory.add(new Sneaker(id, name, brand, sport, size, qty, price)); + CasinoAccount loadedAccount = new CasinoAccount(accountName, password); + loadedAccount.alterAccountBalance(Integer.parseInt(accountBalance)); + return loadedAccount; + } + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } +} diff --git a/src/main/java/com/github/zipcodewilmington/utils/DemoMain.java b/src/main/java/com/github/zipcodewilmington/utils/DemoMain.java new file mode 100644 index 000000000..a0cf0bda8 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/utils/DemoMain.java @@ -0,0 +1,9 @@ +package com.github.zipcodewilmington.utils; + +import com.github.zipcodewilmington.casino.games.blackjack.BlackJackGame; + +public class DemoMain { + public static void main(String[] args) { + new BlackJackGame().run(); + } +} diff --git a/src/main/java/com/github/zipcodewilmington/utils/IOConsole.java b/src/main/java/com/github/zipcodewilmington/utils/IOConsole.java index c7afc01da..b855d24db 100644 --- a/src/main/java/com/github/zipcodewilmington/utils/IOConsole.java +++ b/src/main/java/com/github/zipcodewilmington/utils/IOConsole.java @@ -66,6 +66,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/test/java/com/github/zipcodewilmington/BeetleGameTest.java b/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java new file mode 100644 index 000000000..350af9fa4 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/BeetleGameTest.java @@ -0,0 +1,20 @@ +package com.github.zipcodewilmington; + +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.Beetle.BeetlePlayer; +import org.junit.Test; + +public class BeetleGameTest { + @Test + public void testGameOver(){ +//// BeetlePlayer player1 = new BeetlePlayer("Jeff", 10); +//// BeetlePlayer player2 = new BeetlePlayer("Aria", 10); +// BeetleGame game = new BeetleGame(player1, player2); +// game.add(player1); +// game.add(player2); +// game.run(); +// Boolean isGameOver = game.getIsRunning(); + } +} 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..d1de50bd9 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/BeetleTest.java @@ -0,0 +1,162 @@ +package com.github.zipcodewilmington; + +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 = 0; 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 i = 0; i < 5; i++){ + for(int j = 0; 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 i = 0; i < 4; i++){ + for(int j = 0; j < 6; j++){ + beetle.setPlayerBeetles(0, j); + } + actual = beetle.checkWinner(0); + } + Assert.assertFalse(actual); + } + + @Test + public void getScoreTest1(){ + Beetle beetle = new Beetle(2); + for(int j = 0; j < 6; j++){ + beetle.setPlayerBeetles(0, j); + } + beetle.checkWinner(0); + Integer expected = 6; + Integer actual = beetle.getScore(0); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getScoreTest2(){ + Beetle beetle = new Beetle(2); + + Integer expected = 0; + Integer actual = beetle.getScore(0); + + Assert.assertEquals(expected, actual); + } + + @Test + public void refreshBeetleTest(){ + Beetle beetle = new Beetle(2); + for(int j = 0; j < 6; j++){ + beetle.setPlayerBeetles(0, j); + } + beetle.refreshBeetle(0); + Integer[] actual = beetle.getPlayerCard(0); + Integer[] expected = new Integer[] {0, 0, 0, 0, 0, 0}; + + Assert.assertArrayEquals(actual, expected); + } +} 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..8900a84dd --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/BlackJackGameTest.java @@ -0,0 +1,64 @@ +package com.github.zipcodewilmington; + +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.BlackJackGame; +import org.junit.Assert; +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; + +public class BlackJackGameTest { + + @Test + public void runTest () { + //Player player = new Player("Roger", 5000); + } + 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 addMoneyToBalanceTest () { + + BlackJackGame bj = new BlackJackGame(); + + } + + @Test + public void splitPlayerHitsBlackJack () { + BlackJackGame bj = new BlackJackGame(); + + } +} 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..2cd4eff92 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/BlackJackTest.java @@ -0,0 +1,83 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.games.blackjack.BlackJack; +import org.junit.Assert; +import org.junit.Test; + +import java.util.List; + +public class BlackJackTest { + @Test + public void generateNewDeckTest() { + BlackJack bj = new BlackJack(); + Integer expected = 165; + + 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 playerBroke21orBlackJackTest () { + + + } +} 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/DiceTest.java b/src/test/java/com/github/zipcodewilmington/DiceTest.java new file mode 100644 index 000000000..357497dd4 --- /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 = 14; + 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 = 10; + 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}; + 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/KenoGameTest.java b/src/test/java/com/github/zipcodewilmington/KenoGameTest.java new file mode 100644 index 000000000..b7a628fb2 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/KenoGameTest.java @@ -0,0 +1,47 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.games.keno.KenoGame; +import org.junit.Assert; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class KenoGameTest { + + + @Test + void testForIsUnique() { + //given + KenoGame kenoGame=new KenoGame(); + //when + Boolean boolVal=kenoGame.isUnique(7, new int[]{7, 7}); + //then + Assert.assertFalse(String.valueOf(boolVal),false); + } + + @Test + void testisUnique() { + //given + KenoGame kenoGame=new KenoGame(); + //when + Boolean boolVal=kenoGame.isUnique(7, new int[]{1, 7}); + //then + Assert.assertTrue(String.valueOf(boolVal),true); + } + + + @Test + + void testPayOut(){ + //given + int kenoSpot=11; + int kenoCatch=9; + KenoGame kenoGame=new KenoGame(); + //when + Double expectedValue=kenoGame.payout(11,9,200); + //then + Assert.assertTrue(String.valueOf(expectedValue),true); + } + + +} \ No newline at end of file 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..493a6914b --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/NumberGuessGameTests.java @@ -0,0 +1,50 @@ +package com.github.zipcodewilmington; + +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 setMaxNumberTest(){ + NumberGuessGame game = new NumberGuessGame(); + game.setMaxNumber(50); + Integer actual = game.getMaxNumber(); + Integer expected = 50; + + Assert.assertEquals(actual, expected); + } + + @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 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/PlinkoGameTest.java b/src/test/java/com/github/zipcodewilmington/PlinkoGameTest.java new file mode 100644 index 000000000..dc5a777f6 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/PlinkoGameTest.java @@ -0,0 +1,35 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.games.keno.KenoGame; +import com.github.zipcodewilmington.casino.games.plinko.PlinkoGame; +import org.junit.Assert; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class PlinkoGameTest { + + + + @Test + void getPlinkoSpotTest() { + //given + PlinkoGame plinkoGame=new PlinkoGame(); + //when + Integer expectedValue=plinkoGame.getPlinkoSpot(); + //then + Assert.assertFalse(String.valueOf(expectedValue),false); + } + + @Test + public void calculateWinningsTest() { + //given + PlinkoGame plinkoGame=new PlinkoGame(); + Integer expectedValue=plinkoGame.calculateWinnings(2,200); + //when + Integer actualValue=plinkoGame.calculateWinnings(2,200); + //then + Assert.assertEquals(expectedValue,actualValue); + } + +} \ No newline at end of file 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..a2e55e43b --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/SlotsGameTest.java @@ -0,0 +1,57 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.games.slots.SlotsGame; +import org.junit.Assert; +import org.junit.Test; + +public class SlotsGameTest { + @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 getBetSelectionTest(){ + //given + SlotsGame newGame = new SlotsGame(); + newGame.getBetSelections(); + + } +} 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 + } + +}