diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/jrummikub/model/Table.java | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/src/jrummikub/model/Table.java b/src/jrummikub/model/Table.java index 232986f..71ce27c 100644 --- a/src/jrummikub/model/Table.java +++ b/src/jrummikub/model/Table.java @@ -6,6 +6,17 @@ import jrummikub.util.Pair; public class Table extends StoneTray<StoneSet> implements ITable { + private static class StoneInfo { + 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 * @@ -14,7 +25,14 @@ public class Table extends StoneTray<StoneSet> implements ITable { */ @Override public void pickUpStone(Stone stone) { + StoneInfo info = findStoneInfo(stone); + + splitSet(info.set, info.setPosition, info.stonePosition); + } + + private StoneInfo findStoneInfo(Stone stone) { // Find the set of the stone + StoneInfo info; StoneSet set = null; Position setPosition = null; int stonePosition = 0; @@ -31,11 +49,23 @@ public class Table extends StoneTray<StoneSet> implements ITable { } // Stone not found if (set == null) { - return; + info = null; + } else { + info = new StoneInfo(set, setPosition, stonePosition); } - - splitSet(set, setPosition, stonePosition); + return info; + } + + @Override + public StoneSet findStoneSet(Stone stone) { + StoneInfo info = findStoneInfo(stone); + if (info == null) { + return null; + } + return info.set; } + + private void splitSet(StoneSet set, Position setPosition, int stonePosition) { pickUp(set); |