From 982c2e6e2baf20eace331c19f6aef91b29e3c773 Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Tue, 10 May 2011 16:31:09 +0200 Subject: =?UTF-8?q?Rechtschreibfehler=20und=20=C3=BCberfl=C3=BCssige=20pic?= =?UTF-8?q?kUp(position)=20Klasse=20gefixt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@227 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/model/StoneTray.java | 56 ++++++++++++-------------------------- 1 file changed, 17 insertions(+), 39 deletions(-) (limited to 'src/jrummikub/model/StoneTray.java') diff --git a/src/jrummikub/model/StoneTray.java b/src/jrummikub/model/StoneTray.java index b9902e8..66b0be3 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 - * Type of positioned objects (must implement Sizeable) + * Type of positioned objects (must implement Sizeable) */ public class StoneTray implements IStoneTray { protected HashMap> objects = new HashMap>(); @@ -22,31 +22,6 @@ public class StoneTray implements IStoneTray { LEFT, RIGHT, TOP, BOTTOM; } - @Override - public E pickUp(Position position) { - for (Map.Entry> i : objects.entrySet()) { - Position currentPosition = i.getValue().getSecond(); - E currentObject = i.getKey(); - // Tests if position is left of, above ... the current object - if (position.getX() < currentPosition.getX()) { - continue; - } - if (position.getY() < currentPosition.getY()) { - continue; - } - if (position.getX() > currentPosition.getX() + currentObject.getWidth()) { - continue; - } - if (position.getY() > currentPosition.getY() + currentObject.getHeight()) { - continue; - } - // Position is inside the current object - objects.remove(i.getKey()); - return currentObject; - } - return null; - } - @Override public void drop(E object, Position position) { if (object != null) { @@ -75,7 +50,8 @@ public class StoneTray implements IStoneTray { 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 @@ -86,16 +62,16 @@ public class StoneTray implements IStoneTray { // Move object to avoid overlap switch (newDirection) { case TOP: - newPosition = new Position(currentPosition.getX(), position.getY() - - currentObject.getHeight()); + newPosition = new Position(currentPosition.getX(), + position.getY() - currentObject.getHeight()); break; case BOTTOM: - newPosition = new Position(currentPosition.getX(), position.getY() - + object.getHeight()); + newPosition = new Position(currentPosition.getX(), + position.getY() + object.getHeight()); break; case LEFT: - newPosition = new Position(position.getX() - currentObject.getWidth(), - currentPosition.getY()); + newPosition = new Position(position.getX() + - currentObject.getWidth(), currentPosition.getY()); break; case RIGHT: newPosition = new Position(position.getX() + object.getWidth(), @@ -109,14 +85,14 @@ public class StoneTray implements IStoneTray { } /** - * 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 p - * the object is dropped at + * the object is dropped at * @return null if the drop is valid, new position otherwise */ protected Pair fixInvalidDrop(E object, Position pos, @@ -173,13 +149,15 @@ public class StoneTray implements IStoneTray { 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 -- cgit v1.2.3