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/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..82d7683e 100644 --- a/src/main/java/com/github/zipcodewilmington/Casino.java +++ b/src/main/java/com/github/zipcodewilmington/Casino.java @@ -4,6 +4,7 @@ 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; @@ -19,6 +20,8 @@ public class Casino implements Runnable { @Override public void run() { + CasinoAccountManager.addAllAccounts(); + String arcadeDashBoardInput; CasinoAccountManager casinoAccountManager = new CasinoAccountManager(); do { @@ -26,14 +29,23 @@ 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()); + SlotsGame slots = new SlotsGame(casinoAccount); + try { + slots.run(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } else if (gameSelectionInput.equals("RIDETHEBUS")) { + RideTheBusGame ride = new RideTheBusGame(); + ride.start(); + } else { // TODO - implement better exception handling String errorMessage = "[ %s ] is an invalid game selection"; @@ -49,7 +61,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,11 +79,11 @@ 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 ]") .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); 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..70fe3be3 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/CasinoWar.java @@ -0,0 +1,141 @@ +package com.github.zipcodewilmington; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Scanner; + +public class CasinoWar { + + public static void main(String[] args) { + playCasinoWar(); + } + + 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..237528ee 100644 --- a/src/main/java/com/github/zipcodewilmington/MainApplication.java +++ b/src/main/java/com/github/zipcodewilmington/MainApplication.java @@ -2,6 +2,7 @@ public class MainApplication { public static void main(String[] args) { + 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..a4bc2cb8 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/Accounts.txt @@ -0,0 +1,4 @@ +Santos,Santos,123,100.0 +BobLee,BobLee,4321,0.0 +hans,hans,4321,0.0 +bans,bans,4321,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..6bbee95e 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` * @@ -26,10 +58,19 @@ public CasinoAccount getAccount(String accountName, String accountPassword) { * @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; + + } /** @@ -38,9 +79,72 @@ 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 { + + // create new BufferedWriter for the output file + bf = new BufferedWriter(new FileWriter(file)); + + // iterate map entries + 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/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/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/RideTheBus/RideTheBusGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/RideTheBus/RideTheBusGame.java new file mode 100644 index 00000000..36f703c4 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/RideTheBus/RideTheBusGame.java @@ -0,0 +1,250 @@ +package com.github.zipcodewilmington.casino.games.RideTheBus; + +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 { + public RideTheBusPlayer getRider() { + return rider; + } + + RideTheBusPlayer rider; + Deck deckobj = new Deck(); + Card[] table = new Card[4]; + int index0; + Scanner scan = new Scanner(System.in); + + 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(); + 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?"); + + 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()); + } + + +} 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..7883d331 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/RideTheBus/RideTheBusPlayer.java @@ -0,0 +1,29 @@ +package com.github.zipcodewilmington.casino.games.RideTheBus; + +public class RideTheBusPlayer { + + + double wallet =0; + int currentBet=0; + public RideTheBusPlayer() + { + this.wallet = 10000; + } + + + 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..c7555d54 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Roulette/rouletteGame.java @@ -0,0 +1,8 @@ +package com.github.zipcodewilmington.casino.games.Roulette; + +public class rouletteGame { + + + + +} 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..7a69d94e --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/Roulette/rouletteTable.java @@ -0,0 +1,80 @@ +package com.github.zipcodewilmington.casino.games.Roulette; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Random; + + +public class rouletteTable { + private ArrayList numbers; + private String colors; + Random random = new Random(); + + + + public rouletteTable(ArrayList numbers) { + this.numbers = numbers; + + rouletteGetNumbers(); + rouletteGetColors(); + } + + private void rouletteGetNumbers () { + for (int i = 0; i <= 36; i++) { + numbers.add(i); + } + } + private void rouletteGetColors () { + HashMap numbertocolor = new HashMap<>(); + 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 num + } + + + + +} 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..df2bbb77 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/StreetCraps.java @@ -0,0 +1,5 @@ +package com.github.zipcodewilmington.casino.games; + +public class StreetCraps { + +} 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..a74c4377 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,244 @@ package com.github.zipcodewilmington.casino.games.slots; -/** - * Created by leon on 7/21/2020. - */ +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.PlayerInterface; +import com.github.zipcodewilmington.casino.games.RideTheBus.RideTheBusPlayer; +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")) + { + slotsPlayer.setWallet(slotsPlayer.wallet+ slotsPlayer.CurrentBet); + 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() + { + String ret=""; + String ret2=""; + String ret3=""; + for(int i=0;i<3;i++) + { + int index = rand.nextInt(10); + ret=" " + Words[index]; + if(i==0) + { + wordone=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 trippled your current bet!"); + System.out.println("Your balance 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 balance 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..a2b708f7 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,56 @@ 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 + + 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 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..143b6533 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/CasinoWarTest.java @@ -0,0 +1,33 @@ +package com.github.zipcodewilmington; + +import org.junit.Assert; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class CasinoWarTest { + + private CasinoWar game; + + @BeforeEach + public void setUp() { + game = new CasinoWar(); + + } + + @org.junit.Test + public void testPlayCasinoWar() { + CasinoWar runnable = new CasinoWar(); + runnable.playCasinoWar(); + Assert.assertNotNull(runnable.toString()); + } + + @Test + void testDeclareWinner() { + + int playerScore = 0; + int actual = playerScore + 1; + Assertions.assertEquals(1, actual); + + } +} 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..371f7ae1 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/casino/games/RideTheBus/RideTheBusGameTest.java @@ -0,0 +1,65 @@ +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.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +class RideTheBusGameTest { + + RideTheBusGame rideTheBusGame = new RideTheBusGame(); + + @Test + public void testCheckBet() { + + rideTheBusGame.getRider().setWallet(100); // Set wallet balance to 100 + int bet = 50; + assertTrue(rideTheBusGame.checkbet(bet)); + } + + @Test + public void testtInsufficientFunds() { + RideTheBusPlayer rider = new RideTheBusPlayer(); + rider.setWallet(100); + int bet = 150; + assertFalse(rideTheBusGame.checkbet(bet)); + } + + @Test + public void testCheckHiLow() { + rideTheBusGame.index0 = 0; + rideTheBusGame.table[0] = new Card("Diamonds", 13,"Red","diamonds"); + boolean result = rideTheBusGame.checkHiLow("higher"); + assertTrue(result); + + result = rideTheBusGame.checkHiLow("lower"); + assertFalse(result); + } + + @Test + public void testCheckColor() { + rideTheBusGame.index0 = 2; + rideTheBusGame.table[2] = new Card("Diamonds", 5, "black","clubs"); + boolean result = rideTheBusGame.checkColor("red"); + assertFalse(result); + + result = rideTheBusGame.checkColor("black"); + assertTrue(result); + } + + @Test + public void testCheckSuit() { + rideTheBusGame.index0 = 3; + rideTheBusGame.table[3] = new Card("5", 5,"red","diamonds"); + boolean result = rideTheBusGame.checkSuit("spades"); + assertFalse(result); + + result = rideTheBusGame.checkSuit("diamonds"); + assertTrue(result); + } + + + + + // 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..41801e22 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/casino/games/Roulette/rouletteTableTest.java @@ -0,0 +1,17 @@ +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() { + } + +} \ No newline at end of file