diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-06-08 21:58:16 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-06-08 21:58:16 +0200 |
commit | 45d5b3ae10ed8cfbecb5489636093c6fb0576970 (patch) | |
tree | 1aa1c012f46fe204d997e8c6896940800f5461bb /src/jrummikub/model | |
parent | 2e376414b941da3c6fa3c20ddad085c695175542 (diff) | |
download | JRummikub-45d5b3ae10ed8cfbecb5489636093c6fb0576970.tar JRummikub-45d5b3ae10ed8cfbecb5489636093c6fb0576970.zip |
Implement pause function
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@390 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/model')
-rw-r--r-- | src/jrummikub/model/IPlayer.java | 5 | ||||
-rw-r--r-- | src/jrummikub/model/IStoneTray.java | 10 | ||||
-rw-r--r-- | src/jrummikub/model/StoneHeap.java | 2 | ||||
-rw-r--r-- | src/jrummikub/model/StoneSet.java | 35 | ||||
-rw-r--r-- | src/jrummikub/model/StoneTray.java | 60 |
5 files changed, 52 insertions, 60 deletions
diff --git a/src/jrummikub/model/IPlayer.java b/src/jrummikub/model/IPlayer.java index 25471b8..9df3741 100644 --- a/src/jrummikub/model/IPlayer.java +++ b/src/jrummikub/model/IPlayer.java @@ -17,7 +17,8 @@ public interface IPlayer extends Serializable { /** * Set the current hand of the player * - * @param hand the new hand + * @param hand + * the new hand */ public void setHand(IHand hand); @@ -39,7 +40,7 @@ public interface IPlayer extends Serializable { * Set if the player laid out * * @param laidOut - * the player laid out + * the player laid out * */ void setLaidOut(boolean laidOut); diff --git a/src/jrummikub/model/IStoneTray.java b/src/jrummikub/model/IStoneTray.java index d286484..d411c9e 100644 --- a/src/jrummikub/model/IStoneTray.java +++ b/src/jrummikub/model/IStoneTray.java @@ -8,7 +8,7 @@ import jrummikub.util.Pair; * Interface for the {@link StoneTray} model
*
* @param <E>
- * Objects held by the IStoneTray
+ * Objects held by the IStoneTray
*/
public interface IStoneTray<E extends Sizeable> extends
Iterable<Pair<E, Position>>, Cloneable, Serializable {
@@ -17,9 +17,9 @@ public interface IStoneTray<E extends Sizeable> extends * Adds object to the tray
*
* @param object
- * object to add to Hand
+ * object to add to Hand
* @param position
- * {@link Position} to put the object
+ * {@link Position} to put the object
*/
public void drop(E object, Position position);
@@ -27,7 +27,7 @@ public interface IStoneTray<E extends Sizeable> extends * Returns the position of an object that is already on the tray
*
* @param object
- * object whose position is requested
+ * object whose position is requested
* @return position of the object or null when the object is not on the tray
*/
public Position getPosition(E object);
@@ -36,7 +36,7 @@ public interface IStoneTray<E extends Sizeable> extends * Tries to pick up (remove) a given object
*
* @param object
- * object to pick up
+ * object to pick up
* @return true when the object was successfully removed
*/
public boolean pickUp(E object);
diff --git a/src/jrummikub/model/StoneHeap.java b/src/jrummikub/model/StoneHeap.java index d49bede..2f08767 100644 --- a/src/jrummikub/model/StoneHeap.java +++ b/src/jrummikub/model/StoneHeap.java @@ -14,7 +14,7 @@ import java.util.Random; public class StoneHeap implements Serializable { private static final long serialVersionUID = -5247740086907775125L; - + ArrayList<Stone> heap; private Random generator = new Random(); diff --git a/src/jrummikub/model/StoneSet.java b/src/jrummikub/model/StoneSet.java index 1bb0823..5412a3a 100644 --- a/src/jrummikub/model/StoneSet.java +++ b/src/jrummikub/model/StoneSet.java @@ -14,7 +14,7 @@ import static jrummikub.model.StoneSet.Type.*; /** Class managing {@link Stone}s joined together to form sets */ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable { private static final long serialVersionUID = -3852631195648599398L; - + static final float VERTICAL_BORDER = 0.5f; static final float HORIZONTAL_BORDER = 0.125f; private ArrayList<Stone> stones; @@ -23,7 +23,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable { * Create a new single stone stone set * * @param stone - * single stone of the set + * single stone of the set */ public StoneSet(Stone stone) { stones = new ArrayList<Stone>(Collections.singletonList(stone)); @@ -33,7 +33,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable { * Create a stone set from a list of stones * * @param stones - * list of stones to build a set of + * list of stones to build a set of */ public StoneSet(List<Stone> stones) { this.stones = new ArrayList<Stone>(stones); @@ -53,7 +53,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable { * Test for rule conflict within the StoneSet * * @param settings - * GameSettings + * GameSettings * * @return true when the set is valid according to the rules */ @@ -62,11 +62,11 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable { } /** - * Test for rule conflict within the StoneSet and determine whether the set - * is a group or a run + * Test for rule conflict within the StoneSet and determine whether the set is + * a group or a run * * @param settings - * GameSettings + * GameSettings * * @return GROUP or RUN for valid sets, INVALID otherwise */ @@ -87,14 +87,10 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable { if (stones.size() > settings.getHighestValue()) { return new Pair<Type, Integer>(INVALID, 0); } else if (stones.size() > settings.getStoneColors().size()) { - return new Pair<Type, Integer>( - RUN, - (settings.getHighestValue() * (settings - .getHighestValue() + 1)) - / 2 + return new Pair<Type, Integer>(RUN, + (settings.getHighestValue() * (settings.getHighestValue() + 1)) / 2 - (stones.size() - settings.getHighestValue()) - * (stones.size() - settings.getHighestValue() - 1) - / 2); + * (stones.size() - settings.getHighestValue() - 1) / 2); } else { return new Pair<Type, Integer>(GROUP, stones.size() * settings.getHighestValue()); @@ -117,7 +113,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable { * Test for rule conflict within the StoneSet, assuming we have a run * * @param referencePosition - * position of stone used as reference (any non-joker stone) + * position of stone used as reference (any non-joker stone) * @param settings */ private int isValidRun(int referencePosition, GameSettings settings) { @@ -177,7 +173,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable { * Stone Sets * * @param position - * Splitting {@link Position} + * Splitting {@link Position} * @return A pair of StoneSets, one for each split part */ public Pair<StoneSet, StoneSet> splitAt(int position) { @@ -187,8 +183,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable { return new Pair<StoneSet, StoneSet>(this, null); } StoneSet firstSet = new StoneSet(stones.subList(0, position)); - StoneSet secondSet = new StoneSet(stones.subList(position, - stones.size())); + StoneSet secondSet = new StoneSet(stones.subList(position, stones.size())); return new Pair<StoneSet, StoneSet>(firstSet, secondSet); } @@ -196,7 +191,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable { * Joins StoneSet to another StoneSet and returns the resulting new StoneSet * * @param other - * StoneSet to be joined to active StoneSet + * StoneSet to be joined to active StoneSet * @return the combined StoneSet */ public StoneSet join(StoneSet other) { @@ -219,7 +214,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable { * Returns the i-th stone of the set (starting with 0) * * @param i - * number of the stone to return + * number of the stone to return * @return the i-th stone */ public Stone get(int i) { diff --git a/src/jrummikub/model/StoneTray.java b/src/jrummikub/model/StoneTray.java index 8806b1c..aaedaad 100644 --- a/src/jrummikub/model/StoneTray.java +++ b/src/jrummikub/model/StoneTray.java @@ -11,11 +11,11 @@ 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> { private static final long serialVersionUID = -6329309928640027222L; - + protected HashMap<E, Pair<E, Position>> objects = new HashMap<E, Pair<E, Position>>(); /** Possible move directions in case of overlapping Stones/Sets */ @@ -52,8 +52,7 @@ 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 @@ -63,22 +62,23 @@ 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); @@ -87,14 +87,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, @@ -122,15 +122,13 @@ 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; @@ -171,15 +169,13 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> { double blockingRight = blocking.getSecond().getX() + blocking.getFirst().getWidth(); double overlapRight = Math.min(objectRight, blockingRight); - double overlapLeft = Math.max(position.getX(), blocking.getSecond() - .getX()); + double overlapLeft = Math.max(position.getX(), blocking.getSecond().getX()); double overlapX = overlapRight - overlapLeft; double objectBottom = position.getY() + object.getHeight(); double blockingBottom = blocking.getSecond().getY() + blocking.getFirst().getHeight(); double overlapBottom = Math.min(objectBottom, blockingBottom); - double overlapTop = Math.max(position.getY(), blocking.getSecond() - .getY()); + double overlapTop = Math.max(position.getY(), blocking.getSecond().getY()); double overlapY = overlapBottom - overlapTop; // vertical or horizontal Shift // TODO magic factor |