diff options
-rw-r--r-- | src/jrummikub/control/TurnControl.java | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/jrummikub/control/TurnControl.java b/src/jrummikub/control/TurnControl.java index 840b0e9..fbe026d 100644 --- a/src/jrummikub/control/TurnControl.java +++ b/src/jrummikub/control/TurnControl.java @@ -5,10 +5,12 @@ import java.util.List; import jrummikub.model.IHand; import jrummikub.model.ITable; +import jrummikub.model.Stone; import jrummikub.util.Connection; import jrummikub.util.Event; import jrummikub.util.IEvent; import jrummikub.util.IListener; +import jrummikub.util.IListener2; import jrummikub.view.IView; public class TurnControl { @@ -16,6 +18,9 @@ public class TurnControl { private ITable table; private ITurnTimer timer; private IView view; + + private List<Stone> selectedStones = new ArrayList<Stone>(); + private Event endOfTurnEvent = new Event(); List<Connection> connections = new ArrayList<Connection>(); @@ -44,7 +49,18 @@ public class TurnControl { } }; connections.add(timer.getTimeRunOutEvent().add(endOfTurnListener)); - connections.add(view.getPlayerPanel().getEndTurnEvent().add(endOfTurnListener)); + connections.add(view.getPlayerPanel().getEndTurnEvent() + .add(endOfTurnListener)); + + connections.add(view.getPlayerPanel().getHandPanel().getStoneClickEvent() + .add(new IListener2<Stone, Boolean>() { + + @Override + public void handle(Stone stone, Boolean collect) { + handStoneClick(stone, collect); + + } + })); view.getPlayerPanel().getHandPanel().setStones(hand.clone()); view.enableStartTurnPanel(false); @@ -60,6 +76,19 @@ public class TurnControl { } + private void handStoneClick(Stone stone, boolean collect) { + if (collect) { + if (!selectedStones.remove(stone)) { + selectedStones.add(stone); + } + } else { + selectedStones.clear(); + selectedStones.add(stone); + } + + view.setSelectedStones(selectedStones); + } + private void endOfTurn() { timer.stopTimer(); endOfTurnEvent.emit(); |