diff options
Diffstat (limited to 'src/jrummikub/control')
-rw-r--r-- | src/jrummikub/control/GameControl.java | 8 | ||||
-rw-r--r-- | src/jrummikub/control/RoundControl.java | 80 | ||||
-rw-r--r-- | src/jrummikub/control/network/NetworkRoundControl.java | 65 | ||||
-rw-r--r-- | src/jrummikub/control/turn/AbstractTurnControl.java | 4 |
4 files changed, 92 insertions, 65 deletions
diff --git a/src/jrummikub/control/GameControl.java b/src/jrummikub/control/GameControl.java index 1f659f8..48c1b85 100644 --- a/src/jrummikub/control/GameControl.java +++ b/src/jrummikub/control/GameControl.java @@ -8,6 +8,7 @@ import jrummikub.model.GameSettings; import jrummikub.model.GameState; import jrummikub.model.IPlayer; import jrummikub.model.IRoundState; +import jrummikub.model.PlayerSettings; import jrummikub.model.RoundState; import jrummikub.model.Score; import jrummikub.util.Connection; @@ -183,14 +184,15 @@ public class GameControl { roundControl.getEndOfRoundEvent().add(new IListener1<Score>() { @Override public void handle(Score roundScore) { + gameState.setLastPlayerRedealed(null); endOfRound(roundScore); } }); - roundControl.getRestartRoundEvent().add(new IListener() { - + roundControl.getRestartRoundEvent().add(new IListener1<PlayerSettings>() { @Override - public void handle() { + public void handle(PlayerSettings player) { + gameState.setLastPlayerRedealed(player); restartRound(); } }); diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java index 4227741..2bcbc7e 100644 --- a/src/jrummikub/control/RoundControl.java +++ b/src/jrummikub/control/RoundControl.java @@ -8,7 +8,6 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import jrummikub.control.turn.AIControl; import jrummikub.control.turn.ITurnControl; import jrummikub.control.turn.TurnControlFactory; import jrummikub.control.turn.TurnMode; @@ -16,15 +15,14 @@ import jrummikub.model.IHand; import jrummikub.model.IPlayer; import jrummikub.model.IRoundState; import jrummikub.model.ITable; +import jrummikub.model.PlayerSettings; import jrummikub.model.PlayerSettings.Type; import jrummikub.model.Position; import jrummikub.model.Score; import jrummikub.model.Stone; import jrummikub.model.StoneSet; import jrummikub.util.Connection; -import jrummikub.util.Event; import jrummikub.util.Event1; -import jrummikub.util.IEvent; import jrummikub.util.IEvent1; import jrummikub.util.IListener; import jrummikub.util.IListener2; @@ -113,7 +111,7 @@ public class RoundControl { private ITurnControl turnControl; protected IRoundState roundState; private IView view; - private Event restartRoundEvent = new Event(); + private Event1<PlayerSettings> restartRoundEvent = new Event1<PlayerSettings>(); private Event1<IRoundState> roundStateUpdateEvent = new Event1<IRoundState>(); private Event1<Score> endOfRoundEvent = new Event1<Score>(); protected List<Connection> connections = new ArrayList<Connection>(); @@ -180,7 +178,6 @@ public class RoundControl { * Continue a saved round after loading */ public void continueRound() { - connections.add(view.getStartTurnEvent().add(new IListener() { @Override public void handle() { @@ -222,6 +219,35 @@ public class RoundControl { roundStateUpdateEvent.emit(state); } + protected BottomPanelType showStartTurnPanel() { + boolean isHuman = roundState.getActivePlayer().getPlayerSettings() + .getType() == HUMAN; + boolean oneHuman = roundState.getGameSettings().oneHuman(); + + if (!isHuman) { + return null; + } + + if (roundState.getLastPlayer() != null) { + view.setLastStonePlayerName(roundState.getLastPlayer() + .getPlayerSettings().getName()); + return BottomPanelType.START_LAST_TURN_PANEL; + } + + if (roundState.getTurnNumber() < 1 + && roundState.getGameState().getLastPlayerRedealed() != null) { + view.setRedealedPlayerName(roundState.getGameState() + .getLastPlayerRedealed().getName()); + return BottomPanelType.START_REDEAL_TURN_PANEL; + } + + if (oneHuman) { + return null; + } + + return BottomPanelType.START_TURN_PANEL; + } + /** * Prepare a player's turn by checking the player types and setting the * correct turn control @@ -229,12 +255,7 @@ public class RoundControl { protected void prepareTurn() { doPrepareTurn(); - boolean isHuman = roundState.getActivePlayer().getPlayerSettings() - .getType() == HUMAN; - boolean oneHuman = roundState.getGameSettings().oneHuman(); - boolean isAI = (turnControl instanceof AIControl); - - if (isAI || (isHuman && oneHuman)) { + if (showStartTurnPanel() == null) { startTurn(); } } @@ -245,12 +266,9 @@ public class RoundControl { protected void doPrepareTurn() { updateSidePanel(); - boolean isHuman = roundState.getActivePlayer().getPlayerSettings() - .getType() == HUMAN; - boolean oneHuman = roundState.getGameSettings().oneHuman(); - - if (isHuman && !oneHuman) { - view.setBottomPanel(BottomPanelType.START_TURN_PANEL); + BottomPanelType startTurnPanel = showStartTurnPanel(); + if (startTurnPanel != null) { + view.setBottomPanel(startTurnPanel); } view.getTablePanel().setStoneSets(roundState.getTable().clone()); @@ -259,19 +277,13 @@ public class RoundControl { view.setCurrentPlayerColor(roundState.getActivePlayer().getPlayerSettings() .getColor()); view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer().getLaidOut()); - - turnControl = createTurnControl(roundState.getActivePlayer() - .getPlayerSettings().getType()); } /** * Start a players turn with the correct turn control */ protected void startTurn() { - if (turnControl == null) { - doPrepareTurn(); - } - + doPrepareTurn(); boolean isHuman = roundState.getActivePlayer().getPlayerSettings() .getType() == HUMAN; @@ -294,6 +306,7 @@ public class RoundControl { view.getPlayerPanel().setEndTurnMode(turnMode); } + turnControl = createTurnControl(); turnControl.setup( new ITurnControl.TurnInfo(roundState, turnMode, mayPause), roundState.getGameSettings(), view); @@ -330,7 +343,7 @@ public class RoundControl { view.getSidePanel().setPlayers(players); view.getSidePanel().setHeapCapacity( roundState.getGameSettings().getTotalStones()); - view.getSidePanel().setHeapSize(roundState.getGameHeap().getSize()); + view.getSidePanel().setHeapSize(roundState.getStoneHeap().getSize()); } /** @@ -349,8 +362,9 @@ public class RoundControl { * of the new turn control * @return the new turn control */ - protected ITurnControl createTurnControl(Type type) { - return TurnControlFactory.getFactory(type).create(); + protected ITurnControl createTurnControl() { + return TurnControlFactory.getFactory( + roundState.getActivePlayer().getPlayerSettings().getType()).create(); } /** @@ -361,11 +375,11 @@ public class RoundControl { for (int i = 0; i < roundState.getPlayerCount(); i++) { IHand hand = roundState.getNthNextPlayer(i).getHand(); for (int j = 0; j < roundState.getGameSettings().getNumberOfStonesDealt(); j++) { - hand.drop(roundState.getGameHeap().drawStone(), new Position(0, 0)); + hand.drop(roundState.getStoneHeap().drawStone(), new Position(0, 0)); } } - view.getSidePanel().setHeapSize(roundState.getGameHeap().getSize()); + view.getSidePanel().setHeapSize(roundState.getStoneHeap().getSize()); } /** @@ -429,7 +443,7 @@ public class RoundControl { } if (roundState.getLastPlayer() == null) { - if (roundState.getGameHeap().getSize() == 0) { + if (roundState.getStoneHeap().getSize() == 0) { roundState.setLastPlayer(roundState.getActivePlayer()); roundState.nextPlayer(); roundState.nextTurn(); @@ -547,7 +561,7 @@ public class RoundControl { * * @return the event */ - public IEvent getRestartRoundEvent() { + public IEvent1<PlayerSettings> getRestartRoundEvent() { return restartRoundEvent; } @@ -556,10 +570,12 @@ public class RoundControl { * to do so */ protected void redeal() { + view.setBottomPanel(BottomPanelType.NONHUMAN_HAND_PANEL); + turnControl = null; for (Connection c : new ArrayList<Connection>(connections)) { c.remove(); } - restartRoundEvent.emit(); + restartRoundEvent.emit(roundState.getActivePlayer().getPlayerSettings()); } } diff --git a/src/jrummikub/control/network/NetworkRoundControl.java b/src/jrummikub/control/network/NetworkRoundControl.java index af7f675..05a3424 100644 --- a/src/jrummikub/control/network/NetworkRoundControl.java +++ b/src/jrummikub/control/network/NetworkRoundControl.java @@ -4,7 +4,6 @@ import jrummikub.control.RoundControl; import jrummikub.control.turn.ITurnControl; import jrummikub.model.IRoundState; import jrummikub.model.ITable; -import jrummikub.model.PlayerSettings.Type; import jrummikub.util.IListener; import jrummikub.util.IListener1; import jrummikub.view.IView; @@ -14,6 +13,7 @@ import jrummikub.view.IView; */ public class NetworkRoundControl extends RoundControl { private IConnectionControl connectionControl; + private boolean wasActive; private boolean currentlyActive; /** @@ -33,6 +33,7 @@ public class NetworkRoundControl extends RoundControl { super(roundState, view, false); this.connectionControl = connectionControl; + wasActive = startActive; currentlyActive = startActive; connections.add(connectionControl.getRoundStateUpdateEvent().add( @@ -40,22 +41,21 @@ public class NetworkRoundControl extends RoundControl { @Override public void handle(IRoundState state) { setRoundState(state); + prepareTurn(); } })); - connections.add(connectionControl.getTurnStartEvent().add( - new IListener() { - @Override - public void handle() { - startTurn(); - } - })); - connections.add(connectionControl.getNextPlayerEvent().add( - new IListener() { - @Override - public void handle() { - NetworkRoundControl.super.nextPlayer(); - } - })); + connections.add(connectionControl.getTurnStartEvent().add(new IListener() { + @Override + public void handle() { + NetworkRoundControl.super.startTurn(); + } + })); + connections.add(connectionControl.getNextPlayerEvent().add(new IListener() { + @Override + public void handle() { + NetworkRoundControl.super.nextPlayer(); + } + })); } @Override @@ -69,30 +69,39 @@ public class NetworkRoundControl extends RoundControl { } @Override - protected ITurnControl createTurnControl(Type type) { - switch (type) { - case HUMAN: - currentlyActive = true; - break; - case NETWORK: - currentlyActive = false; - break; - } - + protected ITurnControl createTurnControl() { if (!currentlyActive) { return new NetworkTurnControl(connectionControl); } - return super.createTurnControl(type); + return super.createTurnControl(); } @Override protected void prepareTurn() { - if (currentlyActive) { - connectionControl.startTurn(); + switch (roundState.getActivePlayer().getPlayerSettings().getType()) { + case HUMAN: + currentlyActive = true; + break; + case NETWORK: + currentlyActive = false; + break; } doPrepareTurn(); + + if (showStartTurnPanel() == null) { + if (currentlyActive) { + connectionControl.startTurn(); + } + } + } + + @Override + protected void startTurn() { + if (currentlyActive) { + connectionControl.startTurn(); + } } @Override diff --git a/src/jrummikub/control/turn/AbstractTurnControl.java b/src/jrummikub/control/turn/AbstractTurnControl.java index 9bdd6e2..19a2be4 100644 --- a/src/jrummikub/control/turn/AbstractTurnControl.java +++ b/src/jrummikub/control/turn/AbstractTurnControl.java @@ -226,7 +226,7 @@ public abstract class AbstractTurnControl implements ITurnControl { Set<Stone> tableDiff = tableDifference(turnInfo.getOldTable(), turnInfo.getTable()); // deal penalty, reset - turnInfo.getRoundState().getGameHeap().putBack(tableDiff); + turnInfo.getRoundState().getStoneHeap().putBack(tableDiff); turnInfo.getRoundState().getActivePlayer().setLastTurnInvalid(true); dealPenalty(tableDiff.size()); } @@ -240,7 +240,7 @@ public abstract class AbstractTurnControl implements ITurnControl { rowCount++; } - hand.drop(turnInfo.getRoundState().getGameHeap().drawStone(), + hand.drop(turnInfo.getRoundState().getStoneHeap().drawStone(), new Position(Hand.WIDTH - 1, rowCount - 1)); } |