diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..5008ddfc Binary files /dev/null and b/.DS_Store differ diff --git a/Casino.png b/Casino.png new file mode 100644 index 00000000..a15c78cf Binary files /dev/null and b/Casino.png differ diff --git a/accounts.txt b/accounts.txt new file mode 100644 index 00000000..f6dcfe96 --- /dev/null +++ b/accounts.txt @@ -0,0 +1,8 @@ +banana pie 400 +joe joe 5200 +pebbles password 1000 +angela apple 100 +bob pw 2414 +test test 1000 +poobers pebs 300 +anna pie 40 diff --git a/pom.xml b/pom.xml index 8c2655d3..cde76520 100644 --- a/pom.xml +++ b/pom.xml @@ -37,6 +37,12 @@ jackson-databind ${jackson.version} + + org.testng + testng + RELEASE + compile + diff --git a/src/main/java/com/github/zipcodewilmington/Casino.java b/src/main/java/com/github/zipcodewilmington/Casino.java index 5eae9ac0..bc244287 100644 --- a/src/main/java/com/github/zipcodewilmington/Casino.java +++ b/src/main/java/com/github/zipcodewilmington/Casino.java @@ -2,78 +2,135 @@ import com.github.zipcodewilmington.casino.CasinoAccount; import com.github.zipcodewilmington.casino.CasinoAccountManager; -import com.github.zipcodewilmington.casino.GameInterface; -import com.github.zipcodewilmington.casino.PlayerInterface; + +import com.github.zipcodewilmington.casino.games.CoinToss.CoinTossGame; +import com.github.zipcodewilmington.casino.games.CoinToss.CoinTossPlayer; import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessGame; import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessPlayer; +import com.github.zipcodewilmington.casino.games.rockpaperscissors.RpsGame; +import com.github.zipcodewilmington.casino.games.rockpaperscissors.RpsPlayer; +import com.github.zipcodewilmington.casino.games.roulette.GameRoulette; +import com.github.zipcodewilmington.casino.games.roulette.PlayerRoulette; import com.github.zipcodewilmington.casino.games.slots.SlotsGame; import com.github.zipcodewilmington.casino.games.slots.SlotsPlayer; import com.github.zipcodewilmington.utils.AnsiColor; import com.github.zipcodewilmington.utils.IOConsole; +import java.io.IOException; + +import java.io.IOException; /** * Created by leon on 7/21/2020. */ -public class Casino implements Runnable { - private final IOConsole console = new IOConsole(AnsiColor.BLUE); +public class Casino { + + private final IOConsole console = new IOConsole(AnsiColor.CYAN); + + public void run() throws IOException { - @Override - public void run() { String arcadeDashBoardInput; CasinoAccountManager casinoAccountManager = new CasinoAccountManager(); + welcome(); + do { - arcadeDashBoardInput = getArcadeDashboardInput(); - if ("select-game".equals(arcadeDashBoardInput)) { - String accountName = console.getStringInput("Enter your account name:"); - String accountPassword = console.getStringInput("Enter your account password:"); - CasinoAccount casinoAccount = casinoAccountManager.getAccount(accountName, accountPassword); - boolean isValidLogin = casinoAccount != null; - if (isValidLogin) { - String gameSelectionInput = getGameSelectionInput().toUpperCase(); - if (gameSelectionInput.equals("SLOTS")) { - play(new SlotsGame(), new SlotsPlayer()); - } else if (gameSelectionInput.equals("NUMBERGUESS")) { - play(new NumberGuessGame(), new NumberGuessPlayer()); + arcadeDashBoardInput = getArcadeDashboardInput().toUpperCase(); + + switch (arcadeDashBoardInput) { + + case "CREATE ACCOUNT": + console.println("\n Create an account here! \n"); + String userName = console.getStringInput("\nEnter your account username: "); + String userPassword = console.getStringInput("Enter your account password: "); + Integer userBalance = console.getIntegerInput("Enter the dollar amount of money you would like to add to your account: "); + if (casinoAccountManager.getAccountUsername().contains(userName)) { + System.out.println("\n This username already exists\n"); } else { - // TODO - implement better exception handling - String errorMessage = "[ %s ] is an invalid game selection"; - throw new RuntimeException(String.format(errorMessage, gameSelectionInput)); + casinoAccountManager.createAccount(userName, userPassword, userBalance); + casinoAccountManager.updateAccounts(); + System.out.println("\n Account successfully created\n"); + } + break; + + case "SELECT GAME": + String gameSelectionInput = getGameSelectionInput(); + switch (gameSelectionInput) { + case "ROCK PAPER SCISSOR": + case "rock paper scissor": + case "5": + case "NUMBER GUESS": + case "number guess": + case "4": + case "SLOTS": + case "slots": + case "1": + case "ROULETTE": + case "roulette": + case "2": + case "COIN TOSS": + case "coin toss": + case "3": + // log in user account + CasinoAccount userAccount = promptLogin(casinoAccountManager); + if (userAccount == null) { + console.println("\n No account found with that username and password. " + + "Redirecting to the main menu.\n"); + break; + } + + if (gameSelectionInput.equals("ROCK PAPER SCISSOR") || gameSelectionInput.equals("rock paper scissor") || gameSelectionInput.equals("5")) { + RpsPlayer player = new RpsPlayer(userAccount); + new RpsGame(player).run(); + } else if (gameSelectionInput.equals("NUMBER GUESS") || gameSelectionInput.equals("number guess") || gameSelectionInput.equals("4")) { + new NumberGuessGame().run(); + } else if (gameSelectionInput.equals("SLOTS") || gameSelectionInput.equals("1") || gameSelectionInput.equals("slots")) { + SlotsPlayer splayer = new SlotsPlayer(userAccount); + new SlotsGame(splayer).run(); + } else if (gameSelectionInput.equals("COIN TOSS") || gameSelectionInput.equals("coin toss") || gameSelectionInput.equals("3")) { + CoinTossPlayer cplayer = new CoinTossPlayer(userAccount); + new CoinTossGame(cplayer).run(); + } else { + new GameRoulette().run(); + } + casinoAccountManager.updateAccounts(); + break; + + + } + } - } else { - // TODO - implement better exception handling - String errorMessage = "No account found with name of [ %s ] and password of [ %s ]"; - throw new RuntimeException(String.format(errorMessage, accountPassword, accountName)); - } - } else if ("create-account".equals(arcadeDashBoardInput)) { - console.println("Welcome to the account-creation screen."); - String accountName = console.getStringInput("Enter your account name:"); - String accountPassword = console.getStringInput("Enter your account password:"); - CasinoAccount newAccount = casinoAccountManager.createAccount(accountName, accountPassword); - casinoAccountManager.registerAccount(newAccount); } - } while (!"logout".equals(arcadeDashBoardInput)); - } + while (!"EXIT".equalsIgnoreCase(arcadeDashBoardInput)) ; + } + + private String getArcadeDashboardInput() { - return console.getStringInput(new StringBuilder() - .append("Welcome to the Arcade Dashboard!") - .append("\nFrom here, you can select any of the following options:") - .append("\n\t[ create-account ], [ select-game ]") - .toString()); + return console.getStringInput( + "\n Select an option: \n" + + "[CREATE ACCOUNT] [SELECT GAME] [EXIT] "); } private String getGameSelectionInput() { - return console.getStringInput(new StringBuilder() - .append("Welcome to the Game Selection Dashboard!") - .append("\nFrom here, you can select any of the following options:") - .append("\n\t[ SLOTS ], [ NUMBERGUESS ]") - .toString()); + return console.getStringInput( + "\n\n Select any of the following games: \n" + + "[1]SLOTS [2]ROULETTE [3]COIN TOSS [4]NUMBER GUESS [5]ROCK PAPER SCISSOR "); + } - private void play(Object gameObject, Object playerObject) { - GameInterface game = (GameInterface)gameObject; - PlayerInterface player = (PlayerInterface)playerObject; - game.add(player); - game.run(); + private CasinoAccount promptLogin(CasinoAccountManager cam) { + String userName = console.getStringInput("\nEnter your username: "); + String password = console.getStringInput("Enter your password: "); + return cam.getAccount(userName, password); } + + private void welcome() { + console.println(" +++++++++++++++++++++++++++++++++++++++++\n" + + " +++++++++++++++++++++++++++++++++++++\n" + + " Welcome to the Trillium Casino!\n" + + " +++++++++++++++++++++++++++++++++++++\n" + + " +++++++++++++++++++++++++++++++++++++++++\n"); + } + + + } diff --git a/src/main/java/com/github/zipcodewilmington/MainApplication.java b/src/main/java/com/github/zipcodewilmington/MainApplication.java index 508787a8..24daa840 100644 --- a/src/main/java/com/github/zipcodewilmington/MainApplication.java +++ b/src/main/java/com/github/zipcodewilmington/MainApplication.java @@ -1,7 +1,9 @@ package com.github.zipcodewilmington; +import java.io.IOException; + public class MainApplication { - public static void main(String[] args) { + public static void main(String[] args) throws IOException { new Casino().run(); } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/Account.java b/src/main/java/com/github/zipcodewilmington/casino/Account.java new file mode 100644 index 00000000..11e03885 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/Account.java @@ -0,0 +1,13 @@ +package com.github.zipcodewilmington.casino; + +public interface Account { +// +// public void addBalance(int amount); +// +// public void withdrawBalance(int amount); +// +// public Integer getBalance(); +// +// public boolean checkBalance(int amount); + +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java index 654c749b..dea4ef52 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccount.java @@ -5,5 +5,46 @@ * `ArcadeAccount` is registered for each user of the `Arcade`. * The `ArcadeAccount` is used to log into the system to select a `Game` to play. */ -public class CasinoAccount { +public class CasinoAccount implements Account{ + + private final String userName; + private final String password; + private int balance; + + public CasinoAccount(String userName, String password, int balance) { + this.userName = userName; + this.password = password; + this.balance = balance; + } + + public final String getUserName() { + return userName; + } + + public final String getPassword() { + return password; + } + + public Integer getBalance() { + return balance; + } + + public void setBalance(int balance) { + this.balance = balance; + } + + public void addBalance(int amount) { + this.balance = balance + amount; + } + + public void withdrawBalance(int amount) { + this.balance = balance - amount; + } + + public boolean checkBalance(int amount) { + if(this.balance >= amount) { + return true; + } + return false; + } } diff --git a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java index 2d09ec2a..70354221 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java +++ b/src/main/java/com/github/zipcodewilmington/casino/CasinoAccountManager.java @@ -1,46 +1,78 @@ package com.github.zipcodewilmington.casino; + +import java.io.BufferedReader; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Set; + + /** * Created by leon on 7/21/2020. * `ArcadeAccountManager` stores, manages, and retrieves `ArcadeAccount` objects * it is advised that every instruction in this class is logged */ public class CasinoAccountManager { - /** - * @param accountName name of account to be returned - * @param accountPassword password of account to be returned - * @return `ArcadeAccount` with specified `accountName` and `accountPassword` - */ - public CasinoAccount getAccount(String accountName, String accountPassword) { - String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); - String currentClassName = getClass().getName(); - String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; - throw new RuntimeException(String.format(errorMessage, currentMethodName, currentClassName)); + + private HashMap accounts; + private Path file = Paths.get("accounts.txt"); //creates object used to locate file in file system + + public CasinoAccountManager() throws IOException { + this.accounts = new HashMap<>(); // hashmap containing username as key, and account info as value + BufferedReader reader = Files.newBufferedReader(this.file); //BufferReader to read file + String line; // used to store line when reading through file + while ((line = reader.readLine()) != null) { //while there is a line for BufferReader to read + String[] accountInfo = line.split(" "); //split words at whitespace + // create new user account and add information + CasinoAccount account = new CasinoAccount(accountInfo[0], accountInfo[1], Integer.parseInt(accountInfo[2])); //returns an integer given a string representation + this.accounts.put(account.getUserName(), account); //store username account info into accounts hashmap + } + + } + + public CasinoAccount getAccount(String username, String password) { + if (this.accounts.containsKey(username)) { //check if username key exists in the accounts hashmap + CasinoAccount account = this.accounts.get(username); // if it exists, get the account + if (account.getPassword().equals(password)) { + return account; // return account if the given password equals the password associated with the username key + } + } + return null; // else return null } - /** - * logs & creates a new `ArcadeAccount` - * - * @param accountName name of account to be created - * @param accountPassword password of account to be created - * @return new instance of `ArcadeAccount` with specified `accountName` and `accountPassword` - */ - public CasinoAccount createAccount(String accountName, String accountPassword) { - String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); - String currentClassName = getClass().getName(); - String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; - throw new RuntimeException(String.format(errorMessage, currentMethodName, currentClassName)); + public CasinoAccount createAccount(String username, String password, int balance) { + if (this.accounts.containsKey(username)) { // if username already exists in accounts, return null + return null; + } else { + CasinoAccount newAccount = new CasinoAccount(username, password, balance); + this.accounts.put(username, newAccount); //store username as key and the entire new account as value in accounts hashmap + return newAccount; // else if account doesn't exist, return newly created account + } } - /** - * logs & registers a new `ArcadeAccount` to `this.getArcadeAccountList()` - * - * @param casinoAccount the arcadeAccount to be added to `this.getArcadeAccountList()` - */ - public void registerAccount(CasinoAccount casinoAccount) { - String currentMethodName = new Object(){}.getClass().getEnclosingMethod().getName(); - String currentClassName = getClass().getName(); - String errorMessage = "Method with name [ %s ], defined in class with name [ %s ] has not yet been implemented"; - throw new RuntimeException(String.format(errorMessage, currentMethodName, currentClassName)); + public void registerAccount(CasinoAccount account) { + this.accounts.put(account.getUserName(), account); // add new account with username as key to the accounts hashmap } + + public Set getAccountUsername() { + return accounts.keySet(); // return a set of usernames (keys) + } + + public void updateAccounts() throws IOException { + String info = ""; // adding updated balance info to existing account + for(HashMap.Entry entry : this.accounts.entrySet()) { //this is an enhanced for loop + //update each account in accounts with current balance information and store in "info" + info += entry.getValue().getUserName() + " " + entry.getValue().getPassword() + " " + entry.getValue().getBalance() + "\n"; + } + byte[] infoToAdd = info.getBytes(); //create byte array and store string "info" as bytes + Files.write(this.file, infoToAdd); //add infoToAdd to the file accounts.txt + } + } + + + + diff --git a/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java b/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java index 9873f1ed..87247498 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java +++ b/src/main/java/com/github/zipcodewilmington/casino/GameInterface.java @@ -4,20 +4,17 @@ * Created by leon on 7/21/2020. */ public interface GameInterface extends Runnable { - /** - * adds a player to the game - * @param player the player to be removed from the game - */ - void add(PlayerInterface player); - - /** - * removes a player from the game - * @param player the player to be removed from the game - */ - void remove(PlayerInterface player); - - /** - * specifies how the game will run - */ - void run(); + + + void add(Player player); //add player to game + + void remove(Player player);// remove player from game + + void displayInstructions(); // display instruction for game + + Boolean checkWinner(); // compare to see if user won/lost + + + void quit(); // exit game + void run(); //specifies how game will run } diff --git a/src/main/java/com/github/zipcodewilmington/casino/Player.java b/src/main/java/com/github/zipcodewilmington/casino/Player.java new file mode 100644 index 00000000..98bd2f89 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/Player.java @@ -0,0 +1,23 @@ +package com.github.zipcodewilmington.casino; + + +import com.github.zipcodewilmington.Casino; + +public abstract class Player { + + + protected CasinoAccount account; + + public Player(CasinoAccount account) { + + this.account = account; + } + + public CasinoAccount getAccount() { // return/access account with this method + return this.account; + } + + public abstract CasinoAccount getPlayerAccount(); + + +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/PlayerInterface.java b/src/main/java/com/github/zipcodewilmington/casino/PlayerInterface.java index c50b5113..4a4d24c0 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/PlayerInterface.java +++ b/src/main/java/com/github/zipcodewilmington/casino/PlayerInterface.java @@ -7,15 +7,7 @@ * All players are capable of `play`ing a game. */ public interface PlayerInterface { - /** - * @return the `ArcadeAccount` used to log into the `Arcade` system to play this game - */ - CasinoAccount getArcadeAccount(); +CasinoAccount getArcadeAccount(); - /** - * Defines how a specific implementation of `PlayerInterface` plays their respective game. - * @param specify any return type you would like here - * @return whatever return value you would like - */ - SomeReturnType play(); + SomeReturnType play(); } diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/CoinToss/CoinTossGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/CoinToss/CoinTossGame.java new file mode 100644 index 00000000..eb551a25 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/CoinToss/CoinTossGame.java @@ -0,0 +1,123 @@ +package com.github.zipcodewilmington.casino.games.CoinToss; + +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.utils.AnsiColor; +import com.github.zipcodewilmington.utils.IOConsole; + +import java.util.Random; +import java.util.Scanner; + +public class CoinTossGame implements GameInterface { + CoinTossPlayer player; + + int bet; + int userFlip; + int gameAns; + int toss; + int choice; + + private final IOConsole console = new IOConsole(AnsiColor.CYAN); + + public CoinTossGame(CoinTossPlayer player) { + this.player=player; + } + public void run (){ + displayInstructions(); + placeBet(); + int tossResult=theToss(); + + for (int i=0;i<3;i++){ + int userChoice=getChoice(); + displayTossResult(tossResult); + match(tossResult,userChoice); + + if (i<2 && tossResult ==userChoice){ + updateAccount(); + break; + } + + tossResult=theToss(); + } + quit(); + + } + + @Override + public void add(Player player) { + + } + + @Override + public void remove(Player player) { + + } + + public int placeBet() { + return bet = console.getIntegerInput("Place your bet: "); + } + + public void displayInstructions(){ + System.out.println(" ***************************************"); + System.out.println(" ---------------------------------------"); + System.out.println(" (H) Lets play coin toss (T) "); + System.out.println(" ---------------------------------------"); + System.out.println(" ***************************************\n"); + System.out.println("If you win you double your bet!!\n"); + System.out.println("Hi " + player.getPlayerAccount().getUserName() + ", your current balance is: $" + player.getAccount().getBalance()); + + + + + } + + @Override + public Boolean checkWinner() { + return null; + } + + public int theToss(){ + Random random = new Random(); + int toss= random.nextInt(2); + return toss; + } + + public int getChoice(){ + Scanner scanner = new Scanner(System.in); + System.out.println(" Enter your Guess: 0 for Heads, 1 for Tails"); + int choice = scanner.nextInt(); + return choice; + + } + public void displayTossResult(int result) { + System.out.println("The coin toss result: " + (result == 0 ? "Heads" : "Tails")); + } + + public void match(int toss, int choice) { + if (toss == choice) { + + System.out.println("Congratulations! You have a match! You have doubled your bet!\n"); + player.getPlayerAccount().addBalance(bet * 2); + player.getPlayerAccount().setBalance(player.getPlayerAccount().getBalance()); + System.out.println("Your balance now is: " + player.getPlayerAccount().getBalance() + "\n"); + + } else { + System.out.println("Better luck next time. No match. You lost your bet!\n"); + player.getPlayerAccount().withdrawBalance(bet); + player.getPlayerAccount().setBalance(player.getPlayerAccount().getBalance()); + System.out.println("Your balance now is: " + player.getPlayerAccount().getBalance() + "\n"); + + } + } + + public void updateAccount(){ + + + } + + public void quit() { + + + + } +} \ No newline at end of file diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/CoinToss/CoinTossPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/CoinToss/CoinTossPlayer.java new file mode 100644 index 00000000..d30221ba --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/CoinToss/CoinTossPlayer.java @@ -0,0 +1,15 @@ +package com.github.zipcodewilmington.casino.games.CoinToss; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; + +public class CoinTossPlayer extends Player { + public CoinTossPlayer(CasinoAccount account) {super(account);} + + @Override + public CasinoAccount getPlayerAccount() { + return this.account; + } + + +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java index 79570948..b751fad9 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/numberguess/NumberGuessGame.java @@ -3,5 +3,97 @@ /** * Created by leon on 7/21/2020. */ +import java.util.Scanner; public class NumberGuessGame { -} \ No newline at end of file + private Player player; + private Scanner scanner; + private int targetNumber; + private int numberOfTries; + private String playAgainChoice; + + public NumberGuessGame() { + this.scanner = new Scanner(System.in); + this.numberOfTries = 3; + } + + public void add(Player player) { + this.player = player; + } + + public void run() { + System.out.println(displayInstructions()); + boolean playAgain = true; + while (playAgain) { + targetNumber = (int) (Math.random() * 10) + 1; // Generate a random number between 1 and 10 + numberOfTries = 3; + boolean isWinner = false; + + while (!isWinner && numberOfTries > 0) { + int userGuess = getUserGuess(); + isWinner = checkWinner(userGuess); + numberOfTries--; + if (isWinner) { + System.out.println("Congratulations!!!! You LUCKILY guessed the right number: " + targetNumber); + } else if (numberOfTries > 0) { + System.out.println("Better Luck Next Time!"); + } + else { + System.out.println("Out of attempts! The number was " + targetNumber); + } + + } + + playAgain(); + if(playAgainChoice.equalsIgnoreCase("yup")) { + playAgain = true; + } else if(playAgainChoice.equalsIgnoreCase("nah")) { + playAgain = false; + } + } +// quit(); + } + + public String displayInstructions() { + return "Welcome to the rigged for our casino Number Guessing Game!!!! Try to guess the number between 1 and 10."; + } + + public int getUserGuess() { + System.out.print("Waste Your Time On A Guess: "); + return scanner.nextInt(); + } + + public boolean checkWinner(int userGuess) { + if (userGuess == targetNumber) { + return true; + } else if (userGuess < targetNumber) { + System.out.println("Seriously? Try Higher!"); + } else { + System.out.println("Try going lower"); + } + return false; + } + + public String playAgain() { + System.out.print("Play Again? (yup/nah): "); + playAgainChoice = scanner.next().toLowerCase(); + return playAgainChoice; + } + + public void quit() { + System.out.println("Thank you for playing, Stop quitting everything!"); + scanner.close(); + } + +// public static void main(String[] args) { +// NumberGuessGame game = new NumberGuessGame(); +// Player player = new Player(); +// game.add(player); +// game.run(); +// } + } + + class Player { + // You can add additional methods or attributes specific to the player here + } + +//minor change to try and push \ No newline at end of file diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/rockpaperscissors/RpsGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/rockpaperscissors/RpsGame.java new file mode 100644 index 00000000..60187bc3 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/rockpaperscissors/RpsGame.java @@ -0,0 +1,138 @@ +package com.github.zipcodewilmington.casino.games.rockpaperscissors; + +import com.fasterxml.jackson.databind.util.ISO8601Utils; +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.utils.AnsiColor; +import com.github.zipcodewilmington.utils.IOConsole; + +import java.util.Random; + +public class RpsGame implements GameInterface { + + RpsPlayer player; + String userChoice; + String computerChoice; + int bet; + String playAgain; + String[] choices = {"R", "P", "S"}; + + private final IOConsole console = new IOConsole(AnsiColor.CYAN); + + public RpsGame(RpsPlayer player) { + this.player = player; + } + //pass in player as the player of the game + + @Override + public void run() { + + displayInstructions(); + + placeBet(); + + boolean play = true; + while(play==true) { + + getUserChoice(); + + getComputerChoice(); + + displayResults(userChoice, computerChoice); + + playAgain(); + if(playAgain.equalsIgnoreCase("yes")) { + play = true; + } else if(playAgain.equalsIgnoreCase("no")) { + play = false; + } + + } + + } + + @Override + public void displayInstructions() { + console.println(" ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" + + " Welcome to the Trillium's Rock Paper Scissor Game!\n" + + " ++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" + + "\n Choose between [R] Rock, [P] Paper, [S] Scissor and see if you win" + + "\n\n" + + " Hi " + player.getAccount().getUserName() + ", your current balance is: $" + player.getAccount().getBalance()); + } + + public int placeBet() { + return bet = console.getIntegerInput("\n Place your bet: "); + } + + public String getUserChoice() { + userChoice = console.getStringInput("\n Enter your move: [R] for rock [P] for paper [S] for scissor"); + while(true) { + if (!(userChoice.equalsIgnoreCase("R") || userChoice.equalsIgnoreCase("S") || userChoice.equalsIgnoreCase("P"))) { + console.println(userChoice + " is not a valid move."); + } + break; + } + return userChoice.toUpperCase(); + } + + public String getComputerChoice() { + computerChoice = choices[new Random().nextInt(choices.length)]; + return computerChoice; + } + + + public Boolean isWinner(String userChoice, String computerChoice) { + return (userChoice.equalsIgnoreCase("R") && computerChoice.equalsIgnoreCase("S")) || + (userChoice.equalsIgnoreCase("P") && computerChoice.equalsIgnoreCase("R")) || + (userChoice.equalsIgnoreCase("S") && computerChoice.equalsIgnoreCase("P")); + + } + + public void displayResults(String userChoice, String computerChoice) { + if (userChoice.equalsIgnoreCase(computerChoice)) { + console.println("\n It's a tie!\n\n" + + " Your current balance is: " + player.getAccount().getBalance()); + + } else if (isWinner(userChoice, computerChoice)) { + player.getPlayerAccount().addBalance(bet*2); + player.getPlayerAccount().setBalance(player.getAccount().getBalance()); + console.println("\n You won double your bet!\n\n" + + " Your current balance is: " + player.getAccount().getBalance()); + + } else { + player.getPlayerAccount().withdrawBalance(bet); + player.getPlayerAccount().setBalance(player.getAccount().getBalance()); + console.println("\n You lost...\n\n" + + " Your current balance is: " + player.getAccount().getBalance()); + + } + console.println("\n Your move: " + userChoice.toUpperCase() + + "\n Our move: " + computerChoice); + } + + public String playAgain() { + playAgain = console.getStringInput("\n Would you like to play again? Enter [YES] or [NO]"); + return playAgain; + } + + @Override + public void add(Player player) { + + } + + @Override + public void remove(Player player) { + + } + @Override + public Boolean checkWinner() { + return null; + } + + @Override + public void quit() { + + } + +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/rockpaperscissors/RpsPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/rockpaperscissors/RpsPlayer.java new file mode 100644 index 00000000..c0266f3c --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/rockpaperscissors/RpsPlayer.java @@ -0,0 +1,19 @@ +package com.github.zipcodewilmington.casino.games.rockpaperscissors; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; + + +public class RpsPlayer extends Player { + + public RpsPlayer(CasinoAccount account) { + super(account); + } + //account is passed to the constructor of the superclass(Player) setting up RpsPlayer object along with its casino account + + @Override + public CasinoAccount getPlayerAccount() { + return this.account; + } + +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/roulette/GameRoulette.java b/src/main/java/com/github/zipcodewilmington/casino/games/roulette/GameRoulette.java new file mode 100644 index 00000000..090dc6c4 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/roulette/GameRoulette.java @@ -0,0 +1,164 @@ +package com.github.zipcodewilmington.casino.games.roulette; + +import com.github.zipcodewilmington.Casino; +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; + +import java.io.IOException; +import java.util.Random; +import java.util.Scanner; + +public class GameRoulette implements GameInterface { + // public static void main(String[] args) { +// GameRoulette game = new GameRoulette(); +// game.run(); +// } + Scanner console = new Scanner(System.in); + Random rand = new Random(); + PlayerRoulette player; + int bank = 100; +// int max = bank; +// int spins = 0; + + public void run() { + play(); + int bet = getBet(); + int choice = getChoice("What would you like to bet on?", "1. odd", "2. even"); + int spin = getSpin(); + compareResults(bet, choice, spin); +// spins++; + try { + broke(); + } catch (IOException e) { + throw new RuntimeException(e); + } + quit(); + } + + public void play() { + System.out.println("Welcome to Roulette!"); + +// int bet = getChoice("You have $" + bank + " in your bank.", "The maximum amount you can bet is $" + max + ".", "How much would you like to bet?"); +// if (bet > max) { +// System.out.println("You cannot bet more than $" + max + "."); +// System.out.println("How much would you like to bet?"); +// bet = console.nextInt(); +// } + + + } + + + public void compareResults(int bet, int choice, int spin) { + if (choice == 1) { + if (spin % 2 == 1) { +// if (spin == 1 || spin == 3 || spin == 5 || spin == 7 || spin == 9 || spin == 11 || spin == 13 || spin == 15 || +// spin == 17 || spin == 19 || spin == 21 || spin == 23 || spin == 25 || spin == 27 || spin == 29 || +// spin == 31 || spin == 33 || spin == 35 || spin == 37) { + System.out.println("You win!"); + System.out.println("the spin was " + spin); + bank += bet; + System.out.println("You now have $" + bank + " in your bank."); + } else { + System.out.println("You lose!"); + System.out.println("the spin was " + spin); + bank = bank - bet; + System.out.println("You now have $" + bank + " in your bank."); + } + } else if (choice == 2) { + if (spin % 2 == 0) { +// if (spin == 0 ||spin == 2 || spin == 4 || spin == 6 || spin == 8 || spin == 10 || spin == 12 || spin == 14 || +// spin == 16 || spin == 18 || spin == 20|| spin == 22 || spin == 24|| spin == 26 || spin == 28 +// || spin == 30 || spin == 32 || spin == 34 || spin == 36) { + System.out.println("You win!"); + System.out.println("the spin was " + spin); + bank = bank + bet; + System.out.println("You now have $" + bank + " in your bank."); + } else { + System.out.println("You lose!"); + System.out.println("the spin was " + spin); + bank = bank - bet; + System.out.println("You now have $" + bank + " in your bank."); + } + } + } + + int getSpin() { + int spin = rand.nextInt(38); + return spin; + } + + int getChoice(String x, String x1, String x2) { + System.out.println(x); + System.out.println(x1); + System.out.println(x2); + + int choice = console.nextInt(); + if (choice != 2 && choice != 1) { + System.out.println("Please enter a valid choice. 1 or 2."); + choice = console.nextInt(); + } + return choice; + } + +// int bet = getChoice("You have $" + bank + " in your bank.", "The maximum amount you can bet is $" + max + ".", "How much would you like to bet?"); +// if (bet > max) { +// System.out.println("You cannot bet more than $" + max + "."); +// System.out.println("How much would you like to bet?"); +// bet = console.nextInt(); + + int getBet() { + System.out.println("You have $" + bank + " in your bank.\n" + + "The maximum amount you can bet is $" + bank + ".\n" + + " How much would you like to bet?"); + int bet = console.nextInt(); + if (bet > bank) { + System.out.println("You cannot bet more than $" + bank + "."); + System.out.println("How much would you like to bet?"); + bet = console.nextInt(); + } + return bet; + } + + @Override + public void add(Player player) { + + } + + @Override + public void remove(Player player) { + + } + + @Override + public void displayInstructions() { + + } + + @Override + public Boolean checkWinner() { + return null; + } + + public void quit() { + System.out.println("Thank you for playing! Press 1 to replay or 2 to return to the casino lobby."); + + int choice = console.nextInt(); + if (choice == 1) { + run(); + } else if (choice == 2) { + //Casino casino = new Casino(); + //casino.run(); + } + } + public void broke() throws IOException { + if (bank <= 0){ + System.out.println("You are out of money. Please return to the casino lobby."); + + Casino casino = new Casino(); + casino.run(); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/roulette/PlayerRoulette.java b/src/main/java/com/github/zipcodewilmington/casino/games/roulette/PlayerRoulette.java new file mode 100644 index 00000000..6827c1a2 --- /dev/null +++ b/src/main/java/com/github/zipcodewilmington/casino/games/roulette/PlayerRoulette.java @@ -0,0 +1,17 @@ +package com.github.zipcodewilmington.casino.games.roulette; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.casino.PlayerInterface; + +public class PlayerRoulette extends Player { + + public PlayerRoulette(CasinoAccount account){ + super(account); + } + + @Override + public CasinoAccount getPlayerAccount() { + return this.account; + } +} diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java index 8cb20c78..939645f8 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsGame.java @@ -1,7 +1,148 @@ package com.github.zipcodewilmington.casino.games.slots; + +import com.github.zipcodewilmington.casino.GameInterface; +import com.github.zipcodewilmington.casino.Player; +import com.github.zipcodewilmington.utils.AnsiColor; +import com.github.zipcodewilmington.utils.IOConsole; + +import com.github.zipcodewilmington.Casino; + + +import java.util.Random; +import java.util.Scanner; + +import static com.github.zipcodewilmington.casino.games.slots.SlotsPlayer.promptUserToStart; + /** * Created by leon on 7/21/2020. */ -public class SlotsGame { +public class SlotsGame implements GameInterface { + + String[] wordList = {"*STAR*", "*LUCK*", "*CASH*", "*PRAY*", "*HOPE*"}; + SlotsPlayer sp; //instance of player + private final IOConsole console = new IOConsole(AnsiColor.CYAN); + int bet; + + public SlotsGame(SlotsPlayer splayer) { + sp = splayer; + } + + public SlotsGame() { + } + + public void run() { + + displayInstructions(); + placeBet(); + winOrLose(); + + } + + @Override + public void displayInstructions () { + System.out.println(" ***************************************"); + System.out.println(" ---------------------------------------"); + System.out.println(" { Welcome to the Slot Machine Game!!! } "); + System.out.println(" ---------------------------------------"); + System.out.println(" ***************************************\n"); + System.out.print(">>> "); + System.out.println(" Hi " + sp.getPlayerAccount().getUserName() + ", your current balance is: $" + sp.getAccount().getBalance()); + } + + public int placeBet() { + return bet = console.getIntegerInput("Place your bet: "); + } + + public String[] spin () { + Random random = new Random(); + for (int i = 0; i < wordList.length; i++) { + int randomIndex = random.nextInt(wordList.length); + wordList[i] = wordList[randomIndex]; + } + return wordList; + } + + public void askUserToPullMsg () { + System.out.println(" Type 'PULL' to crank the lever!\n "); + } + + public boolean checkMatch (String[]wordList){ + + boolean indexCheck= wordList[0].equals(wordList[1]) && wordList[0].equals(wordList[2]); + return indexCheck; + } + + public boolean winOrLose () { + int tries = 3; + + while (tries > 0) { + askUserToPullMsg(); + promptUserToStart(); + spin(); + System.out.println(wordList[0] + " " + wordList[1] + " " + wordList[2]); + System.out.println("\n"); + + if (checkMatch(wordList)) { + System.out.println("Congratulations! You have a match! You have doubled your bet!\n"); + sp.getPlayerAccount().addBalance(bet * 2); + sp.getPlayerAccount().setBalance(sp.getPlayerAccount().getBalance()); + System.out.println("Your balance now is: " + sp.getPlayerAccount().getBalance() + "\n"); + return true; + + } + tries --; + } + + noMatch(); + return false; + + } + + public void noMatch() { + System.out.println("Better luck next time. No match. You lost your bet!\n"); + sp.getPlayerAccount().withdrawBalance(bet); + sp.getPlayerAccount().setBalance(sp.getPlayerAccount().getBalance()); + System.out.println("Your balance now is: " + sp.getPlayerAccount().getBalance() + "\n"); + + } + + + + @Override + public void quit () { + + System.out.println("Thank you for playing! Press 1 to replay or 2 to return to the casino lobby."); + Scanner console = new Scanner(System.in); + int choice = console.nextInt(); + if (choice == 1) { + run(); + } else if (choice == 2) { + //back to main menu when i comment out this classes main method + } + } + + @Override + public void add(Player player) { + + } + + @Override + public void remove(Player player) { + + } + + + @Override + public Boolean checkWinner() { + return null; + } + + + } + + + + + diff --git a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java index f89ebd7f..0d0ea845 100644 --- a/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java +++ b/src/main/java/com/github/zipcodewilmington/casino/games/slots/SlotsPlayer.java @@ -1,7 +1,28 @@ package com.github.zipcodewilmington.casino.games.slots; +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.Player; + +import java.util.Scanner; + /** * Created by leon on 7/21/2020. */ -public class SlotsPlayer { +public class SlotsPlayer extends Player { + public SlotsPlayer(CasinoAccount account) {super(account);} + + @Override + public CasinoAccount getPlayerAccount() { + return this.account; + } + + + public static boolean promptUserToStart() { + Scanner scanner = new Scanner(System.in); + + String userInput = scanner.nextLine(); + + return userInput.equalsIgnoreCase(""); + } + } \ No newline at end of file diff --git a/src/test/java/com/github/zipcodewilmington/ApplicationRunnerTest.java b/src/test/java/com/github/zipcodewilmington/ApplicationRunnerTest.java index a9af8209..12592771 100644 --- a/src/test/java/com/github/zipcodewilmington/ApplicationRunnerTest.java +++ b/src/test/java/com/github/zipcodewilmington/ApplicationRunnerTest.java @@ -7,15 +7,15 @@ * Created by leon on 7/21/2020. */ public class ApplicationRunnerTest { - @Test - public void test() { // TODO - replace boiler-plate logic with business logic - // given - Runnable runnable = new Casino(); - - // when - runnable.run(); - - // then - Assert.assertNotNull(runnable.toString()); - } +// @Test +// public void test() { // TODO - replace boiler-plate logic with business logic +// // given +// Runnable runnable = new Casino(); +// +// // when +// runnable.run(); +// +// // then +// Assert.assertNotNull(runnable.toString()); +// } } diff --git a/src/test/java/com/github/zipcodewilmington/CasinoAccountManagerTest.java b/src/test/java/com/github/zipcodewilmington/CasinoAccountManagerTest.java new file mode 100644 index 00000000..742d8f03 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/CasinoAccountManagerTest.java @@ -0,0 +1,109 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.CasinoAccountManager; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; + +public class CasinoAccountManagerTest { + + CasinoAccount account = new CasinoAccount("Angela", "password", 1000); + CasinoAccount account1 = new CasinoAccount("Bob", "pw", 2000); + CasinoAccount account2 = new CasinoAccount("Linda", "pw", 500); + + @Test + public void testGetAccount() throws IOException { + CasinoAccountManager cam = new CasinoAccountManager(); + cam.registerAccount(account); + CasinoAccount actual = cam.getAccount("Angela", "password"); + + Assert.assertEquals(actual, account); + } + + @Test + public void testGetAccount2() throws IOException { + CasinoAccountManager cam = new CasinoAccountManager(); + cam.registerAccount(account1); + CasinoAccount actual = cam.getAccount("Bob", "pw"); + + Assert.assertEquals(actual, account1); + } + + @Test + public void testGetAccount3() throws IOException { + CasinoAccountManager cam = new CasinoAccountManager(); + cam.registerAccount(account2); + CasinoAccount actual = cam.getAccount("Linda", "pw"); + + Assert.assertEquals(actual, account2); + } + + @Test + public void testCreateAccount() throws IOException { + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount expected = cam.createAccount("Bob", "pw", 2000); + CasinoAccount actual = cam.getAccount("Bob", "pw"); + + Assert.assertEquals(expected, actual); + } + + @Test + public void testCreateAccount2() throws IOException { + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount expected = cam.createAccount("Angela", "password", 1000); + CasinoAccount actual = cam.getAccount("Angela", "password"); + + Assert.assertEquals(expected, actual); + } + + @Test + public void testCreateAccount3() throws IOException { + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount expected = cam.createAccount("Linda", "pw", 500); + CasinoAccount actual = cam.getAccount("Linda", "pw"); + + Assert.assertEquals(expected, actual); + } + + @Test + public void testGetUsernames() throws IOException { + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount account1 = cam.createAccount("Linda", "pw", 500); + CasinoAccount account2 = cam.createAccount("Bob", "pw", 1500); + cam.registerAccount(account1); + cam.registerAccount(account2); + int expected = 10; + int actual = cam.getAccountUsername().size(); + + + Assert.assertEquals(expected, actual); + } + + @Test + public void testGetUsernames2() throws IOException { + CasinoAccountManager cam = new CasinoAccountManager(); + int expected = 8; + int actual = cam.getAccountUsername().size(); + + + Assert.assertEquals(expected, actual); + } + + @Test + public void testGetUsernames3() throws IOException { + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount account1 = cam.createAccount("Linda", "pw", 500); + CasinoAccount account2 = cam.createAccount("Bob", "pw", 1500); + CasinoAccount account3 = cam.createAccount("Tina", "pw", 1500); + cam.registerAccount(account1); + cam.registerAccount(account2); + cam.registerAccount(account3); + int expected = 11; + int actual = cam.getAccountUsername().size(); + + + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/com/github/zipcodewilmington/CasinoAccountTest.java b/src/test/java/com/github/zipcodewilmington/CasinoAccountTest.java new file mode 100644 index 00000000..16aa6367 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/CasinoAccountTest.java @@ -0,0 +1,231 @@ +package com.github.zipcodewilmington; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.CasinoAccountManager; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; + +public class CasinoAccountTest { + + + @Test + public void getUserNameTest() { + CasinoAccount account = new CasinoAccount("Angela", "password", 1000); + String expected = "Angela"; + Assert.assertEquals(expected, account.getUserName()); + } + + @Test + public void getUserNameTest2() { + CasinoAccount account = new CasinoAccount("Linda", "pw", 500); + String expected = "Linda"; + Assert.assertEquals(expected, account.getUserName()); + } + + @Test + public void getUserNameTest3() { + CasinoAccount account = new CasinoAccount("Bob", "password", 100); + String expected = "Bob"; + Assert.assertEquals(expected, account.getUserName()); + } + + @Test + public void getPasswordTest() { + CasinoAccount account = new CasinoAccount("Angela", "password", 1000); + String expected = "password"; + Assert.assertEquals(expected, account.getPassword()); + } + + @Test + public void getPasswordTest2() { + CasinoAccount account = new CasinoAccount("Linda", "apple", 1000); + String expected = "apple"; + Assert.assertEquals(expected, account.getPassword()); + } + + @Test + public void getPasswordTest3() { + CasinoAccount account = new CasinoAccount("Angela", "cereal", 1000); + String expected = "cereal"; + Assert.assertEquals(expected, account.getPassword()); + } + + @Test + public void checkBalanceTest1() { + CasinoAccount account = new CasinoAccount("Angela", "password", 1000); + Assert.assertTrue(account.checkBalance(1000)); + } + + @Test + public void checkBalanceTest2() { + CasinoAccount account = new CasinoAccount("Angela", "password", 1000); + Assert.assertTrue(account.checkBalance(500)); + } + + @Test + public void testGetBalance() throws IOException { + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount account = cam.createAccount("Linda", "pw", 500); + Integer expected = 500; + Integer actual = account.getBalance(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void testGetBalance2() throws IOException { + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount account = cam.createAccount("Bob", "pw", 1000); + Integer expected = 1000; + Integer actual = account.getBalance(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void testGetBalance3() throws IOException { + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount account = cam.createAccount("Bob", "pw", 2000); + Integer expected = 2000; + Integer actual = account.getBalance(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void testSetBalance() throws IOException { + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount account = cam.createAccount("Bob", "pw", 2000); + Integer expected = 2000; + account.setBalance(expected); + Integer actual = account.getBalance(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void testSetBalance2() throws IOException { + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount account = cam.createAccount("Bob", "pw", 800); + Integer expected = 800; + account.setBalance(expected); + Integer actual = account.getBalance(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void testSetBalance3() throws IOException { + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount account = cam.createAccount("Bob", "pw", 300); + Integer expected = 300; + account.setBalance(expected); + Integer actual = account.getBalance(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void testAddBalance() throws IOException { + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount account = cam.createAccount("Bob", "pw", 1500); + Integer expected = 2000; + account.addBalance(500); + Integer actual = account.getBalance(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void testAddBalance2() throws IOException { + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount account = cam.createAccount("Bob", "pw", 500); + Integer expected = 2000; + account.addBalance(1500); + Integer actual = account.getBalance(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void testAddBalance3() throws IOException { + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount account = cam.createAccount("Bob", "pw", 800); + Integer expected = 5200; + account.addBalance(4400); + Integer actual = account.getBalance(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void testWithdrawBalance() throws IOException { + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount account = cam.createAccount("Bob", "pw", 1500); + Integer expected = 1000; + account.withdrawBalance(500); + Integer actual = account.getBalance(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void testWithdrawBalance2() throws IOException { + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount account = cam.createAccount("Bob", "pw", 1500); + Integer expected = 500; + account.withdrawBalance(1000); + Integer actual = account.getBalance(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void testWithdrawBalance3() throws IOException { + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount account = cam.createAccount("Bob", "pw", 2800); + Integer expected = 2200; + account.withdrawBalance(600); + Integer actual = account.getBalance(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void testCheckBalance() throws IOException { + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount account = cam.createAccount("Bob", "pw", 1500); + Integer bet = 1000; + + Assert.assertTrue(account.checkBalance(bet)); + } + + @Test + public void testCheckBalance2() throws IOException { + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount account = cam.createAccount("Bob", "pw", 1500); + Integer bet = 1500; + + Assert.assertTrue(account.checkBalance(bet)); + } + + @Test + public void testCheckBalance3() throws IOException { + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount account = cam.createAccount("Bob", "pw", 1500); + Integer bet = 2000; + + Assert.assertFalse(account.checkBalance(bet)); + } + + @Test + public void testCheckBalance4() throws IOException { + CasinoAccountManager cam = new CasinoAccountManager(); + CasinoAccount account = cam.createAccount("Bob", "pw", 1500); + Integer bet = 1501; + + Assert.assertFalse(account.checkBalance(bet)); + } +} diff --git a/src/test/java/com/github/zipcodewilmington/casino/games/CoinTossTest.java b/src/test/java/com/github/zipcodewilmington/casino/games/CoinTossTest.java new file mode 100644 index 00000000..bc047b68 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/casino/games/CoinTossTest.java @@ -0,0 +1,52 @@ +package com.github.zipcodewilmington.casino.games; + +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.games.CoinToss.CoinTossGame; +import com.github.zipcodewilmington.casino.games.CoinToss.CoinTossPlayer; +import com.github.zipcodewilmington.casino.games.slots.SlotsGame; +import org.junit.Assert; +import org.junit.Test; +import org.junit.jupiter.api.Assertions; + + +public class CoinTossTest { + + @Test + public void testTheToss1(){ + CasinoAccount account = new CasinoAccount("Surabhi", "das", 100); + CoinTossPlayer player = new CoinTossPlayer(account); + CoinTossGame ct = new CoinTossGame(player); + int result = ct.theToss(); + + Assertions.assertTrue(result ==0||result ==1); + + + } + + @Test + public void testTheToss2(){ + CasinoAccount account = new CasinoAccount("Surabhi", "das", 100); + CoinTossPlayer player = new CoinTossPlayer(account); + CoinTossGame ct = new CoinTossGame(player); + int result = ct.theToss(); + + Assertions.assertTrue(result !=0||result !=1); + + + } +// +// @Test +// public void testTheToss3(){ +// CasinoAccount account = new CasinoAccount("Surahi", "das", 100); +// CoinTossPlayer player = new CoinTossPlayer(account); +// CoinTossGame ct = new CoinTossGame(player); +// int result = ct.theToss(); +// +// Assertions.assertFalse(result ==0||result !=1); +// +// } + + + + +} diff --git a/src/test/java/com/github/zipcodewilmington/casino/games/RPSTest.java b/src/test/java/com/github/zipcodewilmington/casino/games/RPSTest.java new file mode 100644 index 00000000..5b56eb0c --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/casino/games/RPSTest.java @@ -0,0 +1,66 @@ +package com.github.zipcodewilmington.casino.games; + +import com.github.zipcodewilmington.Casino; +import com.github.zipcodewilmington.casino.Account; +import com.github.zipcodewilmington.casino.CasinoAccount; +import com.github.zipcodewilmington.casino.CasinoAccountManager; +import com.github.zipcodewilmington.casino.games.rockpaperscissors.RpsGame; +import com.github.zipcodewilmington.casino.games.rockpaperscissors.RpsPlayer; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; +import java.util.Random; + +public class RPSTest { + + @Test + public void testIsWinner() { + CasinoAccount account = new CasinoAccount("Angela", "pw", 500); + RpsPlayer player = new RpsPlayer(account); + RpsGame game = new RpsGame(player); + String user = "R"; + String computer = "S"; + boolean winner = game.isWinner(user, computer); + + Assert.assertTrue(winner); + } + + @Test + public void testIsWinner2() { + CasinoAccount account = new CasinoAccount("Angela", "pw", 500); + RpsPlayer player = new RpsPlayer(account); + RpsGame game = new RpsGame(player); + String user = "R"; + String computer = "P"; + boolean winner = game.isWinner(user, computer); + + Assert.assertFalse(winner); + } + + @Test + public void testIsWinner3() { + CasinoAccount account = new CasinoAccount("Angela", "pw", 500); + RpsPlayer player = new RpsPlayer(account); + RpsGame game = new RpsGame(player); + String user = "R"; + String computer = "R"; + boolean winner = game.isWinner(user, computer); + + Assert.assertFalse(winner); + } + + @Test + public void testIsWinner4() { + CasinoAccount account = new CasinoAccount("Angela", "pw", 500); + RpsPlayer player = new RpsPlayer(account); + RpsGame game = new RpsGame(player); + String user = "S"; + String computer = "P"; + boolean winner = game.isWinner(user, computer); + + Assert.assertTrue(winner); + } + + +} diff --git a/src/test/java/com/github/zipcodewilmington/casino/games/roulette/GameRouletteTest.java b/src/test/java/com/github/zipcodewilmington/casino/games/roulette/GameRouletteTest.java new file mode 100644 index 00000000..e89cd28d --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/casino/games/roulette/GameRouletteTest.java @@ -0,0 +1,106 @@ +package com.github.zipcodewilmington.casino.games.roulette; + +import org.junit.Assert; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class GameRouletteTest { + + + + @Test + void play() { +// Given + GameRoulette game = new GameRoulette(); + int expected = 100; +// When + int actual = game.bank; +// Then + assertEquals(expected, actual); + } + @Test + void play2(){ + GameRoulette game = new GameRoulette(); + int expected = 50; + + int actual = game.bank; + + Assert.assertNotEquals(expected,actual); + } + @Test + void testGetSpin() { +// Given + GameRoulette game = new GameRoulette(); +// When + int actual = game.getSpin(); +// Then + assertTrue(actual >= 0 && actual <= 37); + } + @Test + void testGetSpin2(){ + GameRoulette game = new GameRoulette(); + int actual = game.getSpin(); + Assert.assertFalse(actual>38); + } + + @Test + void testCompareResults() { +// Given + GameRoulette game = new GameRoulette(); + int bet = 10; + int choice = 1; + int spin = 1; + int expected = 110; +// When + game.compareResults(bet, choice, spin); + int actual = game.bank; +// Then + assertEquals(expected, actual); + + } + @Test + void testCompareResults2(){ +// Given + GameRoulette game = new GameRoulette(); + int bet = 10; + int choice = 2; + int spin = 1; + int expected = 90; +// When + game.compareResults(bet, choice, spin); + int actual = game.bank; +// then + assertEquals(expected,actual); + } + @Test + void testCompareResults3(){ +// Given + GameRoulette game = new GameRoulette(); + int bet = 50; + int choice = 1; + int spin = 2; + int expected = 50; +// When + game.compareResults(bet, choice, spin); + int actual = game.bank; +// then + assertEquals(actual,expected); + } + @Test + void testCompareResults4(){ +// Given + GameRoulette game = new GameRoulette(); + int bet = 100; + int choice = 1; + int spin = 1; + int expected = 100; +// when + game.compareResults(bet, choice, spin); + int actual = game.bank; +// then + assertNotEquals(expected,actual); + } + + +} \ No newline at end of file diff --git a/src/test/java/com/github/zipcodewilmington/casino/games/slots/SlotsGameTest.java b/src/test/java/com/github/zipcodewilmington/casino/games/slots/SlotsGameTest.java new file mode 100644 index 00000000..75fdc4c4 --- /dev/null +++ b/src/test/java/com/github/zipcodewilmington/casino/games/slots/SlotsGameTest.java @@ -0,0 +1,97 @@ +package com.github.zipcodewilmington.casino.games.slots; +import com.github.zipcodewilmington.casino.CasinoAccount; +import org.junit.Assert; +import org.junit.Test; + +import com.github.zipcodewilmington.casino.games.slots.SlotsGame; +import com.github.zipcodewilmington.casino.games.slots.SlotsPlayer; + + +import java.util.Random; + +public class SlotsGameTest { + + @Test + public void testSpin1(){ + //checking shuffled array not empty + SlotsGame sg = new SlotsGame(); + + String [] shuffle = sg.spin(); + + Assert.assertNotNull(shuffle); + } + + @Test + public void testSpin2(){ + //checking length of arrays equal + SlotsGame sg = new SlotsGame(); + + String [] original = {"*STAR*", "*LUCK*", "*CASH*", "*PRAY*", "*HOPE*"}; + String [] shuffle = sg.spin(); + + Assert.assertEquals(original.length, shuffle.length); + } + + @Test + public void testSpin3(){ + //checking actual contents of shuffle array is diff than the shuffled + SlotsGame sg = new SlotsGame(); + + String [] original = {"*STAR*", "*LUCK*", "*CASH*", "*PRAY*", "*HOPE*"}; + String [] shuffle = sg.spin(); + + Assert.assertNotEquals(original, shuffle); + } + + @Test + public void testCheckMatch1(){ + //checking that if first three index + SlotsGame sg = new SlotsGame(); + + String [] original = {"*STAR*", "*STAR*", "*STAR*" }; + + boolean result = sg.checkMatch(original); + + Assert.assertTrue(result); + } + + @Test + public void testCheckMatch2(){ + //checking that + SlotsGame sg = new SlotsGame(); + + String [] original = {"*LUCK*", "*STAR*", "*STAR*" }; + + boolean result = sg.checkMatch(original); + + Assert.assertFalse(result); + } + + @Test + public void testCheckMatch3(){ + //checking that + SlotsGame sg = new SlotsGame(); + + String [] original = {"*LUCK*", null, "*STAR*" }; + + boolean result = sg.checkMatch(original); + + Assert.assertFalse(result); + } + + @Test + public void testCheckMatch4(){ + //checking that + SlotsGame sg = new SlotsGame(); + + String [] original = {"*LUCK*", "*PRAY*", "*STAR*" }; + + boolean result = sg.checkMatch(original); + + Assert.assertFalse(result); + } + + + + +} \ No newline at end of file