summaryrefslogtreecommitdiffstats
path: root/src/jrummikub
diff options
context:
space:
mode:
authorJannis Harder <harder@informatik.uni-luebeck.de>2011-05-04 19:41:41 +0200
committerJannis Harder <harder@informatik.uni-luebeck.de>2011-05-04 19:41:41 +0200
commit7d7a5e1494efc574ce41558df789db261e086283 (patch)
treef973ddc77ac9525a94d2793d1148e98b359f2c03 /src/jrummikub
parentea37e2f0d26cdef4537d4792fadcab1dbc4ec337 (diff)
downloadJRummikub-7d7a5e1494efc574ce41558df789db261e086283.tar
JRummikub-7d7a5e1494efc574ce41558df789db261e086283.zip
Implemented finding of sets by stone
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@119 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub')
-rw-r--r--src/jrummikub/model/Table.java36
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);