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)
|
if (currentObject == object)
|
||||||
continue;
|
continue;
|
||||||
Position currentPosition = getPosition(currentObject);
|
Position currentPosition = getPosition(currentObject);
|
||||||
if (!objectsOverlap(object, position, currentObject, currentPosition)) {
|
if (!objectsOverlap(object, position, currentObject,
|
||||||
|
currentPosition)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Object would be placed inside the current object
|
// Object would be placed inside the current object
|
||||||
|
@ -82,6 +83,17 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
||||||
}
|
}
|
||||||
Position newPosition = null;
|
Position newPosition = null;
|
||||||
// Move object to avoid overlap
|
// 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) {
|
switch (newDirection) {
|
||||||
case TOP:
|
case TOP:
|
||||||
newPosition = new Position(currentPosition.getX(), position.getY()
|
newPosition = new Position(currentPosition.getX(), position.getY()
|
||||||
|
@ -92,23 +104,20 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
||||||
+ object.getHeight());
|
+ object.getHeight());
|
||||||
break;
|
break;
|
||||||
case LEFT:
|
case LEFT:
|
||||||
newPosition = new Position(position.getX() - currentObject.getWidth(),
|
newPosition = new Position(position.getX()
|
||||||
currentPosition.getY());
|
- currentObject.getWidth(), currentPosition.getY());
|
||||||
break;
|
break;
|
||||||
case RIGHT:
|
case RIGHT:
|
||||||
newPosition = new Position(position.getX() + object.getWidth(),
|
newPosition = new Position(position.getX() + object.getWidth(),
|
||||||
currentPosition.getY());
|
currentPosition.getY());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
return newPosition;
|
||||||
objects.remove(currentObject);
|
|
||||||
drop(currentObject, newPosition, newDirection);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the object may be placed on the given position, computes new
|
* Checks whether the object may be placed on the given position, computes
|
||||||
* position if not
|
* new position if not
|
||||||
*
|
*
|
||||||
* @param object
|
* @param object
|
||||||
* to be dropped
|
* 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
|
* Static method for determining a less or equal relation considering a
|
||||||
* fuzziness
|
* small fuzziness
|
||||||
*
|
*
|
||||||
* @param d
|
* @param d
|
||||||
* the value to be less or equal
|
* 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())) {
|
if (lessOrEqual(position1.getX() + object1.getWidth(), position2.getX())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (lessOrEqual(position1.getY() + object1.getHeight(), position2.getY())) {
|
if (lessOrEqual(position1.getY() + object1.getHeight(),
|
||||||
|
position2.getY())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (lessOrEqual(position2.getX() + object2.getWidth(), position1.getX())) {
|
if (lessOrEqual(position2.getX() + object2.getWidth(), position1.getX())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (lessOrEqual(position2.getY() + object2.getHeight(), position1.getY())) {
|
if (lessOrEqual(position2.getY() + object2.getHeight(),
|
||||||
|
position1.getY())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -230,13 +241,15 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
||||||
double blockingRight = blocking.getSecond().getX()
|
double blockingRight = blocking.getSecond().getX()
|
||||||
+ blocking.getFirst().getWidth();
|
+ blocking.getFirst().getWidth();
|
||||||
double overlapRight = Math.min(objectRight, blockingRight);
|
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 overlapX = overlapRight - overlapLeft;
|
||||||
double objectBottom = position.getY() + object.getHeight();
|
double objectBottom = position.getY() + object.getHeight();
|
||||||
double blockingBottom = blocking.getSecond().getY()
|
double blockingBottom = blocking.getSecond().getY()
|
||||||
+ blocking.getFirst().getHeight();
|
+ blocking.getFirst().getHeight();
|
||||||
double overlapBottom = Math.min(objectBottom, blockingBottom);
|
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;
|
double overlapY = overlapBottom - overlapTop;
|
||||||
return overlapX > overlapY;
|
return overlapX > overlapY;
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,18 +136,7 @@ class WinPanel extends JPanel {
|
||||||
fontSize = MAX_BUTTON_FONT_SIZE;
|
fontSize = MAX_BUTTON_FONT_SIZE;
|
||||||
|
|
||||||
if (type == BottomPanelType.WIN_PANEL) {
|
if (type == BottomPanelType.WIN_PANEL) {
|
||||||
waitingLabel.setVisible(false);
|
rescaleWinPanel(x, buttonWidth, buttonHeight, buttonY, fontSize);
|
||||||
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));
|
|
||||||
} else if (type == BottomPanelType.NETWORK_WIN_PANEL) {
|
} else if (type == BottomPanelType.NETWORK_WIN_PANEL) {
|
||||||
waitingLabel.setBounds(x, y, width, labelHeight);
|
waitingLabel.setBounds(x, y, width, labelHeight);
|
||||||
waitingLabel.setVisible(true);
|
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) {
|
void setType(BottomPanelType type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
rescale();
|
rescale();
|
||||||
|
|
Reference in a new issue