diff options
Diffstat (limited to 'src/jrummikub/control')
-rw-r--r-- | src/jrummikub/control/TurnControl.java | 71 |
1 files changed, 59 insertions, 12 deletions
diff --git a/src/jrummikub/control/TurnControl.java b/src/jrummikub/control/TurnControl.java index a71e56c..3213fd6 100644 --- a/src/jrummikub/control/TurnControl.java +++ b/src/jrummikub/control/TurnControl.java @@ -12,6 +12,7 @@ import jrummikub.util.Connection; import jrummikub.util.Event; import jrummikub.util.IEvent; import jrummikub.util.IListener; +import jrummikub.util.IListener1; import jrummikub.util.IListener2; import jrummikub.view.IView; @@ -59,8 +60,7 @@ public class TurnControl { @Override public void handle(Stone stone, Boolean collect) { - handStoneClick(stone, collect); - + stoneClick(stone, collect); } })); @@ -72,6 +72,36 @@ public class TurnControl { collectionStoneClick(stone, collect); } })); + connections.add(view.getTablePanel().getStoneClickEvent() + .add(new IListener2<Stone, Boolean>() { + + @Override + public void handle(Stone stone, Boolean collect) { + stoneClick(stone, collect); + } + })); + + connections.add(view.getTablePanel().getClickEvent() + .add(new IListener1<Position>() { + @Override + public void handle(Position pos) { + tableClick(pos); + } + })); + connections.add(view.getTablePanel().getLeftConnectorClickEvent() + .add(new IListener1<StoneSet>() { + @Override + public void handle(StoneSet set) { + leftConnectorClick(set); + } + })); + connections.add(view.getTablePanel().getRightConnectorClickEvent() + .add(new IListener1<StoneSet>() { + @Override + public void handle(StoneSet set) { + rightConnectorClick(set); + } + })); view.getPlayerPanel().getHandPanel().setStones(hand.clone()); view.enableStartTurnPanel(false); @@ -87,7 +117,7 @@ public class TurnControl { } - private void handStoneClick(Stone stone, boolean collect) { + private void stoneClick(Stone stone, boolean collect) { if (collect) { if (!selectedStones.remove(stone)) { selectedStones.add(stone); @@ -109,17 +139,34 @@ public class TurnControl { view.setSelectedStones(selectedStones); } - - private void leftConnectorClick(StoneSet set){ - + + private void pickUpSelectedStones() { + for (Stone stone : selectedStones) { + hand.pickUp(stone); + table.pickUpStone(stone); + } + } + + private void tableClick(Position position) { + if (selectedStones.isEmpty()) { + return; + } + + pickUpSelectedStones(); + table.drop(new StoneSet(selectedStones), position); + selectedStones.clear(); + + view.getTablePanel().setStoneSets(table); + view.getPlayerPanel().getHandPanel().setStones(hand); + view.setSelectedStones(selectedStones); } - - private void rightConnectorClick(StoneSet set){ - + + private void leftConnectorClick(StoneSet set) { + } - - private void tableClick(Position position){ - + + private void rightConnectorClick(StoneSet set) { + } private void endOfTurn() { |