diff --git a/bin/cards/maumau/gui/GameTableModel.class b/bin/cards/maumau/gui/GameTableModel.class index ebae0d6..eafd47f 100644 Binary files a/bin/cards/maumau/gui/GameTableModel.class and b/bin/cards/maumau/gui/GameTableModel.class differ diff --git a/bin/cards/maumau/gui/PlayerFrame.class b/bin/cards/maumau/gui/PlayerFrame.class index 4b30b02..98f538d 100644 Binary files a/bin/cards/maumau/gui/PlayerFrame.class and b/bin/cards/maumau/gui/PlayerFrame.class differ diff --git a/bin/cards/maumau/model/ActionHandler.class b/bin/cards/maumau/model/ActionHandler.class index 0f81310..8be4178 100644 Binary files a/bin/cards/maumau/model/ActionHandler.class and b/bin/cards/maumau/model/ActionHandler.class differ diff --git a/bin/cards/maumau/model/Canceled.class b/bin/cards/maumau/model/Canceled.class index 16dc969..801751c 100644 Binary files a/bin/cards/maumau/model/Canceled.class and b/bin/cards/maumau/model/Canceled.class differ diff --git a/bin/cards/maumau/model/CardHandler.class b/bin/cards/maumau/model/CardHandler.class index e79c97e..eb9a422 100644 Binary files a/bin/cards/maumau/model/CardHandler.class and b/bin/cards/maumau/model/CardHandler.class differ diff --git a/bin/cards/maumau/model/Finished.class b/bin/cards/maumau/model/Finished.class index caea057..719c537 100644 Binary files a/bin/cards/maumau/model/Finished.class and b/bin/cards/maumau/model/Finished.class differ diff --git a/bin/cards/maumau/model/GameState.class b/bin/cards/maumau/model/GameState.class index e87cc24..808c0e9 100644 Binary files a/bin/cards/maumau/model/GameState.class and b/bin/cards/maumau/model/GameState.class differ diff --git a/bin/cards/maumau/model/HandlerState.class b/bin/cards/maumau/model/HandlerState.class new file mode 100644 index 0000000..5022551 Binary files /dev/null and b/bin/cards/maumau/model/HandlerState.class differ diff --git a/bin/cards/maumau/model/Initialized.class b/bin/cards/maumau/model/Initialized.class index 3a34cf1..b6430f9 100644 Binary files a/bin/cards/maumau/model/Initialized.class and b/bin/cards/maumau/model/Initialized.class differ diff --git a/bin/cards/maumau/model/JackChosen.class b/bin/cards/maumau/model/JackChosen.class index d7d5948..1dfe43f 100644 Binary files a/bin/cards/maumau/model/JackChosen.class and b/bin/cards/maumau/model/JackChosen.class differ diff --git a/bin/cards/maumau/model/Normal.class b/bin/cards/maumau/model/Normal.class index ea7d610..3d4eb02 100644 Binary files a/bin/cards/maumau/model/Normal.class and b/bin/cards/maumau/model/Normal.class differ diff --git a/bin/cards/maumau/model/SevenChosen.class b/bin/cards/maumau/model/SevenChosen.class index aff18e5..450ca4e 100644 Binary files a/bin/cards/maumau/model/SevenChosen.class and b/bin/cards/maumau/model/SevenChosen.class differ diff --git a/bin/cards/maumau/model/SuitChosen.class b/bin/cards/maumau/model/SuitChosen.class index 4be7a02..bb64e6f 100644 Binary files a/bin/cards/maumau/model/SuitChosen.class and b/bin/cards/maumau/model/SuitChosen.class differ diff --git a/src/cards/maumau/model/ActionHandler.java b/src/cards/maumau/model/ActionHandler.java index 0254a01..02ffb61 100644 --- a/src/cards/maumau/model/ActionHandler.java +++ b/src/cards/maumau/model/ActionHandler.java @@ -12,6 +12,7 @@ class ActionHandler { private int ctr7 = 0; private GameState gameState; + private HandlerState handlerState; /** * Constructs an ActionHandler for the specified MauMau game. @@ -20,7 +21,14 @@ class ActionHandler { */ ActionHandler(MauMau game) { this.game = game; - gameState = new Initialized(this); + } + + void setGameState(GameState gameState) { + this.gameState = gameState; + } + + void setHandlerState (HandlerState handlerState) { + this.handlerState = handlerState; } /** @@ -29,28 +37,28 @@ class ActionHandler { * @param player The player to be added to the game. */ void addPlayer(Player player) { - gameState.addPlayer(player); + //TODO implement } /** * Starts the game. */ void startGame() { - gameState.startGame(); + //TODO implement } /** * Transitions the game state to GAME_OVER. */ void finishGame() { - gameState.finishGame(); + //TODO implement } /** * Transitions the game state to GAME_CANCELED. */ void cancelGame() { - gameState.cancelGame(); + //TODO implement } /** @@ -59,7 +67,7 @@ class ActionHandler { * @param c The card chosen by the player. */ void chooseCard(Card c) { - gameState.chooseCard(c); + //TODO implement } /** @@ -68,21 +76,21 @@ class ActionHandler { * @param suit The suit chosen by the player. */ void chooseSuit(Suit suit) { - gameState.chooseSuit(suit); + //TODO implement } /** * Lets the player skip a round. **/ void skip() { - gameState.skip(); + //TODO implement } /** * Handles the player saying "no 7" in the current state. */ void no7() { - gameState.no7(); + //TODO implement } /** @@ -142,10 +150,6 @@ class ActionHandler { return gameState; } - void setGameState(GameState gameState) { - this.gameState = gameState; - } - /** * Checks if a card can be played by the current player in the current state. * diff --git a/src/cards/maumau/model/Canceled.java b/src/cards/maumau/model/Canceled.java index 2a80fb1..5c356a8 100644 --- a/src/cards/maumau/model/Canceled.java +++ b/src/cards/maumau/model/Canceled.java @@ -3,7 +3,7 @@ package cards.maumau.model; import cards.Card; import cards.Suit; -public class Canceled implements GameState{ +public class Canceled implements HandlerState { private final ActionHandler handler; diff --git a/src/cards/maumau/model/CardHandler.java b/src/cards/maumau/model/CardHandler.java index b0cfe80..194ea3f 100644 --- a/src/cards/maumau/model/CardHandler.java +++ b/src/cards/maumau/model/CardHandler.java @@ -9,7 +9,7 @@ import java.util.List; /** * Manages the draw pile and discard pile in a MauMau game. */ -class CardHandler { +public class CardHandler { private final MauMau game; private final int numCardsPerPlayer; private final List drawPile = new LinkedList<>(); diff --git a/src/cards/maumau/model/Finished.java b/src/cards/maumau/model/Finished.java index f2ba8e9..6c8ca69 100644 --- a/src/cards/maumau/model/Finished.java +++ b/src/cards/maumau/model/Finished.java @@ -3,7 +3,7 @@ package cards.maumau.model; import cards.Card; import cards.Suit; -public class Finished implements GameState{ +public class Finished implements HandlerState{ private final ActionHandler handler; Finished(ActionHandler handler) { diff --git a/src/cards/maumau/model/GameState.java b/src/cards/maumau/model/GameState.java index 283a976..08d3116 100644 --- a/src/cards/maumau/model/GameState.java +++ b/src/cards/maumau/model/GameState.java @@ -1,17 +1,29 @@ package cards.maumau.model; -import cards.Card; -import cards.Suit; - - -interface GameState { - void addPlayer(Player player); - void startGame(); - void finishGame(); - void cancelGame(); - void chooseCard(Card c); - void chooseSuit(Suit suit); - void skip(); - void no7(); - // boolean canPlay(Card c); -} +/** + * Represents the state of the Mau-Mau game. + */ +public enum GameState { + /** + * The game has been initialized, but has not yet started. + */ + GAME_INITIALIZED, + /** + * The game is over. The final ranking of players can be + * obtained using {@link MauMau#getRanking()}. + */ + GAME_OVER, + /** + * The game has been canceled due to insufficient cards. + */ + GAME_CANCELED, + /** + * The game is currently in progress with players taking turns. + */ + PLAY, + /** + * The game is in progress and the current player has played + * a Jack, and is required to choose a suit. + */ + CHOOSE_SUIT +} \ No newline at end of file diff --git a/src/cards/maumau/model/HandlerState.java b/src/cards/maumau/model/HandlerState.java new file mode 100644 index 0000000..9736aa4 --- /dev/null +++ b/src/cards/maumau/model/HandlerState.java @@ -0,0 +1,17 @@ +package cards.maumau.model; + +import cards.Card; +import cards.Suit; + +public interface HandlerState { + + void addPlayer(Player player); + void startGame(); + void finishGame(); + void cancelGame(); + void chooseCard(Card c); + void chooseSuit(Suit suit); + void skip(); + void no7(); + +} diff --git a/src/cards/maumau/model/Initialized.java b/src/cards/maumau/model/Initialized.java index 30bb95e..88f829a 100644 --- a/src/cards/maumau/model/Initialized.java +++ b/src/cards/maumau/model/Initialized.java @@ -3,7 +3,7 @@ package cards.maumau.model; import cards.Card; import cards.Suit; -public class Initialized implements GameState { +public class Initialized implements HandlerState { private final ActionHandler handler; @@ -19,9 +19,12 @@ public class Initialized implements GameState { public void startGame() { try { handler.getGame().getCardHandler().dealCards(); - handler.setGameState(new Normal(handler)); + handler.setHandlerState(new Normal(handler)); + handler.setGameState(GameState.PLAY); } catch (Exception e) { - handler.setGameState(new Canceled(handler)); + System.err.println("Not enough Cards!"); + handler.setHandlerState(new Canceled(handler)); + handler.setGameState(GameState.GAME_CANCELED); } } diff --git a/src/cards/maumau/model/JackChosen.java b/src/cards/maumau/model/JackChosen.java index 81e5f35..5a9bb82 100644 --- a/src/cards/maumau/model/JackChosen.java +++ b/src/cards/maumau/model/JackChosen.java @@ -3,7 +3,7 @@ package cards.maumau.model; import cards.Card; import cards.Suit; -public class JackChosen implements GameState{ +public class JackChosen implements HandlerState{ private final ActionHandler handler; JackChosen(ActionHandler handler) { @@ -14,7 +14,8 @@ public class JackChosen implements GameState{ public void chooseSuit(Suit suit){ handler.setChosenSuit(suit); - handler.setGameState(new SuitChosen(handler)); + handler.setHandlerState(new SuitChosen(handler)); + //handler.setGameState(PLAY); } public void startGame(){} diff --git a/src/cards/maumau/model/Normal.java b/src/cards/maumau/model/Normal.java index 70fd88f..ae9bc86 100644 --- a/src/cards/maumau/model/Normal.java +++ b/src/cards/maumau/model/Normal.java @@ -3,7 +3,7 @@ package cards.maumau.model; import cards.Card; import cards.Suit; -public class Normal implements GameState{ +public class Normal implements HandlerState { private final ActionHandler handler; Normal(ActionHandler handler) { @@ -15,7 +15,7 @@ public class Normal implements GameState{ public void finishGame(){ // Logic for finishing Game ???? if (handler.getGame().getPlayerHandler().getPlayers().isEmpty()) { - handler.setGameState(new Finished(handler)); + handler.setHandlerState(new Finished(handler)); } } public void cancelGame(){} diff --git a/src/cards/maumau/model/SevenChosen.java b/src/cards/maumau/model/SevenChosen.java index fcf9117..2ede84b 100644 --- a/src/cards/maumau/model/SevenChosen.java +++ b/src/cards/maumau/model/SevenChosen.java @@ -3,7 +3,7 @@ package cards.maumau.model; import cards.Card; import cards.Suit; -public class SevenChosen implements GameState{ +public class SevenChosen implements HandlerState{ private final ActionHandler handler; SevenChosen(ActionHandler handler) { @@ -30,6 +30,6 @@ public class SevenChosen implements GameState{ public void no7(){ handler.getGame().getPlayerHandler().getCurrentPlayer().drawCards(2 * handler.get7Counter()); handler.reset7Counter(); - handler.setGameState(new Normal(handler)); + handler.setHandlerState(new Normal(handler)); } } diff --git a/src/cards/maumau/model/SuitChosen.java b/src/cards/maumau/model/SuitChosen.java index 8aa4cab..2729d3a 100644 --- a/src/cards/maumau/model/SuitChosen.java +++ b/src/cards/maumau/model/SuitChosen.java @@ -4,7 +4,7 @@ import cards.Card; import cards.Suit; import cards.Rank; -public class SuitChosen implements GameState{ +public class SuitChosen implements HandlerState{ private final ActionHandler handler; SuitChosen(ActionHandler handler) { @@ -24,13 +24,13 @@ public class SuitChosen implements GameState{ if(c.rank() == Rank.SEVEN) { handler.increment7Counter(); handler.getGame().getPlayerHandler().nextTurn(1); - handler.setGameState(new SevenChosen(handler)); + handler.setHandlerState(new SevenChosen(handler)); } else if (c.rank() == Rank.EIGHT) { handler.getGame().getPlayerHandler().nextTurn(2); - handler.setGameState(new Normal(handler)); + handler.setHandlerState(new Normal(handler)); } else { handler.getGame().getPlayerHandler().nextTurn(1); - handler.setGameState(new Normal(handler)); + handler.setHandlerState(new Normal(handler)); } } diff --git a/src/cards/maumau/model/WaitForNextTurnState.java b/src/cards/maumau/model/WaitForNextTurnState.java index ee44a6d..97bc700 100644 --- a/src/cards/maumau/model/WaitForNextTurnState.java +++ b/src/cards/maumau/model/WaitForNextTurnState.java @@ -1,6 +1,6 @@ package cards.maumau.model; -public class WaitForNextTurnState implements PlayerState { +public class WaitForNextTurnState implements PlayerState { private final PlayerHandler handler; public WaitForNextTurnState(PlayerHandler handler) {