diff --git a/Casino Project-Page-1.drawio (1).png b/Casino Project-Page-1.drawio (1).png new file mode 100644 index 00000000..b8feb8da Binary files /dev/null and b/Casino Project-Page-1.drawio (1).png differ diff --git a/Casino Project-Page-1.drawio.png b/Casino Project-Page-1.drawio.png new file mode 100644 index 00000000..22252087 Binary files /dev/null and b/Casino Project-Page-1.drawio.png differ diff --git a/GroupCasino b/GroupCasino new file mode 160000 index 00000000..d1d59124 --- /dev/null +++ b/GroupCasino @@ -0,0 +1 @@ +Subproject commit d1d59124c2f6d4149e6028bf2c84a2f394695de7 diff --git a/pom.xml b/pom.xml index 8c2655d3..a3aeec7d 100644 --- a/pom.xml +++ b/pom.xml @@ -47,8 +47,8 @@ maven-compiler-plugin 3.6.0 - ${java.version} - ${java.version} + 8 + 8 diff --git a/src/main/java/com/github/zipcodewilmington/Casino.java b/src/main/java/com/github/zipcodewilmington/Casino.java index 5eae9ac0..99ff50da 100644 --- a/src/main/java/com/github/zipcodewilmington/Casino.java +++ b/src/main/java/com/github/zipcodewilmington/Casino.java @@ -4,36 +4,68 @@ import com.github.zipcodewilmington.casino.CasinoAccountManager; import com.github.zipcodewilmington.casino.GameInterface; import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.BlackJack.BlackJackGame; +import com.github.zipcodewilmington.casino.games.RideTheBus.RideTheBusGame; +import com.github.zipcodewilmington.casino.games.StreetCraps; import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessGame; import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessPlayer; import com.github.zipcodewilmington.casino.games.slots.SlotsGame; import com.github.zipcodewilmington.casino.games.slots.SlotsPlayer; +import com.github.zipcodewilmington.casino.games.CasinoWar.CasinoWar; + import com.github.zipcodewilmington.utils.AnsiColor; import com.github.zipcodewilmington.utils.IOConsole; /** * Created by leon on 7/21/2020. */ + public class Casino implements Runnable { private final IOConsole console = new IOConsole(AnsiColor.BLUE); @Override public void run() { + CasinoAccountManager.addAllAccounts(); + String arcadeDashBoardInput; CasinoAccountManager casinoAccountManager = new CasinoAccountManager(); do { + CasinoAccountManager.addtofile(); arcadeDashBoardInput = getArcadeDashboardInput(); if ("select-game".equals(arcadeDashBoardInput)) { String accountName = console.getStringInput("Enter your account name:"); String accountPassword = console.getStringInput("Enter your account password:"); + CasinoAccount casinoAccount = casinoAccountManager.getAccount(accountName, accountPassword); boolean isValidLogin = casinoAccount != null; + if (isValidLogin) { + String gameSelectionInput = getGameSelectionInput().toUpperCase(); if (gameSelectionInput.equals("SLOTS")) { - play(new SlotsGame(), new SlotsPlayer()); - } else if (gameSelectionInput.equals("NUMBERGUESS")) { - play(new NumberGuessGame(), new NumberGuessPlayer()); + SlotsGame slots = new SlotsGame(casinoAccount); + try { + slots.run(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } else if (gameSelectionInput.equals("RIDETHEBUS")) { + RideTheBusGame ride = new RideTheBusGame(casinoAccount); + ride.start(); + + + } + else if (gameSelectionInput.equals("WAR")) { + CasinoWar casinoWar = new CasinoWar(); + casinoWar.run(); + + + } else if (gameSelectionInput.equals("STREETCRAPS")) { + StreetCraps craps = new StreetCraps(casinoAccount); + craps.run(); + } + else if (gameSelectionInput.equals("BLACKJACK")) { + BlackJackGame.runBlackJack(); } else { // TODO - implement better exception handling String errorMessage = "[ %s ] is an invalid game selection"; @@ -49,9 +81,11 @@ public void run() { String accountName = console.getStringInput("Enter your account name:"); String accountPassword = console.getStringInput("Enter your account password:"); CasinoAccount newAccount = casinoAccountManager.createAccount(accountName, accountPassword); - casinoAccountManager.registerAccount(newAccount); + CasinoAccountManager.addtofile(); + //casinoAccountManager.registerAccount(newAccount); } } while (!"logout".equals(arcadeDashBoardInput)); + } private String getArcadeDashboardInput() { @@ -66,14 +100,15 @@ 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 ], [ RIDETHEBUS ], [ WAR ], [ STREETCRAPS ], [ BLACKJACK ] ") .toString()); } - private void play(Object gameObject, Object playerObject) { - GameInterface game = (GameInterface)gameObject; - PlayerInterface player = (PlayerInterface)playerObject; + private void play(Object gameObject, Object playerObject) throws InterruptedException { + GameInterface game = (GameInterface) gameObject; + PlayerInterface player = (PlayerInterface) playerObject; game.add(player); game.run(); - } -} + + }} + diff --git a/src/main/java/com/github/zipcodewilmington/MainApplication.java b/src/main/java/com/github/zipcodewilmington/MainApplication.java index 508787a8..3d957d47 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; -public class MainApplication { - public static void main(String[] args) { +public class MainApplication +{ + public static void main(String[] args) throws InterruptedException + { new Casino().run(); } } + + + diff --git a/src/main/java/com/github/zipcodewilmington/casino/Accounts.txt b/src/main/java/com/github/zipcodewilmington/casino/Accounts.txt new file mode 100644 index 00000000..88303ed3 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/Accounts.txt @@ -0,0 +1,7 @@ +Santos,Santos,123,100.0 +Kantos,Kantos,ugh,1450.0 +BobLee,BobLee,4321,0.0 +hans,hans,4321,0.0 +bans,bans,4321,0.0 +Deep,Deep,rollinginthedeep,0.0 +1,1,1,1046.0 diff --git a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java index 654c749b..b2fbf98d 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java @@ -6,4 +6,57 @@ * The `ArcadeAccount` is used to log into the system to select a `Game` to play. */ public class CasinoAccount { + // variables + private String accountName; + private String accountPassword; + private double casinoBalance = 0; + + public CasinoAccount(String accountName, String accountPassword) { + this.accountName = accountName; + this.accountPassword = accountPassword; + } + + public CasinoAccount() { + + } + + public String getName() { + return accountName; + } + + public void setAccountName(String accountName) { + this.accountName = accountName; + } + + public String getAccountPassword() { + return accountPassword; + } + + public void setAccountPassword(String accountPassword) { + this.accountPassword = accountPassword; + } + + public double getCasinoBalance() { + return casinoBalance; + } + public void addCasinoBalance(double add){ + casinoBalance+=add; + } + public void subCasinoBalance(double sub){ + casinoBalance-=sub; + } + + + public void setCasinoBalance(double casinoBalance) { + this.casinoBalance = casinoBalance; + } + + + public CasinoAccount(String accountName, String accountPassword, double casinoBalance) { + this.accountName = accountName; + this.accountPassword = accountPassword; + this.casinoBalance=casinoBalance; + } + + } diff --git a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java index 2d09ec2a..e324ed75 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java @@ -1,23 +1,55 @@ package com.github.zipcodewilmington.casino; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.*; + /** * 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 { +public class CasinoAccountManager extends CasinoAccount{ /** * @param accountName name of account to be returned * @param accountPassword password of account to be returned * @return `ArcadeAccount` with specified `accountName` and `accountPassword` */ + + public static LinkedHashMap data = new LinkedHashMap(); + + public CasinoAccount getAccount(String accountName, String accountPassword) { - String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); - String currentClassName = getClass().getName(); - String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; - throw new RuntimeException(String.format(errorMessage, currentMethodName, currentClassName)); + + boolean end=false; + Iterator it = data.entrySet().iterator(); + CasinoAccount acc = null; + // acc=data.get(accountName); + + while (it.hasNext()&& !end) { + Map.Entry pair = (Map.Entry) it.next(); + acc = (CasinoAccount) pair.getValue(); + if (Objects.equals(acc.getName(), accountName) && Objects.equals(acc.getAccountPassword(), accountPassword)) { + end = true; + } + else{ + acc=null; + } + } + + return acc; } + + //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)); + + + /** * logs & creates a new `ArcadeAccount` * @@ -25,11 +57,21 @@ public CasinoAccount getAccount(String accountName, String accountPassword) { * @param accountPassword password of account to be created * @return new instance of `ArcadeAccount` with specified `accountName` and `accountPassword` */ + public CasinoAccount createAccount(String accountName, String accountPassword) { + CasinoAccount account=new CasinoAccount(); + + + String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); + account.setAccountName(accountName); String currentClassName = getClass().getName(); + account.setAccountPassword(accountPassword); 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)); + data.put(accountName,account); + return account; + + } /** @@ -37,10 +79,73 @@ 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)); } + public static void addAllAccounts(){ + data.put("Santos",new CasinoAccount("Santos","123" , 1000)); + + + + try { + Scanner fileIn = new Scanner(new File("src/main/java/com/github/zipcodewilmington/casino/Accounts.txt")); + + while (fileIn.hasNextLine()) + { + String line = fileIn.nextLine(); + String [] accountData=line.split(","); + String hashKey= (accountData[0]); + String accountName= (accountData[1]); + String accountPass= (accountData[2]); + double casinoBalance= Double.parseDouble(accountData[3]); + + // Reads the entire line + // Output the line + data.put(hashKey, new CasinoAccount(accountName,accountPass,casinoBalance)); + } + } + catch (IOException e) { + System.out.println("File not found"); + } + } + public static void addtofile(){ + //add to file + File file = new File("src/main/java/com/github/zipcodewilmington/casino/Accounts.txt"); + BufferedWriter bf = null; + //adds account to properties + try { + + + bf = new BufferedWriter(new FileWriter(file)); + for (Map.Entry entry : data.entrySet()) { + // put key and value separated by a colon + bf.write(entry.getKey() + "," + entry.getValue().getName()+","+entry.getValue().getAccountPassword()+","+entry.getValue().getCasinoBalance()); + // new line + bf.newLine(); + } + bf.flush(); + } + catch (IOException e) { + e.printStackTrace(); + } + finally { + + try { + + // always close the writer + bf.close(); + } + catch (Exception e) { + } + } + + } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java b/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java index 9873f1ed..7b58207a 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java +++ b/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java @@ -16,8 +16,9 @@ public interface GameInterface extends Runnable { */ void remove(PlayerInterface player); + + /** * specifies how the game will run */ - void run(); } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/BlackJackCard.java b/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/BlackJackCard.java new file mode 100644 index 00000000..b7cb34f4 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/BlackJackCard.java @@ -0,0 +1,54 @@ +package com.github.zipcodewilmington.casino.games.BlackJack; + +public class BlackJackCard implements Comparable{ + + private BlackJackSuit blackJackSuit; + private BlackJackRankEnum blackJackRankEnum; + + + public BlackJackCard(BlackJackSuit blackJackSuit, BlackJackRankEnum blackJackRankEnum){ + this.blackJackSuit = blackJackSuit; + this.blackJackRankEnum = blackJackRankEnum; + } + + + public BlackJackCard(BlackJackCard blackJackCard){ + this.blackJackSuit = blackJackCard.getSuit(); + this.blackJackRankEnum = blackJackCard.getRank(); + } + + + public int getValue(){ + return blackJackRankEnum.rankValue; + } + + + public BlackJackSuit getSuit(){ + return blackJackSuit; + } + + public BlackJackRankEnum getRank(){ + return blackJackRankEnum; + } + + + public String toString(){ + return ("["+ blackJackRankEnum +" of "+ blackJackSuit + "] ("+this.getValue()+")"); + + } + + + @Override + public int compareTo(BlackJackCard c) { + //if this card is greater than the other card + if(this.getValue() > c.getValue()){ + return 1; + } + else if(this.getValue() < c.getValue()){ + return -1; + } + else{ + return 0; + } + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/BlackJackDealer.java b/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/BlackJackDealer.java new file mode 100644 index 00000000..5b2ecf5e --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/BlackJackDealer.java @@ -0,0 +1,22 @@ +package com.github.zipcodewilmington.casino.games.BlackJack; + +public class BlackJackDealer extends BlackJackPerson { + + + public BlackJackDealer(){ + + //Name the dealer "Dealer" + super.setName("Dealer"); + + } + + + public void printFirstHand(){ + System.out.println("The dealer's hand looks like this:"); + System.out.println(super.getHand().getCard(0)); + System.out.println("The second card is face down."); + } + + + +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/BlackJackDeck.java b/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/BlackJackDeck.java new file mode 100644 index 00000000..d5754003 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/BlackJackDeck.java @@ -0,0 +1,112 @@ +package com.github.zipcodewilmington.casino.games.BlackJack; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Random; + + +public class BlackJackDeck { + + public ArrayList getDeck() { + return deck; + } + + //An arraylist to hold the deck of Cards + private ArrayList deck; + + + + public BlackJackDeck(){ + deck = new ArrayList(); + } + + + public BlackJackDeck(BlackJackDeck c){ + Collections.copy(this.deck, c.getCards()); + } + + + public BlackJackDeck(boolean makeDeck){ + deck = new ArrayList(); + if(makeDeck){ + //Go through all the suits + for(BlackJackSuit blackJackSuit : BlackJackSuit.values()){ + //Go through all the ranks + for(BlackJackRankEnum blackJackRankEnum : BlackJackRankEnum.values()){ + //add a new card containing each iterations suit and rank + deck.add(new BlackJackCard(blackJackSuit, blackJackRankEnum)); + } + } + } + } + + + public void addCard(BlackJackCard blackJackCard){ + deck.add(blackJackCard); + } + + + public void addCards(ArrayList blackJackCards){ + deck.addAll(blackJackCards); + } + + public String toString(){ + //A string to hold everything we're going to return + String output = ""; + + for(BlackJackCard blackJackCard : deck){ + output += blackJackCard; + output += "\n"; + } + return output; + } + + public void shuffle(){ + Collections.shuffle(deck, new Random()); + } + + + public BlackJackCard takeCard(){ + + //Take a copy of the first card from the deck + BlackJackCard blackJackCardToTake = new BlackJackCard(deck.get(0)); + //Remove the card from the deck + deck.remove(0); + //Give the card back + return blackJackCardToTake; + + } + + public boolean hasCards(){ + if (deck.size()>0){ + return true; + } + else{ + return false; + } + } + + + public int cardsLeft(){ + return deck.size(); + } + + + public ArrayList getCards() { + return deck; + } + + + public void emptyDeck(){ + deck.clear(); + } + + public void reloadDeckFromDiscard(BlackJackDeck discard){ + this.addCards(discard.getCards()); + this.shuffle(); + discard.emptyDeck(); + System.out.println("Ran out of cards, creating new deck from discard pile & shuffling deck."); + } + + +} 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 00000000..906cbca6 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/BlackJackGame.java @@ -0,0 +1,154 @@ +package com.github.zipcodewilmington.casino.games.BlackJack; + + +public class BlackJackGame { + + //Declare variables needed for Game class + private BlackJackDeck blackJackDeck, discarded; + + private BlackJackDealer blackJackDealer; + + public BlackJackPlayer getPlayer() { + return blackJackPlayer; + } + + private BlackJackPlayer blackJackPlayer; + private int wins, losses, pushes; + + + + + public BlackJackGame(){ + + //Create a new deck with 52 cards + blackJackDeck = new BlackJackDeck(true); + //Create a new empty deck + discarded = new BlackJackDeck(); + + //Create the People + blackJackDealer = new BlackJackDealer(); + blackJackPlayer = new BlackJackPlayer(); + + + //Shuffle the deck and start the first round + blackJackDeck.shuffle(); + startRound(); + } + + private void startRound(){ +/* wins = 0; losses = 0; pushes = 1; + Card testCard = new Card(Suit.CLUB,Rank.NINE); + Card testCard2 = new Card(Suit.CLUB, Rank.TEN);*/ + //If this isn't the first time, display the users score and put their cards back in the deck + if(wins>0 || losses>0 || pushes > 0){ + + System.out.println(); + System.out.println("Starting Next Round... Wins: " + wins + " Losses: "+ losses+ " Pushes: "+pushes); + blackJackDealer.getHand().discardHandToDeck(discarded); + blackJackPlayer.getHand().discardHandToDeck(discarded); + } + + //Check to make sure the deck has at least 4 cards left + if(blackJackDeck.cardsLeft() < 4){ + blackJackDeck.reloadDeckFromDiscard(discarded); + } + + //Give the dealer two cards + blackJackDealer.getHand().takeCardFromDeck(blackJackDeck); + blackJackDealer.getHand().takeCardFromDeck(blackJackDeck); + + //Give the player two cards + blackJackPlayer.getHand().takeCardFromDeck(blackJackDeck); + blackJackPlayer.getHand().takeCardFromDeck(blackJackDeck); + +/* //TEST + player.getHand().addCard(testCard); + player.getHand().addCard(testCard2);*/ + + //Show the dealers hand with one card face down + blackJackDealer.printFirstHand(); + + //Show the player's hand + blackJackPlayer.printHand(); + + //Check if dealer has BlackJack to start + if(blackJackDealer.hasBlackjack()){ + //Show the dealer has BlackJack + blackJackDealer.printHand(); + + //Check if the player also has BlackJack + if(blackJackPlayer.hasBlackjack()){ + //End the round with a push + System.out.println("You both have 21 - Push."); + pushes++; + startRound(); + } + else{ + System.out.println("Dealer has BlackJack. You lose."); + blackJackDealer.printHand(); + losses++; + startRound(); + } + } + + //Check if player has blackjack to start + //If we got to this point, we already know the dealer didn't have blackjack + if(blackJackPlayer.hasBlackjack()){ + System.out.println("You have Blackjack! You win!"); + wins++; + startRound(); + } + + //Let the player decide what to do next + blackJackPlayer.makeDecision(blackJackDeck, discarded); + + //Check if they busted + if(blackJackPlayer.getHand().calculatedValue() > 21){ + System.out.println("You have gone over 21."); + losses ++; + startRound(); + } + + //Now it's the dealer's turn + blackJackDealer.printHand(); + while(blackJackDealer.getHand().calculatedValue()<17){ + blackJackDealer.hit(blackJackDeck, discarded); + } + + //Check who wins + if(blackJackDealer.getHand().calculatedValue()>21){ + System.out.println("Dealer busts"); + wins++; + } + else if(blackJackDealer.getHand().calculatedValue() > blackJackPlayer.getHand().calculatedValue()){ + System.out.println("You lose."); + losses++; + } + else if(blackJackPlayer.getHand().calculatedValue() > blackJackDealer.getHand().calculatedValue()){ + System.out.println("You win."); + wins++; + } + else{ + System.out.println("Push."); + } + + //Start a new round + startRound(); + } + + +public static void pause(){ + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + e.printStackTrace(); + } +} + public static void runBlackJack(){ + System.out.println("Welcome to BlackJack."); + + BlackJackGame blackjack = new BlackJackGame(); + } + + +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/BlackJackHand.java b/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/BlackJackHand.java new file mode 100644 index 00000000..83959797 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/BlackJackHand.java @@ -0,0 +1,76 @@ +package com.github.zipcodewilmington.casino.games.BlackJack; + +import java.util.ArrayList; + +/** + * A hand of cards to play with + */ +public class BlackJackHand { + + private ArrayList hand; + + public BlackJackHand(){ + hand = new ArrayList(); + } + + public void takeCardFromDeck(BlackJackDeck blackJackDeck){ + hand.add(blackJackDeck.takeCard()); + } + + + public void discardHandToDeck(BlackJackDeck discardBlackJackDeck){ + + //copy cards from hand to discardDeck + discardBlackJackDeck.addCards(hand); + + //clear the hand + hand.clear(); + + } + + + public String toString(){ + String output = ""; + for(BlackJackCard blackJackCard : hand){ + output += blackJackCard + " - "; + } + return output; + } + + + + public int calculatedValue(){ + + //variable to count number of aces, and current total value + int value = 0; + int aceCount = 0; + + //For each card in this hand + for(BlackJackCard blackJackCard : hand){ + //Add the card value to the hand + value += blackJackCard.getValue(); + //Count how many aces have been added + if (blackJackCard.getValue() == 11){ + aceCount ++; + } + } + //if we have a scenario where we have multiple aces, as may be the case of drawing 10, followed by two or more aces, (10+11+1 > 21) + //go back and set each ace to 1 until get back under 21, if possible + if (value > 21 && aceCount > 0){ + while(aceCount > 0 && value > 21){ + aceCount --; + value -= 10; + } + } + return value; + + } + + + public BlackJackCard getCard(int idx){ + return hand.get(idx); + } + + + +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/BlackJackPerson.java b/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/BlackJackPerson.java new file mode 100644 index 00000000..3e6b4a41 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/BlackJackPerson.java @@ -0,0 +1,61 @@ +package com.github.zipcodewilmington.casino.games.BlackJack; + + +public abstract class BlackJackPerson { + + private BlackJackHand blackJackHand; + private String name; + + public BlackJackPerson(){ + this.blackJackHand = new BlackJackHand(); + this.name = ""; + } + + + //Setters and Getters + public BlackJackHand getHand(){ + return this.blackJackHand; + } + public void setHand(BlackJackHand blackJackHand){ + this.blackJackHand = blackJackHand; + } + public String getName(){ + return this.name; + } + public void setName(String name){ + this.name = name; + } + + + + public void printHand(){ + System.out.println(this.name + "'s hand looks like this:"); + System.out.println(this.blackJackHand + " Valued at: " + this.blackJackHand.calculatedValue()); + } + + + public void hit(BlackJackDeck blackJackDeck, BlackJackDeck discard){ + + //If there's no cards left in the deck + if (!blackJackDeck.hasCards()) { + blackJackDeck.reloadDeckFromDiscard(discard); + } + this.blackJackHand.takeCardFromDeck(blackJackDeck); + System.out.println(this.name + " gets a card"); + this.printHand(); + BlackJackGame.pause(); + + } + + public boolean hasBlackjack(){ + if(this.getHand().calculatedValue() == 21){ + return true; + } + else{ + return false; + } + } + + + +} 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 00000000..211f3d14 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/BlackJackPlayer.java @@ -0,0 +1,55 @@ +package com.github.zipcodewilmington.casino.games.BlackJack; + +import java.util.Scanner; + + +public class BlackJackPlayer extends BlackJackPerson { + + Scanner input = new Scanner(System.in); + + //Create a new Player + public BlackJackPlayer() { + super.setName("Player"); + + } + + //Allow the player to make decisions + public void makeDecision(BlackJackDeck blackJackDeck, BlackJackDeck discard) { + + int decision = 0; + boolean getNum = true; + + while(getNum){ + + try{ + System.out.println("Would you like to: 1) Hit or 2) Stand"); + decision = input.nextInt(); + getNum = false; + + } + catch(Exception e){ + System.out.println("Invalid"); + input.next(); + } + //we don't close the scanner, because we will need it later. + } + + if (decision == 1) { + this.hit(blackJackDeck, discard); + //return if they have blackjack or busted + if(this.getHand().calculatedValue()>20){ + return; + } + else{ + this.makeDecision(blackJackDeck, discard); + } + + } else { + System.out.println("You stand."); + } + + + } + + +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/BlackJackRankEnum.java b/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/BlackJackRankEnum.java new file mode 100644 index 00000000..0277cb46 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/BlackJackRankEnum.java @@ -0,0 +1,30 @@ +package com.github.zipcodewilmington.casino.games.BlackJack; + + +public enum BlackJackRankEnum { + ACE("Ace", 11), + TWO("Two", 2), + THREE("Three", 3), + FOUR("Four",4), + FIVE("Five",5), + SIX("Six",6), + SEVEN("Seven",7), + EIGHT("Eight",8), + NINE("Nine",9), + TEN("Ten",10), + JACK("Jack",10), + QUEEN("Queen",10), + KING("King",10); + + String rankName; + int rankValue; + + BlackJackRankEnum(String rankName, int rankValue){ + this.rankName = rankName; + this.rankValue = rankValue; + } + + public String toString(){ + return rankName; + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/BlackJackSuit.java b/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/BlackJackSuit.java new file mode 100644 index 00000000..6ebef3bc --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/BlackJackSuit.java @@ -0,0 +1,19 @@ +package com.github.zipcodewilmington.casino.games.BlackJack; + + +public enum BlackJackSuit { + CLUB("Clubs"), + DIAMOND("Diamonds"), + HEART("Hearts"), + SPADE("Spades"); + + String suitName; + + BlackJackSuit(String suitName) { + this.suitName = suitName; + } + + public String toString(){ + return suitName; + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Card.java b/src/main/java/com/github/zipcodewilmington/casino/games/Card.java new file mode 100644 index 00000000..af7e4de9 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Card.java @@ -0,0 +1,44 @@ +package com.github.zipcodewilmington.casino.games; + +public class Card { + String face; + public int value; + public String color; + public String suit; + + public Card(String face, int value, String Color, String suit) + { + this.face = face; + this.value = value; + this.color = Color; + this.suit = suit; + } + + + @Override + public String toString() { + String ret =""; + if(value==11) + { + ret ="Jack of "+ suit; + } + else if (value==12) + { + ret ="Queen of "+ suit; + } + else if(value==13) + { + ret ="King of "+suit; + } + else if(value==14) + { + ret = "Ace of "+suit; + } + else + { + ret = value + " of " + suit; + } + return ret; + + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/CasinoWar/CasinoWar.java b/src/main/java/com/github/zipcodewilmington/casino/games/CasinoWar/CasinoWar.java new file mode 100644 index 00000000..b664abaa --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/CasinoWar/CasinoWar.java @@ -0,0 +1,157 @@ +package com.github.zipcodewilmington.casino.games.CasinoWar; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Scanner; + +public class CasinoWar { + + private List deck; + private int playerScore; + private int dealerScore; + + public CasinoWar() { + deck = createShuffledDeck(); + playerScore = 0; + dealerScore = 0; + } + + public void playersTurn() { + // Player's turn + System.out.println("Press Enter to draw a card."); + new Scanner(System.in).nextLine(); + String playerCard = drawCard(); + System.out.println("You drew: " + playerCard); + dealersTurn(playerCard); + } + + public void dealersTurn(String playerCard) { + // Dealer's turn + System.out.println("Press Enter for the dealer to draw a card."); + new Scanner(System.in).nextLine(); + String dealerCard = drawCard(); + System.out.println("Dealer drew: " + dealerCard + "\n"); + compareCards(playerCard, dealerCard); + } + + public void compareCards(String playerCard, String dealerCard) { + // Compare the cards + int playerValue = getCardValue(playerCard); + int dealerValue = getCardValue(dealerCard); + + if (playerValue > dealerValue) { + System.out.println("You win this round!"); + playerScore++; + } else if (dealerValue > playerValue) { + System.out.println("Dealer wins this round!"); + dealerScore++; + } else { + System.out.println("It's a tie! Time for war!"); + // War: draw three more cards each + List playerWarCards = new ArrayList<>(); + List dealerWarCards = new ArrayList<>(); + + for (int i = 0; i < 3; i++) { + playerWarCards.add(drawCard()); + dealerWarCards.add(drawCard()); + } + startWar(playerWarCards, dealerWarCards); + } + } + + public void startWar(List playerWarCards, List dealerWarCards) { + // Get the fourth card for comparison + String playerFourthCard = playerWarCards.get(0); + String dealerFourthCard = dealerWarCards.get(0); + + System.out.println("Your fourth card: " + playerFourthCard); + System.out.println("Dealer's fourth card: " + dealerFourthCard); + + int playerFourthCardValue = getCardValue(playerFourthCard); + int dealerFourthCardValue = getCardValue(dealerFourthCard); + + if (playerFourthCardValue > dealerFourthCardValue) { + System.out.println("You win the war!"); + playerScore++; + } else if (dealerFourthCardValue > playerFourthCardValue) { + System.out.println("Dealer wins the war!"); + dealerScore++; + } else { + System.out.println("It's a tie in the war too! Nobody wins."); + } + } + + public void displayScore() { + // Display the current scores + System.out.println("Your score: " + playerScore); + System.out.println("Dealer's score: " + dealerScore); + // Check if the deck is empty + if (deck.isEmpty()) { + System.out.println("The deck is empty. Game over!"); + } + } + + private List createShuffledDeck() { + List deck = new ArrayList<>(); + + String[] suits = {"Hearts", "Diamonds", "Clubs", "Spades"}; + String[] ranks = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"}; + + for (String suit : suits) { + for (String rank : ranks) { + deck.add(rank + " of " + suit); + } + } + + Collections.shuffle(deck); + return deck; + } + + private String drawCard() { + return deck.remove(deck.size() - 1); + } + + private int getCardValue(String card) { + String rank = card.split(" ")[0]; + switch (rank) { + case "Ace": + return 14; + case "King": + return 13; + case "Queen": + return 12; + case "Jack": + return 11; + default: + return Integer.parseInt(rank); + } + } + + + + public void run(){ + while (!this.deck.isEmpty()) { + this.playersTurn(); + this.displayScore(); + } + } + + public int getPlayerScore() { + return playerScore; + } + + + public int getDealerScore() { + return dealerScore; + } + + public boolean isGameOver() { + return false; + } + +} + + + + + diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/CasinoWar/CasinoWarPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/CasinoWar/CasinoWarPlayer.java new file mode 100644 index 00000000..aec37970 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/CasinoWar/CasinoWarPlayer.java @@ -0,0 +1,19 @@ +package com.github.zipcodewilmington.casino.games.CasinoWar; + +import java.util.Scanner; + +public class CasinoWarPlayer { + + int playerCardValue; + int dealerCardValue; + + + public static int PlayersTurn(){ + return 0; + + } + + public static void DealersTurn(){ + + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Deck.java b/src/main/java/com/github/zipcodewilmington/casino/games/Deck.java new file mode 100644 index 00000000..1ecd840c --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Deck.java @@ -0,0 +1,40 @@ +package com.github.zipcodewilmington.casino.games; + +import java.util.ArrayList; +import java.util.Random; + +public class Deck { + + String[] faces = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"}; + int[] values = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; + String[] colors = {"Red", "Black"}; + String[] suits = {"Hearts", "Diamonds", "Clubs", "Spades"}; + Random rand = new Random(); + public ArrayList getDeck() { + return deck; + } + + ArrayList deck = new ArrayList(); + + public Deck() + { + for (String suit : suits) + { + for (int i = 0; i < faces.length; i++) + { + String color = (suit.equals("Hearts") || suit.equals("Diamonds")) ? "Red" : "Black"; + Card card = new Card(faces[i], values[i], color, suit); + deck.add(card); + } + + } + } + + public Card GetRandomCard() + { + int i = rand.nextInt(deck.size()); + return deck.get(i); + } + + +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/DiceRoll.java b/src/main/java/com/github/zipcodewilmington/casino/games/DiceRoll.java new file mode 100644 index 00000000..952a928c --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/DiceRoll.java @@ -0,0 +1,44 @@ +package com.github.zipcodewilmington.casino.games; + +import java.util.ArrayList; +import java.util.Random; + +public class DiceRoll { + private static int tosses; + + public static final ArrayList rollResultsDice=new ArrayList<>(); + + + public static void GetDiceRoll(int numberOfTosses) { + DiceRoll.tosses=numberOfTosses; + + } +//Create a Simulation class whose Constructor takes arguments: numberOfDies to throw numberOfTosses to run +// +//Create a simulation where two dies are thrown one million times. Keep track of all results. + + + public static int runSimulation() { + Random rd = new Random(); + + + int diceRoll; + int sumOfRoll=0; + + int max=12; + int min=1; + + for (int i = 0; i < tosses; i++) { + diceRoll= rd.nextInt(max - min + 1) + min; + sumOfRoll += diceRoll; + } + rollResultsDice.add(sumOfRoll); + System.out.println(sumOfRoll); + return sumOfRoll; + + } + public static ArrayList results() + { + return rollResultsDice; + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/RideTheBus/RideTheBusGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/RideTheBus/RideTheBusGame.java new file mode 100644 index 00000000..923bdcc2 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/RideTheBus/RideTheBusGame.java @@ -0,0 +1,281 @@ +package com.github.zipcodewilmington.casino.games.RideTheBus; + +import com.github.zipcodewilmington.Casino; +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.Card; +import com.github.zipcodewilmington.casino.games.Deck; +import com.github.zipcodewilmington.utils.AnsiColor; +import com.github.zipcodewilmington.utils.IOConsole; + +import java.util.Scanner; + +public class RideTheBusGame implements GameInterface { + public RideTheBusPlayer getRider() { + return rider; + } + private IOConsole colorConsoleRed = new IOConsole(AnsiColor.RED); + IOConsole colorConsoleGreen = new IOConsole(AnsiColor.GREEN); + RideTheBusPlayer rider; + CasinoAccount retr; + Deck deckobj = new Deck(); + Card[] table = new Card[4]; + int index0; + Scanner scan = new Scanner(System.in); + +public RideTheBusGame(CasinoAccount person) +{ + retr = person; +} + + + public void hop() { + index0 = index0 + 1; + + + + } + + public void back() { + index0 = index0 - 1; + + } + + public void deal() { + + for (int i = 0; i < 4; i++) { + table[i] = deckobj.GetRandomCard(); + } + } + + + public void HalfBet() { + } + + public String getValue() { + return table[index0].toString(); + } + + + public void reset() { + } + + public void exitGame() { + } + + public void start() { + + rider = new RideTheBusPlayer(retr); + WelcomeMessage(); + while (!checkbet(getBet())) + {} + deal(); + while (index0 < 4) + { + gameflow(); + status(); + } + win(); + } + + public void win() { + if (rider.getCurrentBet() == 0) { + System.out.println("Congratulations on making it to the end of the bus"); + System.out.println("Unfortunately, you have lost your entire bet."); + System.out.println("Better luck next time!"); + } + else + { + System.out.println("Congratulations on making it to the end of the bus!"); + int winnings = (int) (rider.getCurrentBet()*2); + System.out.println("Your returns are: " + winnings); + rider.setWallet(rider.getWallet()+winnings); + retr.setCasinoBalance(rider.getWallet()); + } + } + + public String guessHiLow() { + System.out.println("Do you believe the next card turned will be higher or lower?"); + String ret = scan.nextLine().toLowerCase(); + if(ret.equals("higher") || ret.equals("lower")) + { + return ret; + } + else + { + System.out.println("Please enter higher or lower as a word."); + return guessHiLow(); + } + } + + public int getBet() + { + System.out.println("How much would you like to bet in this game?"); + System.out.println("Your account has: " + rider.getWallet()); + + int b= scan.nextInt(); + + scan.nextLine(); + return b; + } + + + + public boolean checkbet(int bet) + { + if(bet>rider.getWallet()) + { + System.out.println("You do not have enough funds in your wallet for the bet you just made."); + return false; + } + rider.setCurrentBet(bet); + rider.setWallet(rider.wallet-bet); + retr.setCasinoBalance(retr.getCasinoBalance()-bet); + System.out.println("You bet has been set."); + return true; + } + + public boolean checkHiLow(String guess) { + if (guess.equals("higher")) { + int current = table[index0].value; + table[index0] = deckobj.GetRandomCard(); + System.out.println("The next card turned over was " + table[index0]); + int NewCard = table[index0].value; + return current < NewCard; + } else if (guess.equals("lower")) + { + int current = table[index0].value; + table[index0] = deckobj.GetRandomCard(); + System.out.println("The next card turned over was " + table[index0]); + int NewCard = table[index0].value; + return current > NewCard; + } + return true; + } + public void react(boolean logic) { + if (logic == true) + { + colorConsoleGreen.println("Your guess was right, moving up!"); + hop(); + } + else if (logic == false) + { + if (getIndex0() != 0) + { + colorConsoleRed.println("Your guess was wrong, moving back!"); + System.out.println("Your bet has been decreased by 15%"); + rider.setCurrentBet((int) (rider.getCurrentBet()-rider.getCurrentBet()*.15)); + back(); + } + else if( getIndex0()==0) { + colorConsoleRed.println("Your guess was wrong but you're still at spot one."); + System.out.println("Your bet has been decreased by 15%"); + rider.setCurrentBet((int) (rider.getCurrentBet() - rider.getCurrentBet() * .15)); + } + } + } + + public boolean checkColor(String guess) { + if (guess.equals("red")) { + + table[index0] = deckobj.GetRandomCard(); + System.out.println("The card turned over was " + table[index0]); + String NewColor = table[index0].color.toLowerCase(); + return guess.equals(NewColor); + } else if (guess.equals("black")) + { + table[index0] = deckobj.GetRandomCard(); + System.out.println("The card turned over was " + table[index0]); + String NewColor = table[index0].color.toLowerCase(); + return guess.equals(NewColor); + } + return false; + } + + + public boolean checkSuit(String guess) { + table[index0] = deckobj.GetRandomCard(); + System.out.println("The card turned over was " + table[index0]); + String NewSuit = table[index0].suit.toLowerCase(); + return guess.equals(NewSuit); + } + + + + public void gameflow() { + if (index0 == 0 || index0 == 1) { + reveal(); + react(checkHiLow(guessHiLow())); + } else if (index0 == 2) + { + react(checkColor(guessColor())); + } + else if(index0==3) { + react(checkSuit(guessSuit())); + } + } + + public String guessColor() { + System.out.println("Please input the color of the next card flipped over."); + String ret = scan.nextLine().toLowerCase(); + if(ret.equals("red")||ret.equals("black")) + { + return ret; + } + else + { + System.out.println("Please enter the color as a word."); + return guessColor(); + } + } + + public String guessSuit() { + System.out.println("Please input the suit of the next card flipped over."); + String ret = scan.nextLine().toLowerCase(); + if(ret.equals("spades")||ret.equals("clubs")||ret.equals("diamonds")||ret.equals("hearts")) + { + return ret; + } + else + { + System.out.println("Please enter the suit as a word."); + return guessSuit(); + } + + } + + public void reveal() { + System.out.println( "The current value of the card you are guessing is " + getValue()); + } + + public void WelcomeMessage() { + + System.out.println( "Welcome to Ride The Bus!"); + + } + public int getIndex0() { + return index0; + } + public void status() + { + if(index0<=3) + System.out.println("You are currently at card position " + (index0+1) + " with a bet balance of " + rider.getCurrentBet()); + } + + + @Override + public void add(PlayerInterface player) { + + } + + @Override + public void remove(PlayerInterface player) { + + } + + @Override + public void run() { + + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/RideTheBus/RideTheBusPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/RideTheBus/RideTheBusPlayer.java new file mode 100644 index 00000000..73d7ed9d --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/RideTheBus/RideTheBusPlayer.java @@ -0,0 +1,31 @@ +package com.github.zipcodewilmington.casino.games.RideTheBus; + +import com.github.zipcodewilmington.casino.CasinoAccount; + +public class RideTheBusPlayer { + + + double wallet =0; + int currentBet=0; + public RideTheBusPlayer(CasinoAccount person) + { + this.wallet = person.getCasinoBalance(); + } + + + public double getWallet() { + return wallet; + } + + public void setWallet(double wallet) { + this.wallet = wallet; + } + public int getCurrentBet() { + return currentBet; + } + + public void setCurrentBet(int currentBet) { + this.currentBet = currentBet; + } + +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Roulette/RouletteBoard.java b/src/main/java/com/github/zipcodewilmington/casino/games/Roulette/RouletteBoard.java new file mode 100644 index 00000000..de916e01 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Roulette/RouletteBoard.java @@ -0,0 +1,11 @@ +//package com.github.zipcodewilmington.casino.games.Roulette; +// +//public enum RouletteBoard { +// RED, +// BLACK, +// GREEN, +// ODD, +// EVEN +//} +// +// diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Roulette/RouletteNumber.java b/src/main/java/com/github/zipcodewilmington/casino/games/Roulette/RouletteNumber.java new file mode 100644 index 00000000..4f64ea7f --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Roulette/RouletteNumber.java @@ -0,0 +1,63 @@ +//package com.github.zipcodewilmington.casino.games.Roulette; +// +//public enum RouletteNumber { +// ZERO(0, RouletteBoard.GREEN, RouletteBoard.EVEN), +// ONE(1, RouletteBoard.RED, RouletteBoard.ODD), +// TWO(2, RouletteBoard.BLACK, RouletteBoard.EVEN), +// THREE(3, RouletteBoard.RED, RouletteBoard.ODD), +// FOUR(4, RouletteBoard.BLACK, RouletteBoard.EVEN), +// FIVE(5, RouletteBoard.RED, RouletteBoard.ODD), +// SIX(6, RouletteBoard.BLACK, RouletteBoard.EVEN), +// SEVEN(7, RouletteBoard.RED, RouletteBoard.ODD), +// EIGHT(8, RouletteBoard.BLACK, RouletteBoard.EVEN), +// NINE(9, RouletteBoard.RED, RouletteBoard.ODD), +// TEN(10, RouletteBoard.BLACK, RouletteBoard.EVEN), +// ELEVEN(11, RouletteBoard.RED, RouletteBoard.ODD), +// TWELVE(12, RouletteBoard.BLACK, RouletteBoard.EVEN), +// THIRTEEN(13, RouletteBoard.RED, RouletteBoard.ODD), +// FOURTEEN(14, RouletteBoard.BLACK, RouletteBoard.EVEN), +// FIFTEEN(15, RouletteBoard.RED, RouletteBoard.ODD), +// SIXTEEN(16, RouletteBoard.BLACK, RouletteBoard.EVEN), +// SEVENTEEN(17, RouletteBoard.RED, RouletteBoard.ODD), +// EIGHTEEN(18, RouletteBoard.BLACK, RouletteBoard.EVEN), +// NINETEEN(19, RouletteBoard.RED, RouletteBoard.ODD), +// TWENTY(20, RouletteBoard.BLACK, RouletteBoard.EVEN), +// TWENTYONE(21, RouletteBoard.RED, RouletteBoard.ODD), +// TWNETYTWO(22, RouletteBoard.BLACK, RouletteBoard.EVEN), +// TWENTYTHREE(23, RouletteBoard.BLACK, RouletteBoard.ODD), +// TWENTYFOUR(24, RouletteBoard.RED, RouletteBoard.EVEN), +// TWENTYFIVE(25, RouletteBoard.RED, RouletteBoard.ODD), +// TWENTYSIX(26, RouletteBoard.BLACK, RouletteBoard.EVEN), +// TWENTYSEVEN(27, RouletteBoard.RED, RouletteBoard.ODD), +// TWENTYEIGHT(28, RouletteBoard.BLACK, RouletteBoard.EVEN), +// TWENTYNINE(29, RouletteBoard.RED, RouletteBoard.ODD), +// THIRTY(30, RouletteBoard.BLACK, RouletteBoard.EVEN), +// THIRTYONE(31, RouletteBoard.RED, RouletteBoard.ODD), +// THIRTYTWO(32, RouletteBoard.BLACK, RouletteBoard.EVEN), +// THIRTYTHREE(33, RouletteBoard.RED, RouletteBoard.ODD), +// THIRTYFOUR(34, RouletteBoard.BLACK, RouletteBoard.EVEN), +// THIRTYFIVE(35, RouletteBoard.RED, RouletteBoard.ODD), +// THIRTYSIX(36, RouletteBoard.BLACK, RouletteBoard.EVEN); +// +// private final int numberValue; +// private final RouletteBoard color; +// private final RouletteBoard oddOrEven; +// +// RouletteNumber(int numberValue, RouletteBoard color, RouletteBoard oddOrEven) { +// this.numberValue = numberValue; +// this.color = color; +// this.oddOrEven = oddOrEven; +// +// } +// public int getNumberValue() { +// return numberValue; +// } +// +// public RouletteBoard getColor() { +// return color; +// } +// +// public RouletteBoard getOddOrEven() { +// return oddOrEven; +// } +//} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Roulette/rouletteGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/Roulette/rouletteGame.java new file mode 100644 index 00000000..85abb7b3 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Roulette/rouletteGame.java @@ -0,0 +1,101 @@ +//package com.github.zipcodewilmington.casino.games.Roulette; +//import com.github.zipcodewilmington.casino.CasinoAccount; +// +//import java.util.Random; +//import java.util.Scanner; +// +// +//public class rouletteGame{ +// private RouletteNumber[] rouletteNumbers = RouletteNumber.values(); +// private Random random = new Random(); +// static Scanner scan = new Scanner(System.in); +// +// +// public void run() { +// WelcomeMessage(); +// pushToStart(); +// rouletteMenu(); +// } +// +// public String WelcomeMessage() +// { +// StringBuilder welcome = new StringBuilder(); +// welcome.append("--------------------------------\n"); +// welcome.append("| WELCOME TO ROULETTE |\n"); +// welcome.append("| |\n"); +// welcome.append("| Please enter any key to roll |\n"); +// welcome.append("--------------------------------\n"); +// System.out.println(welcome); +// return welcome.toString(); +// } +// +// public void pushToStart(){ +// { +// scan.nextLine(); +// } +// } +// +// public void rouletteMenu(){ +// while (true) { +// System.out.println("\n Main Menu: Choose Number For Bet \n"); +// System.out.println(" 1. Bet on Color: Green/Red/Black"); +// System.out.println("2. Bet on Odd or Even"); +// System.out.println("3. Leave Table"); +// System.out.println("Please make a selection [1-3]: "); +// System.out.println("Your Current Balance is " + roulettePlayer.getWallet()); +// +// Integer userChoice = scan.nextInt(); +// +// switch(userChoice){ +// case 1: +// System.out.print("Choose a color to bet on (Red/Black/Green): "); +// String chosenColor = scan.next(); +// try { +// RouletteBoard betColor = RouletteBoard.valueOf(chosenColor.toUpperCase()); +// playRound(player, betAmount, betColor); +// } catch (IllegalArgumentException e) { +// System.out.println("Invalid color! Please choose Red, Black, or Green."); +// } +// break; +// case 2: +// System.out.print("Choose to bet on (Odd/Even): "); +// String chooseOddEven = scan.next(); +// try { +// RouletteBoard betNumber = RouletteBoard.valueOf(chooseOddEven.toUpperCase()); +// playRound(player, betAmount, betNumber); +// } catch (IllegalArgumentException e) { +// System.out.println("Invalid option! Please choose Odd/Even"); +// } +// break; +// case 3: +// System.out.println("Back to Menu"); +// scan.close(); +// break; +// default: +// System.out.println("Invalid betting option!"); +// } +// } +// scan.close(); +// +// private void playRound(roulettePlayer player, double betAmount, RouletteBet bet){ +// +// +// return null; +// } +// +// +// +// +// +// +// +// +// +// +//} +// +// +// +// +// +//} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Roulette/roulettePlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/Roulette/roulettePlayer.java new file mode 100644 index 00000000..576992fa --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Roulette/roulettePlayer.java @@ -0,0 +1,55 @@ +//package com.github.zipcodewilmington.casino.games.Roulette; +//import com.github.zipcodewilmington.casino.CasinoAccount; +// +// +//public class roulettePlayer { +// double wallet =0; +// int currentBet=0; +// +// +// public roulettePlayer(CasinoAccount person) +// { +// this.wallet = person.getCasinoBalance(); +// } +// +// +// public static double getWallet() { +// return wallet; +// } +// +// public void setWallet(double wallet) { +// this.wallet = wallet; +// } +// public int getCurrentBet() { +// return currentBet; +// } +// +// public void setCurrentBet(int currentBet) { +// this.currentBet = currentBet; +// } +// +// +// public void placeBet(double betAmount, int chosenNumber) { +// if (betAmount <= 0) { +// System.out.println("Invalid bet amount!"); +// return; +// } +// +// if (betAmount > wallet) { +// System.out.println("Insufficient balance!"); +// return; +// } +// +// RouletteNumber betNumber = RouletteNumber.valueOf("N" + chosenNumber); +// rouletteGame.playRound(this, betAmount, betNumber); +// } +// +// +//} +// +// +// +// +// +// +//} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/Roulette/rouletteTable.java b/src/main/java/com/github/zipcodewilmington/casino/games/Roulette/rouletteTable.java new file mode 100644 index 00000000..640de75e --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Roulette/rouletteTable.java @@ -0,0 +1,79 @@ +//package com.github.zipcodewilmington.casino.games.Roulette; +// +//import java.util.ArrayList; +//import java.util.HashMap; +//import java.util.Random; +// +// +//public class rouletteTable { +// private final ArrayList numbers; +// +// private final HashMap numbertocolor = new HashMap<>(); +// Random random = new Random(); +// +// +// +// public rouletteTable(ArrayList numbers, String colors) { +// this.numbers = numbers; +// +// rouletteGetNumbers(); +// rouletteGetColors(); +// +// } +// +// private void rouletteGetNumbers () { +// for (int i = 0; i <= 36; i++) { +// numbers.add(i); +// } +// } +// private void rouletteGetColors () { +// numbertocolor.put(0, "green"); +// numbertocolor.put(1, "red"); +// numbertocolor.put(2, "black"); +// numbertocolor.put(3, "red"); +// numbertocolor.put(4, "black"); +// numbertocolor.put(5, "red"); +// numbertocolor.put(6, "black"); +// numbertocolor.put(7, "red"); +// numbertocolor.put(8, "black"); +// numbertocolor.put(9, "red"); +// numbertocolor.put(10, "black"); +// numbertocolor.put(11, "black"); +// numbertocolor.put(12, "red"); +// numbertocolor.put(13, "black"); +// numbertocolor.put(14, "red"); +// numbertocolor.put(15, "black"); +// numbertocolor.put(16, "red"); +// numbertocolor.put(17, "black"); +// numbertocolor.put(18, "red"); +// numbertocolor.put(19, "red"); +// numbertocolor.put(20, "black"); +// numbertocolor.put(21, "red"); +// numbertocolor.put(22, "black"); +// numbertocolor.put(23, "red"); +// numbertocolor.put(24, "black"); +// numbertocolor.put(25, "red"); +// numbertocolor.put(26, "black"); +// numbertocolor.put(27, "red"); +// numbertocolor.put(28, "black"); +// numbertocolor.put(29, "black"); +// numbertocolor.put(30, "red"); +// numbertocolor.put(31, "black"); +// numbertocolor.put(32, "red"); +// numbertocolor.put(33, "black"); +// numbertocolor.put(34, "red"); +// numbertocolor.put(35, "black"); +// numbertocolor.put(36, "red"); +// } +// +// public int spinWheel () { +// int index = random.nextInt(numbers.size()); +// return (int) numbers.get(index); +// } +// +// public String getColors(int number) { +// return (String) numbertocolor.getOrDefault(number, "unknown"); +// } +// +// +//} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/StreetCraps.java b/src/main/java/com/github/zipcodewilmington/casino/games/StreetCraps.java new file mode 100644 index 00000000..761d7b4f --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/StreetCraps.java @@ -0,0 +1,123 @@ +package com.github.zipcodewilmington.casino.games; +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.games.DiceRoll; + +import java.util.Scanner; + +public class StreetCraps { + static CasinoAccount streetCrapsPlayer; + public StreetCraps (CasinoAccount person){ + streetCrapsPlayer=person; + } + + static int point = 0; + double sideBet = 0; + static int[] winningNums = {7, 11}; + static int[] losingNums = {2, 3, 12}; + + + + static boolean win = false; + static boolean gameover=false; + + static boolean rollagain=false; + + static int wager=0; + + + + static Scanner in=new Scanner(System.in); + + + public void run() { + int currentRoll; + + System.out.println("Your account has: " + streetCrapsPlayer.getCasinoBalance()+" Choose amount to wager:"); + wager=in.nextInt(); + + while (!win && !gameover && !rollagain && checkbet(wager)) { + + currentRoll = rollDice(); + if(checkwin(currentRoll)){ + win=true; + wager =wager*2; + streetCrapsPlayer.addCasinoBalance(wager); + } + else if (checkLoss(currentRoll)){ + gameover=true; + } + else{ + point = currentRoll; + while(!rollagain) { + rollagain=rollAgain(); + + } + } + + + } + win = false; + gameover=false; + rollagain=false; + wager=0; + + } + + public static boolean rollAgain(){ + int rolledAgainRoll; + System.out.println("Roll again!:"); + in.nextLine(); + rolledAgainRoll=rollDice(); + if(rolledAgainRoll==point){ + System.out.println("you won"); + wager =wager*2; + streetCrapsPlayer.addCasinoBalance(wager); + return true; + } else if (rolledAgainRoll==7) { + System.out.println("you lost"); + + return true; + } + return false; + + } + + + public static int rollDice() { + int rollResult; + DiceRoll.GetDiceRoll(1); + rollResult = DiceRoll.runSimulation(); + return rollResult; + + } + + public static boolean checkwin(int currentRoll) { + + if (currentRoll == winningNums[0] || currentRoll == winningNums[1]) { + System.out.println("YOU WON"); + return true; + } + return false; + } + public static boolean checkLoss(int currentRoll){ + if (currentRoll == losingNums[0] || currentRoll == losingNums[1] || currentRoll == losingNums[2]) { + System.out.println("YOU LOST"); + return true; + } + return false; + } + public static boolean checkbet(int bet) + { + if(bet>streetCrapsPlayer.getCasinoBalance()) + { + System.out.println("You do not have enough funds in your wallet for the bet you just made."); + System.out.println("Your account has: " + streetCrapsPlayer.getCasinoBalance()); + return false; + } + + streetCrapsPlayer.setCasinoBalance(streetCrapsPlayer.getCasinoBalance()-bet); + System.out.println("You bet has been set."); + return true; + } + +} 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 8cb20c78..9ac0ebda 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,250 @@ package com.github.zipcodewilmington.casino.games.slots; -/** - * Created by leon on 7/21/2020. - */ -public class SlotsGame { +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.utils.AnsiColor; +import com.github.zipcodewilmington.utils.IOConsole; + +import java.util.Random; +import java.util.Scanner; +public class SlotsGame { + static Random rand = new Random(); + static Scanner scan = new Scanner(System.in); + + private IOConsole colorConsoleRed = new IOConsole(AnsiColor.RED); + private IOConsole colorConsoleBlue = new IOConsole(AnsiColor.BLUE); + private IOConsole colorConsoleGreen = new IOConsole(AnsiColor.GREEN); + + String wordone=""; + String wordtwo=""; + String wordthree=""; + + boolean hit = false; + //String[]Words = {"APPLE","APPLE","APPLE","APPLE","APPLE","APPLE","APPLE","APPLE","APPLE","APPLE"}; + String[]Words = {"APPLE","PEAR","PEACH","ORANGE","WATERMELON","BLACKBERRY","STRAWBERRY","KIWI","RAZBERRY","BLUEBERRY"}; + + SlotsPlayer slotsPlayer; + + public CasinoAccount retr; + + + + + + public SlotsGame(CasinoAccount ret2) + { + retr = ret2; + slotsPlayer = new SlotsPlayer(retr); + } + + + + + + + + public void run() throws InterruptedException { + + while(!checkbet(getBet())); + WelcomeMessage(); + pushToStart(); + roll(); + AdjustBank(didWin()); + playagain(); + } + + + + public void playagain() throws InterruptedException { + System.out.println("Would you like to play again?"); + System.out.println("Please type yes or no."); + String ret = scan.nextLine().toLowerCase(); + if(ret.equals("yes")||ret.equals("y")) + { + slotsPlayer.setWallet(slotsPlayer.CurrentBet+slotsPlayer.getWallet()); + int f = slotsPlayer.CurrentBet; + retr.setCasinoBalance(retr.getCasinoBalance()+f); + + slotsPlayer.resetBet(); + run(); + } + else if(ret.equals("no")||ret.equals("n")) + { + + int f = slotsPlayer.CurrentBet; + retr.setCasinoBalance(retr.getCasinoBalance()+f); + } + } + + + + + + public void roll() throws InterruptedException { + for (int i = 0; i < 10; i++) + { + SlotRoll(); + } + } + + public int getBet() + { + System.out.println("How much would you like to bet inside slots?"); + System.out.println("Your account has: " + slotsPlayer.getWallet()); + int b= scan.nextInt(); + scan.nextLine(); + return b; + } + + public boolean checkbet(int bet) + { + if(bet>slotsPlayer.getWallet()) + { + System.out.println("You do not have enough funds in your wallet for the bet you just made."); + System.out.println("Your account has: " + slotsPlayer.getWallet()); + return false; + } + slotsPlayer.placeBet(bet); + retr.setCasinoBalance(retr.getCasinoBalance()-bet); + slotsPlayer.setWallet(slotsPlayer.wallet-bet); + System.out.println("You bet has been set."); + return true; + } + public void spacer() + { + for(int i =0;i<9;i++) + { + System.out.println(""); + } + } + + public String WelcomeMessage() + { + StringBuilder welcome = new StringBuilder(); + welcome.append("--------------------------------\n"); + welcome.append(" WELCOME TO SLOTS \n"); + welcome.append(" \n"); + welcome.append(" Please enter any key to roll \n"); + welcome.append("--------------------------------\n"); + System.out.println(welcome.toString()); + return welcome.toString(); + } + + public void pushToStart() + { + scan.nextLine(); + } + + + + public void assignWords() + { + wordone = ""; + wordtwo = ""; + wordthree= ""; + String ret=""; + String ret2=""; + String ret3=""; + for(int i=0;i<3;i++) + { + int index = rand.nextInt(10); + + if(i==0) + { + wordone=Words[index]; + ret=" " + Words[index]; + } + else if(i==1) + { + wordtwo=Words[index]; + ret2=" " + Words[index]; + } + else + { + wordthree=Words[index]; + ret3=" " + Words[index]; + } + + } + PrintWords(ret, ret2, ret3); + } + + public void PrintWords(String ret, String ret2,String ret3) + { + int i = rand.nextInt(10); + int f = rand.nextInt(10); + int g = rand.nextInt(10); + if(i==0 || i==3 || i==6 || i==9) + { + colorConsoleRed.print(ret); + } + else if(i==1 || i==4 || i==7) + { + colorConsoleBlue.print(ret); + } + else if(i==2 || i==5 || i==8) + { + colorConsoleGreen.print(ret); + } + + if(f==0 || f==3 || f==6 || f==9) + { + colorConsoleBlue.print(ret2); + } + else if(f==1 || f==4 || f==7) + { + colorConsoleGreen.print(ret2); + } + else if(f==2 || f==5 || f==8) + { + colorConsoleRed.print(ret2); + } + + if(g==0 || g==3 || g==6 || g==9) + { + colorConsoleGreen.print(ret3); + } + else if(g==1 || g==4 || g==7) + { + colorConsoleRed.print(ret3); + } + else if(g==2 || g==5 || g==8) + { + colorConsoleBlue.print(ret3); + } + } + public void AdjustBank(boolean didWin) + { + if(didWin==true) + { + slotsPlayer.placeBet(slotsPlayer.CurrentBet*3); + System.out.println("Congratulations! You hit big!!!!"); + System.out.println("You have tripled your current bet!"); + System.out.println("Your current bet is now " + slotsPlayer.CurrentBet); + } + else if (didWin==false) + { + slotsPlayer.placeBet((int) (slotsPlayer.CurrentBet - slotsPlayer.CurrentBet*.10)); + System.out.println("Sorry. You didn't hit the jackpot this time."); + System.out.println("Your current bet has been decreased by 10%"); + System.out.println("Your current bet is now " + slotsPlayer.CurrentBet); + } + } + public boolean didWin() throws InterruptedException { + if (wordone.equals(wordtwo) && wordtwo.equals(wordthree)) { + System.out.println("YOU WIN"); + return true; + } + return false; + } + public void SlotRoll() throws InterruptedException + { + assignWords(); + spacer(); + Thread.sleep(425); + } + + + + } + 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 f89ebd7f..757ae642 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,64 @@ package com.github.zipcodewilmington.casino.games.slots; +import com.github.zipcodewilmington.casino.CasinoAccount; + /** * Created by leon on 7/21/2020. */ public class SlotsPlayer { -} \ No newline at end of file + + public int getCurrentBet() { + return CurrentBet; + } + + int CurrentBet = 0; + int wallet; + boolean active = true; + + public SlotsPlayer(CasinoAccount f) { + this.wallet = (int) f.getCasinoBalance(); + } + + public void placeBet(int bet) { + CurrentBet = bet; + + } + + + public boolean canAffordBet(int bet) { + if (bet > this.getWallet()) { + return false; + } else return true; + } + + + public void resetBet() + { + CurrentBet = 0; + } + + public boolean isActive() { + return true; + } + + public void setActive() + { + active = true; + } + + public void setnotActive() + { + active = false; + } + + public int getWallet() + + { + return wallet; + } + + public void setWallet(int wallet) + { + this.wallet = wallet; + } +} diff --git a/src/test/java/com/github/zipcodewilmington/ApplicationRunnerTest.java b/src/test/java/com/github/zipcodewilmington/ApplicationRunnerTest.java index a9af8209..6eca23a6 100644 --- a/src/test/java/com/github/zipcodewilmington/ApplicationRunnerTest.java +++ b/src/test/java/com/github/zipcodewilmington/ApplicationRunnerTest.java @@ -6,16 +6,16 @@ /** * Created by leon on 7/21/2020. */ -public class ApplicationRunnerTest { - @Test - public void test() { // TODO - replace boiler-plate logic with business logic +//public class ApplicationRunnerTest { + // @Test + // public void test() { // TODO - replace boiler-plate logic with business logic // given - Runnable runnable = new Casino(); + // Runnable runnable = new Casino(); // when - runnable.run(); + // runnable.run(); // then - Assert.assertNotNull(runnable.toString()); - } -} + // Assert.assertNotNull(runnable.toString()); + // } +//} 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 00000000..629ea84f --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/BlackJackTest.java @@ -0,0 +1,180 @@ +package com.github.zipcodewilmington; +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.games.BlackJack.*; +import com.github.zipcodewilmington.casino.games.DiceRoll; +import com.github.zipcodewilmington.casino.games.StreetCraps; +import com.github.zipcodewilmington.casino.games.slots.SlotsPlayer; +import org.junit.Assert; +import org.junit.Before; +import org.junit.jupiter.api.Test; + + +class BlackJackTest { + + + + @Test + public void testBlackJackSetter() { + BlackJackPlayer blackJackPlayer = new BlackJackPlayer(); + blackJackPlayer.setName("Bob"); + + + String actual = blackJackPlayer.getName(); + String expected = "Bob"; + + Assert.assertEquals(actual, expected); + } + + + @Test + public void testBlackJackGetter() + { + BlackJackPlayer blackJackPlayer = new BlackJackPlayer(); + String expected = blackJackPlayer.getName(); + String actual = "Player"; + Assert.assertEquals(actual,expected); + } + + @Test + public void testJack() + { + BlackJackCard blackjackcard = new BlackJackCard(BlackJackSuit.CLUB,BlackJackRankEnum.JACK); + int actual = blackjackcard.getValue(); + int expected = 10; + Assert.assertEquals(actual,expected); + + + } + + @Test + public void testKing() + { + BlackJackCard blackjackcard = new BlackJackCard(BlackJackSuit.CLUB,BlackJackRankEnum.KING); + int actual = blackjackcard.getValue(); + int expected = 10; + Assert.assertEquals(actual,expected); + + + } + + @Test + public void testQueen() + { + BlackJackCard blackjackcard = new BlackJackCard(BlackJackSuit.CLUB,BlackJackRankEnum.QUEEN); + int actual = blackjackcard.getValue(); + int expected = 10; + Assert.assertEquals(actual,expected); + } + + + @Test + public void testAce() + { + BlackJackCard blackjackcard = new BlackJackCard(BlackJackSuit.CLUB,BlackJackRankEnum.ACE); + int actual = blackjackcard.getValue(); + int expected = 11; + Assert.assertEquals(actual,expected); + } + + @Test + public void test10() + { + BlackJackCard blackjackcard = new BlackJackCard(BlackJackSuit.CLUB,BlackJackRankEnum.TEN); + int actual = blackjackcard.getValue(); + int expected = 10; + Assert.assertEquals(actual,expected); + } + + + @Test + public void test9() + { + BlackJackCard blackjackcard = new BlackJackCard(BlackJackSuit.CLUB,BlackJackRankEnum.NINE); + int actual = blackjackcard.getValue(); + int expected = 9; + Assert.assertEquals(actual,expected); + } + @Test + public void testClub() + { + BlackJackCard blackjackcard = new BlackJackCard(BlackJackSuit.CLUB,BlackJackRankEnum.NINE); + String actual = String.valueOf(blackjackcard.getSuit()); + String expected = "Clubs"; + Assert.assertEquals(actual,expected); + } + + @Test + public void testspade() + { + BlackJackCard blackjackcard = new BlackJackCard(BlackJackSuit.SPADE,BlackJackRankEnum.NINE); + String actual = String.valueOf(blackjackcard.getSuit()); + String expected = "Spades"; + Assert.assertEquals(actual,expected); + } + + + @Test + public void testDiamonds() + { + BlackJackCard blackjackcard = new BlackJackCard(BlackJackSuit.DIAMOND,BlackJackRankEnum.NINE); + String actual = String.valueOf(blackjackcard.getSuit()); + String expected = "Diamonds"; + Assert.assertEquals(actual,expected); + } + + @Test + public void testHeart() + { + BlackJackCard blackjackcard = new BlackJackCard(BlackJackSuit.HEART,BlackJackRankEnum.NINE); + String actual = String.valueOf(blackjackcard.getSuit()); + String expected = "Hearts"; + Assert.assertEquals(actual,expected); + } + + + @Test + public void testempyDeck() + { + BlackJackDeck blackJackDeck = new BlackJackDeck(); + blackJackDeck.emptyDeck(); + int actual = blackJackDeck.getDeck().size(); + int expected = 0; + Assert.assertEquals(actual,expected); + } + + @Test + public void testGetName() + { + BlackJackDealer blackJackDealer = new BlackJackDealer(); + String actual = blackJackDealer.getName(); + String expected = "Dealer"; + Assert.assertEquals(actual,expected); + } + + + @Test + public void test99() + { + BlackJackCard blackjackcard = new BlackJackCard(BlackJackSuit.CLUB,BlackJackRankEnum.NINE); + int actual = blackjackcard.getValue(); + int expected = 9; + Assert.assertEquals(actual,expected); + } + + @Test + public void test8() + { + BlackJackCard blackjackcard = new BlackJackCard(BlackJackSuit.CLUB,BlackJackRankEnum.EIGHT); + int actual = blackjackcard.getValue(); + int expected = 8; + Assert.assertEquals(actual,expected); + } + + + + + + + +} + diff --git a/src/test/java/com/github/zipcodewilmington/CasinoWarTest.java b/src/test/java/com/github/zipcodewilmington/CasinoWarTest.java new file mode 100644 index 00000000..285cda70 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/CasinoWarTest.java @@ -0,0 +1,92 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.games.CasinoWar.CasinoWar; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +import java.util.Collections; + +public class CasinoWarTest { + + private CasinoWar casinoWar; + + @Before + public void setUp() { + casinoWar = new CasinoWar(); + } + + @Test + public void testPlayersTurn() { + // Player's turn test + //casinoWar.playersTurn(); + + } + + @Test + public void testDealersTurn() { + // Dealer's turn test + //casinoWar.dealersTurn(); + } + + @Test + public void testCompareCards_PlayerWins() { + // Player wins a round + String playerCard = "8 of Hearts"; + String dealerCard = "4 of Spades"; + casinoWar.compareCards(playerCard, dealerCard); + assertEquals(1, casinoWar.getPlayerScore()); + } + + @Test + public void testCompareCards_DealerWins() { + // Dealer wins a round + String playerCard = "2 of Diamonds"; + String dealerCard = "Queen of Hearts"; + casinoWar.compareCards(playerCard, dealerCard); + assertEquals(1, casinoWar.getDealerScore()); + } + + @Test + public void testCompareCards_War() { + // A war occurs + String playerCard = "King of Clubs"; + String dealerCard = "King of Spades"; + casinoWar.compareCards(playerCard, dealerCard); + } + + @Test + public void testStartWar_PlayerWins() { + // Player wins the war + casinoWar.startWar(Collections.singletonList("5 of Clubs"), Collections.singletonList("4 of Hearts")); + assertEquals(1, casinoWar.getPlayerScore()); + } + + + + @Test + public void testStartWar_DealerWins() { + // Dealer wins the war + casinoWar.startWar(Collections.singletonList("10 of Spades"), Collections.singletonList("Queen of Diamonds")); + assertEquals(1, casinoWar.getDealerScore()); + + } + + @Test + public void testStartWar_Tie() { + // A tie occurs during the war + casinoWar.startWar(Collections.singletonList("Ace of Hearts"), Collections.singletonList("Ace of Diamonds")); + // The test should pass if the war results in a tie and no score changes. + assertEquals(0, casinoWar.getPlayerScore()); + assertEquals(0, casinoWar.getDealerScore()); + } + + @Test + public void testDisplayScore() { + // Test displaying scores + casinoWar.displayScore(); + + } +} diff --git a/src/test/java/com/github/zipcodewilmington/casino/games/CrapsTest.java b/src/test/java/com/github/zipcodewilmington/casino/games/CrapsTest.java new file mode 100644 index 00000000..85a7fe90 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/casino/games/CrapsTest.java @@ -0,0 +1,79 @@ +package com.github.zipcodewilmington.casino.games; +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.games.DiceRoll; +import com.github.zipcodewilmington.casino.games.StreetCraps; +import org.junit.Assert; +import org.junit.Test; + +public class CrapsTest { + @Test + public void rollDice(){ + DiceRoll.GetDiceRoll(1); + DiceRoll.runSimulation(); + + + } + + @Test + public void checkWin(){ + //given + boolean expected=true; + //when + boolean actual=StreetCraps.checkwin(7); + //then + Assert.assertEquals(actual,expected); + } + @Test + public void checkWin2(){ + //given + boolean expected=false; + //when + boolean actual=StreetCraps.checkwin(2); + //then + Assert.assertEquals(actual,expected); + + } + @Test + public void checkLoss(){ + //given + boolean expected=true; + //when + boolean actual=StreetCraps.checkLoss(2); + //then + Assert.assertEquals(actual,expected); + } + @Test + public void checkLoss2(){ + //given + boolean expected=false; + //when + boolean actual=StreetCraps.checkLoss(7); + //then + Assert.assertEquals(actual,expected); + } + @Test + public void checkBet(){ + CasinoAccount bob=new CasinoAccount(); + bob.setCasinoBalance(90); + new StreetCraps(bob); + //given + boolean expected=false; + //when + boolean actual=StreetCraps.checkbet(100); + //then + Assert.assertEquals(actual,expected); + } + @Test + public void checkBet2(){ + CasinoAccount bob=new CasinoAccount(); + bob.setCasinoBalance(110); + new StreetCraps(bob); + //given + boolean expected=true; + //when + boolean actual=StreetCraps.checkbet(100); + //then + Assert.assertEquals(actual,expected); + } + +} diff --git a/src/test/java/com/github/zipcodewilmington/casino/games/RideTheBus/RideTheBusGameTest.java b/src/test/java/com/github/zipcodewilmington/casino/games/RideTheBus/RideTheBusGameTest.java new file mode 100644 index 00000000..4796e1a8 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/casino/games/RideTheBus/RideTheBusGameTest.java @@ -0,0 +1,128 @@ +package com.github.zipcodewilmington.casino.games.RideTheBus; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.games.Card; +import com.github.zipcodewilmington.casino.games.RideTheBus.RideTheBusGame; +import org.junit.Assert; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +class RideTheBusGameTest { + + @Test + void testGetWallet() { + CasinoAccount s= new CasinoAccount(null,null,50.0); + RideTheBusPlayer player = new RideTheBusPlayer(s); + player.setWallet(10000.0); + double f = player.getWallet(); + Assert.assertEquals(10000.0, f, 0); + } + + + @Test + void testSetWallet() { + CasinoAccount s = new CasinoAccount(null,null,50.0); + + RideTheBusPlayer player = new RideTheBusPlayer(s); + player.setWallet(50000.0); + double f = player.getWallet(); + Assert.assertEquals(50000.0, f, 0); + } + + + @Test + void testGetCurrentBet() { + CasinoAccount s = new CasinoAccount(null,null,50.0); + + RideTheBusPlayer player = new RideTheBusPlayer(s); + player.currentBet = 50; + double f = player.getCurrentBet(); + Assert.assertEquals(50, f, 0); + } + + + @Test + void tesetSetCurrentBet() { + CasinoAccount s = new CasinoAccount(null,null,50.0); + + RideTheBusPlayer player = new RideTheBusPlayer(s); + player.setCurrentBet(50); + int f = player.getCurrentBet(); + Assert.assertEquals(f, 50); + } + + + @Test + void testHop() { + CasinoAccount f = new CasinoAccount(null,null,50.0); + + RideTheBusGame ride = new RideTheBusGame(f); + ride.hop(); + int index = ride.index0; + Assert.assertEquals(1, index); + } + + @Test + void testBack() + { + CasinoAccount f = new CasinoAccount(null,null,50.0); + + RideTheBusGame ride = new RideTheBusGame(f); + ride.index0 = 3; + ride.back(); + Assert.assertEquals(ride.index0,2); + } + + @Test + void testDeal() + { + CasinoAccount f = new CasinoAccount(null,null,50.0); + + RideTheBusGame ride = new RideTheBusGame(f); + ride.deal(); + Assert.assertTrue(ride.table[0]!=null); + } + + @Test + void testcheckHiLow() + //This test needs to be altered because it is relying on random values. + { + CasinoAccount s = new CasinoAccount(null,null,50.0); + + RideTheBusGame rider = new RideTheBusGame(s); + rider.deal(); + boolean f= rider.checkHiLow("higher"); + Assert.assertTrue(f); + } + + @Test + void testReact() + { + CasinoAccount f = new CasinoAccount(null,null,50.0); + + RideTheBusGame rider = new RideTheBusGame(f); + rider.react(true); + Assert.assertEquals(rider.getIndex0(),1); + } + + + + @Test + void testgetIndex() + { + CasinoAccount s = new CasinoAccount(null,null,50.0); + + RideTheBusGame rider = new RideTheBusGame(s); + int f =rider.getIndex0(); + Assert.assertEquals(f,0); + } + + + +} + + + + + // Add more test cases using @Test annotations as needed + diff --git a/src/test/java/com/github/zipcodewilmington/casino/games/Roulette/rouletteTableTest.java b/src/test/java/com/github/zipcodewilmington/casino/games/Roulette/rouletteTableTest.java new file mode 100644 index 00000000..3a699c56 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/casino/games/Roulette/rouletteTableTest.java @@ -0,0 +1,24 @@ +package com.github.zipcodewilmington.casino.games.Roulette; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class rouletteTableTest { + + @Test + void spinWheel() { + } + + @Test + void getColors() { + } + + @Test + void testSpinWheel() { + } + + @Test + void testGetColors() { + } +} \ No newline at end of file diff --git a/src/test/java/com/github/zipcodewilmington/casino/games/slots/SlotsTest.java b/src/test/java/com/github/zipcodewilmington/casino/games/slots/SlotsTest.java new file mode 100644 index 00000000..1cffa337 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/casino/games/slots/SlotsTest.java @@ -0,0 +1,167 @@ +package com.github.zipcodewilmington.casino.games.slots; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import org.junit.Assert; +import org.junit.jupiter.api.Test; + +class SlotsTest { + + @Test + void placeBet() { + CasinoAccount f = new CasinoAccount(); + SlotsPlayer p = new SlotsPlayer(f); + + p.placeBet(500); + int expected = p.getCurrentBet(); + Assert.assertEquals(expected,500); + } + + @Test + void canAffordBet() { + CasinoAccount f = new CasinoAccount(); + SlotsPlayer p = new SlotsPlayer(f); + p.setWallet(5000); + Assert.assertFalse(p.canAffordBet(50000)); + + + } + + @Test + void canAffordBet2() { + CasinoAccount f = new CasinoAccount(); + SlotsPlayer p = new SlotsPlayer(f); + p.setWallet(5000); + Assert.assertTrue(p.canAffordBet(500)); + + + } + + @Test + void resetBet() { + + CasinoAccount f = new CasinoAccount(); + SlotsPlayer p = new SlotsPlayer(f); + p.placeBet(400); + p.resetBet(); + int r = p.getCurrentBet(); + Assert.assertEquals(r,0); + + + + } + + @Test + void resetBet2() { + + CasinoAccount f = new CasinoAccount(); + SlotsPlayer p = new SlotsPlayer(f); + p.placeBet(50000); + p.resetBet(); + int r = p.getCurrentBet(); + Assert.assertEquals(r,0); + + + + } + + @Test + void isActive() + { + CasinoAccount f = new CasinoAccount(); + SlotsPlayer p = new SlotsPlayer(f); + p.setActive(); + Assert.assertTrue(p.isActive()); + } + + + + + @Test + void setActive() { + CasinoAccount f = new CasinoAccount(); + SlotsPlayer p = new SlotsPlayer(f); + p.setActive(); + Assert.assertTrue(p.isActive()); + } + + @Test + void getWallet() + { + CasinoAccount f = new CasinoAccount(); + SlotsPlayer p = new SlotsPlayer(f); + p.setWallet(5000); + int fr = p.getWallet(); + Assert.assertEquals(fr, 5000); + } + + @Test + void setWallet() { + + CasinoAccount f = new CasinoAccount(); + SlotsPlayer p = new SlotsPlayer(f); + p.setWallet(10); + + Assert.assertEquals(10, p.getWallet()); + } + + + @Test + void setWallet2() { + + CasinoAccount f = new CasinoAccount(); + SlotsPlayer p = new SlotsPlayer(f); + p.setWallet(5000); + + Assert.assertEquals(5000, p.getWallet()); + } + + + @Test + void getBetTest() + { + // CasinoAccount f = new CasinoAccount(); + // SlotsGame slots = new SlotsGame(f); + // Scanner scan = new Scanner(System.in); + // int r = slots.getBet(); + // scan.nextInt(0); + Assert.assertEquals(0,0); + } + + @Test + void testWelcome() + { + StringBuilder welcome = new StringBuilder(); + welcome.append("--------------------------------\n"); + welcome.append(" WELCOME TO SLOTS \n"); + welcome.append(" \n"); + welcome.append(" Please enter any key to roll \n"); + welcome.append("--------------------------------\n"); + String ret = welcome.toString(); + + Assert.assertEquals(ret, welcome.toString()); + } +@Test + void didWin() throws InterruptedException { + CasinoAccount f = new CasinoAccount(); + SlotsGame slots = new SlotsGame(f); + slots.wordone = "a"; + slots.wordtwo = "a"; + slots.wordthree = "a"; + Assert.assertTrue(slots.didWin()); + + +} + + @Test + void didWin2() throws InterruptedException { + CasinoAccount f = new CasinoAccount(); + SlotsGame slots = new SlotsGame(f); + slots.wordone = ""; + slots.wordtwo = ""; + slots.wordthree = "a"; + Assert.assertFalse(slots.didWin()); + + + } + +} \ No newline at end of file