summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/model/StoneTray.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/model/StoneTray.java')
-rw-r--r--src/jrummikub/model/StoneTray.java27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/jrummikub/model/StoneTray.java b/src/jrummikub/model/StoneTray.java
index 52079d0..8b83371 100644
--- a/src/jrummikub/model/StoneTray.java
+++ b/src/jrummikub/model/StoneTray.java
@@ -18,8 +18,22 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
/** Possible move directions in case of overlapping Stones/Sets */
- private static enum Direction {
+ protected static enum Direction {
LEFT, RIGHT, TOP, BOTTOM;
+
+ public Direction reverse() {
+ switch (this) {
+ case LEFT:
+ return RIGHT;
+ case RIGHT:
+ return LEFT;
+ case TOP:
+ return BOTTOM;
+ case BOTTOM:
+ return TOP;
+ }
+ return null;
+ }
}
@Override
@@ -56,6 +70,13 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
@SuppressWarnings("unchecked")
private void drop(E object, Position position, Direction direction) {
+ Pair<Position, Direction> update = fixInvalidDrop(object, position,
+ direction);
+ if (update != null) {
+ position = update.getFirst();
+ direction = update.getSecond();
+ }
+
objects.put(object, new Pair<E, Position>(object, position));
for (Pair<E, Position> i : ((Map<E, Pair<E, Position>>) objects.clone())
.values()) {
@@ -103,11 +124,13 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
*
* @param object
* to be dropped
+ * @param dir
* @param p
* the object is dropped at
* @return null if the drop is valid, new position otherwise
*/
- protected Position fixInvalidDrop(E object, Position pos) {
+ protected Pair<Position, Direction> fixInvalidDrop(E object, Position pos,
+ Direction dir) {
return null;
}