From 3a2c0638e3671af1449dc32a0488620bcfc204c5 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 8 May 2011 18:45:32 +0200 Subject: Make Table.pickUpStone return the the stone sets that are created git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@171 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/model/ITable.java | 5 ++++- src/jrummikub/model/Table.java | 36 ++++++++++++++++++++---------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/jrummikub/model/ITable.java b/src/jrummikub/model/ITable.java index 16fd4d3..1c3fd9f 100644 --- a/src/jrummikub/model/ITable.java +++ b/src/jrummikub/model/ITable.java @@ -1,5 +1,7 @@ package jrummikub.model; +import jrummikub.util.Pair; + public interface ITable extends IStoneTray { /** @@ -7,8 +9,9 @@ public interface ITable extends IStoneTray { * * @param stone * stone to pick up + * @return the stone sets that are created by taking pickung the the stone */ - public void pickUpStone(Stone stone); + public Pair pickUpStone(Stone stone); /** Tests the Table for rule conflicts by checking all the {@link StoneSet} */ public boolean isValid(); diff --git a/src/jrummikub/model/Table.java b/src/jrummikub/model/Table.java index 71ce27c..a763bef 100644 --- a/src/jrummikub/model/Table.java +++ b/src/jrummikub/model/Table.java @@ -10,24 +10,25 @@ public class Table extends StoneTray implements ITable { StoneSet set; Position setPosition; int stonePosition; + public StoneInfo(StoneSet set, Position setPosition, int stonePosition) { this.set = set; this.setPosition = setPosition; this.stonePosition = stonePosition; } } - + /** * Removes {@link Stone} from the Table * * @param stone - * stone to pick up + * stone to pick up */ @Override - public void pickUpStone(Stone stone) { + public Pair pickUpStone(Stone stone) { StoneInfo info = findStoneInfo(stone); - - splitSet(info.set, info.setPosition, info.stonePosition); + + return splitSet(info.set, info.setPosition, info.stonePosition); } private StoneInfo findStoneInfo(Stone stone) { @@ -55,7 +56,7 @@ public class Table extends StoneTray implements ITable { } return info; } - + @Override public StoneSet findStoneSet(Stone stone) { StoneInfo info = findStoneInfo(stone); @@ -64,28 +65,29 @@ public class Table extends StoneTray implements ITable { } return info.set; } - - - private void splitSet(StoneSet set, Position setPosition, int stonePosition) { + private Pair splitSet(StoneSet set, Position setPosition, + int stonePosition) { pickUp(set); - + Pair firstSplit = set.splitAt(stonePosition); Pair secondSplit = firstSplit.getSecond().splitAt(1); - + StoneSet leftSet = firstSplit.getFirst(); StoneSet rightSet = secondSplit.getSecond(); - + if (set.classify() == StoneSet.Type.RUN) { Position leftPosition, rightPosition; leftPosition = setPosition; - rightPosition = new Position(setPosition.getX() + stonePosition, setPosition.getY()); - + rightPosition = new Position(setPosition.getX() + stonePosition, + setPosition.getY()); + drop(leftSet, leftPosition); drop(rightSet, rightPosition); } else { - Position newPosition = new Position(setPosition.getX() + 0.5f, setPosition.getY()); - + Position newPosition = new Position(setPosition.getX() + 0.5f, + setPosition.getY()); + if (leftSet == null) { drop(rightSet, newPosition); } else if (rightSet == null) { @@ -94,6 +96,8 @@ public class Table extends StoneTray implements ITable { drop(leftSet.join(rightSet), newPosition); } } + + return new Pair(leftSet, rightSet); } /** Tests the Table for rule conflicts by checking all the {@link StoneSet} */ -- cgit v1.2.3