diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 000000000..289baba98 Binary files /dev/null and b/.DS_Store differ diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 000000000..e4eb065f6 Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/main/.DS_Store b/src/main/.DS_Store new file mode 100644 index 000000000..12e609c25 Binary files /dev/null and b/src/main/.DS_Store differ diff --git a/src/main/java/.DS_Store b/src/main/java/.DS_Store new file mode 100644 index 000000000..0fbbfc2ca Binary files /dev/null and b/src/main/java/.DS_Store differ diff --git a/src/main/java/io/.DS_Store b/src/main/java/io/.DS_Store new file mode 100644 index 000000000..49995abd3 Binary files /dev/null and b/src/main/java/io/.DS_Store differ diff --git a/src/main/java/io/zipcoder/.DS_Store b/src/main/java/io/zipcoder/.DS_Store new file mode 100644 index 000000000..8d27bf37b Binary files /dev/null and b/src/main/java/io/zipcoder/.DS_Store differ diff --git a/src/main/java/io/zipcoder/casino/.DS_Store b/src/main/java/io/zipcoder/casino/.DS_Store new file mode 100644 index 000000000..779a17dff Binary files /dev/null and b/src/main/java/io/zipcoder/casino/.DS_Store differ diff --git a/src/main/java/io/zipcoder/casino/Casino.java b/src/main/java/io/zipcoder/casino/Casino.java index 16ca0dd74..188e53e43 100644 --- a/src/main/java/io/zipcoder/casino/Casino.java +++ b/src/main/java/io/zipcoder/casino/Casino.java @@ -1,8 +1,12 @@ package io.zipcoder.casino; +import io.zipcoder.casino.player.Player; + public class Casino { public static void main(String[] args) { // write your tests before you start fucking with this + Handler handler = new Handler(); + handler.run(); } } diff --git a/src/main/java/io/zipcoder/casino/Handler.java b/src/main/java/io/zipcoder/casino/Handler.java new file mode 100644 index 000000000..5cdc5a25e --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Handler.java @@ -0,0 +1,101 @@ +package io.zipcoder.casino; +import io.zipcoder.casino.games.*; +import io.zipcoder.casino.player.GoFishPlayer; +import io.zipcoder.casino.player.CrapsPlayer; +import io.zipcoder.casino.player.Player; +import io.zipcoder.casino.player.RoulettePlayer; +import io.zipcoder.casino.player.SlotsPlayer; +import io.zipcoder.casino.utilities.Console; + +import java.util.Scanner; + + +// +public class Handler { + public Console console = new Console(System.in, System.out); + public Player player; + private Integer integerInput; + private String name = ""; + private Double account = 0.0; + private Double tempDeposit; + + + +public void run() { + getNameInput(); + getAccountBalanceInput(); + createPlayer(name, tempDeposit); + +while (true) { + System.out.println("WELCOME TO THE BIG TROUBLE CASINO \n PICK FROM ONE OF OUR GAMES \n \n 0 blackjack -- 1 go fish -- 2 roulette -- 3 craps -- 4 slots \n"); + getGameInput(); + + + + switch (integerInput) { + case 0: + Blackjack blackjack = new Blackjack(); + break; + case 1: + GoFishPlayer goFishPlayer = new GoFishPlayer(player); + GoFish goFish = new GoFish(goFishPlayer, console); + goFish.runGame(); + break; + case 2: + RoulettePlayer roulettePlayer = new RoulettePlayer(player.getName(), player.getAccount()); + Roulette roulette = new Roulette(roulettePlayer); + Scanner scanner = new Scanner(System.in); + boolean isNextRound = false; + do { + roulette.runGame(); + player.setAccount(roulettePlayer.getAccount()); + String continuePlaying = console.getStringInput("Do you want to continue playing (Y/N)?"); + if (continuePlaying != null && continuePlaying.equalsIgnoreCase("Y")) { + isNextRound = true; + } else { + isNextRound = false; + } + } while (isNextRound); + break; + case 3: + CrapsPlayer crapsPlayer = new CrapsPlayer(player); + Craps craps = new Craps(crapsPlayer, console); + craps.runGame(); + break; + case 4: + SlotsPlayer slotsPlayer = new SlotsPlayer(player); + Slots slots = new Slots(slotsPlayer, console); + slots.runGame(); + break; + default: + + System.out.println("you blew it"); + } + } +} + + public Player createPlayer (String name, Double account) { + return player = new Player(name, account); + } + + public void getNameInput() { + this.name = console.getStringInput("Enter Name"); + } + + public void getAccountBalanceInput() { + this.tempDeposit = console.getDoubleInput("How much do you want to deposit in your account?"); + } + + public Boolean testAccountInput (Double tempDeposit) { + if (tempDeposit > 0 && tempDeposit < Double.MAX_VALUE) { + return true; + } else + return false; + } + + public void getGameInput() { + this.integerInput = console.getIntegerInput("What game would you like to play?"); + } + +} +// \ No newline at end of file diff --git a/src/main/java/io/zipcoder/casino/gameTools/Card.java b/src/main/java/io/zipcoder/casino/gameTools/Card.java new file mode 100644 index 000000000..054996e87 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/gameTools/Card.java @@ -0,0 +1,28 @@ +package io.zipcoder.casino.gameTools; + +public class Card { + private CardValue cardValue; + private Suit suit; + + public Card (){} + public Card (CardValue cv, Suit s) { + this.cardValue = cv; + this.suit = s; + } + + public CardValue getCardValue() { + return cardValue; + } + + public void setCardValue(CardValue cardValue) { + this.cardValue = cardValue; + } + + public Suit getSuit() { + return suit; + } + + public void setSuit(Suit suit) { + this.suit = suit; + } +} diff --git a/src/main/java/io/zipcoder/casino/gameTools/CardValue.java b/src/main/java/io/zipcoder/casino/gameTools/CardValue.java new file mode 100644 index 000000000..b213308e6 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/gameTools/CardValue.java @@ -0,0 +1,27 @@ +package io.zipcoder.casino.gameTools; + +public enum CardValue { + TWO(2), + THREE(3), + FOUR(4), + FIVE(5), + SIX(6), + SEVEN(7), + EIGHT(8), + NINE(9), + TEN(10), + JACK(10), + QUEEN(10), + KING(10), + ACE(11); + + private Integer cardValue; + + CardValue(Integer cardValue) { + this.cardValue = cardValue; + } + public Integer getCardIntegerValue() { + return cardValue; + } + +} diff --git a/src/main/java/io/zipcoder/casino/gameTools/Deck.java b/src/main/java/io/zipcoder/casino/gameTools/Deck.java new file mode 100644 index 000000000..dfcf58921 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/gameTools/Deck.java @@ -0,0 +1,57 @@ +package io.zipcoder.casino.gameTools; + +import io.zipcoder.casino.player.CardGamePlayer; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.Stack; + +public class Deck { + + + private Stack cardStack; + public Deck() { + this.cardStack = new Stack(); + for (CardValue c : CardValue.values() + ) { + for (Suit suit : Suit.values() + ) { + Card card = new Card(c,suit); + this.cardStack.add(card); + } + } + Collections.shuffle(cardStack); + } + + + public void shuffle () { + Collections.shuffle(cardStack); + }; + + public void deal (Integer numOfCards, CardGamePlayer player) { + ArrayList result = new ArrayList(); + for (int i = 0; i < numOfCards ; i++) { + result.add(cardStack.pop()); + player.setHand(result); + } + } + + public void dealSingleCard(CardGamePlayer player) { + Card card = cardStack.pop(); + ArrayList hand; + hand = player.getHand(); + hand.add(card); + player.setHand(hand); + + } + + public void setDeck(Stack cardStack) { + this.cardStack = cardStack; + } + public Stack getDeck() { + return cardStack; + } + + +} diff --git a/src/main/java/io/zipcoder/casino/gameTools/Dice.java b/src/main/java/io/zipcoder/casino/gameTools/Dice.java new file mode 100644 index 000000000..5581086b5 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/gameTools/Dice.java @@ -0,0 +1,11 @@ +package io.zipcoder.casino.gameTools; + +public class Dice { + public Integer rollDice() { + int sum = 0; + for (int i = 0; i < 2 ; i++) { + sum += (int) (Math.random()*6+1); + }; + return sum; + } +} diff --git a/src/main/java/io/zipcoder/casino/gameTools/Suit.java b/src/main/java/io/zipcoder/casino/gameTools/Suit.java new file mode 100644 index 000000000..d9c1b52e3 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/gameTools/Suit.java @@ -0,0 +1,8 @@ +package io.zipcoder.casino.gameTools; + +public enum Suit { + HEARTS, + SPADES, + DIAMONDS, + CLUBS; +} diff --git a/src/main/java/io/zipcoder/casino/games/Blackjack.java b/src/main/java/io/zipcoder/casino/games/Blackjack.java new file mode 100644 index 000000000..8a616dd03 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/games/Blackjack.java @@ -0,0 +1,120 @@ +package io.zipcoder.casino.games; + +import io.zipcoder.casino.gameTools.Card; +import io.zipcoder.casino.player.BlackJackPlayer; +import io.zipcoder.casino.player.BlackJackPlayerNPC; +import io.zipcoder.casino.player.Player; + +public class Blackjack extends CardGames implements GamblerGameInterface { + + BlackJackPlayer player1 = new BlackJackPlayer(); + BlackJackPlayerNPC player2 = new BlackJackPlayerNPC(); + + private Integer player1Score; + private Integer player2Score; + private Double currentBet; + + public Blackjack() { + super(); + this.odds = 2.0; + this.player1Score = 0; + this.player2Score = 0; + this.currentBet = 0.0; + + + } + + public void runGame(){ + display("Hello "); //+ BlackJackPlayer.getName() + "!"); + } + + /** public void getWinner(){ + if(player1.currentHand() > 21){ + playerLose(); + } else if (player1.currentHand() < player2.currentHand() && player2 <=21){ + playerLose(); + } else if (player1.currentHand() == 21 && player2.currentHand() == 21){ + push(); + } else if { + + } */ + + public Integer calcPayment(Integer bet, Integer odds) { + return null; + } + + public void updateAccount(Integer num) {} + + public void currentHand(){ + + }; + + //enums for the below + + public void stay() {}; + + public void spilt() {}; + + public void doubleDown(){}; + + public Card hit() { + return null; + } + + public Integer getPlayer1Score() { + return player1Score; + } + + public void setPlayer1Score(Integer player1Score) { + this.player1Score = player1Score; + } + + public Integer getPlayer2Score() { + return player2Score; + } + + public void setPlayer2Score(Integer player2Score) { + this.player2Score = player2Score; + } + + public void setCurrentBet(Double currentBet1) { + + this.currentBet = currentBet; + } + + public double getCurrentBet(){ + return currentBet; + } + + /** public BlackJackPlayer getBlackJackPLayer() { + + return blackJackPlayer; + } */ + + + + + @Override + void nextTurn() { + + } + + @Override + void endGame() { + + } + + public Double calcPayment(Double bet, Double odds) { + return null; + } + + public void withdraw(Double num) { + + } + + public void deposit(Double num) { + + } + + public void getBlackJackPlayer(){}; +} diff --git a/src/main/java/io/zipcoder/casino/games/CardGames.java b/src/main/java/io/zipcoder/casino/games/CardGames.java new file mode 100644 index 000000000..23bc6f8f2 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/games/CardGames.java @@ -0,0 +1,27 @@ +package io.zipcoder.casino.games; + +import io.zipcoder.casino.gameTools.Card; +import io.zipcoder.casino.gameTools.Deck; + +abstract class CardGames extends Games { + Deck deck; + + public CardGames() { + this.deck = new Deck(); + } + + public Card dealCard () { + return null; + } + + @Override + boolean getResults() { + return false; + } + + @Override + public void display(String output) { + super.display(output); + } +} +////// diff --git a/src/main/java/io/zipcoder/casino/games/Craps.java b/src/main/java/io/zipcoder/casino/games/Craps.java new file mode 100644 index 000000000..7deee8154 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/games/Craps.java @@ -0,0 +1,245 @@ +package io.zipcoder.casino.games; + + +import io.zipcoder.casino.Handler; +import io.zipcoder.casino.player.CrapsPlayer; +import io.zipcoder.casino.player.Player; +import io.zipcoder.casino.utilities.Console; + + +public class Craps extends Games implements GamblerGameInterface { + private CrapsPlayer crapsPlayer; + public Handler handler; + public CrapsDataHandler data = new CrapsDataHandler(); + + + + + + public Craps() {} + + public Craps(CrapsPlayer player) { + this.crapsPlayer = player; + crapsPlayer.player.setPlaying(true); + data.setStage(0); + + } + + public Craps(CrapsPlayer player, Console console /*, Handler handler*/) { + this.crapsPlayer = player; + data.setConsole(console); + this.handler = handler; + crapsPlayer.player.setPlaying(true); + data.setStage(0); + + } + + public void runGame() { + display("Welcome to the table " + crapsPlayer.player.getName() + "! \n"); + while(crapsPlayer.player.getPlaying() == true) { + + switch (data.getStage()) { + case 0: + String input = data.getConsole().getStringInput("A game has just ended would you like to join the table?"); + stage0Play(input); + break; + case 1: + if (data.getComeFirstRound()) { + data.setFirstLineBet(data.getConsole().getDoubleInput("LET'S GET STARTED ON A NEW GAME!\n \n Losing rolls: [2] [3] [12]. \n Winning rolls: [7] [11]. \n [Any other roll becomes the on number]\n" + "\n"+ "Place your passline bet!")); + } else {keepPlayingOrQuit();} + if(hasMoenytoBet(data.getFirstLineBet(), crapsPlayer.player)){ + data.setCurrentRoll(crapsPlayer.roll()); + stage1Play(data.getFirstLineBet()); + } + keepPlayingOrQuit(); + break; + case 2: +// keepPlayingOrQuit(); + if(data.getPassFirstRound()) { + data.setSecondLineBet(data.getConsole().getDoubleInput("Winning roll: [" + data.getOnNumber() + "] \n Make your come out bet!")); + data.setMakePropBet(data.getConsole().getStringInput("Would you like to make a prop bet")); + if (checkForPropBet(data.getMakePropBet())) { + data.setFieldBetType(data.getConsole().getIntegerInput("What prop bet do you want to make?")); + data.setFieldBet(data.getConsole().getDoubleInput("how much do you want to bet on this?")); + } else { + display("NO PROP BETS PLACED, ROLL THE DICE! \n");} + } + if (hasMoenytoBet(data.getSecondLineBet() + data.getFieldBet(), crapsPlayer.player)) { + data.setCurrentRoll(crapsPlayer.roll()); + stage2Play(data.getSecondLineBet(), data.getFieldBet(), data.getFieldBetType()); + } + keepPlayingOrQuit(); + break; + } + } + } + +/*----------------STAGE 0---------------*/ + + protected void stage0Play(String input){ + Character firstLetter = input.toLowerCase().charAt(0); + if(input.toLowerCase().equals("play") || firstLetter.equals('y')) { + data.setStage(1); + + } else if (input.toLowerCase().equals("exit") || firstLetter.equals('n')){ + crapsPlayer.player.setPlaying(false); + } else { + display("Excuse me, I didnt understand"); + } + } + +/*----------------STAGE 1---------------*/ + + + protected void stage1Play(Double firstLineBet){ + if (data.getComeFirstRound()) { + withdraw(firstLineBet); + } + data.setComeFirstRound(false); + if(data.getCurrentRoll().equals(2) || data.getCurrentRoll().equals(3) || data.getCurrentRoll().equals(12)) { + display("you rolled a " + data.getCurrentRoll() + "\n" + "SORRY YOU CRAPPED OUT!"); + data.setStage(1); + resetBets(); + display(displayCurrentState()); + resetFirstRoundState(); + } else if (data.getCurrentRoll().equals(7) || data.getCurrentRoll().equals(11)) { + deposit(calcPayment(firstLineBet, data.getFirstLineOdds())); + display(displayCurrentState()); + display("YOU ROLLED A " + data.getCurrentRoll() + "\n" + "YOU WON " + calcPayment(data.getFirstLineOdds(), firstLineBet)); + } else if(!data.getCurrentRoll().equals(2) && !data.getCurrentRoll().equals(3) && !data.getCurrentRoll().equals(12) && !data.getCurrentRoll().equals(7) && !data.getCurrentRoll().equals(11)){ + display(displayCurrentState()); + display("YOU ROLLED A " + data.getCurrentRoll() + ".\n" + data.getCurrentRoll() + " IS NOW THE ON NUMBER! \n "); + data.setOnNumber(data.getCurrentRoll()); + data.setStage(2); + } + + + } + + +/*-----------------STAGE 2----------------*/ + + + protected void stage2Play(Double secondLineBet, Double fieldBet, Integer fieldBetNumber ){ + if(data.getPassFirstRound()) { + withdraw(secondLineBet); + withdraw(fieldBet); + } + data.setPassFirstRound(false); + if(data.getCurrentRoll().equals(7)) { + display("YOU ROLLED A " + data.getCurrentRoll() + "\n" + "SORRY YOU CRAPPED OUT!"); + data.setStage(1); + display(displayCurrentState()); + resetBets(); + resetFirstRoundState(); + } else if (data.getCurrentRoll().equals(fieldBetNumber)) { + display(displayCurrentState()); + Double wins = calcPayment(fieldBet, data.getfieldOdds(fieldBetNumber)); + deposit(wins); + display(displayWinningRoll(wins)); + }else if (data.getCurrentRoll().equals(data.getOnNumber())) { + display(displayCurrentState()); + Double wins = calcPayment(data.getfieldOdds(data.getOnNumber()), secondLineBet) + calcPayment(data.getfieldOdds(data.getOnNumber()), data.getFirstLineBet()); + deposit(wins); + display(displayWinningRoll(wins)); + } else { + display(displayCurrentState()); + display( "YOU ROLLED A " + data.getCurrentRoll() +" NO WINNERS, ROLL AGAIN!"); + } + } + + + @Override + void endGame() { + deposit(data.getFirstLineBet()); + deposit(data.getSecondLineBet()); + deposit(data.getFieldBet()); + + + crapsPlayer.player.setPlaying(false); + } + + @Override + void nextTurn() { + + } + + @Override + boolean getResults() { + return false; + } + + @Override + protected void display(String output) { + System.out.println(output); + } + + public void withdraw(Double num) { + Double temp = crapsPlayer.player.getAccount(); + crapsPlayer.player.setAccount(temp - num); + } + + public void deposit(Double num) { + Double temp = crapsPlayer.player.getAccount(); + crapsPlayer.player.setAccount(temp + num); + } + + public Double calcPayment(Double bet, Double odds) { + return bet * odds; + } + + + protected Boolean hasMoenytoBet(Double bet, Player player) { + if (bet > player.getAccount()){ + display("Not enough Money!!! \n you only have - " + + crapsPlayer.player.getAccount()); + return false; + } else return true; + } + + protected void keepPlayingOrQuit() { + String quitOrContinue = data.getConsole().getStringInput("Would you like to keep playing?").toLowerCase(); + Character firstletter = quitOrContinue.toLowerCase().charAt(0); + if (firstletter.equals('n')) { + endGame(); + } + + } + + protected String displayCurrentState() { + return + "*-----------------------------------*\n" + + "Current Balance: " + crapsPlayer.player.getAccount() + "\n" + + "Passline Bet: " + data.getFirstLineBet() + "\n" + + "Come Out Bet: " + data.getSecondLineBet() + "\n" + + "On Number: " + data.getOnNumber() + "\n" + + "Prop Bet Type: " + data.getFieldBetType() + "\n" + + "Prob Bet: " + data.getFieldBet() + "\n" + "\n" + + "*-----------------------------------*\n"; + } + + protected String displayWinningRoll(Double wins){ + return "YOU ROLLED A " + data.getCurrentRoll() + "\n" + "YOU WON " + wins + "!"; + } + + protected Boolean checkForPropBet (String string) { + Character firstLetter = string.toLowerCase().charAt(0); + if (firstLetter.equals('y')) { + return true; + }else return false; + } + protected void resetFirstRoundState() { + data.setComeFirstRound(true); + data.setPassFirstRound(true); + } + + protected void resetBets() { + data.setFirstLineBet(0.0); + data.setSecondLineBet(0.0); + data.setFieldBet(0.0); + data.setFieldBetType(0); + } + + + +} diff --git a/src/main/java/io/zipcoder/casino/games/CrapsDataHandler.java b/src/main/java/io/zipcoder/casino/games/CrapsDataHandler.java new file mode 100644 index 000000000..4a6b08d58 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/games/CrapsDataHandler.java @@ -0,0 +1,158 @@ +package io.zipcoder.casino.games; + +import io.zipcoder.casino.player.Player; +import io.zipcoder.casino.utilities.Console; + +import java.util.HashMap; + +public class CrapsDataHandler { + private String quit; + private Console console; + private Integer onNumber = 0; + private Double firstLineBet = 0.0; + private Double secondLineBet = 0.0 ; + private Double fieldBet = 0.0; + private Integer fieldBetType =0; + private Double firstLineOdds = 2.0; + private Double secondLineOdds = 2.0; + private Integer currentRoll = 0; + private String makePropBet = ""; + private Integer stage; + private Boolean comeFirstRound = true; + private Boolean passFirstRound = true; + private HashMap fieldOdds = new HashMap(); + public Double getfieldOdds(Integer key) { + return fieldOdds.get(key); + } + + public CrapsDataHandler(){ + fieldOdds.put(2,10.0); + fieldOdds.put(3,9.0); + fieldOdds.put(4,8.0); + fieldOdds.put(5,7.0); + fieldOdds.put(6,6.0); + fieldOdds.put(7,5.0); + fieldOdds.put(8,6.0); + fieldOdds.put(9,7.0); + fieldOdds.put(10,8.0); + fieldOdds.put(11,9.0); + fieldOdds.put(12,10.0); + } + + + + + + public Console getConsole() { + return console; + } + + public void setConsole(Console console) { + this.console = console; + } + + public Integer getOnNumber() { + return onNumber; + } + + public void setOnNumber(Integer onNumber) { + this.onNumber = onNumber; + } + + public Double getFirstLineBet() { + return firstLineBet; + } + + public void setFirstLineBet(Double firstLineBet) { + this.firstLineBet = firstLineBet; + } + + public Double getSecondLineBet() { + return secondLineBet; + } + + public void setSecondLineBet(Double secondLineBet) { + this.secondLineBet = secondLineBet; + } + + public Double getFieldBet() { + return fieldBet; + } + + public void setFieldBet(Double fieldBet) { + this.fieldBet = fieldBet; + } + + public Integer getFieldBetType() { + return fieldBetType; + } + + public void setFieldBetType(Integer fieldBetType) { + this.fieldBetType = fieldBetType; + } + + public Double getFirstLineOdds() { + return firstLineOdds; + } + + public void setFirstLineOdds(Double firstLineOdds) { + this.firstLineOdds = firstLineOdds; + } + + public Double getSecondLineOdds() { + return secondLineOdds; + } + + public void setSecondLineOdds(Double secondLineOdds) { + this.secondLineOdds = secondLineOdds; + } + + public Integer getCurrentRoll() { + return currentRoll; + } + + public void setCurrentRoll(Integer currentRoll) { + this.currentRoll = currentRoll; + } + + public String getMakePropBet() { + return makePropBet; + } + + public void setMakePropBet(String makePropBet) { + this.makePropBet = makePropBet; + } + + public String getQuit() { + return quit; + } + + public void setQuit(String quit) { + this.quit = quit; + } + + public Integer getStage() { + return stage; + } + + public void setStage(Integer stage) { + this.stage = stage; + } + + public Boolean getComeFirstRound() { + return comeFirstRound; + } + + public void setComeFirstRound(Boolean comeFirstRound) { + this.comeFirstRound = comeFirstRound; + } + + public Boolean getPassFirstRound() { + return passFirstRound; + } + + public void setPassFirstRound(Boolean passFirstRound) { + this.passFirstRound = passFirstRound; + } + +} diff --git a/src/main/java/io/zipcoder/casino/games/GamblerGameInterface.java b/src/main/java/io/zipcoder/casino/games/GamblerGameInterface.java new file mode 100644 index 000000000..9c1057e7c --- /dev/null +++ b/src/main/java/io/zipcoder/casino/games/GamblerGameInterface.java @@ -0,0 +1,11 @@ +package io.zipcoder.casino.games; + +interface GamblerGameInterface { + + Double calcPayment(Double bet, Double odds); + + void withdraw(Double num); + + void deposit(Double num); + +} diff --git a/src/main/java/io/zipcoder/casino/games/Games.java b/src/main/java/io/zipcoder/casino/games/Games.java new file mode 100644 index 000000000..1ed9f0709 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/games/Games.java @@ -0,0 +1,30 @@ +package io.zipcoder.casino.games; + + +import java.security.PublicKey; + +abstract class Games { + + Double odds; + + abstract void nextTurn(); + + abstract void endGame(); + + abstract boolean getResults(); + + void display(String output) { + System.out.println(output); + } + + public Double getOdds() { + return odds; + } + + public void setOdds(Double odds) { + this.odds = odds; + } + + + +} diff --git a/src/main/java/io/zipcoder/casino/games/GoFish.java b/src/main/java/io/zipcoder/casino/games/GoFish.java new file mode 100644 index 000000000..59104080b --- /dev/null +++ b/src/main/java/io/zipcoder/casino/games/GoFish.java @@ -0,0 +1,317 @@ +package io.zipcoder.casino.games; + +import io.zipcoder.casino.gameTools.Card; +import io.zipcoder.casino.gameTools.CardValue; +import io.zipcoder.casino.gameTools.Deck; +import io.zipcoder.casino.player.GoFishPlayer; +import io.zipcoder.casino.player.Player; +import io.zipcoder.casino.utilities.Console; + +import java.util.ArrayList; +import java.util.Random; + +public class GoFish extends Games { + Console console; + private GoFishPlayer goFishPlayer; +// private GoFishPlayer computer = new GoFishPlayer(); + private Player test = new Player("Computer"); + GoFishPlayer computer = new GoFishPlayer(test); + private GoFishPlayer currentPlayer; + private ArrayList hand = new ArrayList(); + private boolean isPlaying = true; + private boolean breakTheGame = false; + + private Deck deck = new Deck(); + Integer computerScore = 0; + + public GoFish() {} + + public GoFish(GoFishPlayer player, Console console) { + super(); + this.goFishPlayer = player; + this.console = console; + + } + + public void runGame () { + console.println("Hey " + goFishPlayer.getName() + "! \nWelcome to GO FISH GAME\n"); + while (isPlaying) { + dealHands(); + currentPlayer = goFishPlayer; + while (deck.getDeck().size() > 0) { + if (currentPlayer == goFishPlayer) { + playerTurn(); + } else { + compTurn(); + } + } + getWinner(); + String choice = console.getStringInput("would you like to play again?"); + isPlaying = playAgain(choice); + } + + } + + public boolean playAgain(String choice) { + + if (choice.equalsIgnoreCase("yes")) { + return true; + } + else { + return false; + } + } + + public Boolean checkForFour (GoFishPlayer player) { + hand = player.getHand(); + String valueString; + Integer value; + int [] cardCount = new int[15]; + for (Card card : hand + ) { + valueString = card.getCardValue().name(); + value = cardValueToIntValue(valueString); + cardCount[value]++; + if (cardCount[value] == 4) { + return true; + } + } + return false; + } + + + public boolean checkProperPick (String userInput, GoFishPlayer player) { + for (Card card: player.getHand() + ) { + if (card.getCardValue().name().equals(userInput)) { + return true; + } + } + return false; + } + + + public void removeFour (String stringValue, ArrayList hand) { + ArrayList cardsToRemove = new ArrayList(); + for (Card card : hand + ) { + if (card.getCardValue().name().equals(stringValue)) { + cardsToRemove.add(card); + } + } + hand.removeAll(cardsToRemove); + + } + public void getWinner() { + if (goFishPlayer.getScore() > computerScore) { + console.println(goFishPlayer.getName() + "is the winner!\n Congratulations!"); + } + if (goFishPlayer.getScore() < computerScore) { + console.println("Sorry " + goFishPlayer.getName() + "! You lost this game\n Would you like to play again?"); + } + else { + console.println("DRAW!\n Hey "+ goFishPlayer.getName() + "! Would you like to play again?"); + + } + } + + public void updateScore(GoFishPlayer player) { + player.setScore(player.getScore() + 1); + console.println("You score is " + player.getScore()); + } + + public void playerTurn() { + hand = goFishPlayer.getHand(); + console.println( goFishPlayer.getName() + " your turn now! Your score is " + goFishPlayer.getScore() + "\n"); + console.println(seeHand(hand)); + + String input = searchFor(); + if (!breakTheGame) { + while (!checkProperPick(input, goFishPlayer)) { + console.println("no such card in your hand, impossible move, try again"); + input = searchFor(); + } + ArrayList temp = checkHand(input, computer); + + while (!temp.isEmpty()) { + removeFromHand(temp, computer); + addToHand(temp, goFishPlayer); + console.println("You got card/s from computer"); + console.println(seeHand(temp)); + console.getStringInput(""); + + if (checkForFour(goFishPlayer)) { + console.println(goFishPlayer.getName() + ", look at this!!! Boomoooooooom! 4 of the kind\n"); + removeFour(input, hand); + goFishPlayer.setHand(hand); + updateScore(goFishPlayer); + } + + console.println("your hand: \n" + seeHandByPlayer(goFishPlayer)); + + input = searchFor(); + temp = checkHand(input, computer); + + } + goFishAction(goFishPlayer); + + if (checkForFour(goFishPlayer)) { + console.println(goFishPlayer.getName() + ", look at this!!! Boomoooooooom! 4 of the kind\n"); + removeFour(input, hand); + goFishPlayer.setHand(hand); + updateScore(goFishPlayer); + } + currentPlayer = computer; + } + } + + public void compTurn() { + console.println("computers turn"); + Integer compValueInt = compPickValue(); + String compValueString = getCardValue(compValueInt); + + while (!checkProperPick(compValueString,computer)) { + compValueInt = compPickValue(); + compValueString = getCardValue(compValueInt); + } + + console.println("Computer picking " + compValueString); + ArrayList temp = checkHand(compValueString, goFishPlayer); + + while (!temp.isEmpty()) { + removeFromHand(temp, goFishPlayer); + addToHand(temp, computer); + console.println("Comp got this card/s from you"); + console.println(seeHand(temp)); + if (checkForFour(goFishPlayer)) { + console.println( "Boomoooooooom! 4 of the kind for COMPUTERMAN\n"); + removeFour(compValueString, hand); + computer.setHand(hand); + computerScore++; + } + compValueInt = compPickValue(); + compValueString = getCardValue(compValueInt); + temp = checkHand(compValueString, goFishPlayer); + + } + console.getStringInput(""); + goFishAction(computer); + if (checkForFour(goFishPlayer)) { + console.println( "Boomoooooooom! 4 of the kind for COMPUTERMAN\n"); + removeFour(compValueString, hand); + computer.setHand(hand); + computerScore++; + } + currentPlayer = goFishPlayer; + } + + public Integer compPickValue () { + Random random = new Random(); + Integer value = random.nextInt(13); + return value; + } + + public String getCardValue (Integer input) { + String result = ""; + CardValue[] cardValues = CardValue.values(); + for (CardValue c: cardValues + ) { + if (c.ordinal() == input) { + result = c.name(); + break; + } + } + return result; + } + + public ArrayList checkHand (String value, GoFishPlayer player){ + + ArrayList cards = new ArrayList(0); + + for (Card c : player.getHand() + ) { + if(c.getCardValue().equals(CardValue.valueOf(value))) { + cards.add(c); + } + } + return cards; + } + + public void removeFromHand (ArrayList cards, GoFishPlayer player) { + player.getHand().removeAll(cards); + } + + public void addToHand (ArrayList cards, GoFishPlayer player) { + ArrayList temp; + temp = player.getHand(); + temp.addAll(cards); + player.setHand(temp); + } + + public void dealHands () { + deck.deal(5, goFishPlayer); + deck.deal(5, computer); + } + + public String seeHand(ArrayList hand) { + String result = ""; + for (Card c: hand + ) { + result += c.getCardValue() + " of " + c.getSuit() + "\n"; + } + return result; + } + + public String seeHandByPlayer(GoFishPlayer player) { + String hand = ""; + for (Card c: player.getHand() + ) { + hand += c.getCardValue() + " of " + c.getSuit() + "\n"; + } + return hand; + } + + + public String searchFor() { + String userInput = console.getStringInput("What are you looking for?"); + if (userInput.equalsIgnoreCase("exit")) { + console.println("Good bye!"); + breakTheGame = true; + } + return userInput.toUpperCase(); + } + + public Integer cardValueToIntValue (String string) { + if (string.equals("TWO")) {return 2;} + else if (string.equals("THREE")) {return 3;} + else if (string.equals("FOUR")) {return 4;} + else if (string.equals("FIVE")) {return 5;} + else if (string.equals("SIX")) {return 6;} + else if (string.equals("SEVEN")) {return 7;} + else if (string.equals("EIGHT")) {return 8;} + else if (string.equals("NINE")) {return 9;} + else if (string.equals("TEN")) {return 10;} + else if (string.equals("JACK")) {return 11;} + else if (string.equals("QUEEN")) {return 12;} + else if (string.equals("KING")) {return 13;} + else if (string.equals("ACE")) {return 14;} + else return null; + } + public void goFishAction(GoFishPlayer player) { + console.println("no such card in the hand!\nYOU GO FISH!"); + deck.dealSingleCard(player); + } + + @Override + void nextTurn() { + } + + @Override + void endGame() { } + + @Override + boolean getResults() { + return false; + } + +} diff --git a/src/main/java/io/zipcoder/casino/games/Roulette.java b/src/main/java/io/zipcoder/casino/games/Roulette.java new file mode 100644 index 000000000..f8e017625 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/games/Roulette.java @@ -0,0 +1,161 @@ +package io.zipcoder.casino.games; + +import io.zipcoder.casino.player.Player; +import io.zipcoder.casino.player.RoulettePlayer; + +import java.util.*; + +public class Roulette extends Games implements GamblerGameInterface { + String betType; // red/back - odd / even / number + protected RoulettePlayer roulettePlayer; + private Double currentBet; + + String[] redArray = {"2","4","6","8","10","12","14","16","18","20","22","24","26","28","30","32","34","36"}; + String[] blackArray = {"1","3","5","7","9","11","13","15","17","19","21","23","25","27","29","31","33","35"}; + //List list = new ArrayList(); + List redList = Arrays.asList(redArray); + List blackList = Arrays.asList(blackArray); + + public Roulette(RoulettePlayer roulettePlayer) { + this.roulettePlayer = roulettePlayer; + } + + @Override + void nextTurn() { + + } + + @Override + void endGame() { + // end game and go back to main menu + + } + + @Override + boolean getResults() { + // determine win or loose + return false; + } + + @Override + public void display(String output) { + + super.display(output); + } + + public Integer calcPayment(Integer bet, Integer odds) { + //calculate payment amount to be payed based on the position + return bet + odds * bet; + } + + public void updateAccount(Integer num) { + //add or remove money from the balance + this.roulettePlayer.setAccount((double)(num)); + } + + public Double getCurrentBet() { + + return currentBet; + } + + public void setCurrentBet(Double currentBet) { + this.currentBet = currentBet; + } + + public Double calcPayment(Double bet, Double odds) { + //no of odds aganist = n(1 + odds) + + return bet + odds * bet; + } + + public void withdraw(Double num) { + + } + + public void deposit(Double num) { + + } + + public void runGame() { + + // Get Bet Amount + Scanner sc = new Scanner(System.in); + System.out.println("Enter Bet Amount : "); + int enterBet = sc.nextInt(); + sc.nextLine(); + + // Set Current Bet on a bettable place like 0,1,2,3,... or Even/Odd or Red/Black or 1st/2nd/3rd 12, etc + System.out.println("Bet position : "); + String betPosition = sc.nextLine(); + + // Calculate the odds based on the position. + if(betPosition.equalsIgnoreCase("red") || betPosition.equalsIgnoreCase("Black") || betPosition.equalsIgnoreCase("even") || betPosition.equalsIgnoreCase("odd")) { + odds = 1d; + + } + else if(betPosition.equalsIgnoreCase("1st12") || betPosition.equalsIgnoreCase("2nd12") || betPosition.equalsIgnoreCase("3rd12")) { + odds = 2d; + } + else { + odds = 35d; + } + + // Deduct the current bet from the account balance + this.updateBalance(enterBet * (-1d)); + + // Generate a random number where the ball is going to fall - Range should be 0 to 36 + int random = (int)(Math.random() * 36 + 1); + System.out.println(" Winning Number " +random); + //System.out.println("Even " +); + + // Identify if the position of bet is winning position + if(isWinner(betPosition, random)) { + System.out.println("You Won....."); + double d = calcPayment((double)enterBet,odds ); + updateBalance(d); + } + else { + System.out.println("You Lose....."); + } + System.out.println("Game Over \n"); + System.out.println("Your Balance is : " +this.roulettePlayer.getAccount()); + // Update the Account Balance + + + } + public void updateBalance(Double amount) { + Double d = this.roulettePlayer.getAccount(); + Double add = d + amount; + this.roulettePlayer.setAccount(add); + + } + + public boolean isWinner(String betPosition,int random ) { + if(betPosition.equalsIgnoreCase("even") && random % 2 == 0) { + return true; + } + else if(betPosition.equalsIgnoreCase("odd") && random % 2 != 0) { + return true; + } + else if(betPosition.equalsIgnoreCase("red") && redList.contains(Integer.toString(random))) { + return true; + } + else if(betPosition.equalsIgnoreCase("black") && blackList.contains(Integer.toString(random))) { + return true; + } + else if(betPosition.equalsIgnoreCase("1st12") && random <= 12 && random >=1) { + return true; + } + else if(betPosition.equalsIgnoreCase("2nd12") && random <=24 && random >=13) { + return true; + } + else if(betPosition.equalsIgnoreCase("3rd12") && random <= 36 && random >=14) { + return true; + } + else if(betPosition.equalsIgnoreCase(Integer.toString(random))) { + return true; + } + return false; + } + +} diff --git a/src/main/java/io/zipcoder/casino/games/Slots.java b/src/main/java/io/zipcoder/casino/games/Slots.java new file mode 100644 index 000000000..6d069bdea --- /dev/null +++ b/src/main/java/io/zipcoder/casino/games/Slots.java @@ -0,0 +1,217 @@ +package io.zipcoder.casino.games; + +import io.zipcoder.casino.Handler; +import io.zipcoder.casino.player.Player; +import io.zipcoder.casino.player.SlotsPlayer; +import io.zipcoder.casino.utilities.Console; + +import java.lang.reflect.Array; +import java.util.Random; + +public class Slots extends Games implements GamblerGameInterface { + + SlotsPlayer slotsPlayer; + private Double currentBet; + public Console console; + private Double bet; + private Double result; + + + + + public Player player; + + Integer random = 0; + String[] characters = new String[]{"cherry ", "orange ", "bell ", "bars ", "apple ", "seven "}; + String[][] toSave = new String[3][3]; + + + public Slots() { + } + + public Slots(SlotsPlayer player, Console console) { + this.slotsPlayer = player; + this.console = console; + } + +//////////////////////////////////////////Run Game///////////////////////////////////////// + + + public void runGame() { + display("Welcome to the slots " + slotsPlayer.player.getName() + "! \n"); + + + int max = characters.length; + int min = 1; + int range = max - min + 1; + slotsPlayer.setPlaying(true); + + + do { + Double tempBet = console.getDoubleInput("How many lines would you like to bet? 1.0, 3.0 or 5.0?"); + + console.println(slotsPlayer.player.getAccount().toString()); + if (tempBet==1||tempBet==3||tempBet==5){ + bet =tempBet; + } + else{ + console.println("please, choose between 1 or 3 or 5"); + continue; + + } + withdraw(bet); + //check user input here for bet + + // if user input == 1||3||5 + // ==> set useer input to bet; + for (int i = 0; i <= 2; i++) { + for (int j = 0; j <= 2; j++) { + int rand = (int) (Math.random() * range); + System.out.print(characters[rand]); + toSave[i][j] = characters[rand]; + } + System.out.println(); + } + + + CheckWins(bet); + + System.out.println(); + System.out.println(slotsPlayer.player.getAccount().toString()); + System.out.println(); + String tryAgain = console.getStringInput("do you want to play again? choose between yes/no"); + + + //if it is no it should bring you to the menu, where you are choosing the game) + if (tryAgain.equals("no")) { + slotsPlayer.setPlaying(false); + } + + } while (slotsPlayer.getPlaying().equals(true)); + // should be added something that sends back to the main menu + + + endGame(); + + } + +///////////////////////////////////Check Wins//////////////////////////////////////////////////////// + + public Double CheckWins(Double bet) { + Double countPayLines = 0.0; + + + + if (bet >= 1) { + if (toSave[1][0] == toSave[1][1] && toSave[1][1] == toSave[1][2]) { + System.out.println(); + System.out.println("you won horizontal middle"); + countPayLines++; + + } + } + if (bet >= 3) { + if (toSave[0][0] == toSave[0][1] && toSave[0][1] == toSave[0][2]) { + System.out.println(); + System.out.println("you won horizontal top"); + countPayLines++; + + } + if (toSave[2][0] == toSave[2][1] && toSave[2][1] == toSave[2][2]) { + System.out.println(); + System.out.println("you won horizontal bottom"); + countPayLines++; + } + } + if (bet >= 5) { + if (toSave[2][0] == toSave[1][1] && toSave[1][1] == toSave[0][2]) { + System.out.println(); + System.out.println("you won diagonally right"); + countPayLines++; + } + if (toSave[0][0] == toSave[1][1] && toSave[1][1] == toSave[2][2]) { + System.out.println(); + System.out.println("you won diagonally left "); + countPayLines++; + } + + } + if(countPayLines>0) { + deposit(calcPayment1(bet, countPayLines)+bet); + } + return countPayLines; + } + +////////////////////////////////////////////////account////////////////////////////////////////////// + + + + @Override + void nextTurn() { + } + + @Override + void endGame() { +// Handler handler = new Handler(); +// handler.run(); + } + + @Override + boolean getResults() { + return false; + } + + @Override + public void display(String output) { + super.display(output); + } + + + ///////////////mine//////// + + public Double calcPayment1(Double bet, Double countPayLines) { + + result =bet * countPayLines; + System.out.println("You won "+ result+"$"); + updateAccount(result); + return result; + + } + + +//////////////////////////////mine + + + + public Double getCurrentBet() { + return currentBet; + } + + public void setCurrentBet(Double currentBet) { + this.currentBet = currentBet; + } + + public Double calcPayment(Double bet, Double odds) { + return bet * odds; + } + + public void withdraw(Double num) { + Double tempAccount = slotsPlayer.player.getAccount(); + slotsPlayer.setAccount(tempAccount-num); + + + } + + public void deposit(Double num) { + Double tempAccount = slotsPlayer.player.getAccount(); + slotsPlayer.player.setAccount(tempAccount+num); + + + + + } + + public void updateAccount(Double num) { + + } +} diff --git a/src/main/java/io/zipcoder/casino/player/BlackJackPlayer.java b/src/main/java/io/zipcoder/casino/player/BlackJackPlayer.java new file mode 100644 index 000000000..4dc1e1c87 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/player/BlackJackPlayer.java @@ -0,0 +1,29 @@ +package io.zipcoder.casino.player; + +// + + +public class BlackJackPlayer extends CardGamePlayer implements GamblerInterface { + + + public BlackJackPlayer(){ + super(); + + } + public void bet(Double bet) { + } + + public void betType (String betType) { + } + + public void cashout() { + } + + public void displayAccoutBal() { + + } + + public void endturn() {}; + + +} diff --git a/src/main/java/io/zipcoder/casino/player/BlackJackPlayerNPC.java b/src/main/java/io/zipcoder/casino/player/BlackJackPlayerNPC.java new file mode 100644 index 000000000..5494022ef --- /dev/null +++ b/src/main/java/io/zipcoder/casino/player/BlackJackPlayerNPC.java @@ -0,0 +1,19 @@ +package io.zipcoder.casino.player; + +public class BlackJackPlayerNPC extends CardGamePlayer implements NPCInterface { + + public void bet(Double bet) { + + } + + public void betType(String betType) { + + } + + public void logicNPC() { + + } + + public void endturn() {}; + +} diff --git a/src/main/java/io/zipcoder/casino/player/CardGamePlayer.java b/src/main/java/io/zipcoder/casino/player/CardGamePlayer.java new file mode 100644 index 000000000..3b06118b4 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/player/CardGamePlayer.java @@ -0,0 +1,75 @@ +package io.zipcoder.casino.player; + + +import io.zipcoder.casino.gameTools.Card; + +import java.util.ArrayList; + + +public class CardGamePlayer { + private Player player; + private ArrayList hand; + private Integer score; + private String name; + + + public Player getPlayer() { + return player; + } + + public void setPlayer(Player player) { + this.player = player; + } + + + public Integer getScore() { + return score; + } + + public void setScore(Integer score) { + this.score = score; + } + + + + public CardGamePlayer (Player player) { + this.player = player; + } + public CardGamePlayer () { + + } + public ArrayList getHand() { + return hand; + } + + public void setHand(ArrayList hand) { + this.hand = hand; + } + + public void endturn() {}; + + public CardGamePlayer(String name, Integer score) { + this.name = name; + this.score = score; + } + + public String getName() { + return player.getName(); + } + + + public void setName(String name) { + player.setName(name); + } + + public void setAccount(Double balance) { + player.setAccount(balance); + } + + public Double getAccount() { + return player.getAccount(); + } + + + +} diff --git a/src/main/java/io/zipcoder/casino/player/CrapsPlayer.java b/src/main/java/io/zipcoder/casino/player/CrapsPlayer.java new file mode 100644 index 000000000..44cdb0e9e --- /dev/null +++ b/src/main/java/io/zipcoder/casino/player/CrapsPlayer.java @@ -0,0 +1,35 @@ +package io.zipcoder.casino.player; + +import io.zipcoder.casino.gameTools.Dice; + +public class CrapsPlayer extends Player implements GamblerInterface { + public Player player; + + public CrapsPlayer(){}; + + public CrapsPlayer(Player player){ + this.player = player; + } + + public Integer roll() { + Dice dice = new Dice(); + + return dice.rollDice(); + } + + public void bet(Double bet) { + + } + + public void betType(String betType) { + + } + + public void cashout() { + this.player.setPlaying(false); + } + + public void displayAccoutBal() { + System.out.println(player.getAccount()); + } +} diff --git a/src/main/java/io/zipcoder/casino/player/GamblerInterface.java b/src/main/java/io/zipcoder/casino/player/GamblerInterface.java new file mode 100644 index 000000000..7cad98620 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/player/GamblerInterface.java @@ -0,0 +1,15 @@ +package io.zipcoder.casino.player; + +public interface GamblerInterface { + void bet(Double bet); + + void betType (String betType); + + void cashout(); + + void displayAccoutBal(); + + + + +} diff --git a/src/main/java/io/zipcoder/casino/player/GoFishPlayer.java b/src/main/java/io/zipcoder/casino/player/GoFishPlayer.java new file mode 100644 index 000000000..721f69560 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/player/GoFishPlayer.java @@ -0,0 +1,51 @@ +package io.zipcoder.casino.player; +import io.zipcoder.casino.gameTools.Card; +import io.zipcoder.casino.games.GoFish; +import io.zipcoder.casino.gameTools.Card; + + +import java.util.ArrayList; + +public class GoFishPlayer extends CardGamePlayer { + String name; + Integer score; + + public GoFishPlayer(String name, Integer score) { + this.name = name; + this.score = score; + } + + public GoFishPlayer() {} + + public Integer getScore() { + return score; + } + + public void setScore(Integer score) { + this.score = score; + } + + + public GoFishPlayer(Player player) { + super(player); + score = 0; + } + + public void endturn() {}; + + @Override + public ArrayList getHand() { + return super.getHand(); + } + + @Override + public void setHand(ArrayList hand) { + super.setHand(hand); + } + + @Override + public Double getAccount() { + return super.getAccount(); + } + +} diff --git a/src/main/java/io/zipcoder/casino/player/GoFishPlayerNPC.java b/src/main/java/io/zipcoder/casino/player/GoFishPlayerNPC.java new file mode 100644 index 000000000..3654b3424 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/player/GoFishPlayerNPC.java @@ -0,0 +1,22 @@ +package io.zipcoder.casino.player; + +public class GoFishPlayerNPC extends CardGamePlayer implements NPCInterface { + + + String betType; // red/back - odd / even / number + + public void bet(Double bet) { + + } + + public void betType(String betType) { + + } + + public void logicNPC() { + + } + + public void endturn() {}; + +} diff --git a/src/main/java/io/zipcoder/casino/player/NPCInterface.java b/src/main/java/io/zipcoder/casino/player/NPCInterface.java new file mode 100644 index 000000000..a6b64ebdc --- /dev/null +++ b/src/main/java/io/zipcoder/casino/player/NPCInterface.java @@ -0,0 +1,9 @@ +package io.zipcoder.casino.player; + +interface NPCInterface { + void bet(Double bet); + + void betType (String betType); + + void logicNPC(); +} diff --git a/src/main/java/io/zipcoder/casino/player/Player.java b/src/main/java/io/zipcoder/casino/player/Player.java new file mode 100644 index 000000000..b596d5388 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/player/Player.java @@ -0,0 +1,47 @@ +package io.zipcoder.casino.player; + +public class Player { +private String name = "Elvis"; +private Double account = 0.0; +private Boolean isPlaying = false; + + public Boolean getPlaying() { + return isPlaying; + } + + public void setPlaying(Boolean playing) { + isPlaying = playing; + } + + + public Player(){} + + public Player(Double account) { + this.account = account; + } + + public Player(String name) { + this.name = name; + } + + public Player(String name, Double account) { + this.account = account; + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Double getAccount() { + return account; + } + + public void setAccount(Double sum) { + this.account = sum; + } +} diff --git a/src/main/java/io/zipcoder/casino/player/RoulettePlayer.java b/src/main/java/io/zipcoder/casino/player/RoulettePlayer.java new file mode 100644 index 000000000..8538374d7 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/player/RoulettePlayer.java @@ -0,0 +1,34 @@ +package io.zipcoder.casino.player; + +import java.util.Random; + +public class RoulettePlayer extends Player implements GamblerInterface { + + + public RoulettePlayer(String name, Double account) { + super(name, account); + } + + public void bet(Double bet) { + + } + + public void betType (String betType) { + + } + + public void cashout() { + System.out.println("Your balance has been cashed" +this.getAccount()); + + } + + public void displayAccoutBal() { + + } + + // TODO - Create method for updating current Balance - Arg - int + // Get current balance using getAccount() + + // Add the argument to currentBalance + // set the balance using setAccount +} diff --git a/src/main/java/io/zipcoder/casino/player/SlotsPlayer.java b/src/main/java/io/zipcoder/casino/player/SlotsPlayer.java new file mode 100644 index 000000000..2680498aa --- /dev/null +++ b/src/main/java/io/zipcoder/casino/player/SlotsPlayer.java @@ -0,0 +1,37 @@ +package io.zipcoder.casino.player; + +public class SlotsPlayer extends Player implements GamblerInterface { + + public Player player; + + + public SlotsPlayer(){ + + } + public SlotsPlayer(Player player){ + this.player = player; + } + + + public void bet(Double bet) { + + } + + public void betType (String betType) { + + } + + public void cashout() { + + } + + @Override + public Double getAccount() { + return super.getAccount(); + } + + + public void displayAccoutBal() { + + } +} diff --git a/src/main/java/io/zipcoder/casino/utilities/Console.java b/src/main/java/io/zipcoder/casino/utilities/Console.java index ab896c956..40cfbaf20 100644 --- a/src/main/java/io/zipcoder/casino/utilities/Console.java +++ b/src/main/java/io/zipcoder/casino/utilities/Console.java @@ -42,6 +42,8 @@ public Double getDoubleInput(String prompt, Object... args) { } } + + public Long getLongInput(String prompt, Object... args) { String stringInput = getStringInput(prompt, args); try { diff --git a/src/test/io/zipcoder/casino/HandlerTest.java b/src/test/io/zipcoder/casino/HandlerTest.java new file mode 100644 index 000000000..c669a5a7f --- /dev/null +++ b/src/test/io/zipcoder/casino/HandlerTest.java @@ -0,0 +1,52 @@ +package io.zipcoder.casino; + +import io.zipcoder.casino.player.Player; +import org.junit.Assert; +import org.junit.Test; + + +public class HandlerTest { + + + + @Test + public void createPlayer() { + Handler handler = new Handler(); + Player player; + String name = "bob"; + Double account = 100.0; + + player = handler.createPlayer(name, account); + + Assert.assertEquals("bob", player.getName()); + + } + + + @Test + public void testAccountInputneg() { + Handler handler = new Handler(); + Boolean actual = handler.testAccountInput(-2445.0); + Boolean expeceted = false; + + Assert.assertEquals(expeceted,actual); + } + + @Test + public void testAccountInputOver() { + Handler handler = new Handler(); + Boolean actual = handler.testAccountInput(Double.MAX_VALUE+10); + Boolean expeceted = false; + + Assert.assertEquals(expeceted,actual); + } + + @Test + public void testAccountInputHappy() { + Handler handler = new Handler(); + Boolean actual = handler.testAccountInput(1000.0); + Boolean expeceted = true; + + Assert.assertEquals(expeceted,actual); + } +} \ No newline at end of file diff --git a/src/test/io/zipcoder/casino/gameTools/DeckTest.java b/src/test/io/zipcoder/casino/gameTools/DeckTest.java new file mode 100644 index 000000000..9c1c304f1 --- /dev/null +++ b/src/test/io/zipcoder/casino/gameTools/DeckTest.java @@ -0,0 +1,94 @@ +package io.zipcoder.casino.gameTools; + +import io.zipcoder.casino.player.CardGamePlayer; +import io.zipcoder.casino.player.GoFishPlayer; +import io.zipcoder.casino.player.Player; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.EmptyStackException; + +import static io.zipcoder.casino.gameTools.Suit.CLUBS; + +public class DeckTest { + + @Test + public void shuffle() { + Deck testDeck = new Deck(); + + Card beforeShuffle = testDeck.getDeck().peek(); + testDeck.shuffle(); + Card afterShuffle = testDeck.getDeck().peek(); + Assert.assertFalse(beforeShuffle.equals(afterShuffle)); + } + @Test + public void shuffleNotWorking() { + Deck testDeck = new Deck(); + Card beforeShuffle = testDeck.getDeck().peek(); + Card afterShuffle = testDeck.getDeck().peek(); + Assert.assertFalse(!beforeShuffle.equals(afterShuffle)); + } + + @Test + public void deal5() { + CardGamePlayer testPlayer = new GoFishPlayer(); + Integer numCards = 5; + Deck deck = new Deck(); + deck.deal(numCards,testPlayer); + Integer expected = 5; + Integer actual = testPlayer.getHand().size(); + Assert.assertEquals(expected,actual); + } + + @Test + public void deal2() { + CardGamePlayer testPlayer = new GoFishPlayer(); + Integer numCards = 2; + Deck deck = new Deck(); + deck.deal(numCards,testPlayer); + Integer expected = 2; + Integer actual = testPlayer.getHand().size(); + Assert.assertEquals(expected,actual); + } + + @Test(expected = EmptyStackException.class) + public void testEmptyStackException() { + CardGamePlayer testPlayer = new GoFishPlayer(); + Integer numCards = 53; + Deck deck = new Deck(); + deck.deal(numCards,testPlayer); + } + @Test(expected = NullPointerException.class) + public void testNumCardslessthan1() { + CardGamePlayer testPlayer = new GoFishPlayer(); + Integer numCards = -1; + Deck deck = new Deck(); + deck.deal(numCards,testPlayer); + testPlayer.getHand().size(); + } + + @Test + public void dealSingleCard1() { + + CardGamePlayer testPlayer = new GoFishPlayer(); + ArrayListtestHand = new ArrayList(2); + Deck deck = new Deck(); + testPlayer.setHand(testHand); + deck.dealSingleCard(testPlayer); + Integer expected = 1; + Integer actual = testPlayer.getHand().size(); + Assert.assertEquals(expected,actual); + } + @Test + public void dealSingleCard2() { + CardGamePlayer testPlayer = new GoFishPlayer(); + ArrayListtestHand = new ArrayList(2); + Deck deck = new Deck(); + testPlayer.setHand(testHand); + deck.dealSingleCard(testPlayer); + Integer expected = 1; + Integer actual = testPlayer.getHand().size(); + Assert.assertEquals(expected,actual); + } +} \ No newline at end of file diff --git a/src/test/io/zipcoder/casino/gameTools/DiceTest.java b/src/test/io/zipcoder/casino/gameTools/DiceTest.java new file mode 100644 index 000000000..3c4428fdc --- /dev/null +++ b/src/test/io/zipcoder/casino/gameTools/DiceTest.java @@ -0,0 +1,18 @@ +package io.zipcoder.casino.gameTools; + +import io.zipcoder.casino.gameTools.Dice; +import org.junit.Assert; +import org.junit.Test; + +public class DiceTest { + + @Test + public void rollDice() { + Dice dice = new Dice(); + Integer result = dice.rollDice(); + + Assert.assertTrue(result <= 12 && result >=2); + } + + +} \ No newline at end of file diff --git a/src/test/io/zipcoder/casino/games/BlackjackTest.java b/src/test/io/zipcoder/casino/games/BlackjackTest.java new file mode 100644 index 000000000..a3fc4289f --- /dev/null +++ b/src/test/io/zipcoder/casino/games/BlackjackTest.java @@ -0,0 +1,93 @@ +package io.zipcoder.casino.games; + + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import io.zipcoder.casino.Handler; +import io.zipcoder.casino.player.Player; + +public class BlackjackTest { + + @Test + public void stayTest() { + + } + + @Test + public void splitTest() { + + } + + @Test + public void doubleDownTest() { + + } + + @Test + public void getPlayer1ScoreTest() { + + } + + @Test + public void setPlayer1ScoreTest() { + + } + + @Test + public void getPlayer2ScoreTest() { + + } + + @Test + public void setPlayer2ScoreTest() { + + } + + @Test + public void nextTurnTest() { + + } + + @Test + public void endGameTest() { + Handler handler = new Handler(); + Player player = handler.createPlayer("Sally", 200.0); + Blackjack blackjack = new Blackjack(); + + + Boolean expected = false; + Boolean actual = player.getPlaying(); + + Assert.assertEquals(expected, actual); + + } + + @Test + public void calcBJPaymentTest() { + Blackjack blackjack = new Blackjack(); + + blackjack.setOdds(3.0); + blackjack.setCurrentBet(10.0); + + Double expected = 30.0; + Double actual = blackjack.calcPayment(blackjack.odds, blackjack.getCurrentBet()); + + Assert.assertEquals(expected, actual); + } +} + + + /* @Test +>>>>>>> modified:src/test/java/io/zipcoder/casino/games/BlackjackTest.java + public void updateAccount(){ + Blackjack blackjack = new Blackjack(); + + blackjack.getBlackJackPlayer().setAccount(30.0); + Double expected = 30.0; + Double actual = blackjack.getBlackJackPlayer().getAccount(); + + Assert.assertEquals(expected, actual); +<<<<<<< HEAD:src/test/io/zipcoder/casino/games/BlackjackTest.java + } +} */ diff --git a/src/test/io/zipcoder/casino/games/CrapsDataHandlerTest.java b/src/test/io/zipcoder/casino/games/CrapsDataHandlerTest.java new file mode 100644 index 000000000..6b00b70d9 --- /dev/null +++ b/src/test/io/zipcoder/casino/games/CrapsDataHandlerTest.java @@ -0,0 +1,213 @@ +package io.zipcoder.casino.games; + +import com.sun.xml.internal.ws.api.ha.StickyFeature; +import io.zipcoder.casino.Handler; +import io.zipcoder.casino.utilities.Console; +import org.junit.Assert; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class CrapsDataHandlerTest { + CrapsDataHandler data = new CrapsDataHandler(); + Handler handler= new Handler(); + + @Test + public void getOnNumber() { + Handler handler = new Handler(); + + Craps craps = new Craps(); + + data.setOnNumber(10); + + Integer expected = 10; + Integer actual = data.getOnNumber(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void setOnNumber() { + Handler handler = new Handler(); + handler.createPlayer("", 100.0); + Craps craps = new Craps(); + + data.setOnNumber(8); + + Integer expected = 8; + Integer actual = data.getOnNumber(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getFirstLineBet() { + Handler handler = new Handler(); + handler.createPlayer("", 100.0); + Craps craps = new Craps(); + + data.setFirstLineBet(10.0); + + Double expected = 10.0; + Double actual = data.getFirstLineBet(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void setFirstLineBet() { + Handler handler = new Handler(); + handler.createPlayer("", 100.0); + Craps craps = new Craps(); + + data.setFirstLineBet(10.0); + + Double expected = 10.0; + Double actual = data.getFirstLineBet(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getSecondLineBet() { + Handler handler = new Handler(); + handler.createPlayer("", 100.0); + Craps craps = new Craps(); + + data.setSecondLineBet(10.0); + + Double expected = 10.0; + Double actual = data.getSecondLineBet(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void setSecondLineBet() { + Handler handler = new Handler(); + handler.createPlayer("", 100.0); + Craps craps = new Craps(); + + data.setSecondLineBet(10.0); + + Double expected = 10.0; + Double actual = data.getSecondLineBet(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getOtherBet() { + Handler handler = new Handler(); + handler.createPlayer("", 100.0); + Craps craps = new Craps(); + + data.setFieldBet(10.0); + + Double expected = 10.0; + Double actual = data.getFieldBet(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void setOtherBet() { + Handler handler = new Handler(); + handler.createPlayer("", 100.0); + Craps craps = new Craps(); + + data.setFieldBet(10.0); + + Double expected = 10.0; + Double actual = data.getFieldBet(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getFirstLineOdds() { + data.setFirstLineOdds(10.0); + Double actual = data.getFirstLineOdds(); + Double expected = 10.0; + + Assert.assertEquals(expected,actual); + } + + @Test + public void setFirstLineOdds() { + data.setFirstLineOdds(10.0); + Double actual = data.getFirstLineOdds(); + Double expected = 10.0; + + Assert.assertEquals(expected,actual); + } + + @Test + public void getSecondLineOdds() { + data.setSecondLineOdds(10.0); + Double actual = data.getSecondLineOdds(); + Double expected = 10.0; + + Assert.assertEquals(expected,actual); + } + + @Test + public void setSecondLineOdds() { + data.setSecondLineOdds(10.0); + Double actual = data.getSecondLineOdds(); + Double expected = 10.0; + + Assert.assertEquals(expected,actual); + } + + @Test + public void getQuit() { + data.setQuit("yes"); + String actual = data.getQuit(); + String expected = "yes"; + + Assert.assertEquals(expected,actual); + + } + + @Test + public void setQuit() { + data.setQuit("yes"); + String actual = data.getQuit(); + String expected = "yes"; + + Assert.assertEquals(expected,actual); + } + + @Test + public void getMakePropBet() { + data.setMakePropBet("no"); + String actual = data.getMakePropBet(); + String expected = "no"; + + Assert.assertEquals(expected,actual); + } + + @Test + public void setMakePropBet() { + data.setMakePropBet("no"); + String actual = data.getMakePropBet(); + String expected = "no"; + + Assert.assertEquals(expected,actual); + } + + @Test + public void getConsole() { + Console actual = data.getConsole(); + Console expected = handler.console; + } + + @Test + public void setConsole() { + data.setConsole(handler.console); + Console actual = data.getConsole(); + Console expected = handler.console; + + } +} \ No newline at end of file diff --git a/src/test/io/zipcoder/casino/games/CrapsTest.java b/src/test/io/zipcoder/casino/games/CrapsTest.java new file mode 100644 index 000000000..49d5f86f2 --- /dev/null +++ b/src/test/io/zipcoder/casino/games/CrapsTest.java @@ -0,0 +1,305 @@ +package io.zipcoder.casino.games; + +import com.sun.org.apache.xpath.internal.operations.Bool; +import io.zipcoder.casino.Handler; +import io.zipcoder.casino.player.CrapsPlayer; +import io.zipcoder.casino.player.Player; +import org.junit.Assert; +import org.junit.Test; + +public class CrapsTest { + + Handler handler = new Handler(); + Player player = handler.createPlayer("", 1000.0); + CrapsPlayer crapsPlayer = new CrapsPlayer(player); + Craps craps = new Craps(crapsPlayer); + + + @Test + public void calcPayment() { + Craps craps = new Craps(); + + craps.setOdds(2.0); + craps.data.setFirstLineBet(10.0); + + Double expected = 20.0; + Double actual = craps.calcPayment(craps.getOdds(), craps.data.getFirstLineBet()); + + Assert.assertEquals(expected, actual); + } + + @Test + public void updateAccount() { + CrapsPlayer crapsPlayer = new CrapsPlayer(); + + crapsPlayer.setAccount(10.0); + Double expected = 10.0; + Double actual = crapsPlayer.getAccount(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void withdraw() { + craps.withdraw(100.0); + Double expected = 900.0; + Double actual = player.getAccount(); + + Assert.assertEquals(expected, actual); + } + + + @Test + public void deposit() { + craps.deposit(100.0); + Double expected = 1100.0; + Double actual = player.getAccount(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void display() { + + } + + @Test + public void hasMoenytoBet() { + Boolean expected = true; + Boolean actual = craps.hasMoenytoBet(50.0, player); + + Assert.assertEquals(expected, actual); + + } + + @Test + public void stage0PlayPlay() { + craps.stage0Play("play"); + + Integer actual = 1; + Integer expected = craps.data.getStage(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void stage0PlayExit() { + craps.stage0Play("exit"); + + Boolean actual = false; + Boolean expected = crapsPlayer.player.getPlaying(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void stage0PlayInvalidInput() { + craps.stage0Play("234234"); + + Integer actual = 0; + Integer expected = craps.data.getStage(); + + Assert.assertEquals(expected, actual); + } + + + @Test + public void stage1Play() { + craps.data.setCurrentRoll(10); + craps.data.setFirstLineBet(500.0); +// + craps.stage1Play(10.0); + + Integer actual = 2; + Integer expected = craps.data.getStage(); + + Assert.assertEquals(expected, actual); + + } + + @Test + public void stage1PlayCrap() { + craps.data.setCurrentRoll(7); + craps.stage1Play(10.0); + + Integer actual = 0; + Integer expected = craps.data.getStage(); + + Assert.assertEquals(expected, actual); + + } + + @Test + public void stage1PlayCrapWin() { + craps.data.setCurrentRoll(7); + + craps.stage1Play(10.0); + + Double actual = 1010.0; + Double expected = player.getAccount(); + + Assert.assertEquals(expected, actual); + + } + + @Test + public void stage2PlayWinOnNumber() { + craps.data.setOnNumber(8); + craps.data.setCurrentRoll(8); + craps.data.setFirstLineBet(10.0); + craps.stage2Play(10.0, 10.0, 5); + + + Double actual = 1100.0; + Double expected = player.getAccount(); + + Assert.assertEquals(expected, actual); + + } + + @Test + public void stage2PlayWinField() { + craps.data.setOnNumber(8); + craps.data.setCurrentRoll(9); + craps.stage2Play(10.0, 10.0, 9); + + + Double actual = 1050.0; + Double expected = player.getAccount(); + + Assert.assertEquals(expected, actual); + + } + + // + @Test + public void stage2PlayCrapOut() { + craps.data.setCurrentRoll(7); + craps.stage2Play(10.0, 10.0, 5); + + Integer actual = 1; + Integer expected = craps.data.getStage(); + + Assert.assertEquals(expected, actual); + + + } + + @Test + public void stage2PlaywinwithOnNumber() { + craps.data.setOnNumber(4); + craps.data.setCurrentRoll(4); + craps.data.setFirstLineBet(10.0); + craps.stage2Play(100.0, 100.0, 9); + + + Double actual = 1680.0; + Double expected = player.getAccount(); + + Assert.assertEquals(expected, actual); + + + } + + @Test + public void hasMoenytoBetFalse() { + Boolean actual = false; + Boolean expected = craps.hasMoenytoBet(100000.0, player); + + Assert.assertEquals(expected, actual); + } + + @Test + public void hasMoenytoBetTrue() { + Boolean actual = true; + Boolean expected = craps.hasMoenytoBet(10.0, player); + + Assert.assertEquals(expected, actual); + } + + @Test + public void hasMoenytoBetexcat() { + Boolean actual = true; + Boolean expected = craps.hasMoenytoBet(1000.0, player); + + Assert.assertEquals(expected, actual); + } + + @Test + public void displayCurrentState() { + String actual = + "*-----------------------------------*\nCurrent Balance: 1000.0\nPassline Bet: 0.0\nCome Out Bet: 0.0\nOn Number: null\nProp Bet Type: 0\nProb Bet: 0.0\n\n*-----------------------------------*\n"; + + String expected = craps.displayCurrentState(); + + Assert.assertEquals(expected, actual); + + + } + + @Test + public void displayWinningRoll() { + craps.data.setCurrentRoll(9); + + String actual = craps.displayWinningRoll(10.0); + String expected = "YOU ROLLED A 9 \n YOU WON 10!"; + + + } + + @Test + public void resetFirstRoundState() { + + craps.stage1Play(100.0); + + + Boolean expeceted1 = false; + Boolean actual1 = craps.data.getComeFirstRound(); + + craps.resetFirstRoundState(); + + Boolean expeceted = true; + Boolean actual = craps.data.getComeFirstRound(); + + Assert.assertEquals(actual,expeceted); + Assert.assertEquals(actual1,expeceted1); + } + + + @Test + public void checkForPropBet() { + + + Boolean actual1 = craps.checkForPropBet("yes");; + Boolean expeceted = true; + Assert.assertEquals(actual1,expeceted); + + } + + @Test + public void checkForPropBetUppercase() { + + + Boolean actual1 = craps.checkForPropBet("Yes");; + Boolean expeceted = true; + Assert.assertEquals(actual1,expeceted); + + } + + @Test + public void checkForPropBetNum() { + + + Boolean actual1 = craps.checkForPropBet("3258235");; + Boolean expeceted = false; + Assert.assertEquals(actual1,expeceted); + + } + + + + @Test + public void keepPlayingOrQuit() { + + } +} \ No newline at end of file diff --git a/src/test/io/zipcoder/casino/games/GoFishTest.java b/src/test/io/zipcoder/casino/games/GoFishTest.java new file mode 100644 index 000000000..ea366b26c --- /dev/null +++ b/src/test/io/zipcoder/casino/games/GoFishTest.java @@ -0,0 +1,245 @@ +package io.zipcoder.casino.games; + +import io.zipcoder.casino.gameTools.Card; +import io.zipcoder.casino.gameTools.CardValue; +import io.zipcoder.casino.gameTools.Suit; +import io.zipcoder.casino.player.GoFishPlayer; +import io.zipcoder.casino.player.Player; +import io.zipcoder.casino.utilities.Console; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; + +public class GoFishTest { + Console console = new Console(System.in, System.out); + Player player = new Player("Aaaaa"); + GoFishPlayer goFishPlayer = new GoFishPlayer(player); + GoFish goFish = new GoFish(goFishPlayer,console); + + + @Test + public void removeFourTest() { + GoFish goFish = new GoFish(); + ArrayList hand = new ArrayList(4); + Card card1 = new Card(CardValue.ACE, Suit.CLUBS); + Card card2 = new Card(CardValue.ACE, Suit.CLUBS); + Card card3 = new Card(CardValue.ACE, Suit.CLUBS); + Card card4 = new Card(CardValue.ACE, Suit.CLUBS); + hand.add(card1); + hand.add(card2); + hand.add(card3); + hand.add(card4); + goFish.removeFour("ACE",hand); + Integer expected = 0; + Integer actual = hand.size(); + Assert.assertEquals(expected,actual); + } + + @Test + public void removeFourTest1() { + GoFish goFish = new GoFish(); + ArrayList hand = new ArrayList(4); + Card card1 = new Card(CardValue.ACE, Suit.CLUBS); + Card card2 = new Card(CardValue.ACE, Suit.CLUBS); + Card card3 = new Card(CardValue.ACE, Suit.CLUBS); + Card card4 = new Card(CardValue.ACE, Suit.CLUBS); + Card card5 = new Card(CardValue.TWO, Suit.CLUBS); + + hand.add(card1); + hand.add(card2); + hand.add(card3); + hand.add(card4); + hand.add(card5); + + goFish.removeFour("ACE",hand); + Integer expected = 1; + Integer actual = hand.size(); + Assert.assertEquals(expected,actual); + } + + @Test + public void removeFourTest2() { + GoFish goFish = new GoFish(); + ArrayList hand = new ArrayList(4); + Card card1 = new Card(CardValue.ACE, Suit.CLUBS); + Card card2 = new Card(CardValue.ACE, Suit.CLUBS); + Card card3 = new Card(CardValue.ACE, Suit.CLUBS); + Card card4 = new Card(CardValue.ACE, Suit.CLUBS); + Card card5 = new Card(CardValue.TWO, Suit.CLUBS); + + hand.add(card1); + hand.add(card2); + hand.add(card3); + hand.add(card4); + hand.add(card5); + + goFish.removeFour("ACE",hand); + Assert.assertTrue(hand.get(0).equals(card5)); + } + + + @Test + public void checkProperPickTest() { + ArrayList hand = new ArrayList(4); + Card card1 = new Card(CardValue.ACE, Suit.CLUBS); + Card card2 = new Card(CardValue.ACE, Suit.CLUBS); + Card card3 = new Card(CardValue.ACE, Suit.CLUBS); + Card card4 = new Card(CardValue.ACE, Suit.CLUBS); + Card card5 = new Card(CardValue.TWO, Suit.CLUBS); + hand.add(card1); + hand.add(card2); + hand.add(card3); + hand.add(card4); + hand.add(card5); + goFishPlayer.setHand(hand); + Assert.assertTrue(goFish.checkProperPick("TWO",goFishPlayer)); + } + @Test + public void checkProperPickTest1() { + ArrayList hand = new ArrayList(4); + Card card1 = new Card(CardValue.ACE, Suit.CLUBS); + Card card2 = new Card(CardValue.ACE, Suit.CLUBS); + Card card3 = new Card(CardValue.ACE, Suit.CLUBS); + Card card4 = new Card(CardValue.ACE, Suit.CLUBS); + Card card5 = new Card(CardValue.TWO, Suit.CLUBS); + hand.add(card1); + hand.add(card2); + hand.add(card3); + hand.add(card4); + hand.add(card5); + goFishPlayer.setHand(hand); + Assert.assertFalse(goFish.checkProperPick("SIX",goFishPlayer)); + } + @Test (expected = NullPointerException.class) + public void checkProperPickTest2() { + ArrayList hand = new ArrayList(4); + Card card1 = new Card(CardValue.ACE, Suit.CLUBS); + Card card2 = new Card(CardValue.ACE, Suit.CLUBS); + Card card3 = new Card(CardValue.ACE, Suit.CLUBS); + Card card4 = new Card(CardValue.ACE, Suit.CLUBS); + Card card5 = new Card(CardValue.TWO, Suit.CLUBS); + hand.add(card1); + hand.add(card2); + hand.add(card3); + hand.add(card4); + hand.add(card5); + goFishPlayer.setHand(hand); + goFish.checkProperPick("SIX",new GoFishPlayer()); + } + + @Test + public void checkForFourTest() { + ArrayList hand = new ArrayList(4); + Card card1 = new Card(CardValue.ACE, Suit.CLUBS); + Card card2 = new Card(CardValue.ACE, Suit.CLUBS); + Card card3 = new Card(CardValue.ACE, Suit.CLUBS); + Card card4 = new Card(CardValue.ACE, Suit.CLUBS); + Card card5 = new Card(CardValue.TWO, Suit.CLUBS); + hand.add(card1); + hand.add(card2); + hand.add(card3); + hand.add(card4); + hand.add(card5); + goFishPlayer.setHand(hand); + goFish.checkForFour(goFishPlayer); + Integer expected = 1; + Integer actual = goFishPlayer.getHand().size(); + Assert.assertTrue(goFish.checkForFour(goFishPlayer)); + } + @Test + public void checkForFourTest1() { + ArrayList hand = new ArrayList(4); + Card card1 = new Card(CardValue.KING, Suit.CLUBS); + Card card2 = new Card(CardValue.ACE, Suit.CLUBS); + Card card3 = new Card(CardValue.ACE, Suit.CLUBS); + Card card4 = new Card(CardValue.ACE, Suit.CLUBS); + Card card5 = new Card(CardValue.TWO, Suit.CLUBS); + hand.add(card1); + hand.add(card2); + hand.add(card3); + hand.add(card4); + hand.add(card5); + goFishPlayer.setHand(hand); + goFish.checkForFour(goFishPlayer); + Integer expected = 1; + Integer actual = goFishPlayer.getHand().size(); + Assert.assertFalse(goFish.checkForFour(goFishPlayer)); + } + + @Test + public void playAgainTest() { + String choice = "YES"; + Assert.assertTrue(goFish.playAgain(choice)); + } + @Test + public void playAgainTest1() { + String choice = "no"; + Assert.assertFalse(goFish.playAgain(choice)); + } + + @Test + public void removeFromHandTest() { + ArrayList hand = new ArrayList(4); + Card card1 = new Card(CardValue.KING, Suit.CLUBS); + Card card2 = new Card(CardValue.ACE, Suit.CLUBS); + Card card3 = new Card(CardValue.ACE, Suit.CLUBS); + Card card4 = new Card(CardValue.ACE, Suit.CLUBS); + Card card5 = new Card(CardValue.TWO, Suit.CLUBS); + hand.add(card1); + hand.add(card2); + hand.add(card3); + hand.add(card4); + hand.add(card5); + ArrayList cardsRemove = new ArrayList(); + cardsRemove.add(card1); + goFishPlayer.setHand(hand); + goFish.removeFromHand(cardsRemove,goFishPlayer); + Integer expected = 4; + Integer actual = goFishPlayer.getHand().size(); + Assert.assertEquals(expected,actual); + } + @Test + public void removeFromHandTest1() { + ArrayList hand = new ArrayList(4); + Card card1 = new Card(CardValue.KING, Suit.CLUBS); + Card card2 = new Card(CardValue.ACE, Suit.CLUBS); + Card card3 = new Card(CardValue.ACE, Suit.CLUBS); + Card card4 = new Card(CardValue.ACE, Suit.CLUBS); + Card card5 = new Card(CardValue.TWO, Suit.CLUBS); + hand.add(card1); + hand.add(card2); + hand.add(card3); + hand.add(card4); + hand.add(card5); + ArrayList cardsRemove = new ArrayList(); + cardsRemove.addAll(hand); + goFishPlayer.setHand(hand); + goFish.removeFromHand(cardsRemove,goFishPlayer); + Assert.assertTrue(goFishPlayer.getHand().isEmpty()); + } + + @Test + public void addToHandTest() { + ArrayList hand = new ArrayList(4); + Card card1 = new Card(CardValue.KING, Suit.CLUBS); + Card card2 = new Card(CardValue.ACE, Suit.CLUBS); + Card card3 = new Card(CardValue.ACE, Suit.CLUBS); + Card card4 = new Card(CardValue.ACE, Suit.CLUBS); + Card card5 = new Card(CardValue.TWO, Suit.CLUBS); + hand.add(card1); + hand.add(card2); + hand.add(card3); + hand.add(card4); + hand.add(card5); + ArrayList cardsToAdd = new ArrayList(); + cardsToAdd.add(card1); + goFishPlayer.setHand(hand); + goFish.addToHand(cardsToAdd,goFishPlayer); + Integer expected = 6; + Integer actual = goFishPlayer.getHand().size(); + Assert.assertEquals(expected,actual); + } + +} + diff --git a/src/test/io/zipcoder/casino/games/RouletteTest.java b/src/test/io/zipcoder/casino/games/RouletteTest.java new file mode 100644 index 000000000..e19b14164 --- /dev/null +++ b/src/test/io/zipcoder/casino/games/RouletteTest.java @@ -0,0 +1,92 @@ +package io.zipcoder.casino.games; + +import io.zipcoder.casino.games.Roulette; +import io.zipcoder.casino.player.Player; +import io.zipcoder.casino.player.RoulettePlayer; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class RouletteTest { + private Roulette roulette; + + + @Before //it will get invoked before each test method + public void setup() { + RoulettePlayer roulettePlayer = new RoulettePlayer("Player", 20d); + this.roulette = new Roulette(roulettePlayer); + } + + + + + + @Test + public void calcPaymentTest() { + + Integer actual = this.roulette.calcPayment(1, 35); + Assert.assertEquals(36,actual.intValue()); + } + +// @Test +// public void updateAccountTest() { +// this.roulette.updateAccount(10); +// Double actual = this.roulette.roulettePlayer.getAccount(); +// Assert.assertEquals(10,actual.doubleValue(),0.0); +// +// } + + + @Test + public void calcPaymentDoubleTest(){ + Double actual = this.roulette.calcPayment(2.5,2d); + Assert.assertEquals(7.5,actual.doubleValue(),0.0); + + } + + + @Test + public void isWinnerEvenTest() { + boolean actual = this.roulette.isWinner("even",2); + Assert.assertEquals(true,actual); + + } + + @Test + public void isWinnerOddTest() { + boolean actual = this.roulette.isWinner("odd",3); + Assert.assertEquals(true,actual); + + } + @Test + public void isWinnerRedTest() { + boolean actual = this.roulette.isWinner("red",12); + Assert.assertEquals(true,actual); + + } + @Test + public void isWinnerBlackTest() { + boolean actual = this.roulette.isWinner("black",35); + Assert.assertEquals(true,actual); + + } + @Test + public void isFirstTwelveTest() { + boolean actual = this.roulette.isWinner("1st12",12); + Assert.assertEquals(true,actual); + + } + @Test + public void isSecondTwelveTest() { + boolean actual = this.roulette.isWinner("2nd12",13); + Assert.assertEquals(true,actual); + + } + @Test + public void isThirdTwelveTest() { + boolean actual = this.roulette.isWinner("3rd12",35); + Assert.assertEquals(true,actual); + + } + +} diff --git a/src/test/io/zipcoder/casino/player/CrapsPlayerTest.java b/src/test/io/zipcoder/casino/player/CrapsPlayerTest.java new file mode 100644 index 000000000..f2dae4178 --- /dev/null +++ b/src/test/io/zipcoder/casino/player/CrapsPlayerTest.java @@ -0,0 +1,29 @@ +package io.zipcoder.casino.player; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class CrapsPlayerTest { + + + @Test + public void roll1() { + } + + @Test + public void bet() { + } + + @Test + public void betType() { + } + + @Test + public void cashout1() { + } + + @Test + public void displayAccoutBal() { + } +} \ No newline at end of file diff --git a/src/test/io/zipcoder/casino/player/GoFishPlayerTest.java b/src/test/io/zipcoder/casino/player/GoFishPlayerTest.java new file mode 100644 index 000000000..c4a5f2fc3 --- /dev/null +++ b/src/test/io/zipcoder/casino/player/GoFishPlayerTest.java @@ -0,0 +1,46 @@ +package io.zipcoder.casino.player; + +import io.zipcoder.casino.gameTools.Card; +import io.zipcoder.casino.gameTools.Deck; +import io.zipcoder.casino.player.GoFishPlayer; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; + +import static org.junit.Assert.*; + +public class GoFishPlayerTest { + GoFishPlayer goFishPlayer = new GoFishPlayer(); + ArrayList hand = new ArrayList(1); + + + @Test + public void endturn() { + } + + @Test + public void getHand() { + Deck deck = new Deck(); + deck.deal(1,goFishPlayer); + Integer expected = 1; + Integer actual = goFishPlayer.getHand().size(); + Assert.assertEquals(expected,actual); + } + @Test + public void getHand1() { + Deck deck = new Deck(); + deck.deal(52,goFishPlayer); + Integer expected = 52; + Integer actual = goFishPlayer.getHand().size(); + Assert.assertEquals(expected,actual); + } + + @Test + public void setHand() { + } + + @Test + public void getAccount() { + } +} \ No newline at end of file diff --git a/src/test/io/zipcoder/casino/player/PlayerTest.java b/src/test/io/zipcoder/casino/player/PlayerTest.java new file mode 100644 index 000000000..5b5c69d0c --- /dev/null +++ b/src/test/io/zipcoder/casino/player/PlayerTest.java @@ -0,0 +1,40 @@ +package io.zipcoder.casino.player; + +import io.zipcoder.casino.Handler; +import org.junit.Assert; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class PlayerTest { + + @Test + public void getName() { + Player player = new Player("bob" , 100.0); + Assert.assertEquals("bob", player.getName()); + } + + @Test + public void setName() { + Player player = new Player(); + player.setName("bob"); + Assert.assertEquals("bob", player.getName()); + } + + @Test + public void getAccount() { + Player player = new Player("bob", 10000.0); + Double expected = 10000.0; + Double actual = player.getAccount(); + Assert.assertEquals(expected, actual); + } + + @Test + public void setAccount() { + Player player = new Player(); + player.setAccount(100.0); + Double expected = 100.0; + Double actual = player.getAccount(); + Assert.assertEquals(expected, actual); + } +} \ No newline at end of file diff --git a/src/test/io/zipcoder/casino/player/RoulettePlayerTest.java b/src/test/io/zipcoder/casino/player/RoulettePlayerTest.java new file mode 100644 index 000000000..e4fcf3670 --- /dev/null +++ b/src/test/io/zipcoder/casino/player/RoulettePlayerTest.java @@ -0,0 +1,27 @@ +package io.zipcoder.casino.player; + +import io.zipcoder.casino.player.RoulettePlayer; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class RoulettePlayerTest { + private RoulettePlayer roulettePlayer; + @Before + public void setup() { + String name = ""; + Double account = 0.0; + this.roulettePlayer = new RoulettePlayer(name,account); + } + + @Test + public void cashoutTest() { + this.roulettePlayer.cashout(); + Double actual = this.roulettePlayer.getAccount(); + + Assert.assertEquals(0.0,actual.doubleValue(),0.0); + } + + + +} diff --git a/src/test/io/zipcoder/casino/player/gameTools/CardTest.java b/src/test/io/zipcoder/casino/player/gameTools/CardTest.java new file mode 100644 index 000000000..aeca25c70 --- /dev/null +++ b/src/test/io/zipcoder/casino/player/gameTools/CardTest.java @@ -0,0 +1,43 @@ +package io.zipcoder.casino.player.gameTools; + +import com.sun.source.tree.AssertTree; +import io.zipcoder.casino.gameTools.Card; +import io.zipcoder.casino.gameTools.CardValue; +import io.zipcoder.casino.gameTools.Deck; +import io.zipcoder.casino.gameTools.Suit; +import org.junit.Assert; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class CardTest { + Deck deck = new Deck(); + + @Test + public void getCardValueAce() { + Card card = deck.getDeck().pop(); + Assert.assertEquals("Ace", CardValue.ACE.name()); + } + @Test + public void getCardValueTwo() { + Card card = deck.getDeck().pop(); + Assert.assertEquals("Two",CardValue.TWO.name()); + } + + @Test + public void getSuitSpades() { + Card card = deck.getDeck().pop(); + Assert.assertEquals("Spades", Suit.SPADES.name()); + } + @Test + public void getSuitHearts() { + Card card = deck.getDeck().pop(); + Assert.assertEquals("Hearts",Suit.HEARTS.name()); + } + @Test + public void checkObjectTest(){ + Object card = deck.getDeck().pop(); + Assert.assertTrue(card instanceof Card); + } + +} \ No newline at end of file diff --git a/src/test/java/io/zipcoder/casino/CasinoTest.java b/src/test/java/io/zipcoder/casino/CasinoTest.java deleted file mode 100644 index e92865236..000000000 --- a/src/test/java/io/zipcoder/casino/CasinoTest.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.zipcoder.casino; - - -public class CasinoTest { -}