Skip to content

Commit 06712c8

Browse files
authored
Merge pull request #28 from Zoedayz/JamesBranch
James branch
2 parents 36e1140 + 0fe7e4f commit 06712c8

File tree

15 files changed

+940
-49
lines changed

15 files changed

+940
-49
lines changed

.claude/worktrees/zealous-curran

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit e6982a57eba077af5065b606bd6c000206a9b558

docs/readme-uml.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# GroupCasino UML (README-Aligned)
2+
3+
```mermaid
4+
classDiagram
5+
direction LR
6+
7+
class MainApplication {
8+
+main(args String[]) void
9+
}
10+
11+
class Casino {
12+
-console IOConsole
13+
+run() void
14+
-getArcadeDashboardInput() String
15+
-getGameSelectionInput() String
16+
-play(gameObject Object, playerObject Object) void
17+
}
18+
19+
class CasinoAccountManager {
20+
+getAccount(accountName String, accountPassword String) CasinoAccount
21+
+createAccount(accountName String, accountPassword String) CasinoAccount
22+
+registerAccount(casinoAccount CasinoAccount) void
23+
}
24+
25+
class CasinoAccount {
26+
-username String
27+
-password String
28+
-balance double
29+
+depositToBalance(amount double) void
30+
+withdrawBalance(amount double) void
31+
+getUsername() String
32+
+getPassword() String
33+
+getBalance() double
34+
}
35+
36+
class GameInterface {
37+
<<interface>>
38+
+add(player PlayerInterface) void
39+
+remove(player PlayerInterface) void
40+
+run() void
41+
}
42+
43+
class PlayerInterface {
44+
<<interface>>
45+
+getArcadeAccount() CasinoAccount
46+
+play() SomeReturnType
47+
}
48+
49+
class SlotsGame
50+
class NumberGuessGame
51+
class BlackjackGame
52+
53+
class SlotsPlayer
54+
class NumberGuessPlayer
55+
class BlackjackPlayer
56+
57+
class Deck
58+
class Card
59+
class BlackjackHand
60+
61+
MainApplication --> Casino : starts
62+
Casino --> CasinoAccountManager : uses
63+
Casino --> GameInterface : runs selected game
64+
CasinoAccountManager --> CasinoAccount : creates/gets
65+
66+
GameInterface <|.. SlotsGame
67+
GameInterface <|.. NumberGuessGame
68+
GameInterface <|.. BlackjackGame
69+
70+
PlayerInterface <|.. SlotsPlayer
71+
PlayerInterface <|.. NumberGuessPlayer
72+
PlayerInterface <|.. BlackjackPlayer
73+
74+
SlotsGame o--> SlotsPlayer : add/remove players
75+
NumberGuessGame o--> NumberGuessPlayer : add/remove players
76+
BlackjackGame o--> BlackjackPlayer : add/remove players
77+
78+
SlotsPlayer --> CasinoAccount : has account
79+
NumberGuessPlayer --> CasinoAccount : has account
80+
BlackjackPlayer --> CasinoAccount : has account
81+
82+
BlackjackGame --> Deck : uses
83+
BlackjackGame --> BlackjackHand : dealer hand
84+
BlackjackPlayer --> BlackjackHand : player hand
85+
Deck o--> Card : contains
86+
BlackjackHand o--> Card : contains
87+
```

src/main/java/com/github/zipcodewilmington/Casino.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
import com.github.zipcodewilmington.casino.CasinoAccountManager;
55
import com.github.zipcodewilmington.casino.GameInterface;
66
import com.github.zipcodewilmington.casino.PlayerInterface;
7+
import com.github.zipcodewilmington.casino.games.blackjack.BlackjackGame;
8+
import com.github.zipcodewilmington.casino.games.blackjack.BlackjackPlayer;
9+
import com.github.zipcodewilmington.casino.games.craps.CrapsGame;
10+
import com.github.zipcodewilmington.casino.games.craps.CrapsPlayer;
711
import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessGame;
812
import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessPlayer;
913
import com.github.zipcodewilmington.casino.games.slots.SlotsGame;
@@ -34,8 +38,17 @@ public void run() {
3438
play(new SlotsGame(), new SlotsPlayer());
3539
} else if (gameSelectionInput.equals("NUMBERGUESS")) {
3640
play(new NumberGuessGame(), new NumberGuessPlayer());
41+
} else if (gameSelectionInput.equals("BLACKJACK")) {
42+
play(new BlackjackGame(), new BlackjackPlayer(casinoAccount));
43+
} else if (gameSelectionInput.equals("CRAPS")) {
44+
play(new CrapsGame(), new CrapsPlayer(casinoAccount));
45+
// ── Teammates: uncomment your game below when ready ──────────
46+
// } else if (gameSelectionInput.equals("ROULETTE")) {
47+
// play(new RouletteGame(), new RoulettePlayer(casinoAccount));
48+
// } else if (gameSelectionInput.equals("HANGMAN")) {
49+
// play(new HangmanGame(), new HangmanPlayer(casinoAccount));
50+
// ─────────────────────────────────────────────────────────────
3751
} else {
38-
// TODO - implement better exception handling
3952
String errorMessage = "[ %s ] is an invalid game selection";
4053
throw new RuntimeException(String.format(errorMessage, gameSelectionInput));
4154
}
@@ -66,13 +79,11 @@ private String getGameSelectionInput() {
6679
return console.getStringInput(new StringBuilder()
6780
.append("Welcome to the Game Selection Dashboard!")
6881
.append("\nFrom here, you can select any of the following options:")
69-
.append("\n\t[ SLOTS ], [ NUMBERGUESS ]")
82+
.append("\n\t[ SLOTS ], [ NUMBERGUESS ], [ BLACKJACK ], [ CRAPS ]")
7083
.toString());
7184
}
7285

73-
private void play(Object gameObject, Object playerObject) {
74-
GameInterface game = (GameInterface)gameObject;
75-
PlayerInterface player = (PlayerInterface)playerObject;
86+
private void play(GameInterface game, PlayerInterface player) {
7687
game.add(player);
7788
game.run();
7889
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,80 @@
11
package com.github.zipcodewilmington.casino;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
5+
36
/**
47
* Created by leon on 7/21/2020.
58
* `ArcadeAccount` is registered for each user of the `Arcade`.
69
* The `ArcadeAccount` is used to log into the system to select a `Game` to play.
710
*/
811
public class CasinoAccount {
12+
private String username;
13+
private String password;
14+
private double balance;
15+
private final List<CasinoAccount> accounts = new ArrayList<>();
16+
17+
public CasinoAccount(String username, String password) {
18+
this.username = username;
19+
this.password = password;
20+
this.balance = 0.0;
21+
}
22+
23+
public void displayBalance() {
24+
System.out.printf("Current balance: $%.2f%n", balance);
25+
}
26+
27+
public void depositToBalance(double amount) {
28+
if (amount <= 0) {
29+
System.out.println("Deposit amount must be greater than zero.");
30+
return;
31+
}
32+
balance += amount;
33+
System.out.printf("Deposited $%.2f. New balance: $%.2f%n", amount, balance);
34+
}
35+
36+
public void withdrawBalance(double amount) {
37+
if (amount <= 0) {
38+
System.out.println("Withdrawal amount must be greater than zero.");
39+
return;
40+
}
41+
if (amount > balance) {
42+
System.out.println("Insufficient funds.");
43+
return;
44+
}
45+
balance -= amount;
46+
System.out.printf("Withdrew $%.2f. New balance: $%.2f%n", amount, balance);
47+
}
48+
49+
public String getUsername() { return username; }
50+
public String getPassword() { return password; }
51+
public double getBalance() { return balance; }
52+
53+
public CasinoAccount createAccount(String accountName, String accountPassword) {
54+
System.out.printf("Creating account for [ %s ]...%n", accountName);
55+
CasinoAccount newAccount = new CasinoAccount(accountName, accountPassword);
56+
System.out.printf("Account created for [ %s ].%n", accountName);
57+
return newAccount;
58+
}
59+
60+
public void registerAccount(CasinoAccount casinoAccount) {
61+
System.out.printf("Registering account [ %s ]...%n",
62+
casinoAccount.getUsername());
63+
accounts.add(casinoAccount);
64+
System.out.printf("Account [ %s ] registered successfully.%n",
65+
casinoAccount.getUsername());
66+
}
67+
68+
public CasinoAccount getAccount(String accountName, String accountPassword) {
69+
System.out.printf("Looking up account for [ %s ]...%n", accountName);
70+
for (CasinoAccount account : accounts) {
71+
if (account.getUsername().equals(accountName) &&
72+
account.getPassword().equals(accountPassword)) {
73+
System.out.printf("Account found for [ %s ].%n", accountName);
74+
return account;
75+
}
76+
}
77+
System.out.printf("No account found for [ %s ].%n", accountName);
78+
return null;
79+
}
980
}
Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,46 @@
1-
package com.github.zipcodewilmington.casino;
2-
3-
/**
4-
* Created by leon on 7/21/2020.
5-
*/
6-
public interface GameInterface extends Runnable {
7-
/**
8-
* adds a player to the game
9-
* @param player the player to be removed from the game
10-
*/
11-
void add(PlayerInterface player);
12-
13-
/**
14-
* removes a player from the game
15-
* @param player the player to be removed from the game
16-
*/
17-
void remove(PlayerInterface player);
18-
19-
/**
20-
* specifies how the game will run
21-
*/
22-
void run();
23-
}
1+
package com.github.zipcodewilmington.casino;
2+
3+
/**
4+
* Contract for all games in the Casino.
5+
* Methods marked `default` are optional overrides — implement them in your game class as needed.
6+
*/
7+
public interface GameInterface extends Runnable {
8+
9+
// ── Required (must implement) ─────────────────────────────────────
10+
11+
/** Add a player to the game. */
12+
void add(PlayerInterface player);
13+
14+
/** Remove a player from the game. */
15+
void remove(PlayerInterface player);
16+
17+
/** Main game loop — drives a full session. */
18+
void run();
19+
20+
// ── Optional hooks (override in your game class as needed) ────────
21+
22+
/** Load or reset any game state before a session starts. */
23+
default void fetch() {}
24+
25+
/** Called at the start of each round. */
26+
default void start() {}
27+
28+
/** Called at the end of each round. */
29+
default void end() {}
30+
31+
/** Register or initialise any sub-games or game variants. */
32+
default void loadGames() {}
33+
34+
/**
35+
* Factory method — create and return a player for this game.
36+
* Override to return your concrete player type (e.g. new BlackjackPlayer(account)).
37+
*/
38+
default PlayerInterface createPlayer(CasinoAccount account) {
39+
return null;
40+
}
41+
42+
/** Remove and clean up a player — delegates to remove() by default. */
43+
default void deletePlayer(PlayerInterface player) {
44+
remove(player);
45+
}
46+
}
Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
1-
package com.github.zipcodewilmington.casino;
2-
3-
/**
4-
* Created by leon on 7/21/2020.
5-
* All players of a game should abide by `PlayerInterface`.
6-
* All players must have reference to the `ArcadeAccount` used to log into the `Arcade` system.
7-
* All players are capable of `play`ing a game.
8-
*/
9-
public interface PlayerInterface {
10-
/**
11-
* @return the `ArcadeAccount` used to log into the `Arcade` system to play this game
12-
*/
13-
CasinoAccount getArcadeAccount();
14-
15-
/**
16-
* Defines how a specific implementation of `PlayerInterface` plays their respective game.
17-
* @param <SomeReturnType> specify any return type you would like here
18-
* @return whatever return value you would like
19-
*/
20-
<SomeReturnType> SomeReturnType play();
21-
}
1+
package com.github.zipcodewilmington.casino;
2+
3+
/**
4+
* Contract for all players in the Casino.
5+
* All players must hold a CasinoAccount reference and know how to play their game.
6+
* Methods marked `default` are provided for free — override them if you need custom behaviour.
7+
*/
8+
public interface PlayerInterface {
9+
10+
// ── Required (must implement) ─────────────────────────────────────
11+
12+
/** @return the CasinoAccount used to log into the Casino system. */
13+
CasinoAccount getArcadeAccount();
14+
15+
/**
16+
* Defines how this player plays their game.
17+
* @param <SomeReturnType> any return type you need
18+
*/
19+
<SomeReturnType> SomeReturnType play();
20+
21+
// ── Provided for free (override if needed) ────────────────────────
22+
23+
/**
24+
* Alias for getArcadeAccount() — matches the UML name.
25+
* Override if your player stores the account under a different field.
26+
*/
27+
default CasinoAccount fetchCasinoAccount() {
28+
return getArcadeAccount();
29+
}
30+
31+
/** @return the player's current balance, or 0.0 if no account is set. */
32+
default double getBalance() {
33+
CasinoAccount account = getArcadeAccount();
34+
return account != null ? account.getBalance() : 0.0;
35+
}
36+
}

0 commit comments

Comments
 (0)