diff options
author | Ida Massow <massow@informatik.uni-luebeck.de> | 2011-06-22 00:12:07 +0200 |
---|---|---|
committer | Ida Massow <massow@informatik.uni-luebeck.de> | 2011-06-22 00:12:07 +0200 |
commit | 9861417ac10271103d74abeb591518ec2a50b43a (patch) | |
tree | 015e2df54e96b6f68397b4eda518ca565a84deab | |
parent | b7da5ad6313ae17dee738593ab3482c56675b61a (diff) | |
download | JRummikub-9861417ac10271103d74abeb591518ec2a50b43a.tar JRummikub-9861417ac10271103d74abeb591518ec2a50b43a.zip |
ALLES was muss und da ist ist kommentiert
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@561 72836036-5685-4462-b002-a69064685172
-rw-r--r-- | src/jrummikub/model/StoneTray.java | 109 | ||||
-rw-r--r-- | src/jrummikub/view/impl/WinPanel.java | 29 |
2 files changed, 78 insertions, 60 deletions
diff --git a/src/jrummikub/model/StoneTray.java b/src/jrummikub/model/StoneTray.java index f2f1151..8681c75 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> { private static final long serialVersionUID = -6329309928640027222L; @@ -36,11 +36,11 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> { * dropped one collides with position-wise evade in * * @param object - * the object to add to Hand + * the object to add to Hand * @param position - * {@link Position} to put the object + * {@link Position} to put the object * @param direction - * the direction the other stones evade in + * the direction the other stones evade in */ private void drop(E object, Position position, Direction direction) { Pair<Position, Direction> update = fixInvalidDrop(object, position, @@ -57,11 +57,11 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> { * Subroutine to "drop" to execute the actual drop * * @param object - * the object to add to Hand + * the object to add to Hand * @param position - * {@link Position} to put the object + * {@link Position} to put the object * @param direction - * the direction the other stones evade in + * the direction the other stones evade in */ @SuppressWarnings("unchecked") private void dropUnchecked(E object, Position position, Direction direction) { @@ -73,7 +73,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 @@ -82,39 +83,47 @@ 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; - } + newPosition = getNewPosition(object, position, newDirection, + currentObject, currentPosition); objects.remove(currentObject); drop(currentObject, newPosition, newDirection); } } + private Position getNewPosition(E object, Position position, + Direction newDirection, E currentObject, Position currentPosition) { + Position newPosition = new Position(0, 0); + 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; + } + return newPosition; + } + /** - * 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, @@ -123,13 +132,13 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> { } /** - * Static method for determining a less or equal relation considering a small - * fuzziness + * Static method for determining a less or equal relation considering a + * small fuzziness * * @param d - * the value to be less or equal + * the value to be less or equal * @param e - * than the other one + * than the other one * @return if d is less or equal e */ private static boolean lessOrEqual(double d, double e) { @@ -149,13 +158,13 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> { * Tests whether two objects overlap * * @param object1 - * first object + * first object * @param position1 - * first object's position + * first object's position * @param object2 - * second object + * second object * @param position2 - * second object's position + * second object's position * * @return whether they overlap **/ @@ -165,13 +174,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; @@ -181,11 +192,11 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> { * Returns the direction to move the object in * * @param object - * the object + * the object * @param position - * the object's position + * the object's position * @param blocking - * the object thats blocking + * the object thats blocking * @return the direction */ private Direction getMoveDirection(E object, Position position, @@ -216,11 +227,11 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> { * Will the object be moved horizontally or vertically * * @param object - * the object + * the object * @param position - * the objects position + * the objects position * @param blocking - * the object thats blocking + * the object thats blocking * * @return boolean vertical movement */ @@ -230,13 +241,15 @@ 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; return overlapX > overlapY; } diff --git a/src/jrummikub/view/impl/WinPanel.java b/src/jrummikub/view/impl/WinPanel.java index d274b19..4d9aacc 100644 --- a/src/jrummikub/view/impl/WinPanel.java +++ b/src/jrummikub/view/impl/WinPanel.java @@ -136,18 +136,7 @@ class WinPanel extends JPanel { fontSize = MAX_BUTTON_FONT_SIZE; if (type == BottomPanelType.WIN_PANEL) { - waitingLabel.setVisible(false); - newRoundButton.setBounds(x, buttonY, buttonWidth, buttonHeight); - newRoundButton.setFont(newRoundButton.getFont().deriveFont(fontSize)); - newRoundButton.setVisible(true); - - newGameButton.setBounds(x + buttonWidth + PANEL_SEPARATOR, buttonY, - buttonWidth, buttonHeight); - newGameButton.setFont(newGameButton.getFont().deriveFont(fontSize)); - - endProgramButton.setBounds(x + 2 * (buttonWidth + PANEL_SEPARATOR), - buttonY, buttonWidth, buttonHeight); - endProgramButton.setFont(endProgramButton.getFont().deriveFont(fontSize)); + rescaleWinPanel(x, buttonWidth, buttonHeight, buttonY, fontSize); } else if (type == BottomPanelType.NETWORK_WIN_PANEL) { waitingLabel.setBounds(x, y, width, labelHeight); waitingLabel.setVisible(true); @@ -163,6 +152,22 @@ class WinPanel extends JPanel { } } + private void rescaleWinPanel(int x, int buttonWidth, int buttonHeight, + int buttonY, float fontSize) { + waitingLabel.setVisible(false); + newRoundButton.setBounds(x, buttonY, buttonWidth, buttonHeight); + newRoundButton.setFont(newRoundButton.getFont().deriveFont(fontSize)); + newRoundButton.setVisible(true); + + newGameButton.setBounds(x + buttonWidth + PANEL_SEPARATOR, buttonY, + buttonWidth, buttonHeight); + newGameButton.setFont(newGameButton.getFont().deriveFont(fontSize)); + + endProgramButton.setBounds(x + 2 * (buttonWidth + PANEL_SEPARATOR), + buttonY, buttonWidth, buttonHeight); + endProgramButton.setFont(endProgramButton.getFont().deriveFont(fontSize)); + } + void setType(BottomPanelType type) { this.type = type; rescale(); |