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..72e424327 100644 --- a/src/main/java/com/github/zipcodewilmington/Casino.java +++ b/src/main/java/com/github/zipcodewilmington/Casino.java @@ -42,7 +42,7 @@ public void run() { } 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."); diff --git a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java index 654c749b4..cd5b53aef 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java @@ -1,9 +1,32 @@ 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; + + + public CasinoAccount(String accountName, String accountPassword){ + this.accountName = accountName; + this.password = accountPassword; + } + + + public String getPassword() { + return password; + } + + public String getAccountName() { + return accountName; + } + } 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..01ddd0568 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,21 @@ 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..607512047 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/Player.java @@ -0,0 +1,42 @@ +package com.github.zipcodewilmington.casino; + +public class Player{ + + String name; + Integer balance; + Integer currentBet = 0; + + public Player(String name, Integer initialDeposit) { + this.name = name; + this.balance = initialDeposit; + } + + + public String getName() { + return name; + } + + + public Integer getBalance() { + return balance; + } + + private 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; + } + + private Integer getCurrentBet() { + return currentBet; + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/PlayerInterface.java b/src/main/java/com/github/zipcodewilmington/casino/PlayerInterface.java index c50b5113b..9d6800a71 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/PlayerInterface.java +++ b/src/main/java/com/github/zipcodewilmington/casino/PlayerInterface.java @@ -17,5 +17,5 @@ public interface PlayerInterface { * @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..f205cc4d5 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/Beetle.java @@ -0,0 +1,96 @@ +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; + + 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]++; + //return this.checkWinner(player); + } + + 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 Boolean checkWinner(Integer player){ + if(this.beetleIsComplete(player)){ + 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 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..479423e7d --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetleGame.java @@ -0,0 +1,86 @@ +package com.github.zipcodewilmington.casino.games.Beetle; + +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.PlayerInterface; + +import java.util.ArrayList; + +public class BeetleGame implements GameInterface { + private ArrayList players = new ArrayList(); + private Beetle game; + private Boolean isRunning = false; + private PlayerInterface player; + public void add(PlayerInterface player){ + players.add(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(){ + Integer turnCount = 0; + if(isRunning){ + turnCount++; + this.nextPlayer(); + game.getDice().tossAndSum(); + executeTurn(); + isGameOver(game.checkWinner(game.getCurrentPlayer())); + } + System.out.println("game over after " + turnCount); + } + + public void isGameOver(boolean playerWon){ + if(playerWon){ + isRunning = false; + } + } + public void nextPlayer(){ + game.setCurrentPlayer(-1); + game.nextPlayer(); + } + + public void executeTurn(){ + Integer currentPlayer = game.getCurrentPlayer(); + game.setPlayerBeetles(currentPlayer, game.getDice().tossAndSum()); + } + + /** + * Calculate player's winning payout amount of bet x multiplier + * @return (double) amount of money winnings + */ + public Integer calculateWinnings(Integer multiplier, Integer betAmount){ + return 0; + } + + /** + * Subtract the bet amount from player's balance + */ + public void subtractBetFromBalance(Integer betAmount){ + + } + + + /** + * 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(); + } + + + +} 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..b4c16f59e --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Beetle/BeetlePlayer.java @@ -0,0 +1,9 @@ +package com.github.zipcodewilmington.casino.games.Beetle; + +public class BeetlePlayer { + private Integer bet; + + public BeetlePlayer(){ + + } +} 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..7138b34a3 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJack.java @@ -0,0 +1,129 @@ +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; + BlackJackGame theGame = new BlackJackGame(); + boolean gameEnd = false; + + 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(); + 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 playersCurrentValue() { + givePlayerCard(); + Integer sum = 0; + for (int i = 0; i < this.playersHand.size(); i++) { + sum += this.playersHand.get(i); + } + return sum; + } + + public Integer dealersCurrentValue() { + giveDealerCard(); + Integer sum = 0; + for (int i = 0; i < this.dealersHand.size(); i++) { + sum += this.dealersHand.get(i); + } + return sum; + } + + + + + public void dealersGame() { + while (!gameEnd) { + System.out.println("The dealer has : " + dealersCurrentValue()); + if (dealersCurrentValue() > 21) { + System.out.println("You win!"); + theGame.calculateWinnings(2, theGame.userBet); + gameEnd = true; + } else if (dealersCurrentValue() == 21) { + System.out.println("The dealer has won!"); + theGame.subtractBetFromBalance(theGame.userBet); + gameEnd = true; + } else if (dealersCurrentValue() > playersCurrentValue()) { + System.out.println("The dealer has won!"); + theGame.subtractBetFromBalance(theGame.userBet); + gameEnd = true; + } else { + giveDealerCard(); + System.out.println("The dealer has : " + dealersCurrentValue()); + } + } + } + + + + + public boolean playerBreaks21() { + + if (playersCurrentValue() > 21) { + return true; + } else { + return false; + } + } + + public boolean playerHitsBlackJack() { + if (playersCurrentValue() == 21) { + theGame.calculateWinnings(3, betAmount); + 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..79c6e2e54 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/blackjack/BlackJackGame.java @@ -0,0 +1,109 @@ +package com.github.zipcodewilmington.casino.games.blackjack; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.utils.IOConsole; + + +public class BlackJackGame implements GameInterface, PlayerInterface { + private Boolean isRunning = false; + private PlayerInterface player; + Integer userBet; + IOConsole input = new IOConsole(); + boolean isWinner = false; + + @Override + public void add(PlayerInterface player) { + + } + + @Override + public void remove(PlayerInterface player) { + + } + + @Override + public void run() { + while(isRunning) { + // include betting range + BlackJack bj = new BlackJack(); + Integer userInput = input.getIntegerInput("1. Start A Hand" + "\n" + "2. Quit" + "\n"); + + switch (userInput) { + case 1: + + this.userBet = (input.getIntegerInput("How much would you like to bet?")); + + this.userBet = (input.getIntegerInput("How much would you like to bet?")); + + // include betting forum in case 1 + startGame(); + break; + case 2: + isRunning = true; + } + } + } + + public void startGame () { + BlackJack bj = new BlackJack(); + 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()); + Integer userChoice = input.getIntegerInput("1. Hit" + "\n" + "2. Stay"); + while (!isWinner) { + switch (userChoice) { + case 1: + bj.givePlayerCard(); + bj.playersCurrentValue(); + if(bj.playerBreaks21()) { + System.out.println("Sorry bud, you got " + bj.playersCurrentValue() + + "better luck next time"); + subtractBetFromBalance(userBet); + isWinner = true; + } else if (bj.playerHitsBlackJack()) { + System.out.println("BLACK JACK!!"); + calculateWinnings(3, userBet); + isWinner = true; + } + break; + case 2: + bj.giveDealerCard(); + System.out.println("The dealers first card : " + bj.dealersCurrentValue()); + bj.giveDealerCard(); + System.out.println("The dealer has : " + bj.dealersCurrentValue()); + bj.dealersGame(); + break; + } + } + } + + + @Override + public CasinoAccount getArcadeAccount() { + return null; + } + + @Override + public SomeReturnType play() { + return null; + } + + @Override + public Integer calculateWinnings(Integer multiplier, Integer betAmount) { + return null; + } + + @Override + public void subtractBetFromBalance(Integer betAmount) { + + } + + @Override + public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + + } +} 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..fd882a351 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/plinko/PlinkoGame.java @@ -0,0 +1,93 @@ +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; + +public class PlinkoGame implements GameInterface,PlayerInterface { + private Map moneyGenerator=new HashMap(); + + public int initialPosition; + private double betAmount; + public int multiplier; + + public PlinkoGame(int initialPosition){ + this.initialPosition=initialPosition; + } + + public String playPlinko(int initialPosition){ + if(initialPosition<10 && initialPosition>0){ + int max=9; + int min=1; + Random rand = new Random(); + int randomNumber=rand.nextInt(max - min + 1) + min; + return String.valueOf(randomNumber); + } + else + return "Invalid Entry"; + } + + public void run2() { + if (initialPosition < 10 && initialPosition > 0) { + int max = 9; + int min = 1; + Random rand = new Random(); + multiplier = rand.nextInt(max - min + 1) + min; + System.out.println("Now your position is: " + multiplier); + } + else + { + System.out.println("Invalid Entry"); + } + } + + @Override + public Integer calculateWinnings(Integer multiplier, Integer betAmount) { + 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(multiplier)){ + moneyWon=moneyGenerator.get(pos); + } + } + return moneyWon; + } + + + + @Override + public void subtractBetFromBalance(Integer betAmount) { + + } + + @Override + public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + + } + + @Override + public CasinoAccount getArcadeAccount() { + return null; + } + + @Override + public SomeReturnType play() { + return null; + } + +} + 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..ec0b36e6b --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/Slots.java @@ -0,0 +1,95 @@ +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; + } + + 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 result; + } + +//new comment + + +} 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..102c0eb63 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,46 @@ package com.github.zipcodewilmington.casino.games.slots; +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.PlayerInterface; + /** - * Created by leon on 7/21/2020. + * Created by Nathan on 7/12/21 */ -public class SlotsGame { +public class SlotsGame implements GameInterface { + + + @Override + public void add(PlayerInterface player) { + + } + + @Override + public void remove(PlayerInterface player) { + + } + + @Override + public void run() { + Slots slotMachine = new Slots(); + //Integer[] bets = takeBet(); + slotMachine.spinSlots(); + //slotMachine.compareBetVsWinningLines(); + + + } + + @Override + public Integer calculateWinnings(Integer multiplier, Integer betAmount) { + return null; + } + + @Override + public void subtractBetFromBalance(Integer betAmount) { + + } + + @Override + public void addMoneyToBalance(PlayerInterface Player, Integer winnings) { + + } } 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..c5c6df9d3 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 @@ -4,4 +4,5 @@ * Created by leon on 7/21/2020. */ public class SlotsPlayer { + } \ No newline at end of file diff --git a/src/main/java/com/github/zipcodewilmington/casino/models/Card.java b/src/main/java/com/github/zipcodewilmington/casino/models/Card.java new file mode 100644 index 000000000..296ce2f9a --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/models/Card.java @@ -0,0 +1,49 @@ +package com.github.zipcodewilmington.casino.models; + +import java.util.*; + +public class Card { + List cardPool; + + // Let's hope this works! If you can see this, that'd be cool + // Boilage <== hack + + 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..3df284267 --- /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 - 1; + 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() * 7) + 1; + } + this.incrementBin(sum); + return sum; + } + +} diff --git a/src/test/java/com/github/zipcodewilmington/BeetleGame.java b/src/test/java/com/github/zipcodewilmington/BeetleGame.java new file mode 100644 index 000000000..4761cbdd3 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/BeetleGame.java @@ -0,0 +1,11 @@ +package com.github.zipcodewilmington; + +import org.junit.Test; + +public class BeetleGame { + @Test + public void testGameOver(){ + BeetleGame game = new BeetleGame(); + + } +} 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/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/PlinkoTest.java b/src/test/java/com/github/zipcodewilmington/PlinkoTest.java new file mode 100644 index 000000000..bdf4e8ba5 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/PlinkoTest.java @@ -0,0 +1,45 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.games.plinko.PlinkoGame; +import org.junit.Assert; +import org.junit.Test; + +public class PlinkoTest { + + @Test + public void testCalculateWinnings() { + //given + + Integer expectedValue=0; + PlinkoGame plinkoGame=new PlinkoGame(7); + plinkoGame.run(); + //when + Integer actualValue=plinkoGame.calculateWinnings(2,200); + + //then + Assert.assertEquals(expectedValue,actualValue); + } + + @Test + public void testConstructor(){ + //given + int expectedValue=8; + //when + PlinkoGame plinkoGame=new PlinkoGame(8); + int actualValue=plinkoGame.initialPosition; + //then + Assert.assertEquals(expectedValue,actualValue); + } + + @Test + public void testPlayPlinko(){ + //given + String expectedValue="Invalid Entry"; + //when + PlinkoGame plinkoGame=new PlinkoGame(10); + String actualValue=plinkoGame.playPlinko(10); + //then + Assert.assertFalse(expectedValue, Boolean.parseBoolean(actualValue)); + } +} + 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..e21f3cf68 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/SlotsTest.java @@ -0,0 +1,133 @@ +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); + } + + +}