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..dcf35465 100644 --- a/src/main/java/com/github/zipcodewilmington/Casino.java +++ b/src/main/java/com/github/zipcodewilmington/Casino.java @@ -4,21 +4,27 @@ import com.github.zipcodewilmington.casino.CasinoAccountManager; import com.github.zipcodewilmington.casino.GameInterface; import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.RideTheBus.RideTheBusGame; 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 { @@ -26,15 +32,29 @@ public void run() { 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()); - } else { + 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.playCasinoWar(); + + } + else { // TODO - implement better exception handling String errorMessage = "[ %s ] is an invalid game selection"; throw new RuntimeException(String.format(errorMessage, gameSelectionInput)); @@ -49,7 +69,8 @@ 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)); } @@ -66,14 +87,13 @@ 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 ]") .toString()); } - private void play(Object gameObject, Object 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/CasinoWar.java b/src/main/java/com/github/zipcodewilmington/CasinoWar.java new file mode 100644 index 00000000..f941b67f --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/CasinoWar.java @@ -0,0 +1,140 @@ +package com.github.zipcodewilmington; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Scanner; + +public class CasinoWar { + + + + + static void playCasinoWar() { + Scanner scanner = new Scanner(System.in); + + // Change to call deck + List deck = createShuffledDeck(); + + int playerScore = 0; + int dealerScore = 0; + + while (!deck.isEmpty()) { + // Player's turn + System.out.println("Press Enter to draw a card."); + scanner.nextLine(); + String playerCard = drawCard(deck); + System.out.println("You drew: " + playerCard); + int playerCardValue = getCardValue(playerCard); + + // Dealer's turn + System.out.println("Press Enter for the dealer to draw a card."); + scanner.nextLine(); + String dealerCard = drawCard(deck); + System.out.println("Dealer drew: " + dealerCard + "\n"); + int dealerCardValue = getCardValue(dealerCard); + + // Compare the cards + if (playerCardValue > dealerCardValue) { + System.out.println("You win this round!"); + playerScore++; + } else if (dealerCardValue > playerCardValue) { + 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 < 2; i++) { + playerWarCards.add(drawCard(deck)); + dealerWarCards.add(drawCard(deck)); + } + + // Get the fourth card for comparison + String playerFourthCard = drawCard(deck); + String dealerFourthCard = drawCard(deck); + + 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."); + } + } + + + // 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!"); + break; + } + + + // Ask the player if they want to continue playing + System.out.println("\n Press enter to play again or (exit) to leave."); + String input = scanner.nextLine(); + if (input.equalsIgnoreCase("exit")) { + System.out.println("Thanks for playing! Final scores:"); + System.out.println("Your score: " + playerScore); + System.out.println("Dealer's score: " + dealerScore); + break; + } + } + + scanner.close(); + } + + private static 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 static String drawCard(List deck) { + return deck.remove(deck.size() - 1); + } + + private static 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); + } + } + + +} + + diff --git a/src/main/java/com/github/zipcodewilmington/MainApplication.java b/src/main/java/com/github/zipcodewilmington/MainApplication.java index 508787a8..45ac34a9 100644 --- a/src/main/java/com/github/zipcodewilmington/MainApplication.java +++ b/src/main/java/com/github/zipcodewilmington/MainApplication.java @@ -1,7 +1,9 @@ package com.github.zipcodewilmington; public class MainApplication { - public static void main(String[] args) { + + 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..3e40f283 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/Accounts.txt @@ -0,0 +1,6 @@ +Santos,Santos,123,100.0 +Kantos,kantos,ugh,1000.0 +BobLee,BobLee,4321,0.0 +hans,hans,4321,0.0 +bans,bans,4321,0.0 +Deep,Deep,rollinginthedeep,0.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..b58f4b53 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java @@ -6,4 +6,49 @@ * The `ArcadeAccount` is used to log into the system to select a `Game` to play. */ public class CasinoAccount { + // 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 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/BlackJack.java b/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/BlackJack.java new file mode 100644 index 00000000..642f39af --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/BlackJack.java @@ -0,0 +1,20 @@ +package com.github.zipcodewilmington.casino.games.BlackJack; +import com.github.zipcodewilmington.casino.games.Deck; + +public class BlackJack { + + // created variables for the blackjack game class + private int wins; + private int losses; + private int pushes; + +//created a constructor for the blackjack game class + public BlackJack(){ + wins = 0; + losses = 0; + pushes = 0; //anytime a blackjack object is made it is automatically going to be 0 + } + //create and start the game here + + +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/Rank.java b/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/Rank.java new file mode 100644 index 00000000..e27f8502 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/Rank.java @@ -0,0 +1,28 @@ +package com.github.zipcodewilmington.casino.games.BlackJack; + +public enum Rank { + + 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; + Rank(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/Suit.java b/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/Suit.java new file mode 100644 index 00000000..116695e3 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/BlackJack/Suit.java @@ -0,0 +1,22 @@ +package com.github.zipcodewilmington.casino.games.BlackJack; + +public enum Suit { + + + CLUB("Clubs"), + DIAMOND("Diamonds"), + HEART("Hearts"), + SPADE("Spades"); + String suitName; + + Suit(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..e1faffe7 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/CasinoWar/CasinoWar.java @@ -0,0 +1,154 @@ +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 static void main(String[] args) { + CasinoWar casinoWar = new CasinoWar(); + + while (!casinoWar.deck.isEmpty()) { + casinoWar.playersTurn(); + casinoWar.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..84f8cbac --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Deck.java @@ -0,0 +1,38 @@ +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..53182ba5 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/RideTheBus/RideTheBusGame.java @@ -0,0 +1,275 @@ +package com.github.zipcodewilmington.casino.games.RideTheBus; + +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; + } + CasinoAccount f; + RideTheBusPlayer rider; + Deck deckobj = new Deck(); + Card[] table = new Card[4]; + int index0; + Scanner scan = new Scanner(System.in); + +public RideTheBusGame(CasinoAccount person) +{ + f = 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(f); + 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 = rider.getCurrentBet()*2; + System.out.println("Your returns are: " + winnings); + rider.setWallet(rider.getWallet()+winnings); + } + } + + 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); + 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) + { + System.out.println("Your guess was right, moving up!"); + hop(); + } + else if (logic == false) + { + if (getIndex0() != 0) + { + System.out.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) { + System.out.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() + { + 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/rouletteGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/Roulette/rouletteGame.java new file mode 100644 index 00000000..2e73b792 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Roulette/rouletteGame.java @@ -0,0 +1,66 @@ +package com.github.zipcodewilmington.casino.games.Roulette; +import java.util.Random; +import java.util.Scanner; + + +public class rouletteGame{ + + static Random rand = 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 String 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]: "); + + + + } + + + + + + + + +} + + + + + +} 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..fd703f90 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Roulette/roulettePlayer.java @@ -0,0 +1,8 @@ +package com.github.zipcodewilmington.casino.games.Roulette; + +public class roulettePlayer { + + + + +} 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..96e41cbb --- /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..8d39ba81 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/StreetCraps.java @@ -0,0 +1,90 @@ +package com.github.zipcodewilmington.casino.games; +import com.github.zipcodewilmington.casino.games.DiceRoll; + +import java.util.Scanner; + +public class StreetCraps { + + 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 Scanner in=new Scanner(System.in); + + + public static void main(String[] args) { + int currentRoll; + + while (!win && !gameover && !rollagain) { + System.out.println("press any key to roll dice:"); + in.nextLine(); + currentRoll = rollDice(); + if(checkwin(currentRoll)){ + win=true; + } + else if (checkLoss(currentRoll)){ + gameover=true; + } + else{ + point = currentRoll; + while(!rollagain) { + rollagain=rollAgain(); + + } + } + + + } + } + + public static boolean rollAgain(){ + int rolledAgainRoll; + System.out.println("Roll again!:"); + in.nextLine(); + rolledAgainRoll=rollDice(); + if(rolledAgainRoll==point){ + System.out.println("you won"); + 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; + } +} 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..5594d96d 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,245 @@ 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.casino.GameInterface; +import com.github.zipcodewilmington.casino.PlayerInterface; +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","PEAR","PEACH","ORANGE","WATERMELON","APPLE","STRAWBERRY","KIWI","RASBERRY","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")) + { + + run(); + } + else if(ret=="no"||ret=="n") + { + slotsPlayer.setWallet(slotsPlayer.wallet+ slotsPlayer.CurrentBet); + retr.setCasinoBalance(retr.getCasinoBalance()+ slotsPlayer.getWallet()); + } + } + + + + + + 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); + 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/CasinoWarTest.java b/src/test/java/com/github/zipcodewilmington/CasinoWarTest.java new file mode 100644 index 00000000..3b7b76cc --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/CasinoWarTest.java @@ -0,0 +1,89 @@ +package com.github.zipcodewilmington; + + +import static org.junit.Assert.assertEquals; + +import com.github.zipcodewilmington.casino.games.CasinoWar.CasinoWar; +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/CrapsTest.java b/src/test/java/com/github/zipcodewilmington/CrapsTest.java new file mode 100644 index 00000000..4bf6250c --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/CrapsTest.java @@ -0,0 +1,54 @@ +package com.github.zipcodewilmington; +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); + } + +} 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..c6d43681 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/casino/games/RideTheBus/RideTheBusGameTest.java @@ -0,0 +1,108 @@ +package com.github.zipcodewilmington.casino.games.RideTheBus; + +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() { + RideTheBusPlayer player = new RideTheBusPlayer(); + player.setWallet(10000.0); + double f = player.getWallet(); + Assert.assertEquals(10000.0, f, 0); + } + + + @Test + void testSetWallet() { + RideTheBusPlayer player = new RideTheBusPlayer(); + player.setWallet(50000.0); + double f = player.getWallet(); + Assert.assertEquals(50000.0, f, 0); + } + + + @Test + void testGetCurrentBet() { + RideTheBusPlayer player = new RideTheBusPlayer(); + player.currentBet = 50; + double f = player.getCurrentBet(); + Assert.assertEquals(50, f, 0); + } + + + @Test + void tesetSetCurrentBet() { + RideTheBusPlayer player = new RideTheBusPlayer(); + player.setCurrentBet(50); + int f = player.getCurrentBet(); + Assert.assertEquals(f, 50); + } + + + @Test + void testHop() { + RideTheBusGame ride = new RideTheBusGame(); + ride.hop(); + int index = ride.index0; + Assert.assertEquals(1, index); + } + + @Test + void testBack() + { + RideTheBusGame ride = new RideTheBusGame(); + ride.index0 = 3; + ride.back(); + Assert.assertEquals(ride.index0,2); + } + + @Test + void testDeal() + { + RideTheBusGame ride = new RideTheBusGame(); + ride.deal(); + Assert.assertTrue(ride.table[0]!=null); + } + + @Test + void testcheckHiLow() + //This test needs to be altered because it is relying on random values. + { + RideTheBusGame rider = new RideTheBusGame(); + rider.deal(); + boolean f= rider.checkHiLow("higher"); + Assert.assertTrue(f); + } + + @Test + void testReact() + { + RideTheBusGame rider = new RideTheBusGame(); + rider.react(true); + Assert.assertEquals(rider.getIndex0(),1); + } + + + + @Test + void testgetIndex() + { + RideTheBusGame rider = new RideTheBusGame(); + 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