diff --git a/bin/cards/maumau/gui/GameTableModel.class b/bin/cards/maumau/gui/GameTableModel.class index ac806bc..ebae0d6 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 3a69d9e..4b30b02 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 f75a044..0f81310 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 edb5901..3616afd 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/Finished.class b/bin/cards/maumau/model/Finished.class index 8aff7e9..9ba14ca 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 5067285..e87cc24 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/Initialized.class b/bin/cards/maumau/model/Initialized.class index 092d124..3a34cf1 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 bb04f7c..d7d5948 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/MauMau.class b/bin/cards/maumau/model/MauMau.class index a4409da..937b9c2 100644 Binary files a/bin/cards/maumau/model/MauMau.class and b/bin/cards/maumau/model/MauMau.class differ diff --git a/bin/cards/maumau/model/Normal.class b/bin/cards/maumau/model/Normal.class index 9acae6a..1883676 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 4f593d0..f8be00a 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 20f3fd0..4be7a02 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 b542416..0254a01 100644 --- a/src/cards/maumau/model/ActionHandler.java +++ b/src/cards/maumau/model/ActionHandler.java @@ -2,7 +2,6 @@ package cards.maumau.model; import cards.Card; import cards.Suit; -import cards.maumau.model.gamestate.*; /** * Manages the actions and state transitions within a MauMau game. @@ -30,28 +29,28 @@ class ActionHandler { * @param player The player to be added to the game. */ void addPlayer(Player player) { - //TODO implement + gameState.addPlayer(player); } /** * Starts the game. */ void startGame() { - //TODO implement + gameState.startGame(); } /** * Transitions the game state to GAME_OVER. */ void finishGame() { - //TODO implement + gameState.finishGame(); } /** * Transitions the game state to GAME_CANCELED. */ void cancelGame() { - //TODO implement + gameState.cancelGame(); } /** @@ -60,7 +59,7 @@ class ActionHandler { * @param c The card chosen by the player. */ void chooseCard(Card c) { - //TODO implement + gameState.chooseCard(c); } /** @@ -69,21 +68,21 @@ class ActionHandler { * @param suit The suit chosen by the player. */ void chooseSuit(Suit suit) { - //TODO implement + gameState.chooseSuit(suit); } /** * Lets the player skip a round. **/ void skip() { - //TODO implement + gameState.skip(); } /** * Handles the player saying "no 7" in the current state. */ void no7() { - //TODO implement + gameState.no7(); } /** @@ -140,8 +139,11 @@ class ActionHandler { * Returns the current state of the game. */ GameState getGameState() { - //TODO implement - return null; + return gameState; + } + + void setGameState(GameState gameState) { + this.gameState = gameState; } /** diff --git a/src/cards/maumau/model/Canceled.java b/src/cards/maumau/model/Canceled.java index 37196f2..3659a89 100644 --- a/src/cards/maumau/model/Canceled.java +++ b/src/cards/maumau/model/Canceled.java @@ -2,4 +2,9 @@ package cards.maumau.model; public class Canceled implements GameState{ + private final ActionHandler handler; + + Canceled(ActionHandler handler) { + this.handler = handler; + } } diff --git a/src/cards/maumau/model/Finished.java b/src/cards/maumau/model/Finished.java index 651ce45..9ca4324 100644 --- a/src/cards/maumau/model/Finished.java +++ b/src/cards/maumau/model/Finished.java @@ -1,5 +1,9 @@ package cards.maumau.model; public class Finished implements GameState{ + private final ActionHandler handler; + Finished(ActionHandler handler) { + this.handler = handler; + } } diff --git a/src/cards/maumau/model/GameState.java b/src/cards/maumau/model/GameState.java index 00e47ca..283a976 100644 --- a/src/cards/maumau/model/GameState.java +++ b/src/cards/maumau/model/GameState.java @@ -4,14 +4,14 @@ import cards.Card; import cards.Suit; -public interface GameState { - public void addPlayer(Player player); - public void startGame(); - public void finishGame(); - public void cancelGame(); - public void chooseCard(Card c); - public void chooseSuit(Suit suit); - public void skip(); - public void no7(); - boolean canPlay(Card c); +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); } diff --git a/src/cards/maumau/model/Initialized.java b/src/cards/maumau/model/Initialized.java index 78ac9dd..30bb95e 100644 --- a/src/cards/maumau/model/Initialized.java +++ b/src/cards/maumau/model/Initialized.java @@ -1,5 +1,8 @@ package cards.maumau.model; +import cards.Card; +import cards.Suit; + public class Initialized implements GameState { private final ActionHandler handler; @@ -12,5 +15,20 @@ public class Initialized implements GameState { handler.getGame().getPlayerHandler().addPlayer(player); } + + public void startGame() { + try { + handler.getGame().getCardHandler().dealCards(); + handler.setGameState(new Normal(handler)); + } catch (Exception e) { + handler.setGameState(new Canceled(handler)); + } + } + public void finishGame(){} + public void cancelGame(){} + public void chooseCard(Card c){} + public void chooseSuit(Suit suit){} + public void skip(){} + public void no7(){} } diff --git a/src/cards/maumau/model/JackChosen.java b/src/cards/maumau/model/JackChosen.java index 6e95349..81e5f35 100644 --- a/src/cards/maumau/model/JackChosen.java +++ b/src/cards/maumau/model/JackChosen.java @@ -1,5 +1,27 @@ package cards.maumau.model; -public class JackChosen implements GameState{ +import cards.Card; +import cards.Suit; +public class JackChosen implements GameState{ + private final ActionHandler handler; + + JackChosen(ActionHandler handler) { + this.handler = handler; + } + + + + public void chooseSuit(Suit suit){ + handler.setChosenSuit(suit); + handler.setGameState(new SuitChosen(handler)); + } + + public void startGame(){} + public void addPlayer(Player player){} + public void finishGame(){} + public void cancelGame(){} + public void chooseCard(Card c){} + public void skip(){} + public void no7(){} } diff --git a/src/cards/maumau/model/MauMau.java b/src/cards/maumau/model/MauMau.java index 0c972ee..1b5bfd0 100644 --- a/src/cards/maumau/model/MauMau.java +++ b/src/cards/maumau/model/MauMau.java @@ -2,7 +2,6 @@ package cards.maumau.model; import cards.Card; import cards.Suit; -import cards.maumau.model.gamestate.*; import java.util.ArrayList; import java.util.List; diff --git a/src/cards/maumau/model/Normal.java b/src/cards/maumau/model/Normal.java index a7e368f..64372b1 100644 --- a/src/cards/maumau/model/Normal.java +++ b/src/cards/maumau/model/Normal.java @@ -1,5 +1,9 @@ package cards.maumau.model; public class Normal implements GameState{ + private final ActionHandler handler; + Normal(ActionHandler handler) { + this.handler = handler; + } } diff --git a/src/cards/maumau/model/SevenChosen.java b/src/cards/maumau/model/SevenChosen.java index 5c2d73b..37c72f6 100644 --- a/src/cards/maumau/model/SevenChosen.java +++ b/src/cards/maumau/model/SevenChosen.java @@ -1,5 +1,9 @@ package cards.maumau.model; public class SevenChosen implements GameState{ + private final ActionHandler handler; + SevenChosen(ActionHandler handler) { + this.handler = handler; + } } diff --git a/src/cards/maumau/model/SuitChosen.java b/src/cards/maumau/model/SuitChosen.java index 9ccb255..8aa4cab 100644 --- a/src/cards/maumau/model/SuitChosen.java +++ b/src/cards/maumau/model/SuitChosen.java @@ -1,5 +1,47 @@ package cards.maumau.model; -public class SuitChosen implements GameState{ +import cards.Card; +import cards.Suit; +import cards.Rank; +public class SuitChosen implements GameState{ + private final ActionHandler handler; + + SuitChosen(ActionHandler handler) { + this.handler = handler; + } + + public void addPlayer(Player player){} + public void startGame(){} + public void finishGame(){} + public void cancelGame(){} + + public void chooseCard(Card c){ + if (handler.canPlay(c)) { + handler.setChosenSuit(null); + handler.getGame().getPlayerHandler().getCurrentPlayer().playCard(c); + + if(c.rank() == Rank.SEVEN) { + handler.increment7Counter(); + handler.getGame().getPlayerHandler().nextTurn(1); + handler.setGameState(new SevenChosen(handler)); + } else if (c.rank() == Rank.EIGHT) { + handler.getGame().getPlayerHandler().nextTurn(2); + handler.setGameState(new Normal(handler)); + } else { + handler.getGame().getPlayerHandler().nextTurn(1); + handler.setGameState(new Normal(handler)); + } + + } + } + + public void chooseSuit(Suit suit){} + + public void skip(){ + handler.getGame().getPlayerHandler().getCurrentPlayer().drawCards(1); + handler.getGame().getPlayerHandler().nextTurn(1); + } + + public void no7(){} }