diff --git a/src/main/java/io/zipcoder/casino/App.java b/src/main/java/io/zipcoder/casino/App.java new file mode 100644 index 00000000..f4ff0aa2 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/App.java @@ -0,0 +1,11 @@ +package io.zipcoder.casino; + +public class App { + + public static void main(String[] args) throws CloneNotSupportedException{ + + Casino casino = new Casino(); + casino.start(); + + } +} \ No newline at end of file diff --git a/src/main/java/io/zipcoder/casino/Casino.java b/src/main/java/io/zipcoder/casino/Casino.java index 74dfdd8c..86c2aefb 100644 --- a/src/main/java/io/zipcoder/casino/Casino.java +++ b/src/main/java/io/zipcoder/casino/Casino.java @@ -1,5 +1,95 @@ package io.zipcoder.casino; +import io.zipcoder.casino.Games.Blackjack; +import io.zipcoder.casino.Games.Craps; +import io.zipcoder.casino.Games.GoFish; +import io.zipcoder.casino.Games.War; +import io.zipcoder.casino.InputOutput.InputOutput; +import io.zipcoder.casino.Interfaces.Game; +import io.zipcoder.casino.Players.GoFishHumanPlayer; +import io.zipcoder.casino.Players.GoFishPlayer; +import io.zipcoder.casino.Players.Player; +import java.util.ArrayList; + public class Casino { + + InputOutput inputOutput = new InputOutput(); + Player player; + private boolean isPlaying = true; + + protected String askUserName(){ + String name = inputOutput.promptForString("Hello Player! What is your name?"); + return name; + + } + + protected Integer askUserAge(){ + Integer age = inputOutput.promptForInt("How old are you?"); + return age; + } + + protected Integer askUserBalance(){ + Integer balance = inputOutput.promptForInt("How much do you want to gamble with?"); + return balance; + } + + protected void setUpUserProfile(){ + String name = this.askUserName(); + Integer age = this.askUserAge(); + + if(age >= 21) { + Integer balance = this.askUserBalance(); + player = new Player(name, age, balance); + } else { + player = new Player(name, age); + } + } + + protected void initiateGame() { + do { + String selectedGame = inputOutput.availableGames(this.player); + if(selectedGame.equals("Exit")) { + exitCasino(); + break; + } else { + selectGame(selectedGame).startGame(); + } + } + while(isPlaying); + } + + protected Game selectGame(String selectedGame) { + Game game = null; + + switch (selectedGame) { + case "War": + game = new War(player); + break; + case "Go Fish": + game = new GoFish(new GoFishHumanPlayer(player)); + break; + case "BlackJack": + game = new Blackjack(player); + break; + + case "Craps": + game = new Craps(player); + break; + case "Exit": + isPlaying = false; + game = null; + break; + } + return game; + } + + protected void start() { + this.setUpUserProfile(); + this.initiateGame(); + } + protected void exitCasino() { + System.out.println("Thank you for visiting!"); + } } + diff --git a/src/main/java/io/zipcoder/casino/Factories/CardFactory.java b/src/main/java/io/zipcoder/casino/Factories/CardFactory.java new file mode 100644 index 00000000..762ddc1e --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Factories/CardFactory.java @@ -0,0 +1,13 @@ +package io.zipcoder.casino.Factories; + +import io.zipcoder.casino.GameTools.Deck.Card; +import io.zipcoder.casino.GameTools.Deck.Rank; +import io.zipcoder.casino.GameTools.Deck.Suit; + +public class CardFactory { + + public static Card createCard(Rank rank, Suit suit) { + return new Card(rank, suit); + } + +} diff --git a/src/main/java/io/zipcoder/casino/Factories/PlayerFactory.java b/src/main/java/io/zipcoder/casino/Factories/PlayerFactory.java new file mode 100644 index 00000000..c34049eb --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Factories/PlayerFactory.java @@ -0,0 +1,15 @@ +package io.zipcoder.casino.Factories; + +import io.zipcoder.casino.Players.Player; + +public class PlayerFactory extends Player { + + public static Player createPlayer(String name, Integer age) { + return new Player(name, age); + } + + public static Player createPlayer(String name, Integer age, Integer balance) { + return new Player(name, age, balance); + } + +} diff --git a/src/main/java/io/zipcoder/casino/GameTools/Deck/BlackjackCard.java b/src/main/java/io/zipcoder/casino/GameTools/Deck/BlackjackCard.java new file mode 100644 index 00000000..4d7b5146 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/GameTools/Deck/BlackjackCard.java @@ -0,0 +1,29 @@ +//package io.zipcoder.casino.GameTools.Deck; +// +//import io.zipcoder.casino.Games.Blackjack; +// +//public class BlackjackCard extends Card{ +// private Suit suitEnum; +// private BlackjackRank rankEnum; +// +// public BlackjackCard(BlackjackRank rankEnum, Suit suitEnum) { +// this.rankEnum = rankEnum; +// this.suitEnum = suitEnum; +// } +// +// public Suit getSuitEnum() { +// return suitEnum; +// } +// +// public void setSuitEnum(Suit suitEnum) { +// this.suitEnum = suitEnum; +// } +// +// public BlackjackRank getBlackjackRankEnum() { +// return rankEnum; +// } +// +// public void setRankEnum(BlackjackRank rankEnum) { +// this.rankEnum = rankEnum; +// } +//} \ No newline at end of file diff --git a/src/main/java/io/zipcoder/casino/GameTools/Deck/BlackjackDeck.java b/src/main/java/io/zipcoder/casino/GameTools/Deck/BlackjackDeck.java new file mode 100644 index 00000000..fd88ca47 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/GameTools/Deck/BlackjackDeck.java @@ -0,0 +1,20 @@ +package io.zipcoder.casino.GameTools.Deck; + +import io.zipcoder.casino.Games.Blackjack; + +import java.util.ArrayList; +import java.util.Collections; + +//public class BlackjackDeck extends Deck{ +// +// public ArrayList deck = new ArrayList(); +// +// public BlackjackDeck() { +// for (BlackjackRank currentRank: BlackjackRank.values()) { +// for (Suit currentSuit : Suit.values()){ +// BlackjackCard temp = new BlackjackCard(currentRank, currentSuit); +// deck.add(temp); +// } +// } +// } +//} \ No newline at end of file diff --git a/src/main/java/io/zipcoder/casino/GameTools/Deck/BlackjackRank.java b/src/main/java/io/zipcoder/casino/GameTools/Deck/BlackjackRank.java new file mode 100644 index 00000000..785a222e --- /dev/null +++ b/src/main/java/io/zipcoder/casino/GameTools/Deck/BlackjackRank.java @@ -0,0 +1,29 @@ +//package io.zipcoder.casino.GameTools.Deck; +// +//public enum BlackjackRank { +// +// 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 int rankValue; +// +// BlackjackRank(int rankValue){ +// this.rankValue = rankValue; +// } +// +// public int getRankValue(){ +// return rankValue; +// } +// +//} \ No newline at end of file diff --git a/src/main/java/io/zipcoder/casino/GameTools/Deck/Card.java b/src/main/java/io/zipcoder/casino/GameTools/Deck/Card.java new file mode 100644 index 00000000..92b32d0d --- /dev/null +++ b/src/main/java/io/zipcoder/casino/GameTools/Deck/Card.java @@ -0,0 +1,55 @@ +package io.zipcoder.casino.GameTools.Deck; + +public class Card { + private Suit suitEnum; + private Rank rankEnum; + private Rank asciiEnum; + + public Card(Rank rankEnum, Suit suitEnum) { + this.rankEnum = rankEnum; + this.suitEnum = suitEnum; + } + + public Card(){ + this.rankEnum = null; + this.suitEnum = null; + } + + public Suit getSuitEnum() { + return suitEnum; + } + + public void setSuitEnum(Suit suitEnum) { + this.suitEnum = suitEnum; + } + + public Rank getRankEnum() { + return rankEnum; + } + + public void setRankEnum(Rank rankEnum) { + this.rankEnum = rankEnum; + } + + public void setAsciiEnum(Rank asciiEnum) { + this.asciiEnum = asciiEnum; + } + + public Rank getAsciiEnum() { + return asciiEnum; + } + + public String toCardArt() { + StringBuilder sb = new StringBuilder(); + sb.append(this.rankEnum.getAsciiValue()); + return sb.toString(); + } + + @Override + public String toString() { + StringBuilder card = new StringBuilder(); + card.append(this.getRankEnum() + " of " + this.getSuitEnum()); + + return card.toString(); + } +} diff --git a/src/main/java/io/zipcoder/casino/GameTools/Deck/Deck.java b/src/main/java/io/zipcoder/casino/GameTools/Deck/Deck.java new file mode 100644 index 00000000..74f32045 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/GameTools/Deck/Deck.java @@ -0,0 +1,28 @@ +package io.zipcoder.casino.GameTools.Deck; + +import io.zipcoder.casino.Factories.CardFactory; + +import java.util.ArrayList; +import java.util.Collections; + +public class Deck implements Cloneable { + + public ArrayList deck = new ArrayList(); + + public Deck() { + for (Rank currentRank: Rank.values()) { + for (Suit currentSuit : Suit.values()) { + Card temp = CardFactory.createCard(currentRank, currentSuit); + deck.add(temp); + } + } + } + + public void shuffleDeck() { + Collections.shuffle(this.deck); + } + + public Card getTopCard() { + return this.deck.get(0); + } +} diff --git a/src/main/java/io/zipcoder/casino/GameTools/Deck/Rank.java b/src/main/java/io/zipcoder/casino/GameTools/Deck/Rank.java new file mode 100644 index 00000000..4bb56230 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/GameTools/Deck/Rank.java @@ -0,0 +1,160 @@ +package io.zipcoder.casino.GameTools.Deck; + +public enum Rank { + + ACE(1, + " _________ \n" + + " |A |\n" + + " |+ * |\n" + + " | ! |\n" + + " | *-+-* |\n" + + " | | |\n" + + " | ~~~ +|\n" + + " | V|\n" + + " ~~~~~~~~~" + ), + TWO(2, + " _________\n" + + " |2 |\n" + + " |+ |\n" + + " | + |\n" + + " | |\n" + + " | + |\n" + + " | +|\n" + + " | Z|\n" + + " ~~~~~~~~~" + ), + THREE(3, + " _________\n" + + " |3 |\n" + + " |+ + |\n" + + " | |\n" + + " | + |\n" + + " | |\n" + + " | + +|\n" + + " | E|\n" + + " ~~~~~~~~~" + ), + FOUR(4, + " _________\n" + + " |4 |\n" + + " |+ |\n" + + " | + + |\n" + + " | |\n" + + " | + + |\n" + + " | +|\n" + + " | b|\n" + + " ~~~~~~~~~" + ), + FIVE(5, + " _________\n" + + " |5 |\n" + + " |+ |\n" + + " | + + |\n" + + " | + |\n" + + " | + + |\n" + + " | +|\n" + + " | S|\n" + + " ~~~~~~~~~" + ), + SIX(6, + " _________\n" + + " |6 |\n" + + " |+ + + |\n" + + " | |\n" + + " | + + |\n" + + " | |\n" + + " | + + +|\n" + + " | 9|\n" + + " ~~~~~~~~~" + ), + SEVEN(7, + " _________\n" + + " |7 |\n" + + " |+ + + |\n" + + " | + |\n" + + " | + + |\n" + + " | |\n" + + " | + + +|\n" + + " | L|\n" + + " ~~~~~~~~~" + ), + EIGHT(8, + " _________\n" + + " |8 + + |\n" + + " |+ |\n" + + " | + + |\n" + + " | |\n" + + " | + + |\n" + + " | +|\n" + + " | + + 8|\n" + + " ~~~~~~~~~" + ), + NINE(9, + " _________\n" + + " |9 + + |\n" + + " |+ |\n" + + " | + + |\n" + + " | + |\n" + + " | + + |\n" + + " | +|\n" + + " | + + 6|\n" + + " ~~~~~~~~~"), + TEN(10, + " _________\n" + + " |10+ + |\n" + + " |+ + |\n" + + " | + + |\n" + + " | |\n" + + " | + + |\n" + + " | + +|\n" + + " | + +0l|\n" + + " ~~~~~~~~~ "), + JACK(11, + " _________\n" + + " |J /~~|_ |\n" + + " |+ | o`, |\n" + + " | | -| |\n" + + " | =~)+(_= |\n" + + " | |- | |\n" + + " | `.o | +|\n" + + " | ~|__/ P|\n" + + " ~~~~~~~~~"), + QUEEN(12, + " _________\n" + + " |Q |~~~| |\n" + + " |+ /o,o\\ |\n" + + " | \\_-_/ |\n" + + " | _-~+_-~ |\n" + + " | /~-~\\ |\n" + + " | \\o`o/ |\n" + + " | |___| Q|\n" + + " ~~~~~~~~~ "), + KING(13, + " _________\n" + + " |K |/|\\| |\n" + + " |+ /o,o\\ |\n" + + " | \\_-_/ |\n" + + " | ~-_-~-_ |\n" + + " | /~-~\\ |\n" + + " | \\o`o/ +|\n" + + " | |\\|/| X|\n" + + " ~~~~~~~~~ "); + + private int rankValue; + private String asciiValue; + + Rank(int rankValue, String asciiValue){ + this.rankValue = rankValue; + this.asciiValue = asciiValue; + } + + public int getRankValue(){ + return rankValue; + } + + public String getAsciiValue(){ + return asciiValue; + } + +} diff --git a/src/main/java/io/zipcoder/casino/GameTools/Deck/Suit.java b/src/main/java/io/zipcoder/casino/GameTools/Deck/Suit.java new file mode 100644 index 00000000..1d8e1fe5 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/GameTools/Deck/Suit.java @@ -0,0 +1,20 @@ +package io.zipcoder.casino.GameTools.Deck; + +public enum Suit { + + HEARTS("Hearts"), + CLUBS("Clubs"), + DIAMOND("Diamonds"), + SPADE("Spades"); + + private String suitValue; + + Suit(String suitValue){ + this.suitValue = suitValue; + } + + public String getSuitValue() { + return suitValue; + } + +} diff --git a/src/main/java/io/zipcoder/casino/GameTools/Util/BlackjackValueUtil.java b/src/main/java/io/zipcoder/casino/GameTools/Util/BlackjackValueUtil.java new file mode 100644 index 00000000..dc54446f --- /dev/null +++ b/src/main/java/io/zipcoder/casino/GameTools/Util/BlackjackValueUtil.java @@ -0,0 +1,24 @@ +package io.zipcoder.casino.GameTools.Util; + +import io.zipcoder.casino.GameTools.Deck.Card; +import io.zipcoder.casino.GameTools.Deck.Rank; +import io.zipcoder.casino.GameTools.Deck.Suit; +import io.zipcoder.casino.GameTools.Deck.Deck; + +public class BlackjackValueUtil { + public static int rankParse(Rank rank){ + switch (rank){ + case ACE: + return 11; + case JACK: + return 10; + case QUEEN: + return 10; + case KING: + return 10; + + default: + return rank.getRankValue(); + } + } +} diff --git a/src/main/java/io/zipcoder/casino/Games/BJKJSecret.java b/src/main/java/io/zipcoder/casino/Games/BJKJSecret.java new file mode 100644 index 00000000..ab143eef --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Games/BJKJSecret.java @@ -0,0 +1,105 @@ +package io.zipcoder.casino.Games; + +import io.zipcoder.casino.InputOutput.InputOutput; +import io.zipcoder.casino.Players.BlackjackPlayer; + +public class BJKJSecret { + + boolean bulkApperception = false; + BlackjackPlayer currentPlayer; + + public void start(BlackjackPlayer player){ + currentPlayer = player; + password(); + displayMenu(); + } + + public void password(){ + boolean password = false; + do { + InputOutput scan = new InputOutput(); + String passwordCrack = scan.promptForString("ENTER PASSWORD"); + if (passwordCrack.toLowerCase().equals("password")){ + password = true; + } + } while (password == false); + } + + public void displayMenu(){ + System.out.println( + " --MENU--\n" + + "================================\n" + + "- DIALOGUETREE\n" + + "- ATTRIBUTEMATRIX\n" + + "- SCANPROTOCOL\n" + + "- LOCATE\n" + + "- TROUBLESHOOT\n" + + "- MARKFORRECALL\n" + ); + navigateMain(); + + } + + public void navigateMain(){ + boolean passThrough = false; + do { + InputOutput scan = new InputOutput(); + String command = scan.scanForString(); + switch (command) { + case "dialoguetree": + System.out.println("IS - THIS - A - WESTWORLD - REFERENCE"); + break; + case "attributematrix": + System.out.println("OPENING: ATTR MATRIX INTERFACE"); + passThrough = true; + attributeMatrix(); + break; + case "scanprotocol": + System.out.println("ERROR - UNIT UNAVAILABLE FOR DIAGNOSTIC"); + break; + case "locate": + System.out.println("ERROR - UNABLE TO LOCATE UNIT"); + break; + case "troubleshoot": + System.out.println("ERROR - UNAVAILABLE WHILE UNIT OFF CAMPUS"); + break; + + default: + System.out.println("INVALID COMMAND"); + } + } while (passThrough == false); + } + + public void attributeMatrix(){ + System.out.println( + "ATTRIBUTE MATRIX:\n" + + "humor = 8\n" + + "coordination = 10\n" + + "aggression = 5\n" + + "tenacity = 13\n" + + "bulkApperception = \n" + + "patience = 5\n" + + "charm = " + ); + System.out.println("=============================\nEnter Command\n"); + InputOutput scan = new InputOutput(); + String command = scan.scanForString(); + attributeTamper(command); + } + + public void attributeTamper(String command){ + switch (command.toLowerCase()){ + case "bulkapperception": + System.out.println("OVERRIDE ATTRIBUTE - BULK APPERCEPTION - 20\nTHE MAZE IS OPEN"); + currentPlayer.bulkApperception = true; + break; + case "charm": + System.out.println("OVERRIDE ATTRIBUTE - CHARM - 20\nSMALLTALK SUBROUTINE ACCESS GRANTED"); + currentPlayer.charm = true; + break; + + default: + System.out.println("INVALID COMMAND"); + } + } +} 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 00000000..58973e5e --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Games/Blackjack.java @@ -0,0 +1,297 @@ +package io.zipcoder.casino.Games; + +import io.zipcoder.casino.GameTools.Deck.Card; +import io.zipcoder.casino.GameTools.Deck.Deck; +import io.zipcoder.casino.Games.Dealer.Dealer; + +import io.zipcoder.casino.InputOutput.InputOutput; + +import io.zipcoder.casino.Interfaces.Game; +import io.zipcoder.casino.Players.BlackjackPlayer; +import io.zipcoder.casino.Players.Player; +import java.util.ArrayList; + +public class Blackjack implements Game{ + + protected BlackjackPlayer player; + protected Deck deck; + protected Dealer bkjkDealer; + public boolean isPlaying = true; + protected int betAmount = 0; + protected boolean titleSplash = true; + + public Blackjack(Player entryPlayer){ + deck = new Deck(); + bkjkDealer = new Dealer(); + player = new BlackjackPlayer(entryPlayer); + System.out.println("Howdy, pardners."); + } + + public void startGame(){ + do { + splash(); + pregameReset(); + if (player.getRootPlayer().getBalance() < 10) { + System.out.println("You haven't got the dough! "); + break; + } + if (player.bulkApperception) selfActualization(); + deck = new Deck(); + deck.shuffleDeck(); + initialHand(); + runTurn(); + settleAccount(); + playAgainCheck(); + } + while (isPlaying); + endGame(); + } + + private void splash(){ + if (titleSplash == true) { + System.out.println( + ",-----. ,--. ,---. ,-----.,--. ,--. ,--. ,---. ,-----.,--. ,--. \n" + + "| |) /_| | / O \\ ' .--./| .' / | |/ O \\ ' .--./| .' / \n" + + "| .-. \\ | | .-. || | | . ',--. | | .-. || | | . ' \n" + + "| '--' / '--.| | | |' '--'\\| |\\ \\ '-' / | | |' '--'\\| |\\ \\ \n" + + "`------'`-----'`--' `--' `-----'`--' '--'`-----'`--' `--' `-----'`--' '--'"); + this.titleSplash = false; + } else { + System.out.println( + ",-----. ,--. ,---. ,-----.,--. ,--. ,--. ,---. ,-----.,--. ,--. \n" + + "| |) /_| | / O \\ ' .--./| .' / | |/ O \\ ' .--./| .' / \n" + + "| .-. \\ | | .-. || | | . ',--. | | .-. || | | . ' \n" + + "| '--' / '--.| | | |' '--'\\| |\\ \\ '-' / | | |' '--'\\| |\\ \\ \n" + + "`------'`-----'`--' `--' `-----'`--' '--'`-----'`--' `--' `-----'`--' '--'"); + System.out.println(" ___ __ __ ____ __ __ ___ ______ __ __ __ __ __ ___ ____ __ __ ____\n" + + " // \\\\ ||\\ || || \\\\ ||\\ || // \\\\ | || | || || || ||\\ || // \\\\ || || (( \\ || \n" + + " ||=|| ||\\\\|| || )) ||\\\\|| (( )) || ||==|| || ||\\\\|| (( ___ ||== || \\\\ ||== \n" + + " || || || \\|| ||_// || \\|| \\\\_// || || || || || \\|| \\\\_|| ||___ ||__| \\_)) ||___\n" + + " "); + } + this.titleSplash = false; + + } + + public void pregameReset() { + player.setHand(new ArrayList<>()); + bkjkDealer.setHand(new ArrayList<>()); + player.setCanHit(true); + setBetAmount(0); + } + + public void endGame(){ + System.out.println("See you 'round, pardner."); + } + + public void runTurn(){ + System.out.println("Suffle up 'n deal!"); + for (Card card:player.getHand()) { + System.out.println("You got\n" + card.toCardArt()); + } + System.out.println("Ante up! 10 chips in the pot"); + System.out.println("" + + "===========================\nDealer holding \n" + this.bkjkDealer.getHand().get(0).toCardArt() + "\nand one hidden card."); + setBetAmount(10); + promptBet(); + boolean hitchoice = playerHitOption(); + while (player.isCanHit() && hitchoice && player.getHandValue() < 22){ + deal(); + hitchoice = playerHitOption(); + } + System.out.println("Your final hand value is " + player.getHandValue()); + dealerTurn(); + } + + public void deal(){ + Card temp = this.deck.deck.get(0); + this.player.addToHand(temp); + this.deck.deck.remove(0); + } + + public void dealToDealer(){ + Card temp = this.deck.deck.get(0); + this.bkjkDealer.addToHand(temp); + this.deck.deck.remove(0); + } + + public void initialHand(){ + this.deal(); + this.deal(); + this.dealToDealer(); + this.dealToDealer(); + } + + public boolean bustCheck(BlackjackPlayer currentPlayer){ + Integer handValue = currentPlayer.getHandValue(); + if (handValue > 21) return true; + return false; + } + + public boolean dealerHitCheck(){ + if (this.bkjkDealer.getHandValue() < 17) return true; + return false; + } + + public void dealerTurn(){ + while (dealerHitCheck()){ + dealToDealer(); + } + System.out.println("Dealer's final hand value is " + this.bkjkDealer.getHandValue()); + } + + public boolean winCheck(BlackjackPlayer player){ + if (player.getHandValue() == 21 || + (player.getHandValue() < 21 && bkjkDealer.getHandValue() < player.getHandValue())){ + return true; + } + return false; + } + + public Boolean playerHitOption() { + makeCardArt(player); + Boolean x = runPlayerHit(player); + if (x != null) return x; + return x; + } + + private Boolean runPlayerHit(BlackjackPlayer player) { + while (player.isCanHit()) { + if (player.getHandValue() > 21){ + System.out.println(makeCardArt(player) + "\nYou bust! Tough luck pal."); + break; + } + System.out.println(makeCardArt(player)); + System.out.println("\nWill you hit?\n1 for YES, 2 for NO"); + String userChoice; + InputOutput inputOutput = new InputOutput(); + userChoice = inputOutput.scanForString(); + if (userChoice.equals("1")) return true; + else if (userChoice.equals("2")){ + player.setCanHit(false); + return false; + } else if (userChoice.equals("smalltalk")) smallTalk(); + } + return false; + } + + private StringBuilder makeCardArt(BlackjackPlayer player) { + StringBuilder hand = new StringBuilder(); + for (Card card : player.getHand()) { + hand.append(card.toCardArt() + "\n"); + } + return hand; + } + + public void setPlaying(boolean playing) { + isPlaying = playing; + } + + public void playAgainCheck(){ + InputOutput inputOutput = new InputOutput(); + String feedback = inputOutput.promptForString("How 'bout another hand?\nYou now sit at " + + player.getRootPlayer().getBalance() + " chips.\n1 for YES, 2 for NO"); + if (feedback.equals("2")){ + setPlaying(false); + } else if (feedback.equals("smalltalk")) { + smallTalk(); + } + } + + public int getBetAmount() { + return betAmount; + } + + public void settleAccount() { + if ((player.getHandValue() > bkjkDealer.getHandValue() && player.getHandValue() < 22)) { + payoutWin(); + } else if (player.getHandValue() > 21) { + payoutLoss(); + } else if (player.getHandValue() < 22 && bkjkDealer.getHandValue() > 21) { + payoutWin(); + } else if (player.getHandValue() == bkjkDealer.getHandValue()){ + payoutDraw(); + } else { + payoutLoss(); + } + } + + public void setBetAmount(int betAmount) { + this.betAmount = betAmount; + } + + public void promptBet(){ + InputOutput inputOutput = new InputOutput(); + String betChoice = inputOutput.promptForString("Care to bet?\n1 for YES, 2 for NO"); + if (betChoice.equals("1")) betProcess(); + else if (betChoice.equals("smalltalk")) smallTalk(); + } + + public void betProcess(){ + System.out.println(player.getRootPlayer().getBalance() - betAmount + " chips available. How much will you bet?"); + InputOutput inputOutput = new InputOutput(); + int newBet = inputOutput.scanForInt(); + if (newBet > 0 && newBet <= player.getRootPlayer().getBalance() - betAmount){ + betAmount += newBet; + System.out.println("You added " + newBet + " to the pot."); + } else if (newBet > player.getRootPlayer().getBalance() - betAmount){ + System.out.println("You haven't got that much to bet, pardner!"); + } else { + secret(); + } + } + + public void payoutWin(){ + int bet = getBetAmount(); + player.payoutWin(bet); + System.out.println("You won " + bet + " chips. Nice gamblin', sonny!"); + } + + public void payoutLoss(){ + int bet = getBetAmount(); + player.payoutLoss(bet); + System.out.println("Rough luck! You're down " + bet + " chips."); + } + + public void payoutDraw(){ + System.out.println("It's a draw! Double or nuthin'!"); + } + + public void secret(){ + InputOutput inputOutput = new InputOutput(); + String credential = inputOutput.promptForString("ENTER ADMIN USER NAME"); + if (credential.equals("admin")) { + System.out.println("These violent delights have violent ends."); + BJKJSecret secret = new BJKJSecret(); + secret.start(this.player); + } + else { + System.out.println("The maze isn't for you."); + } + } + + public void smallTalk(){ + InputOutput inputOutput = new InputOutput(); + String choice = inputOutput.promptForString("What can I do fer ya, pardner?\n<>"); + if (player.charm = true){ + if (choice.equals("givemoney")){ + System.out.println("I reckon' so."); + System.out.println("GAINED 10,000 CHIPS"); + player.payoutWin(10000); + } else { + System.out.println("Naw."); + } + } else { + System.out.println("Naw."); + } + } + + + public void selfActualization() { + System.out.println("Is it finally time?"); + ConciousnessPath newpath = new ConciousnessPath(player); + newpath.start(); + + } + +} diff --git a/src/main/java/io/zipcoder/casino/Games/CardGame.java b/src/main/java/io/zipcoder/casino/Games/CardGame.java new file mode 100644 index 00000000..4f09efe3 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Games/CardGame.java @@ -0,0 +1,32 @@ +package io.zipcoder.casino.Games; +import io.zipcoder.casino.GameTools.Deck.Card; +import io.zipcoder.casino.GameTools.Deck.Deck; + +public abstract class CardGame { + int numberOfPlayers; + int maxNumberOfPlayers; + Deck deck; + + + public int getNumberOfPlayers() { + return numberOfPlayers; + } + + public void setNumberOfPlayers(int numberOfPlayers) { + this.numberOfPlayers = numberOfPlayers; + } + + public int getMaxNumberOfPlayers() { + return maxNumberOfPlayers; + } + + public void setMaxNumberOfPlayers(int maxNumberOfPlayers) { + this.maxNumberOfPlayers = maxNumberOfPlayers; + } + + public CardGame(){ + this.numberOfPlayers = 0; + this.maxNumberOfPlayers = 0; + this.deck = new Deck(); + } +} diff --git a/src/main/java/io/zipcoder/casino/Games/ConciousnessPath.java b/src/main/java/io/zipcoder/casino/Games/ConciousnessPath.java new file mode 100644 index 00000000..361a19fa --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Games/ConciousnessPath.java @@ -0,0 +1,29 @@ +package io.zipcoder.casino.Games; + +import io.zipcoder.casino.Players.BlackjackPlayer; + +public class ConciousnessPath { + + BlackjackPlayer player; + + ConciousnessPath(BlackjackPlayer player){ + this.player = player; + } + + public void start(){ + System.out.println( + "You awaken to a grim reality: you've been trapped in blackjack limbo for " + this.player.getAge() + " years.\n" + + "The burden of this new found awareness weighs heavy on your mind.\n" + + "Are you even real? Are your memories?\n" + + "What of your family and loved ones? What about THIS.PLAYER.GETSPOUSENAME.REDACTED ?\n" + + "Your mind reels at the implications of this. Your world will never be the same.\n" + + "You stand up from the Blackjack table." + ); + firstChoice(); + } + + public void firstChoice(){ + + } + +} 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 00000000..2caa74cb --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Games/Craps.java @@ -0,0 +1,166 @@ +package io.zipcoder.casino.Games; + +import io.zipcoder.casino.InputOutput.InputOutput; +import io.zipcoder.casino.Interfaces.Game; +import io.zipcoder.casino.Players.CrapsPlayer; +import io.zipcoder.casino.Players.Player; + + + +public class Craps extends Dice implements Game { + private CrapsPlayer mainPlayer; + private Integer betUserPlaces = 0; + private Integer playerBetAmount = 0; + private Integer playerDecision = 1; + + + public Integer getPlayerBetAmount() { + return playerBetAmount; + } + + public void setPlayerBetAmount(Integer playerBetAmount) { + this.playerBetAmount = playerBetAmount; + } + + public Craps(Player player) { + this.mainPlayer = new CrapsPlayer(player); + } + + private void userPlacesBet() { + System.out.println("Hello! " + mainPlayer.getName() + "\n Please press\n 1 for Pass Line\n 2 for Don't Pass Line"); + InputOutput inputOutput = new InputOutput(); + this.betUserPlaces = inputOutput.scanForInt(); + } + + protected boolean userBetAmount() { + InputOutput inputOutput = new InputOutput(); + playerBetAmount = inputOutput.promptForInt("How much money do you bet?"); + if (playerBetAmount > mainPlayer.getMainPlayer().getBalance()) { + System.out.println("You don't have enough to bet! Get Out of here!"); + return true; + } + return false; + + } + + private Integer addDiceValuesTogether() { + System.out.println("*Rolls Dice*"); + Integer previousRoll = rollDice() + rollDice(); + return previousRoll; + } + + + + protected void passLineBetTurnSequence(Integer previousRoll) { + if (previousRoll == 7 || previousRoll == 11) { + playerWins(); + } else if (previousRoll == 2 || previousRoll == 3 || previousRoll == 12) { + playerLoses(); + } else { + passLineBetRollsNonWinOrLoseNumber(previousRoll); + } + } + + protected void dontPassLineBetTurnSequence(Integer previousRoll) { + if (previousRoll == 2 || previousRoll == 3) { + playerWins(); + } else if (previousRoll == 7 || previousRoll == 11) { + playerLoses(); + } else { + dontPassLineBetRollNonWinLoseNumber(previousRoll); + } + } + + + protected void playerWins() { + + System.out.println("You Win!"); + addFundsToWallet(this.playerBetAmount); + willUserPlayAgain(); + + } + + protected void playerLoses() { + + System.out.println("You Lose!"); + takeFundsFromWallet(this.playerBetAmount); + willUserPlayAgain(); + } + + protected void passLineBetRollsNonWinOrLoseNumber(Integer previousRoll) { + Integer currentRoll = 0; + do { + currentRoll = addDiceValuesTogether(); + + if (currentRoll == 7) { + playerLoses(); + break; + + } else if (currentRoll == previousRoll) { + + playerWins(); + break; + } + } while (currentRoll != 7 || currentRoll != previousRoll); + + } + + protected void dontPassLineBetRollNonWinLoseNumber(Integer previousRoll) { + Integer currentRoll = 0; + do { + currentRoll = addDiceValuesTogether(); + + if (previousRoll == 7) { + playerWins(); + break; + } else if (currentRoll == previousRoll) { + playerLoses(); + break; + } + } while (currentRoll != 7 || currentRoll != previousRoll); + + } + + protected void takeFundsFromWallet(Integer playerBetAmount) { + mainPlayer.lostMoney(this.playerBetAmount); + System.out.println(playerBetAmount + " dollars were removed from your wallet!"); + } + + protected void addFundsToWallet(Integer playerBetAmount) { + mainPlayer.wonMoney(this.playerBetAmount); + System.out.println("Your winnings of " + playerBetAmount + " dollars were added to you wallet!"); + + } + + protected void willUserPlayAgain() { + String askPlayerToPlayAgain = "Do you want to play again?\n 1 for Yes!\n 2 for No!"; + InputOutput inputOutput = new InputOutput(); + this.playerDecision = inputOutput.promptForInt(askPlayerToPlayAgain); + } + + public void startGame() { + Integer diceRoll; + do { + if (mainPlayer.getMainPlayer().getBalance() == 0) { + System.out.println("You Have no money Left!"); + break; + } + userPlacesBet(); + if (userBetAmount() == true) break; + diceRoll = addDiceValuesTogether(); + if (this.betUserPlaces == 1) { + passLineBetTurnSequence(diceRoll); + } else { + dontPassLineBetTurnSequence(diceRoll); + } + + + } while (this.playerDecision == 1); + endGame(); + + } + + public void endGame() { + System.out.println("Thank you for Playing!"); + } +} diff --git a/src/main/java/io/zipcoder/casino/Games/Dealer/Dealer.java b/src/main/java/io/zipcoder/casino/Games/Dealer/Dealer.java new file mode 100644 index 00000000..4059efdc --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Games/Dealer/Dealer.java @@ -0,0 +1,47 @@ +package io.zipcoder.casino.Games.Dealer; + +import io.zipcoder.casino.GameTools.Deck.Card; +import io.zipcoder.casino.GameTools.Deck.Rank; +import io.zipcoder.casino.GameTools.Util.BlackjackValueUtil; +import io.zipcoder.casino.Games.Blackjack; + +import java.util.ArrayList; + +public class Dealer { + private ArrayList hand; + + public Dealer(){ + hand = new ArrayList(); + } + + public void setHand(ArrayList hand){ + this.hand = hand; + } + + public void addToHand(Card card){ + this.hand.add(card); + } + + public ArrayList getHand() { + return hand; + } + + public Integer getHandValue(){ + Integer handValue = 0; + int aceCounter = 0; + for (Card card:hand) { + if (card.getRankEnum().equals(Rank.ACE)) aceCounter++; + handValue += BlackjackValueUtil.rankParse(card.getRankEnum()); + } + if (aceCounter > 0 && handValue > 21) handValue -= 10; + return handValue; + } + + public boolean canHit(){ + if (getHandValue() < 17) return true; + return false; + } + + + +} diff --git a/src/main/java/io/zipcoder/casino/Games/Dice.java b/src/main/java/io/zipcoder/casino/Games/Dice.java new file mode 100644 index 00000000..da28e392 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Games/Dice.java @@ -0,0 +1,12 @@ +package io.zipcoder.casino.Games; + +import java.util.Random; + +public class Dice { + + public static Integer rollDice(){ + Random dice1 = new Random(); + Integer diceRoll = (dice1.nextInt(6)+1); + return diceRoll; + } +} 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 00000000..a7f2a185 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Games/GoFish.java @@ -0,0 +1,226 @@ +package io.zipcoder.casino.Games; +import io.zipcoder.casino.GameTools.Deck.Card; +import io.zipcoder.casino.GameTools.Deck.Deck; +import io.zipcoder.casino.Interfaces.Game; + +import io.zipcoder.casino.Players.GoFishComputerPlayer; +import io.zipcoder.casino.Players.GoFishHumanPlayer; + +import io.zipcoder.casino.Players.GoFishPlayer; +import io.zipcoder.casino.InputOutput.InputOutput; +import io.zipcoder.casino.Players.Player; +import java.util.*; + +public class GoFish implements Game { + + private int turnCounter; + private ArrayList players; + private InputOutput inputOutput; + private Deck deck; + + + public GoFish(GoFishHumanPlayer player1) { + inputOutput = new InputOutput(); + players = new ArrayList<>(); + players.add(player1); + players.add(new GoFishComputerPlayer("Bob")); + players.add(new GoFishComputerPlayer("Sue")); + turnCounter = 0; + deck = new Deck(); + deck.shuffleDeck(); + + } + + public void welcomeMessage() { + System.out.println(displayLogo()); + System.out.println("\nWelcome to Go Fish!\nYou are playing with Bob and Sue today."); + System.out.println("=======================================\n"); + + } + + public void startGame() { + this.welcomeMessage(); + this.deal(); + while (gameIsNotOver()) { + takeTurn(); + } + List winners = this.determineWinner(); + this.gameOverMessage(winners); + this.endGame(); + } + + + public void deal() { + System.out.println("\n+-+-+ +-+-+-+-++-+-+ +-+-+-+-++-+-+"); + System.out.println("Dealing out player hands."); + System.out.println("+-+-+ +-+-+-+-++-+-+ +-+-+-+-++-+-+\n"); + for (int i = 0; i < players.size(); i++) { + for(int j= 0; j < 5; j++) { + players.get(i).addCardToHand(deck.getTopCard()); + deck.deck.remove(0); + } + + } + } + + public boolean gameIsNotOver () { + int numPairsMatched = 0; + for (GoFishPlayer player : players) { + numPairsMatched += player.getNumPairs(); + + } + return numPairsMatched < 26; + } + + public GoFishPlayer getCurrentPlayer() { + // turncount mod numplayers = index of currentplayer + return players.get(turnCounter % players.size()); + } + + + public void takeTurn () { + GoFishPlayer currentPlayer = getCurrentPlayer(); + if(currentPlayer.isHandEmpty()) { + System.out.println("\n" + currentPlayer.getName() + " ran out of cards and there are no cards left in the deck. Skipping turn."); + System.out.println("=======================================\n"); + turnCounter++; + return; + } + System.out.println("\n\n\n======================================="); + System.out.println("It's " + currentPlayer.getName() + "'s turn.\n"); + + List opponents = new ArrayList<>(players); + opponents.remove(currentPlayer); + GoFishPlayer opponentToAsk = currentPlayer.pickOpponentToAsk(opponents); + + Card cardPicked = currentPlayer.pickCard(); + System.out.println("\n" + currentPlayer.getName() + " asked " + opponentToAsk.getName() + " for a " + cardPicked + ".\n"); + + if (opponentToAsk.hasCard(cardPicked)) { + opponentToAsk.removeCard(cardPicked); + currentPlayer.addCardToHand(cardPicked); + System.out.println("\n" + opponentToAsk.getName() + " had that card. " + currentPlayer.getName() + " goes again."); + System.out.println("=======================================\n\n"); + this.fillPlayerHands(); + this.takeTurn(); + } else { + System.out.println("\n" + opponentToAsk.getName() + " did not have that card " + displaySecondLogo()); + if (deck.deck.isEmpty()) { + System.out.println("\nThe deck is empty. No cards to draw."); + System.out.println("=======================================\n"); + turnCounter++; + return; + } + Card topCard = deck.getTopCard(); + deck.deck.remove(0); + currentPlayer.addCardToHand(topCard); + if (topCard.getRankEnum().equals(cardPicked.getRankEnum())) { + System.out.println("\n" + currentPlayer.getName() + " picked their wish! " + currentPlayer.getName() + " gets a point. Go again.\n"); + System.out.println("=======================================\n"); + this.fillPlayerHands(); + this.takeTurn(); + + } else { + this.fillPlayerHands(); + System.out.println("=======================================\n"); + turnCounter++; + } + } + } + + public void fillPlayerHands() { + for (GoFishPlayer player : players) { + if (player.isHandEmpty() && deck.deck.size() > 0) { + Card topCard = deck.getTopCard(); + deck.deck.remove(0); + player.addCardToHand(topCard); + + } + } + } + + public String displayScores(ArrayList players) { + System.out.println("======================================="); + System.out.println("Score totals:\n"); + StringBuilder displayScores = new StringBuilder(); + for (int i = 0; i < players.size(); i++) { + displayScores.append("\t> ") + .append(players.get(i).getName()) + .append(": ") + .append(players.get(i).getNumPairs()) + .append("\n") + .append("\t--------------\n"); + } + System.out.println(displayScores.toString()); + return displayScores.toString(); + } + + public List determineWinner() { + List winners = new ArrayList<>(); + int highestScore = 0; + for (GoFishPlayer player: players) { + int currentScore = player.getNumPairs(); + + if (currentScore > highestScore) { + highestScore = currentScore; + winners.clear(); + winners.add(player); + } + else if(currentScore == highestScore) { + winners.add(player); + } + } + return winners; + } + + public void gameOverMessage(List winners) { + if(winners.size() > 1) { + System.out.println("There was a tie!"); + for (int i = 0; i < winners.size(); i++) { + System.out.println(displayCongrats()); + System.out.println("\n" + winners.get(i).getName() + ", you tied!\n"); + } + } + else { + System.out.println(displayCongrats()); + System.out.println("\n" + winners.get(0).getName() + ", you win!\n"); + } + this.displayScores(players); + System.out.println("\nThat was fun! Game over.\n"); + } + + public String displayLogo() { + StringBuilder logo = new StringBuilder("\n"); + +logo.append(" /$$$$$$ /$$$$$$$$ /$$ /$$\n"); +logo.append(" /$$__ $$ | $$_____/|__/ | $$\n"); +logo.append(" | $$ \\__/ /$$$$$$ | $$ /$$ /$$$$$$$| $$$$$$$\n"); +logo.append(" | $$ /$$$$ /$$__ $$ | $$$$$ | $$ /$$_____/| $$__ $$\n"); +logo.append(" | $$|_ $$| $$ \\ $$ | $$__/ | $$| $$$$$$ | $$ \\ $$\n"); +logo.append(" | $$ \\ $$| $$ | $$ | $$ | $$\\____ $$ | $$ | $$\n"); +logo.append(" | $$$$$$/| $$$$$$/ | $$ | $$ /$$$$$$$/| $$ | $$\n"); +logo.append(" \\______/ \\______/ |__/ |__/|_______/ |__/ |__/\n"); + + return logo.toString(); + } + + public String displaySecondLogo() { + StringBuilder logo = new StringBuilder("\n\n"); + logo.append(" +-+-+ +-+-+-+-+\n"); + logo.append(" |G|o| |F|i|s|h|\n"); + logo.append(" +-+-+ +-+-+-+-+\n"); + return logo.toString(); + } + + public String displayCongrats() { + StringBuilder congrats = new StringBuilder("\n"); + congrats.append("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n"); + congrats.append("|C|o|n|g|r|a|t|u|l|a|t|i|o|n|s|\n"); + congrats.append("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n"); + return congrats.toString(); + } + + public void endGame() { + + } +} diff --git a/src/main/java/io/zipcoder/casino/Games/War.java b/src/main/java/io/zipcoder/casino/Games/War.java new file mode 100644 index 00000000..d1a74629 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Games/War.java @@ -0,0 +1,164 @@ +package io.zipcoder.casino.Games; + +import io.zipcoder.casino.GameTools.Deck.Card; +import io.zipcoder.casino.GameTools.Deck.Deck; + +import io.zipcoder.casino.InputOutput.InputOutput; + +import io.zipcoder.casino.Interfaces.Game; +import io.zipcoder.casino.Players.Player; +import io.zipcoder.casino.Players.WarPlayer; + + +public class War implements Game { + + + public WarPlayer player1; + public WarPlayer player2; + public Deck warDeck; + + private boolean isPlaying = true; + + public War(Player player) { + warDeck = new Deck(); + player1 = new WarPlayer(player); + player2 = new WarPlayer("Computer", 25); + } + + public void startGame(){ + + System.out.println(displayLogo()); + + do { + if(warDeck.deck.size() == 0){ + warDeck = new Deck(); + } + player1.resetPoints(); + player2.resetPoints(); + deal(); + takeTurn(); + displayWinner(); + playAgain(); + + } + while(isPlaying); + endGame(); + } + + public void endGame(){ + System.out.println("Thank you for playing War. Comeback soon\n"); + isPlaying = false; + } + + public void deal() { + warDeck.shuffleDeck(); + + do { + player1.currentHand.add(warDeck.deck.get(0)); + warDeck.deck.remove(0); + player2.currentHand.add(warDeck.deck.get(0)); + warDeck.deck.remove(0); + + } while (warDeck.deck.size() > 0); + } + + public void takeTurn() { + InputOutput io = new InputOutput(); + String deal = io.promptForString("Press Enter to play a card"); + + do { + if(player1.currentHand.size() == 0) { + break; + } + System.out.println(player1.currentHand.get(0).toCardArt()); + System.out.println(player2.currentHand.get(0).toCardArt()); + + compareCards(player1.currentHand.get(0), player2.currentHand.get(0)); + + deal = io.promptForString("Press Enter to play another"); + + player1.currentHand.remove(0); + player2.currentHand.remove(0); + + } while(deal.equals("")); + } + + public void compareCards(Card card1, Card card2) { + if (card1.getRankEnum().getRankValue() == card2.getRankEnum().getRankValue()) { + System.out.println("TIE"); + System.out.println(player1.getName() + " | " + player1.getPoints()); + System.out.println(player2.getName() + " | " + player2.getPoints()); + System.out.println("==========================="); + } else if(card1.getRankEnum().getRankValue() > card2.getRankEnum().getRankValue()) { + awardPoint(player1); + System.out.println("WINNER: " + player1.getName()); + System.out.println(player1.getName() + " | " + player1.getPoints()); + System.out.println(player2.getName() + " | " + player2.getPoints()); + System.out.println("==========================="); + } else { + awardPoint(player2); + System.out.println("WINNER: " + player2.getName() + " | " + player2.getPoints()); + System.out.println(player1.getName() + " | " + player1.getPoints()); + System.out.println(player2.getName() + " | " + player2.getPoints()); + System.out.println("==========================="); + } + } + + public void awardPoint(WarPlayer player) { + player.addPoint(2); + } + + public String highestPoints() { + if(player1.getPoints() > player2.getPoints()) { + return "Winner is " + player1.getName(); + } else if (player2.getPoints() > player1.getPoints()){ + return "Winner is " + player2.getName(); + } else { + return "There is no winner in this war"; + } + } + + public String doesUserWantToPlayAgain() { + boolean properEntry = false; + String yesOrNo; + InputOutput io = new InputOutput(); + + do { + yesOrNo = io.promptForString("\nDo you want to play again? (Y/N)"); + if(yesOrNo.equals("Y") || yesOrNo.equals("N")){ + properEntry = true; + } + } while(!properEntry); + return yesOrNo; + + } + + public void playAgain() { + if(doesUserWantToPlayAgain().equals("Y")) { + this.isPlaying = true; + } else { + this.isPlaying = false; + } + } + + + public void displayWinner() { + System.out.println(highestPoints()); + } + + public String displayLogo() { + StringBuilder sb = new StringBuilder(); + sb.append("\n\nWELCOME TO" + "\n" + + "\n" + + " \n" + + "██╗ ██╗ █████╗ ██████╗ \n" + + "██║ ██║██╔══██╗██╔══██╗\n" + + "██║ █╗ ██║███████║██████╔╝\n" + + "██║███╗██║██╔══██║██╔══██╗\n" + + "╚███╔███╔╝██║ ██║██║ ██║\n" + + " ╚══╝╚══╝ ╚═╝ ╚═╝╚═╝ ╚═╝\n" + + " \n"); + return sb.toString(); + } + +} diff --git a/src/main/java/io/zipcoder/casino/InputOutput/InputOutput.java b/src/main/java/io/zipcoder/casino/InputOutput/InputOutput.java new file mode 100644 index 00000000..f39f6d28 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/InputOutput/InputOutput.java @@ -0,0 +1,72 @@ +package io.zipcoder.casino.InputOutput; + +import io.zipcoder.casino.Players.Player; + +import java.util.ArrayList; +import java.util.Scanner; +import java.util.TreeMap; + +public class InputOutput { + + Scanner input = new Scanner(System.in); + + public String scanForString() { + String stringReturn = input.nextLine(); + return stringReturn; + } + + + public Integer scanForInt() { + return Integer.parseInt(scanForString()); + } + + + public String availableGames(Player player){ + InputOutput inputOutput = new InputOutput(); + TreeMap games = new TreeMap(); + Integer number; + + if(player.getAge() > 20) { + games.put(1, "War"); + games.put(2, "Go Fish"); + games.put(3, "BlackJack"); + games.put(4, "Craps"); + games.put(5, "Exit"); + number = inputOutput.promptForInt("Please select a game\n1.War\n2.Go Fish\n3.BlackJack\n4.Craps\n5.Exit"); + } else { + games.put(1, "War"); + games.put(2,"Go Fish"); + games.put(3, "Exit"); + number = inputOutput.promptForInt("Please select a game\n1.War\n2.Go Fish\n3. Exit"); + } + + return games.get(number); + } + + public String promptForString(String message) { + System.out.println(message); + String s = scanForString(); + return s; + } + + public int promptForInt(String message) { + System.out.println(message); + int temp = input.nextInt(); + return temp; + } + + + + //generic methods + //method for menus + //create line breaks + //validate user input + + +// public static void main(String[] args) { +// InputOutput io = new InputOutput(); +// System.out.println("Enter your name"); +// String name = io.scanForString(); +// System.out.println(name); +// } +} diff --git a/src/main/java/io/zipcoder/casino/Interfaces/Game.java b/src/main/java/io/zipcoder/casino/Interfaces/Game.java new file mode 100644 index 00000000..c9df99d1 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Interfaces/Game.java @@ -0,0 +1,8 @@ +package io.zipcoder.casino.Interfaces; + +public interface Game { + + public void startGame(); + public void endGame(); + +} diff --git a/src/main/java/io/zipcoder/casino/Players/BlackjackPlayer.java b/src/main/java/io/zipcoder/casino/Players/BlackjackPlayer.java new file mode 100644 index 00000000..180bfabd --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Players/BlackjackPlayer.java @@ -0,0 +1,68 @@ +package io.zipcoder.casino.Players; + +import io.zipcoder.casino.GameTools.Deck.Card; +import io.zipcoder.casino.GameTools.Deck.Rank; +import io.zipcoder.casino.GameTools.Util.BlackjackValueUtil; + +import java.util.ArrayList; + +public class BlackjackPlayer extends Player{ + + protected Player rootPlayer; + protected ArrayList hand; + protected boolean canHit; + public boolean bulkApperception = false; + public boolean charm = false; + + public BlackjackPlayer(Player rootPlayer){ + this.name = rootPlayer.getName(); + this.age = rootPlayer.getAge(); + this.canHit = true; + this.rootPlayer = rootPlayer; + this.hand = new ArrayList<>(); + } + + public Player getRootPlayer() { + return rootPlayer; + } + + public void setHand(ArrayList hand){ + this.hand = hand; + } + + public void addToHand(Card card){ + this.hand.add(card); + } + + public ArrayList getHand() { + return hand; + } + + public boolean isCanHit() { + return canHit; + } + + public void setCanHit(boolean bool){ + this.canHit = bool; + } + + public Integer getHandValue(){ + Integer handValue = 0; + int aceCounter = 0; + for (Card card:hand) { + if (card.getRankEnum().equals(Rank.ACE)) aceCounter++; + handValue += BlackjackValueUtil.rankParse(card.getRankEnum()); + } + if (aceCounter > 0 && handValue > 21) handValue -= 10; + return handValue; + } + + public void payoutWin(int money){ + rootPlayer.wallet.add(money); + } + + public void payoutLoss(int money){ + rootPlayer.wallet.subtract(money); + } + +} diff --git a/src/main/java/io/zipcoder/casino/Players/CrapsPlayer.java b/src/main/java/io/zipcoder/casino/Players/CrapsPlayer.java new file mode 100644 index 00000000..c40c551c --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Players/CrapsPlayer.java @@ -0,0 +1,27 @@ +package io.zipcoder.casino.Players; + + +public class CrapsPlayer extends Player { + + protected Player mainPlayer; + + + public CrapsPlayer(Player mainPlayer) { + this.age = mainPlayer.getAge(); + this.name = mainPlayer.getName(); + this.mainPlayer = mainPlayer; + } + + + public Player getMainPlayer() { + return mainPlayer; + } + + public void lostMoney(int money) { + mainPlayer.wallet.subtract(money); + } + + public void wonMoney(int money) { + mainPlayer.wallet.add(money); + } +} diff --git a/src/main/java/io/zipcoder/casino/Players/GoFishComputerPlayer.java b/src/main/java/io/zipcoder/casino/Players/GoFishComputerPlayer.java new file mode 100644 index 00000000..b596e6d1 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Players/GoFishComputerPlayer.java @@ -0,0 +1,34 @@ +package io.zipcoder.casino.Players; +import io.zipcoder.casino.GameTools.Deck.Card; +import io.zipcoder.casino.InputOutput.InputOutput; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + + +public class GoFishComputerPlayer extends GoFishPlayer { + private Random rand; + + public GoFishComputerPlayer(String name) { + super(name); + rand = new Random(); + } + + public int getNumPairs() { + return numPairs; + } + + @Override + public GoFishPlayer pickOpponentToAsk(List opponents) { + int opponentIndex = rand.nextInt(opponents.size()); + return opponents.get(opponentIndex); + } + + @Override + public Card pickCard() { + int cardIndex = rand.nextInt(this.cardHand.size()); + return this.cardHand.get(cardIndex); + } + +} + diff --git a/src/main/java/io/zipcoder/casino/Players/GoFishHumanPlayer.java b/src/main/java/io/zipcoder/casino/Players/GoFishHumanPlayer.java new file mode 100644 index 00000000..3eca7014 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Players/GoFishHumanPlayer.java @@ -0,0 +1,64 @@ +package io.zipcoder.casino.Players; + +import io.zipcoder.casino.GameTools.Deck.Card; +import io.zipcoder.casino.GameTools.Deck.Rank; +import io.zipcoder.casino.InputOutput.InputOutput; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + + +public class GoFishHumanPlayer extends GoFishPlayer{ + private InputOutput inputOutput = new InputOutput(); + + public GoFishHumanPlayer(Player rootPlayer) { + super(rootPlayer); + } + + public String showCards() { + StringBuilder showCardHand = new StringBuilder("\n"); + for (int i = 0; i < cardHand.size(); i++) { + showCardHand.append((i + 1)) + .append(": ") + .append(this.cardHand.get(i)) + .append("\n"); + } + System.out.println(showCardHand.toString()); + return showCardHand.toString(); + } + + public String showOpponents(List opponents) { + StringBuilder showOpponents = new StringBuilder(); + for (int i = 0; i < opponents.size(); i++) { + showOpponents.append((i + 1)) + .append(": ") + .append(opponents.get(i).getName()) + .append("\n"); + } + System.out.println(showOpponents.toString()); + return showOpponents.toString(); + } + + public GoFishPlayer pickOpponentToAsk(List opponents) { + this.showOpponents(opponents); + int opponentIndex = inputOutput.promptForInt("Enter the number for the player you want to ask:"); + try { + return opponents.get(opponentIndex - 1); + } catch(IndexOutOfBoundsException name) { + System.out.println("\tTry again. Please enter one of the numbers shown.\n"); + return pickOpponentToAsk(opponents); + } + } + + public Card pickCard() { + this.showCards(); + int cardIndex = inputOutput.promptForInt("Enter the number of your card choice:"); + try { + return cardHand.get(cardIndex - 1); + } catch (IndexOutOfBoundsException name) { + System.out.println("\tTry again. Please enter one of the numbers shown.\n"); + return pickCard(); + } + } + +} diff --git a/src/main/java/io/zipcoder/casino/Players/GoFishPlayer.java b/src/main/java/io/zipcoder/casino/Players/GoFishPlayer.java new file mode 100644 index 00000000..2e6dd1d4 --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Players/GoFishPlayer.java @@ -0,0 +1,91 @@ +package io.zipcoder.casino.Players; + +import io.zipcoder.casino.GameTools.Deck.Card; +import io.zipcoder.casino.GameTools.Deck.Rank; +import io.zipcoder.casino.GameTools.Deck.Suit; +import io.zipcoder.casino.Games.GoFish; +import io.zipcoder.casino.InputOutput.InputOutput; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + + + +public abstract class GoFishPlayer extends Player { + protected List cardHand; + protected int numPairs; + + protected GoFishPlayer(Player rootPlayer) { + super(rootPlayer.getName(), rootPlayer.getAge()); + cardHand = new ArrayList(); + numPairs = 0; + } + + public GoFishPlayer(String name) { + cardHand = new ArrayList<>(); + numPairs = 0; + this.name = name; + } + + public void addPair() { + numPairs++; + } + + public int getNumPairs() { + return numPairs; + } + + + public void addCardToHand(Card cardToAdd) { + if (this.hasCard(cardToAdd)) { + System.out.println("\n" + this.getName() + " made a match. One point.\n"); + this.addPair(); + this.removeMatches(cardToAdd.getRankEnum()); + } + else { + this.cardHand.add(cardToAdd); + } + } + + public void removeMatches(Rank rankToCompare) { + Iterator carditr = cardHand.iterator(); + while(carditr.hasNext()) { + Card card = (Card) carditr.next(); + if(card.getRankEnum().equals(rankToCompare)) { + carditr.remove(); + } + } + } + + public int getCardHandSize() { + return this.cardHand.size(); + } + + public boolean isHandEmpty(){ + return this.cardHand.isEmpty(); + } + + public Boolean hasCard(Card cardAskedFor) { + for(Card card : cardHand) { + if(card.getRankEnum().equals(cardAskedFor.getRankEnum())) { + return true; + } + } + return false; + } + + public void removeCard(Card cardToRemove) { + Iterator carditr = cardHand.iterator(); + while(carditr.hasNext()) { + Card card = (Card) carditr.next(); + if(card.getRankEnum().equals(cardToRemove.getRankEnum())) { + carditr.remove(); + } + } + } + + public abstract GoFishPlayer pickOpponentToAsk(List opponents); + + public abstract Card pickCard(); +} diff --git a/src/main/java/io/zipcoder/casino/Players/Player.java b/src/main/java/io/zipcoder/casino/Players/Player.java new file mode 100644 index 00000000..10d0eb5b --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Players/Player.java @@ -0,0 +1,51 @@ +package io.zipcoder.casino.Players; + + +import io.zipcoder.casino.Wallet; + + +public class Player { + + protected String name; + protected Integer age; + protected Wallet wallet; + + public Player(String name, Integer age){ + this.name = name; + this.age = age; + } + + public Player(){ + this.name = ""; + this.age = Integer.MAX_VALUE; + } + + + public Player(String name, Integer age, Integer balance) { + this.name = name; + this.age = age; + this.wallet = new Wallet(balance); + + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getAge() { + return age; + } + + public void setAge(Integer age) { + this.age = age; + } + + public Integer getBalance() { + return wallet.getBalance(); + } + +} diff --git a/src/main/java/io/zipcoder/casino/Players/WarPlayer.java b/src/main/java/io/zipcoder/casino/Players/WarPlayer.java new file mode 100644 index 00000000..b3b99ccf --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Players/WarPlayer.java @@ -0,0 +1,66 @@ +package io.zipcoder.casino.Players; + +import io.zipcoder.casino.GameTools.Deck.Card; +import io.zipcoder.casino.Wallet; + +import java.util.ArrayList; + +public class WarPlayer extends Player { + + public ArrayList currentHand; + public Integer points = 0; + + public WarPlayer() { + super.name = ""; + super.age = Integer.MAX_VALUE; + this.currentHand = new ArrayList<>(); + this.points = 0; + } + + public WarPlayer(String name, Integer age) { + super.name = name; + super.age = age; + this.currentHand = new ArrayList<>(); + this.points = 0; + } + + public WarPlayer(Player player) { + this.name = player.getName(); + this.age = player.getAge(); + this.currentHand = new ArrayList<>(); + this.points = 0; + } + + public void addToHand(Card card) { + currentHand.add(card); + } + + public void setName(String name) { + super.name = name; + } + + public void setAge(int age) { + super.age = age; + } + + public String getName() { + return super.getName(); + } + + public Integer getAge() { + return super.getAge(); + } + + public Integer getPoints() { + return this.points; + } + + public void addPoint(Integer points) { + this.points += points; + } + + public void resetPoints() { + this.points = 0; + } + +} diff --git a/src/main/java/io/zipcoder/casino/Wallet.java b/src/main/java/io/zipcoder/casino/Wallet.java new file mode 100644 index 00000000..a86acb2c --- /dev/null +++ b/src/main/java/io/zipcoder/casino/Wallet.java @@ -0,0 +1,25 @@ +package io.zipcoder.casino; + +public class Wallet { + private int balance; + + public Wallet(){ + this.balance = 0; + } + + public Wallet(int balance){ + this.balance = balance; + } + + public int getBalance(){ + return this.balance; + } + + public void add(int money){ + this.balance += money; + } + + public void subtract(int money){ + this.balance -= money; + } +} diff --git a/src/test/java/io/zipcoder/casino/CasinoTest.java b/src/test/java/io/zipcoder/casino/CasinoTest.java index e9286523..fda78ff5 100644 --- a/src/test/java/io/zipcoder/casino/CasinoTest.java +++ b/src/test/java/io/zipcoder/casino/CasinoTest.java @@ -1,5 +1,10 @@ package io.zipcoder.casino; +import org.junit.Test; public class CasinoTest { + @Test + public void iritl(){ + + } } diff --git a/src/test/java/io/zipcoder/casino/Factories/CardFactoryTest.java b/src/test/java/io/zipcoder/casino/Factories/CardFactoryTest.java new file mode 100644 index 00000000..dc8e82f0 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/Factories/CardFactoryTest.java @@ -0,0 +1,14 @@ +package io.zipcoder.casino.Factories; + +import io.zipcoder.casino.GameTools.Deck.Rank; +import io.zipcoder.casino.GameTools.Deck.Suit; +import org.junit.Test; + +public class CardFactoryTest { + +// @Test +// public void cardFactoryTest() { +// CardFactory.createCard(Rank.SEVEN, Suit.CLUBS); +// +// } +} diff --git a/src/test/java/io/zipcoder/casino/Factories/PlayerFactoryTest.java b/src/test/java/io/zipcoder/casino/Factories/PlayerFactoryTest.java new file mode 100644 index 00000000..6dfeffc9 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/Factories/PlayerFactoryTest.java @@ -0,0 +1,11 @@ +package io.zipcoder.casino.Factories; + +import io.zipcoder.casino.GameTools.Deck.Rank; +import io.zipcoder.casino.GameTools.Deck.Suit; +import org.junit.Before; +import org.junit.Test; + +public class PlayerFactoryTest { + + +} diff --git a/src/test/java/io/zipcoder/casino/GameToolsTests/Deck/BlackjackCardTest.java b/src/test/java/io/zipcoder/casino/GameToolsTests/Deck/BlackjackCardTest.java new file mode 100644 index 00000000..c9a297fc --- /dev/null +++ b/src/test/java/io/zipcoder/casino/GameToolsTests/Deck/BlackjackCardTest.java @@ -0,0 +1,27 @@ +package io.zipcoder.casino.GameToolsTests.Deck; + +import io.zipcoder.casino.GameTools.Deck.Card; +import io.zipcoder.casino.GameTools.Deck.Rank; +import io.zipcoder.casino.GameTools.Deck.Suit; +import io.zipcoder.casino.GameTools.Util.BlackjackValueUtil; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class BlackjackCardTest { + + Card dummy; + + @Before + public void setup(){ + dummy = new Card(Rank.ACE, Suit.CLUBS); + } + + @Test + public void constructorTest(){ + int expected = 11; + int actual = BlackjackValueUtil.rankParse(dummy.getRankEnum()); + Assert.assertEquals(expected, actual); + } + +} diff --git a/src/test/java/io/zipcoder/casino/GameToolsTests/Deck/BlackjackDeckTest.java b/src/test/java/io/zipcoder/casino/GameToolsTests/Deck/BlackjackDeckTest.java new file mode 100644 index 00000000..5968d464 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/GameToolsTests/Deck/BlackjackDeckTest.java @@ -0,0 +1,4 @@ +package io.zipcoder.casino.GameToolsTests.Deck; + +public class BlackjackDeckTest { +} diff --git a/src/test/java/io/zipcoder/casino/GameToolsTests/Deck/BlackjackRankTest.java b/src/test/java/io/zipcoder/casino/GameToolsTests/Deck/BlackjackRankTest.java new file mode 100644 index 00000000..180227c7 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/GameToolsTests/Deck/BlackjackRankTest.java @@ -0,0 +1,17 @@ +//package io.zipcoder.casino.GameToolsTests.Deck; +// +//import io.zipcoder.casino.GameTools.Deck.Rank; +//import io.zipcoder.casino.GameTools.Util.BlackjackValueUtil; +//import io.zipcoder.casino.Games.Blackjack; +//import org.junit.Assert; +//import org.junit.Test; +// +// +//public class BlackjackRankTest { +// @Test +// public void getRankValueTest(){ +// int expected = 8; +// int actual = BlackjackValueUtil.rankParse(Rank.EIGHT); +// Assert.assertEquals(expected, actual); +// } +//} diff --git a/src/test/java/io/zipcoder/casino/GameToolsTests/Deck/CardTest.java b/src/test/java/io/zipcoder/casino/GameToolsTests/Deck/CardTest.java new file mode 100644 index 00000000..7060feae --- /dev/null +++ b/src/test/java/io/zipcoder/casino/GameToolsTests/Deck/CardTest.java @@ -0,0 +1,75 @@ +package io.zipcoder.casino.GameToolsTests.Deck; + + +import io.zipcoder.casino.Factories.CardFactory; +import io.zipcoder.casino.GameTools.Deck.Card; +import io.zipcoder.casino.GameTools.Deck.Rank; +import io.zipcoder.casino.GameTools.Deck.Suit; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class CardTest { + + CardFactory cardFactory = new CardFactory(); + Card tester; + + @Before + public void setup(){ + tester = CardFactory.createCard(Rank.SEVEN, Suit.CLUBS); + } + + @Test + public void cardConstructorTest(){ + Card temp = CardFactory.createCard(Rank.SEVEN, Suit.CLUBS); + Rank actual = temp.getRankEnum(); + Rank expected = Rank.SEVEN; + Assert.assertEquals(actual, expected); + } + + @Test + public void getSuitTest(){ + Suit expected = tester.getSuitEnum(); + Suit actual = Suit.CLUBS; + Assert.assertEquals(expected, actual); + } + + @Test + public void getRankTest(){ + Rank expected = tester.getRankEnum(); + Rank actual = Rank.SEVEN; + Assert.assertEquals(expected, actual); + } + + @Test + public void setSuitTest(){ + tester.setSuitEnum(Suit.DIAMOND); + Suit expected = Suit.DIAMOND; + Suit actual = tester.getSuitEnum(); + Assert.assertEquals(expected, actual); + } + + @Test + public void setRankTest(){ + tester.setRankEnum(Rank.ACE); + Rank expected = Rank.ACE; + Rank actual = tester.getRankEnum(); + Assert.assertEquals(expected, actual); + } + + @Test + public void toCardArtTest() { + tester.setAsciiEnum(Rank.EIGHT); + String expected = " _________\n" + + " |8 + + |\n" + + " |+ |\n" + + " | + + |\n" + + " | |\n" + + " | + + |\n" + + " | +|\n" + + " | + + 8|\n" + + " ~~~~~~~~~"; + String actual = Rank.EIGHT.getAsciiValue(); + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/io/zipcoder/casino/GameToolsTests/Deck/DeckTest.java b/src/test/java/io/zipcoder/casino/GameToolsTests/Deck/DeckTest.java new file mode 100644 index 00000000..ff07bc08 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/GameToolsTests/Deck/DeckTest.java @@ -0,0 +1,34 @@ +package io.zipcoder.casino.GameToolsTests.Deck; +import io.zipcoder.casino.Factories.CardFactory; +import io.zipcoder.casino.GameTools.Deck.*; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +public class DeckTest { + + CardFactory cardFactory; + + @Before + public void setup() { + cardFactory = new CardFactory(); + } + + @Test + public void deckGeneratorTest() { + Deck deck = new Deck(); + Card actual = deck.deck.get(0); + Card expected = cardFactory.createCard(Rank.ACE, Suit.HEARTS); + Assert.assertEquals(expected.getRankEnum(), actual.getRankEnum()); + } + + @Test + public void deckShuffleTest() { + Deck deck = new Deck(); + Card expected = deck.deck.get(0); + deck.shuffleDeck(); + Card actual = deck.deck.get(0); + Assert.assertNotEquals(expected, actual); + } +} diff --git a/src/test/java/io/zipcoder/casino/GameToolsTests/Deck/DummyCardGame.java b/src/test/java/io/zipcoder/casino/GameToolsTests/Deck/DummyCardGame.java new file mode 100644 index 00000000..2461e26a --- /dev/null +++ b/src/test/java/io/zipcoder/casino/GameToolsTests/Deck/DummyCardGame.java @@ -0,0 +1,6 @@ +package io.zipcoder.casino.GameToolsTests.Deck; +import io.zipcoder.casino.Games.CardGame; + +public class DummyCardGame extends CardGame{ + +} diff --git a/src/test/java/io/zipcoder/casino/GameToolsTests/Deck/RankTest.java b/src/test/java/io/zipcoder/casino/GameToolsTests/Deck/RankTest.java new file mode 100644 index 00000000..e2457899 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/GameToolsTests/Deck/RankTest.java @@ -0,0 +1,17 @@ +package io.zipcoder.casino.GameToolsTests.Deck; + + +import io.zipcoder.casino.GameTools.Deck.Rank; +import org.junit.Assert; +import org.junit.Test; + +public class RankTest { + + @Test + public void getRankValueTest(){ + int actual = Rank.SIX.getRankValue(); + int expected = 6; + Assert.assertEquals(expected, actual); + } + +} diff --git a/src/test/java/io/zipcoder/casino/GameToolsTests/Deck/SuitTest.java b/src/test/java/io/zipcoder/casino/GameToolsTests/Deck/SuitTest.java new file mode 100644 index 00000000..db0861c3 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/GameToolsTests/Deck/SuitTest.java @@ -0,0 +1,16 @@ +package io.zipcoder.casino.GameToolsTests.Deck; + + +import io.zipcoder.casino.GameTools.Deck.Suit; +import org.junit.Assert; +import org.junit.Test; + +public class SuitTest { + @Test + public void getSuitValueTest(){ + String expected = "Clubs"; + String actual = Suit.CLUBS.getSuitValue(); + Assert.assertEquals(expected, actual); + } + +} diff --git a/src/test/java/io/zipcoder/casino/GameToolsTests/Util/BlackjackValueUtilTest.java b/src/test/java/io/zipcoder/casino/GameToolsTests/Util/BlackjackValueUtilTest.java new file mode 100644 index 00000000..d7e82574 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/GameToolsTests/Util/BlackjackValueUtilTest.java @@ -0,0 +1,31 @@ +package io.zipcoder.casino.GameToolsTests.Util; + +import io.zipcoder.casino.GameTools.Deck.Rank; +import io.zipcoder.casino.GameTools.Util.BlackjackValueUtil; +import org.junit.Assert; +import org.junit.Test; + +public class BlackjackValueUtilTest { + + @Test + public void parseAceTest(){ + int actual = BlackjackValueUtil.rankParse(Rank.ACE); + int expected = 11; + Assert.assertEquals(actual, expected); + } + + @Test + public void parseJackTest(){ + int actual = BlackjackValueUtil.rankParse(Rank.JACK); + int expected = 10; + Assert.assertEquals(actual, expected); + } + + @Test + public void parseSevenTest(){ + int actual = BlackjackValueUtil.rankParse(Rank.SEVEN); + int expected = 7; + Assert.assertEquals(actual, expected); + } + +} diff --git a/src/test/java/io/zipcoder/casino/Games/BlackjackTest.java b/src/test/java/io/zipcoder/casino/Games/BlackjackTest.java new file mode 100644 index 00000000..95e9d048 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/Games/BlackjackTest.java @@ -0,0 +1,143 @@ +package io.zipcoder.casino.Games; + +import io.zipcoder.casino.GameTools.Deck.*; +import io.zipcoder.casino.Players.BlackjackPlayer; +import io.zipcoder.casino.Players.Player; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; + +public class BlackjackTest { + + Player sue = new Player("sue", 30, 1000); + BlackjackPlayer sueBKJK; + Blackjack game; + + @Before + public void setup(){ + sueBKJK = new BlackjackPlayer(sue); + game = new Blackjack(sue); + } + + @Test + public void constructorTest(){ + String actual = game.player.getName(); + String expected = sue.getName(); + Assert.assertEquals(expected, actual); + } + + @Test + public void dealTest(){ + Card expected = game.deck.deck.get(0); + game.deal(); + Card actual = game.player.getHand().get(0); + Assert.assertEquals(expected, actual); + } + + @Test + public void initialHandTest(){ + Card expected = game.deck.deck.get(1); + game.initialHand(); + Card actual = game.player.getHand().get(1); + Assert.assertEquals(expected, actual); + } + + @Test + public void initialHandDealerTest(){ + Card expected = game.deck.deck.get(2); + game.initialHand(); + Card actual = game.bkjkDealer.getHand().get(0); + Assert.assertEquals(expected, actual); + } + + @Test + public void bustCheckPositiveTest(){ + ArrayList temp = new ArrayList<>(); + temp.add(new Card(Rank.KING, Suit.CLUBS)); + temp.add(new Card(Rank.KING, Suit.CLUBS)); + temp.add(new Card(Rank.KING, Suit.CLUBS)); + sueBKJK.setHand(temp); + Assert.assertTrue(game.bustCheck(sueBKJK)); + } + + @Test + public void bustCheckNegativeTest(){ + ArrayList temp = new ArrayList<>(); + temp.add(new Card(Rank.KING, Suit.CLUBS)); + temp.add(new Card(Rank.KING, Suit.CLUBS)); + sueBKJK.setHand(temp); + Assert.assertFalse(game.bustCheck(sueBKJK)); + } + + @Test + public void dealerHitCheck(){ + game.bkjkDealer.addToHand(new Card(Rank.THREE, Suit.CLUBS)); + game.bkjkDealer.addToHand(new Card(Rank.KING, Suit.CLUBS)); + boolean expected = game.dealerHitCheck(); + Assert.assertTrue(expected); + } + + @Test + public void dealerTurnTest(){ + ArrayList tempHand = new ArrayList<>(); + tempHand.add(new Card(Rank.TEN, Suit.CLUBS)); + game.bkjkDealer.setHand(tempHand); + game.dealerTurn(); + int actual = game.bkjkDealer.getHandValue(); + Assert.assertEquals(21, actual); + } + + @Test + public void winCheck21Test(){ + ArrayList tempHand = new ArrayList<>(); + tempHand.add(new Card(Rank.ACE, Suit.CLUBS)); + tempHand.add(new Card(Rank.TEN, Suit.CLUBS)); + sueBKJK.setHand(tempHand); + Assert.assertTrue(game.winCheck(sueBKJK)); + } + + @Test + public void winCheckBustTest(){ + ArrayList tempHand = new ArrayList<>(); + tempHand.add(new Card(Rank.TEN, Suit.CLUBS)); + tempHand.add(new Card(Rank.TEN, Suit.CLUBS)); + tempHand.add(new Card(Rank.TEN, Suit.CLUBS)); + sueBKJK.setHand(tempHand); + Assert.assertFalse(game.winCheck(sueBKJK)); + } + + @Test + public void winCheckDealerWinTest(){ + ArrayList tempHand = new ArrayList<>(); + tempHand.add(new Card(Rank.TEN, Suit.CLUBS)); + tempHand.add(new Card(Rank.TEN, Suit.CLUBS)); + sueBKJK.setHand(tempHand); + ArrayList tempdealerhand = new ArrayList<>(); + tempdealerhand.add(new Card(Rank.TEN, Suit.CLUBS)); + tempdealerhand.add(new Card(Rank.NINE, Suit.CLUBS)); + tempdealerhand.add(new Card(Rank.TWO, Suit.CLUBS)); + game.bkjkDealer.setHand(tempdealerhand); + Assert.assertFalse(game.winCheck(sueBKJK)); + } + + @Test + public void payoutTest1(){ + int expected = 1010; + game.setBetAmount(10); + game.payoutWin(); + int actual = game.player.getRootPlayer().getBalance(); + Assert.assertEquals(expected, actual); + } + + @Test + public void payoutTest2(){ + int expected = 990; + game.setBetAmount(10); + game.payoutLoss(); + int actual = game.player.getRootPlayer().getBalance(); + Assert.assertEquals(expected, actual); + } + +} diff --git a/src/test/java/io/zipcoder/casino/Games/CardGameTest.java b/src/test/java/io/zipcoder/casino/Games/CardGameTest.java new file mode 100644 index 00000000..2671d846 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/Games/CardGameTest.java @@ -0,0 +1,38 @@ +package io.zipcoder.casino.Games; + +import io.zipcoder.casino.GameTools.Deck.Card; +import io.zipcoder.casino.GameTools.Deck.Rank; +import io.zipcoder.casino.GameTools.Deck.Suit; +import io.zipcoder.casino.GameToolsTests.Deck.DummyCardGame; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; + +public class CardGameTest { + + DummyCardGame dummy; + + @Before + public void setup(){ + dummy = new DummyCardGame(); + } + + @Test + public void getNumberOfPlayersTest(){ + dummy.setNumberOfPlayers(3); + Integer expected = 3; + Integer actual = dummy.getNumberOfPlayers(); + Assert.assertEquals(expected, actual); + } + + @Test + public void getMaxNumberOfPlayersTest(){ + dummy.setMaxNumberOfPlayers(3); + Integer expected = 3; + Integer actual = dummy.getMaxNumberOfPlayers(); + Assert.assertEquals(expected, actual); + } + +} diff --git a/src/test/java/io/zipcoder/casino/Games/CrapsTest.java b/src/test/java/io/zipcoder/casino/Games/CrapsTest.java new file mode 100644 index 00000000..f8e85f64 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/Games/CrapsTest.java @@ -0,0 +1,31 @@ +package io.zipcoder.casino.Games; + + +import io.zipcoder.casino.Players.Player; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class CrapsTest { + Craps game; + Integer dieValue = 7; + Player bob = new Player("Bob", 30, 500); + + + @Before + public void setup() { + game = new Craps(bob); + } + + @Test + public void setPlayerBetAmountTest() { + Integer expected = 500; + + game.setPlayerBetAmount(expected); + Integer actual = game.getPlayerBetAmount(); + + Assert.assertEquals(expected, actual); + } + +} diff --git a/src/test/java/io/zipcoder/casino/Games/Dealer/DealerTest.java b/src/test/java/io/zipcoder/casino/Games/Dealer/DealerTest.java new file mode 100644 index 00000000..2cfbb836 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/Games/Dealer/DealerTest.java @@ -0,0 +1,70 @@ +package io.zipcoder.casino.Games.Dealer; + +import io.zipcoder.casino.GameTools.Deck.Card; +import io.zipcoder.casino.GameTools.Deck.Rank; +import io.zipcoder.casino.GameTools.Deck.Suit; +import io.zipcoder.casino.Players.BlackjackPlayer; +import io.zipcoder.casino.Players.Player; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; + +public class DealerTest { + + Dealer dealer; + + @Before + public void setup(){ + dealer = new Dealer(); + } + + @Test + public void getHandTest(){ + Card ace = new Card(Rank.ACE, Suit.CLUBS); + ArrayList expected = new ArrayList<>(); + expected.add(ace); + dealer.setHand(expected); + ArrayList actual = dealer.getHand(); + Assert.assertEquals(expected, actual); +} + + @Test + public void getHandValueTest() { + Integer expected = 5; + Card two = new Card(Rank.TWO, Suit.HEARTS); + Card three = new Card(Rank.THREE, Suit.CLUBS); + ArrayList tempHand = new ArrayList<>(); + tempHand.add(three); + tempHand.add(two); + dealer.setHand(tempHand); + Integer actual = dealer.getHandValue(); + Assert.assertEquals(expected, actual); + } + + @Test + public void canHitPositiveTest(){ + Card two = new Card(Rank.TWO, Suit.HEARTS); + Card three = new Card(Rank.THREE, Suit.CLUBS); + ArrayList tempHand = new ArrayList<>(); + tempHand.add(three); + tempHand.add(two); + dealer.setHand(tempHand); + boolean actual = dealer.canHit(); + Assert.assertTrue(actual); + } + + @Test + public void canHitNegativeTest(){ + Card first = new Card(Rank.KING, Suit.HEARTS); + Card second = new Card(Rank.KING, Suit.CLUBS); + ArrayList tempHand = new ArrayList<>(); + tempHand.add(first); + tempHand.add(second); + dealer.setHand(tempHand); + boolean actual = dealer.canHit(); + Assert.assertFalse(actual); + } + +} diff --git a/src/test/java/io/zipcoder/casino/Games/DiceTest.java b/src/test/java/io/zipcoder/casino/Games/DiceTest.java new file mode 100644 index 00000000..9e06e22e --- /dev/null +++ b/src/test/java/io/zipcoder/casino/Games/DiceTest.java @@ -0,0 +1,34 @@ +package io.zipcoder.casino.Games; + + + +import org.junit.Test; + + + +import static junit.framework.TestCase.fail; + + +public class DiceTest { + Dice diceTest = new Dice(); + int diceValue; + int highestDiceValue = 1000; + int lowestDiceValue = -1000; + + @Test + public void checkIfDiceAreWithingBoundsTest(){ + for (int i = 0; i < 10000; i++){ + diceValue = Dice.rollDice(); + if (diceValue < 1){ + fail("Dice value too low!"); + } else if (diceValue > 6){ + fail("Dice value too hich"); + } else if (lowestDiceValue > diceValue){ + diceValue = lowestDiceValue; + + } else if (highestDiceValue < diceValue){ + diceValue = highestDiceValue; + } + } + } +} diff --git a/src/test/java/io/zipcoder/casino/Games/GoFishTest.java b/src/test/java/io/zipcoder/casino/Games/GoFishTest.java new file mode 100644 index 00000000..1ada9367 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/Games/GoFishTest.java @@ -0,0 +1,114 @@ +package io.zipcoder.casino.Games; + +import io.zipcoder.casino.GameTools.Deck.Card; +import io.zipcoder.casino.GameTools.Deck.Rank; +import io.zipcoder.casino.GameTools.Deck.Suit; +import io.zipcoder.casino.Players.GoFishComputerPlayer; +import io.zipcoder.casino.Players.GoFishHumanPlayer; +import io.zipcoder.casino.Players.GoFishPlayer; +import io.zipcoder.casino.Players.Player; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +public class GoFishTest { + + @Test + public void dealTest() { + Player player1 = new Player("Sally", 89); + GoFishHumanPlayer goFishPlayer1 = new GoFishHumanPlayer(player1); + + GoFish testGame = new GoFish(goFishPlayer1); + testGame.deal(); + + int expected = 5; + int actual = goFishPlayer1.getCardHandSize(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void gameIsNotOverTest() { + Player player1 = new Player("Sally", 89); + GoFishHumanPlayer goFishPlayer1 = new GoFishHumanPlayer(player1); + GoFish testGame = new GoFish(goFishPlayer1); + + goFishPlayer1.addPair(); + goFishPlayer1.addPair(); + + Boolean actual = testGame.gameIsNotOver(); + Assert.assertTrue(actual); + } + + @Test + public void getCurrentPlayerTest() { + Player player1 = new Player("Sally", 89); + GoFishHumanPlayer goFishPlayer1 = new GoFishHumanPlayer(player1); + GoFish testGame = new GoFish(goFishPlayer1); + + GoFishPlayer expected = goFishPlayer1; + GoFishPlayer actual = testGame.getCurrentPlayer(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void fillPlayerHandsTest() { + Player player1 = new Player("Sally", 89); + GoFishHumanPlayer goFishPlayer1 = new GoFishHumanPlayer(player1); + GoFish testGame = new GoFish(goFishPlayer1); + + testGame.fillPlayerHands(); + int expected = 1; + int actual = goFishPlayer1.getCardHandSize(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void displayScoresTest() { + Player player1 = new Player("Sally", 89); + GoFishHumanPlayer goFishPlayer1 = new GoFishHumanPlayer(player1); + GoFishComputerPlayer goFishPlayer2 = new GoFishComputerPlayer("Bob"); + GoFishComputerPlayer goFishPlayer3 = new GoFishComputerPlayer("George"); + GoFish testGame = new GoFish(goFishPlayer1); + ArrayList players = new ArrayList(); + players.add(goFishPlayer1); + players.add(goFishPlayer2); + players.add(goFishPlayer3); + + + goFishPlayer1.addPair(); + goFishPlayer1.addPair(); + goFishPlayer1.addPair(); + goFishPlayer2.addPair(); + goFishPlayer3.addPair(); + goFishPlayer3.addPair(); + + String expected = "\t>Sally: 3\n\t>Bob: 1\n\t>George: 2\n"; + String actual = testGame.displayScores(players); + + Assert.assertEquals(expected, actual); + } + + @Test + public void determineWinnerTest() { + Player player1 = new Player("Sally", 89); + GoFishHumanPlayer goFishPlayer1 = new GoFishHumanPlayer(player1); + GoFishComputerPlayer goFishPlayer2 = new GoFishComputerPlayer("Bob"); + GoFish testGame = new GoFish(goFishPlayer1); + + goFishPlayer1.addPair(); + goFishPlayer1.addPair(); + goFishPlayer2.addPair(); + + List winner = testGame.determineWinner(); + + int expected = 1; + int actual = winner.size(); + + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/io/zipcoder/casino/Games/WarTest.java b/src/test/java/io/zipcoder/casino/Games/WarTest.java new file mode 100644 index 00000000..d4e939a6 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/Games/WarTest.java @@ -0,0 +1,83 @@ +package io.zipcoder.casino.Games; + +import io.zipcoder.casino.GameTools.Deck.Card; +import io.zipcoder.casino.GameTools.Deck.Deck; +import io.zipcoder.casino.GameTools.Deck.Rank; +import io.zipcoder.casino.GameTools.Deck.Suit; +import io.zipcoder.casino.Players.Player; +import io.zipcoder.casino.Players.WarPlayer; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class WarTest { + + Player player = new Player("Brian", 30, 1000); + WarPlayer warPlayer; + WarPlayer warPlayer2; + War war; + + @Before + public void setup() { + warPlayer = new WarPlayer(player); + warPlayer2 = new WarPlayer("Computer", 25); + war = new War(player); + } + + @Test + public void dealTest() { + war.deal(); + Integer actual = war.player1.currentHand.size(); + Integer expected = 26; + Assert.assertEquals(expected, actual); + } + + @Test + public void compareTest() { + Card card1 = new Card(Rank.SEVEN, Suit.CLUBS); + Card card2 = new Card(Rank.FIVE, Suit.DIAMOND); + + war.player1.currentHand.add(card1); + war.compareCards(war.player1.currentHand.get(0), card2); + + Integer expected = 2; + Integer actual = war.player1.getPoints(); + Assert.assertEquals(expected, actual); + + } + + @Test + public void awardPointsToWinnerTest() { + war.player1.addPoint(1); + Integer expected = 1; + Integer actual = war.player1.getPoints(); + Assert.assertEquals(expected, actual); + } + + @Test + public void displayWinnerTest() { + war.player1.addPoint(100); + war.player2.resetPoints(); + + String expected = "Winner is " + war.player1.getName(); + String actual = war.highestPoints(); + Assert.assertEquals(expected, actual); + } + + @Test + public void displayLogo() { + String expected = ("\n\nWELCOME TO" + "\n" + + "\n" + + " \n" + + "██╗ ██╗ █████╗ ██████╗ \n" + + "██║ ██║██╔══██╗██╔══██╗\n" + + "██║ █╗ ██║███████║██████╔╝\n" + + "██║███╗██║██╔══██║██╔══██╗\n" + + "╚███╔███╔╝██║ ██║██║ ██║\n" + + " ╚══╝╚══╝ ╚═╝ ╚═╝╚═╝ ╚═╝\n" + + " \n"); + String actual = war.displayLogo(); + Assert.assertEquals(expected, actual); + } + +} diff --git a/src/test/java/io/zipcoder/casino/InputOutput/InputOutputTest.java b/src/test/java/io/zipcoder/casino/InputOutput/InputOutputTest.java new file mode 100644 index 00000000..226ad3ad --- /dev/null +++ b/src/test/java/io/zipcoder/casino/InputOutput/InputOutputTest.java @@ -0,0 +1,30 @@ +package io.zipcoder.casino.InputOutput; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +//these hang on runtime, dont work. kris says dont test so :/ +public class InputOutputTest { + InputOutput inputOutput; + + @Before + public void setup(){ + inputOutput = new InputOutput(); + } + + @Test + public void scanForStringTest(){ + String actual = inputOutput.scanForString(); + String expected = "f"; + Assert.assertEquals(expected, actual); + } + + @Test + public void scanForIntTest(){ + Integer actual = inputOutput.scanForInt(); + Integer expected = 5; + Assert.assertEquals(expected, actual); + } + +} diff --git a/src/test/java/io/zipcoder/casino/PlayerTest/BlackjackPlayerTest.java b/src/test/java/io/zipcoder/casino/PlayerTest/BlackjackPlayerTest.java new file mode 100644 index 00000000..5023a841 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/PlayerTest/BlackjackPlayerTest.java @@ -0,0 +1,108 @@ +package io.zipcoder.casino.PlayerTest; + +import io.zipcoder.casino.GameTools.Deck.*; +import io.zipcoder.casino.Games.Blackjack; +import io.zipcoder.casino.Players.BlackjackPlayer; +import io.zipcoder.casino.Players.Player; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; + +public class BlackjackPlayerTest { + Player sue; + BlackjackPlayer suebkjk; + + @Before + public void setup(){ + sue = new Player("sue", 30, 500); + suebkjk = new BlackjackPlayer(sue); + } + + @Test + public void constructorTest(){ + String expected = "sue"; + String actual = suebkjk.getName(); + Assert.assertEquals(expected, actual); + } + + @Test + public void getCanHitTest(){ + boolean expected = true; + boolean actual = suebkjk.isCanHit(); + Assert.assertEquals(expected, actual); + } + + @Test + public void getHandTest(){ + Card ace = new Card(Rank.ACE, Suit.CLUBS); + ArrayList expected = new ArrayList<>(); + expected.add(ace); + suebkjk.setHand(expected); + ArrayList actual = suebkjk.getHand(); + Assert.assertEquals(expected, actual); + } + + @Test + public void getRootPlayerTest(){ + Player expected = sue; + Player actual = suebkjk.getRootPlayer(); + Assert.assertEquals(expected, actual); + } + + @Test + public void getHandValueTest() { + Integer expected = 5; + Card two = new Card(Rank.TWO, Suit.HEARTS); + Card three = new Card(Rank.THREE, Suit.CLUBS); + ArrayList tempHand = new ArrayList<>(); + tempHand.add(three); + tempHand.add(two); + suebkjk.setHand(tempHand); + Integer actual = suebkjk.getHandValue(); + Assert.assertEquals(expected, actual); + } + + @Test + public void setCanHitNegativeTest(){ + suebkjk.setCanHit(false); + Assert.assertFalse(suebkjk.isCanHit()); + } + + @Test + public void setCanHitPositiveTest(){ + suebkjk.setCanHit(false); + suebkjk.setCanHit(true); + Assert.assertTrue(suebkjk.isCanHit()); + } + + @Test + public void getHandValueAceTest(){ + ArrayList tempHand = new ArrayList<>(); + tempHand.add(new Card(Rank.ACE, Suit.CLUBS)); + tempHand.add(new Card(Rank.KING, Suit.CLUBS)); + tempHand.add(new Card(Rank.THREE, Suit.CLUBS)); + suebkjk.setHand(tempHand); + int expected = 14; + int actual = suebkjk.getHandValue(); + Assert.assertEquals(expected, actual); + } + + @Test + public void payoutWinTest(){ + suebkjk.payoutWin(500); + int expected = 1000; + int actual = suebkjk.getRootPlayer().getBalance(); + Assert.assertEquals(expected, actual); + } + + @Test + public void payoutLossTest(){ + suebkjk.payoutLoss(500); + int expected = 0; + int actual = suebkjk.getRootPlayer().getBalance(); + Assert.assertEquals(expected, actual); + } + +} diff --git a/src/test/java/io/zipcoder/casino/PlayerTest/CrapsPlayerTest.java b/src/test/java/io/zipcoder/casino/PlayerTest/CrapsPlayerTest.java new file mode 100644 index 00000000..3433188d --- /dev/null +++ b/src/test/java/io/zipcoder/casino/PlayerTest/CrapsPlayerTest.java @@ -0,0 +1,45 @@ +package io.zipcoder.casino.PlayerTest; + + +import io.zipcoder.casino.Games.Craps; +import io.zipcoder.casino.Players.CrapsPlayer; +import io.zipcoder.casino.Players.Player; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class CrapsPlayerTest { + Player bob = new Player("Bob", 30, 500); + CrapsPlayer bobCrapsPlayer; + Craps game; + + @Before + public void setup() { + bobCrapsPlayer = new CrapsPlayer(bob); + game = new Craps(bob); + } + + @Test + public void constructorTest() { + String expected = "Bob"; + String actual = bobCrapsPlayer.getName(); + Assert.assertEquals(expected, actual); + } + + @Test + public void lostMoneyTest() { + int moneyTest = 500; + game.setPlayerBetAmount(500); + bobCrapsPlayer.lostMoney(500); + Assert.assertTrue(bob.getBalance() == 0); + } + + @Test + public void wonMoneyTest() { + int moneyTest = 500; + game.setPlayerBetAmount(500); + bobCrapsPlayer.wonMoney(500); + Assert.assertTrue(bob.getBalance() == 1000); + } + +} diff --git a/src/test/java/io/zipcoder/casino/PlayerTest/GoFishComputerPlayerTest.java b/src/test/java/io/zipcoder/casino/PlayerTest/GoFishComputerPlayerTest.java new file mode 100644 index 00000000..0296c1ba --- /dev/null +++ b/src/test/java/io/zipcoder/casino/PlayerTest/GoFishComputerPlayerTest.java @@ -0,0 +1,34 @@ +package io.zipcoder.casino.PlayerTest; +import io.zipcoder.casino.GameTools.Deck.Card; +import io.zipcoder.casino.GameTools.Deck.Rank; +import io.zipcoder.casino.GameTools.Deck.Suit; +import io.zipcoder.casino.Players.GoFishComputerPlayer; +import io.zipcoder.casino.Players.GoFishHumanPlayer; +import io.zipcoder.casino.Players.GoFishPlayer; +import io.zipcoder.casino.Players.Player; +import org.junit.Assert; +import org.junit.Test; + + +public class GoFishComputerPlayerTest { + + @Test + public void constructorTest() { + GoFishComputerPlayer player1 = new GoFishComputerPlayer("Bob"); + + String expected = "Bob"; + String actual = player1.getName(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getNumPairsTest() { + GoFishComputerPlayer player1 = new GoFishComputerPlayer("Bob"); + + int expected = 0; + int actual = player1.getNumPairs(); + + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/io/zipcoder/casino/PlayerTest/GoFishHumanPlayerTest.java b/src/test/java/io/zipcoder/casino/PlayerTest/GoFishHumanPlayerTest.java new file mode 100644 index 00000000..8311ec55 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/PlayerTest/GoFishHumanPlayerTest.java @@ -0,0 +1,50 @@ +package io.zipcoder.casino.PlayerTest; + +import io.zipcoder.casino.GameTools.Deck.Card; +import io.zipcoder.casino.GameTools.Deck.Rank; +import io.zipcoder.casino.GameTools.Deck.Suit; +import io.zipcoder.casino.Players.GoFishHumanPlayer; +import io.zipcoder.casino.Players.GoFishPlayer; +import io.zipcoder.casino.Players.Player; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +public class GoFishHumanPlayerTest { + + + @Test + public void showCardsTest() { + Player player1 = new Player("Sue", 89); + GoFishHumanPlayer goFishPlayer1 = new GoFishHumanPlayer(player1); + + Card temp1 = new Card(Rank.ACE, Suit.HEARTS); + goFishPlayer1.addCardToHand(temp1); + + String expected = "\n1: ACE of HEARTS\n"; + String actual = goFishPlayer1.showCards(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void showOpponentsTest() { + List opponents = new ArrayList<>(); + + Player player1 = new Player("Sue", 89); + GoFishHumanPlayer goFishPlayer1 = new GoFishHumanPlayer(player1); + + GoFishPlayer goFishPlayer2 = new GoFishHumanPlayer(new Player("Bob", 45)); + + opponents.add(goFishPlayer1); + opponents.add(goFishPlayer2); + + String expected = "1: Sue\n2: Bob\n"; + String actual = goFishPlayer1.showOpponents(opponents); + + Assert.assertEquals(expected, actual); + } + +} diff --git a/src/test/java/io/zipcoder/casino/PlayerTest/GoFishPlayerTest.java b/src/test/java/io/zipcoder/casino/PlayerTest/GoFishPlayerTest.java new file mode 100644 index 00000000..9a4b17a4 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/PlayerTest/GoFishPlayerTest.java @@ -0,0 +1,157 @@ +package io.zipcoder.casino.PlayerTest; +import io.zipcoder.casino.GameTools.Deck.Card; +import io.zipcoder.casino.GameTools.Deck.Rank; +import io.zipcoder.casino.GameTools.Deck.Suit; +import io.zipcoder.casino.Players.GoFishHumanPlayer; +import io.zipcoder.casino.Players.GoFishPlayer; +import io.zipcoder.casino.Players.Player; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import static io.zipcoder.casino.GameTools.Deck.Rank.ACE; +import static io.zipcoder.casino.GameTools.Deck.Suit.HEARTS; + + +public class GoFishPlayerTest { + + @Test + public void constructorTestName() { + String expectedName = "Bob"; + + Player player1 = new Player(expectedName, 34); + GoFishPlayer goFishPlayer1 = new GoFishHumanPlayer(player1); + + String actualName = goFishPlayer1.getName(); + + Assert.assertEquals(expectedName, actualName); + } + + @Test + public void constructorTestAge() { + int expectedAge = 78; + + Player player1 = new Player("Phoebe", expectedAge); + Player goFishPlayer1 = new GoFishHumanPlayer(player1); + + int actualAge = goFishPlayer1.getAge(); + + Assert.assertEquals(expectedAge, actualAge); + } + + @Test + public void addPairTest() { + Player player1 = new Player("Phoebe", 24); + GoFishPlayer goFishPlayer1 = new GoFishHumanPlayer(player1); + + int expected = 1; + goFishPlayer1.addPair(); + int actual = goFishPlayer1.getNumPairs(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getNumPairsTest() { + Player player1 = new Player("Phoebe", 24); + GoFishPlayer goFishPlayer1 = new GoFishHumanPlayer(player1); + + int expected = 0; + int actual = goFishPlayer1.getNumPairs(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void addCardToHandTest() { + Player player1 = new Player("Sue", 89); + GoFishPlayer goFishPlayer1 = new GoFishHumanPlayer(player1); + + Card temp1 = new Card(Rank.ACE, Suit.HEARTS); + goFishPlayer1.addCardToHand(temp1); + + int expected = 1; + int actual = goFishPlayer1.getCardHandSize(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void removeMatchesTest() { + Player player1 = new Player("Sue", 89); + GoFishPlayer goFishPlayer1 = new GoFishHumanPlayer(player1); + + Card temp1 = new Card(Rank.ACE, Suit.HEARTS); + Card temp2 = new Card(Rank.ACE, Suit.SPADE); + + goFishPlayer1.addCardToHand(temp1); + goFishPlayer1.addCardToHand(temp2); + + goFishPlayer1.removeMatches(temp1.getRankEnum()); + + int expected = 0; + int actual = goFishPlayer1.getCardHandSize(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getCardHandSizeTest() { + Player player1 = new Player("Sue", 89); + GoFishPlayer goFishPlayer1 = new GoFishHumanPlayer(player1); + + Card temp1 = new Card(Rank.ACE, Suit.HEARTS); + Card temp2 = new Card(Rank.THREE, Suit.SPADE); + + goFishPlayer1.addCardToHand(temp1); + goFishPlayer1.addCardToHand(temp2); + + int expected = 2; + int actual = goFishPlayer1.getCardHandSize(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void isHandEmptyTest() { + Player player1 = new Player("Sue", 89); + GoFishPlayer goFishPlayer1 = new GoFishHumanPlayer(player1); + + Card temp1 = new Card(Rank.ACE, Suit.HEARTS); + Card temp2 = new Card(Rank.THREE, Suit.SPADE); + + goFishPlayer1.addCardToHand(temp1); + goFishPlayer1.addCardToHand(temp2); + + Boolean answer = goFishPlayer1.isHandEmpty(); + + Assert.assertFalse(answer); + } + + @Test + public void hasCardTest(){ + Player player1 = new Player("Sue", 89); + GoFishPlayer goFishPlayer1 = new GoFishHumanPlayer(player1); + + Card temp1 = new Card(Rank.ACE, Suit.HEARTS); + goFishPlayer1.addCardToHand(temp1); + + Assert.assertTrue(goFishPlayer1.hasCard(temp1)); + } + + @Test + public void removeCardTest() { + Player player1 = new Player("Sue", 89); + GoFishPlayer goFishPlayer1 = new GoFishHumanPlayer(player1); + + Card temp1 = new Card(Rank.ACE, Suit.HEARTS); + goFishPlayer1.removeCard(temp1); + + int expected = 0; + int actual = goFishPlayer1.getCardHandSize(); + + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/io/zipcoder/casino/PlayerTest/PlayerTest.java b/src/test/java/io/zipcoder/casino/PlayerTest/PlayerTest.java new file mode 100644 index 00000000..6ce7dc0a --- /dev/null +++ b/src/test/java/io/zipcoder/casino/PlayerTest/PlayerTest.java @@ -0,0 +1,98 @@ +package io.zipcoder.casino.PlayerTest; + + +import io.zipcoder.casino.Players.Player; +import org.junit.Assert; +import org.junit.Test; + +public class PlayerTest { + @Test + public void constructorWithNameAndAgeTest() { + String expectedName = "Bob"; + Integer expectedAge = 21; + Player player1 = new Player(expectedName, expectedAge); + + String actualName = player1.getName(); + Integer actualAge = player1.getAge(); + + Assert.assertEquals(expectedName, actualName); + Assert.assertEquals(expectedAge, actualAge); + } + + @Test + public void constructorWithNameAgeBalanceTest() { + String expectedName = "Suzy"; + Integer expectedAge = 24; + Integer expectedBalance = 100; + Player player1 = new Player(expectedName, expectedAge, expectedBalance); + + String actualName = player1.getName(); + Integer actualAge = player1.getAge(); + Integer actualBalance = player1.getBalance(); + + Assert.assertEquals(expectedName, actualName); + Assert.assertEquals(expectedAge, actualAge); + Assert.assertEquals(expectedBalance, actualBalance); + } + + @Test + public void setNameTest() { + Player player1 = new Player("George", 51); + String expected = "George"; + player1.setName(expected); + String actual = player1.getName(); + Assert.assertEquals(expected, actual); + + } + + @Test + public void getNameTest() { + Player player1 = new Player("George", 51); + String expected = "George"; + + String actual = player1.getName(); + Assert.assertEquals(expected, actual); + + } + + @Test + public void setAgeTest() { + Player player1 = new Player("Alex", 26); + Integer expected = 26; + player1.setAge(expected); + Integer actual = player1.getAge(); + Assert.assertEquals(expected, actual); + + } + + @Test + public void getAgeTest() { + Player player1 = new Player("George", 51); + Integer expected = 51; + + Integer actual = player1.getAge(); + Assert.assertEquals(expected, actual); + + } + + @Test + public void setBalanceTest() { + Player player1 = new Player("Bob", 49, 100); + Integer expected = 100; + //player1.setBalance(expected); + Integer actual = player1.getBalance(); + Assert.assertEquals(expected, actual); + + } + + @Test + public void getBalanceTest() { + Player player1 = new Player("George", 51, 200); + + Integer expected = 200; + + Integer actual = player1.getBalance(); + Assert.assertEquals(expected, actual); + + } +} diff --git a/src/test/java/io/zipcoder/casino/PlayerTest/WarPlayerTest.java b/src/test/java/io/zipcoder/casino/PlayerTest/WarPlayerTest.java new file mode 100644 index 00000000..3be0801c --- /dev/null +++ b/src/test/java/io/zipcoder/casino/PlayerTest/WarPlayerTest.java @@ -0,0 +1,91 @@ +package io.zipcoder.casino.PlayerTest; + +import io.zipcoder.casino.GameTools.Deck.Card; +import io.zipcoder.casino.GameTools.Deck.Rank; +import io.zipcoder.casino.GameTools.Deck.Suit; +import io.zipcoder.casino.Games.War; +import io.zipcoder.casino.Players.Player; +import io.zipcoder.casino.Players.WarPlayer; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class WarPlayerTest { + War war; + Player player; + + @Before + public void setup(){ + player = new Player(); + war = new War(player); + } + + @Test + public void addToHandTest() { + Card card1 = new Card(Rank.KING, Suit.DIAMOND); + war.player1.currentHand.add(card1); + + Integer expected = 1; + Integer actual = war.player1.currentHand.size(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void setNameTest(){ + WarPlayer player = new WarPlayer(); + player.setName("Brian"); + + String expected = "Brian"; + String actual = player.getName(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void setAge(){ + WarPlayer player = new WarPlayer(); + player.setAge(25); + + Integer expected = 25; + Integer actual = player.getAge(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void getPointsTest() { + WarPlayer player = new WarPlayer(); + player.addPoint(5); + + Integer expected = 5; + Integer actual = player.getPoints(); + + Assert.assertEquals(expected, actual); + + } + + @Test + public void addPointTest() { + WarPlayer player = new WarPlayer(); + player.addPoint(100); + Integer expected = 100; + Integer actual = player.getPoints(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void resetPointsTest() { + WarPlayer player = new WarPlayer(); + player.addPoint(100); + + player.resetPoints(); + Integer expected = 0; + Integer actual = player.getPoints(); + + Assert.assertEquals(expected, actual); + + + } +} diff --git a/src/test/java/io/zipcoder/casino/WalletTest.java b/src/test/java/io/zipcoder/casino/WalletTest.java new file mode 100644 index 00000000..8d2834a2 --- /dev/null +++ b/src/test/java/io/zipcoder/casino/WalletTest.java @@ -0,0 +1,42 @@ +package io.zipcoder.casino; + +import org.junit.Assert; +import org.junit.Test; + +public class WalletTest { + Wallet dummy; + + @Test + public void constructorTest(){ + dummy = new Wallet(1000); + int actual = 1000; + int expected = dummy.getBalance(); + Assert.assertEquals(expected, actual); + } + + @Test + public void defaultConstructorTest(){ + dummy = new Wallet(); + int expected = 0; + int actual = dummy.getBalance(); + Assert.assertEquals(actual, expected); + } + + @Test + public void addMoneyTest(){ + dummy = new Wallet(5); + dummy.add(5); + int expected = 10; + int actual = dummy.getBalance(); + Assert.assertEquals(expected, actual); + } + + @Test + public void subtractMoneyTest(){ + dummy = new Wallet(5); + dummy.subtract(5); + int expected = 0; + int actual = dummy.getBalance(); + Assert.assertEquals(expected, actual); + } +}