From 7d7a5e1494efc574ce41558df789db261e086283 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Wed, 4 May 2011 19:41:41 +0200 Subject: Implemented finding of sets by stone git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@119 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/model/Table.java | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'src/jrummikub/model') 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 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 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 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); -- cgit v1.2.3