Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
431963a
added uml
surabhidas47 Jul 17, 2023
84edbfe
uml update 2
Jhuntenburg Jul 18, 2023
53f816f
Merge pull request #1 from Jhuntenburg/master
Jhuntenburg Jul 18, 2023
a5e7050
created interfaces/abstract classes
angelakim318 Jul 19, 2023
0d008fc
roulette folders added
Jhuntenburg Jul 19, 2023
59261e5
Merge pull request #2 from aakkim/master
angelakim318 Jul 19, 2023
1f4d30b
Merge pull request #3 from Jhuntenburg/master
Jhuntenburg Jul 19, 2023
115be02
edit
angelakim318 Jul 19, 2023
a110d58
Merge pull request #4 from aakkim/master
angelakim318 Jul 19, 2023
be67777
testing merging games to console
angelakim318 Jul 20, 2023
438860b
Merge pull request #5 from aakkim/master
angelakim318 Jul 20, 2023
d24c939
game updates
Jul 20, 2023
a502edf
roulette
Jhuntenburg Jul 20, 2023
cbee94d
Merge remote-tracking branch 'upstream/master'
Jhuntenburg Jul 20, 2023
1d2a930
Merge remote-tracking branch 'upstream/master'
Jul 20, 2023
dba309f
games added
surabhidas47 Jul 20, 2023
b45d367
Merge remote-tracking branch 'upstream/master'
surabhidas47 Jul 20, 2023
bb1cd7a
NumberGuessGame update
Jul 20, 2023
e001cd2
roulette cleaned up and a couple tests
Jhuntenburg Jul 20, 2023
b5334a7
no merge conflicts
Jhuntenburg Jul 20, 2023
58b455e
tests done
surabhidas47 Jul 20, 2023
ffaf66e
coin toss
surabhidas47 Jul 21, 2023
cfeb316
updated console
angelakim318 Jul 21, 2023
0ece42e
updated rps
angelakim318 Jul 21, 2023
6abdfc7
roulette implements Gameinterface
Jhuntenburg Jul 21, 2023
a0e29c7
roulette implements Gameinterface
Jhuntenburg Jul 21, 2023
8627260
Merge remote-tracking branch 'origin/master'
Jhuntenburg Jul 21, 2023
09a16b6
coin toss updated
surabhidas47 Jul 21, 2023
000e314
Merge pull request #7 from surabhidas47/master
surabhidas47 Jul 21, 2023
c34a112
7/21/23
Jul 21, 2023
6b57144
Merge pull request #1 from Trillium-9-1/master
Jhuntenburg Jul 21, 2023
cea9f7a
Merge pull request #8 from KeenenNalls/master
KeenenNalls Jul 21, 2023
096dbf3
Merge pull request #6 from Jhuntenburg/master
Jhuntenburg Jul 21, 2023
5ef872b
updated rps
angelakim318 Jul 21, 2023
6b7e92a
Merge branch 'master' into master
angelakim318 Jul 21, 2023
89c361f
Merge pull request #9 from aakkim/master
angelakim318 Jul 21, 2023
71ab166
merged other team's games with my updated casino
angelakim318 Jul 21, 2023
ec6f0ec
most updated version of casino
angelakim318 Jul 21, 2023
52d46e1
Merge pull request #10 from aakkim/master
angelakim318 Jul 21, 2023
67e004d
pre merge commit
Jhuntenburg Jul 21, 2023
522750f
Merge remote-tracking branch 'upstream/master'
Jhuntenburg Jul 21, 2023
bbf879a
roulette test added
Jhuntenburg Jul 21, 2023
a5e0f54
slots tests
surabhidas47 Jul 21, 2023
7e4d9c9
updated RPS
angelakim318 Jul 21, 2023
1113d01
tests for coin toss
surabhidas47 Jul 21, 2023
17f4526
roulette test added2
Jhuntenburg Jul 21, 2023
2598794
bets added in slots
surabhidas47 Jul 21, 2023
595203c
updated console
angelakim318 Jul 21, 2023
b82a9fa
roulette test added again
Jhuntenburg Jul 21, 2023
392e4a1
trying to refractor methods to make better test
surabhidas47 Jul 22, 2023
be0c7b6
rearraged methods
surabhidas47 Jul 22, 2023
931d664
roulette test added again
Jhuntenburg Jul 24, 2023
290969f
added tests to casino account manager
angelakim318 Jul 24, 2023
792e8eb
more tests to account manager
angelakim318 Jul 24, 2023
cac7b07
added password tests for account
angelakim318 Jul 24, 2023
494e354
added some coins toss tests
surabhidas47 Jul 24, 2023
f5476d7
tests for get balance
angelakim318 Jul 24, 2023
602b9d5
more tests for account
angelakim318 Jul 24, 2023
f8de617
more tests for account manager
angelakim318 Jul 24, 2023
da1f6ba
more tests
angelakim318 Jul 24, 2023
83c1b61
worked on coin toss
surabhidas47 Jul 24, 2023
8f8b4e6
cointoss tests
surabhidas47 Jul 24, 2023
dc9ac47
adjustments to casino
angelakim318 Jul 24, 2023
20f324b
Merge pull request #12 from surabhidas47/master
surabhidas47 Jul 24, 2023
5020ac9
Merge branch 'master' into master
Jhuntenburg Jul 24, 2023
f5b6eda
merge mess
angelakim318 Jul 24, 2023
e3a9d37
Merge pull request #13 from aakkim/master
angelakim318 Jul 24, 2023
47f2de4
Merge pull request #11 from Jhuntenburg/master
Jhuntenburg Jul 24, 2023
cd189d8
casino
angelakim318 Jul 25, 2023
1d2a907
finished
angelakim318 Jul 25, 2023
007a545
Merge pull request #14 from aakkim/master
angelakim318 Jul 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added Casino.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions accounts.txt
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>

</dependencies>

Expand Down
155 changes: 106 additions & 49 deletions src/main/java/com/github/zipcodewilmington/Casino.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}



}
Original file line number Diff line number Diff line change
@@ -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();
}
}
13 changes: 13 additions & 0 deletions src/main/java/com/github/zipcodewilmington/casino/Account.java
Original file line number Diff line number Diff line change
@@ -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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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<String, CasinoAccount> 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<String> 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<String, CasinoAccount> 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
}

}




Loading