From 0b66e7d7631a0effca6fb03b8285e0d4372f5eef Mon Sep 17 00:00:00 2001 From: Bennet Gerlach Date: Thu, 5 May 2011 20:22:14 +0200 Subject: Implemented stone clicking on hand git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@154 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/TurnControl.java | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/jrummikub') 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 selectedStones = new ArrayList(); + private Event endOfTurnEvent = new Event(); List connections = new ArrayList(); @@ -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() { + + @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(); -- cgit v1.2.3