summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/model
diff options
context:
space:
mode:
authorIda Massow <massow@informatik.uni-luebeck.de>2011-05-31 22:06:23 +0200
committerIda Massow <massow@informatik.uni-luebeck.de>2011-05-31 22:06:23 +0200
commit63192810a3fe4ec2c81b5b52dd0278d145324bfb (patch)
tree414c338e86bb4c31696293535a4ce80c3b7f404e /src/jrummikub/model
parentd7aba3d722fbc4dacc94207e97098fd8e27933b4 (diff)
downloadJRummikub-63192810a3fe4ec2c81b5b52dd0278d145324bfb.tar
JRummikub-63192810a3fe4ec2c81b5b52dd0278d145324bfb.zip
kleine fixes
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@364 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/model')
-rw-r--r--src/jrummikub/model/StoneSet.java2
-rw-r--r--src/jrummikub/model/StoneTray.java65
2 files changed, 38 insertions, 29 deletions
diff --git a/src/jrummikub/model/StoneSet.java b/src/jrummikub/model/StoneSet.java
index 39fb158..0d53b52 100644
--- a/src/jrummikub/model/StoneSet.java
+++ b/src/jrummikub/model/StoneSet.java
@@ -208,7 +208,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
*
* @return number of stones
*/
- public int size() {
+ public int getSize() {
return stones.size();
}
diff --git a/src/jrummikub/model/StoneTray.java b/src/jrummikub/model/StoneTray.java
index 60b8cc3..c4230f2 100644
--- a/src/jrummikub/model/StoneTray.java
+++ b/src/jrummikub/model/StoneTray.java
@@ -11,7 +11,7 @@ import jrummikub.util.Pair;
* or {@link StoneSet}s.
*
* @param <E>
- * Type of positioned objects (must implement Sizeable)
+ * Type of positioned objects (must implement Sizeable)
*/
public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
protected HashMap<E, Pair<E, Position>> objects = new HashMap<E, Pair<E, Position>>();
@@ -50,7 +50,8 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
if (currentObject == object)
continue;
Position currentPosition = getPosition(currentObject);
- if (!objectsOverlap(object, position, currentObject, currentPosition)) {
+ if (!objectsOverlap(object, position, currentObject,
+ currentPosition)) {
continue;
}
// Object would be placed inside the current object
@@ -60,23 +61,22 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
Position newPosition = null;
// Move object to avoid overlap
switch (newDirection) {
- case TOP:
- newPosition = new Position(currentPosition.getX(), position.getY()
- - currentObject.getHeight());
- break;
- case BOTTOM:
- newPosition = new Position(currentPosition.getX(), position.getY()
- + object.getHeight());
- break;
- case LEFT:
- newPosition = new Position(
- position.getX() - currentObject.getWidth(),
- currentPosition.getY());
- break;
- case RIGHT:
- newPosition = new Position(position.getX() + object.getWidth(),
- currentPosition.getY());
- break;
+ case TOP:
+ newPosition = new Position(currentPosition.getX(),
+ position.getY() - currentObject.getHeight());
+ break;
+ case BOTTOM:
+ newPosition = new Position(currentPosition.getX(),
+ position.getY() + object.getHeight());
+ break;
+ case LEFT:
+ newPosition = new Position(position.getX()
+ - currentObject.getWidth(), currentPosition.getY());
+ break;
+ case RIGHT:
+ newPosition = new Position(position.getX() + object.getWidth(),
+ currentPosition.getY());
+ break;
}
objects.remove(currentObject);
@@ -85,14 +85,14 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
}
/**
- * Checks whether the object may be placed on the given position, computes new
- * position if not
+ * Checks whether the object may be placed on the given position, computes
+ * new position if not
*
* @param object
- * to be dropped
+ * to be dropped
* @param dir
* @param pos
- * the object is dropped at
+ * the object is dropped at
* @return null if the drop is valid, new position otherwise
*/
protected Pair<Position, Direction> fixInvalidDrop(E object, Position pos,
@@ -100,7 +100,7 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
return null;
}
- private boolean lessOrEqual(float x, float y) {
+ private static boolean lessOrEqual(float x, float y) {
if (-0.000001f < y && y < 0.000001f) {
return (x < y + 0.000001f);
}
@@ -120,13 +120,15 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
if (lessOrEqual(position1.getX() + object1.getWidth(), position2.getX())) {
return false;
}
- if (lessOrEqual(position1.getY() + object1.getHeight(), position2.getY())) {
+ if (lessOrEqual(position1.getY() + object1.getHeight(),
+ position2.getY())) {
return false;
}
if (lessOrEqual(position2.getX() + object2.getWidth(), position1.getX())) {
return false;
}
- if (lessOrEqual(position2.getY() + object2.getHeight(), position1.getY())) {
+ if (lessOrEqual(position2.getY() + object2.getHeight(),
+ position1.getY())) {
return false;
}
return true;
@@ -156,19 +158,26 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
}
}
+ /**
+ * Will the object be moved horizontally or vertically
+ *
+ * @return boolean vertical movement
+ */
private boolean getMoveOrientation(E object, Position position,
Pair<E, Position> blocking) {
float objectRight = position.getX() + object.getWidth();
float blockingRight = blocking.getSecond().getX()
+ blocking.getFirst().getWidth();
float overlapRight = Math.min(objectRight, blockingRight);
- float overlapLeft = Math.max(position.getX(), blocking.getSecond().getX());
+ float overlapLeft = Math.max(position.getX(), blocking.getSecond()
+ .getX());
float overlapX = overlapRight - overlapLeft;
float objectBottom = position.getY() + object.getHeight();
float blockingBottom = blocking.getSecond().getY()
+ blocking.getFirst().getHeight();
float overlapBottom = Math.min(objectBottom, blockingBottom);
- float overlapTop = Math.max(position.getY(), blocking.getSecond().getY());
+ float overlapTop = Math.max(position.getY(), blocking.getSecond()
+ .getY());
float overlapY = overlapBottom - overlapTop;
// vertical or horizontal Shift
// TODO magic factor