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
This commit is contained in:
parent
b7da5ad631
commit
9861417ac1
2 changed files with 78 additions and 60 deletions
|
@ -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,6 +83,17 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
|||
}
|
||||
Position newPosition = null;
|
||||
// Move object to avoid overlap
|
||||
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()
|
||||
|
@ -92,23 +104,20 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
|||
+ 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(),
|
||||
currentPosition.getY());
|
||||
break;
|
||||
}
|
||||
|
||||
objects.remove(currentObject);
|
||||
drop(currentObject, newPosition, newDirection);
|
||||
}
|
||||
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
|
||||
|
@ -123,8 +132,8 @@ 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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Reference in a new issue