Skip to content

Commit 0fe7e4f

Browse files
committed
Work on GameInterface and PlayerInterface to create shell
1 parent ea256f8 commit 0fe7e4f

File tree

3 files changed

+94
-49
lines changed

3 files changed

+94
-49
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import com.github.zipcodewilmington.casino.PlayerInterface;
77
import com.github.zipcodewilmington.casino.games.blackjack.BlackjackGame;
88
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;
911
import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessGame;
1012
import com.github.zipcodewilmington.casino.games.numberguess.NumberGuessPlayer;
1113
import com.github.zipcodewilmington.casino.games.slots.SlotsGame;
@@ -38,8 +40,15 @@ public void run() {
3840
play(new NumberGuessGame(), new NumberGuessPlayer());
3941
} else if (gameSelectionInput.equals("BLACKJACK")) {
4042
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+
// ─────────────────────────────────────────────────────────────
4151
} else {
42-
// TODO - implement better exception handling
4352
String errorMessage = "[ %s ] is an invalid game selection";
4453
throw new RuntimeException(String.format(errorMessage, gameSelectionInput));
4554
}
@@ -70,13 +79,11 @@ private String getGameSelectionInput() {
7079
return console.getStringInput(new StringBuilder()
7180
.append("Welcome to the Game Selection Dashboard!")
7281
.append("\nFrom here, you can select any of the following options:")
73-
.append("\n\t[ SLOTS ], [ NUMBERGUESS ], [ BLACKJACK ]")
82+
.append("\n\t[ SLOTS ], [ NUMBERGUESS ], [ BLACKJACK ], [ CRAPS ]")
7483
.toString());
7584
}
7685

77-
private void play(Object gameObject, Object playerObject) {
78-
GameInterface game = (GameInterface)gameObject;
79-
PlayerInterface player = (PlayerInterface)playerObject;
86+
private void play(GameInterface game, PlayerInterface player) {
8087
game.add(player);
8188
game.run();
8289
}
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)