summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/model
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/model')
-rw-r--r--src/jrummikub/model/GameState.java2
-rw-r--r--src/jrummikub/model/IStoneTray.java9
-rw-r--r--src/jrummikub/model/StoneHeap.java2
-rw-r--r--src/jrummikub/model/StoneTray.java56
4 files changed, 19 insertions, 50 deletions
diff --git a/src/jrummikub/model/GameState.java b/src/jrummikub/model/GameState.java
index 69c5570..5861a32 100644
--- a/src/jrummikub/model/GameState.java
+++ b/src/jrummikub/model/GameState.java
@@ -12,7 +12,7 @@ public class GameState implements IGameState {
private StoneHeap gameHeap;
/**
- * Create a new GameState with an empty table and (currntly) 4 new players.
+ * Create a new GameState with an empty table and (currently) 4 new players.
*/
public GameState() {
table = new Table();
diff --git a/src/jrummikub/model/IStoneTray.java b/src/jrummikub/model/IStoneTray.java
index c1ed05d..f9c9d88 100644
--- a/src/jrummikub/model/IStoneTray.java
+++ b/src/jrummikub/model/IStoneTray.java
@@ -12,15 +12,6 @@ public interface IStoneTray<E extends Sizeable> extends
Iterable<Pair<E, Position>>, Cloneable {
/**
- * Removes object from tray and returns it
- *
- * @param position
- * position of the object that will be removed
- * @return the picked up stone
- */
- public E pickUp(Position position);
-
- /**
* Adds object to the tray
*
* @param object
diff --git a/src/jrummikub/model/StoneHeap.java b/src/jrummikub/model/StoneHeap.java
index d9d754f..c013570 100644
--- a/src/jrummikub/model/StoneHeap.java
+++ b/src/jrummikub/model/StoneHeap.java
@@ -13,7 +13,7 @@ import java.util.Random;
public class StoneHeap {
List<Stone> heap;
- Random generator = new Random();
+ private Random generator = new Random();
/** Creates 106 Stones according to standard rules */
public StoneHeap() {
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 <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>>();
@@ -23,31 +23,6 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
}
@Override
- public E pickUp(Position position) {
- for (Map.Entry<E, Pair<E, Position>> 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) {
drop(object, position, null);
@@ -75,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
@@ -86,16 +62,16 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
// 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<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 p
- * 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,
@@ -173,13 +149,15 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
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