Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/bugfix/#52-javadoc-coverage' int…
Browse files Browse the repository at this point in the history
…o bugfix/#52-javadoc-coverage
  • Loading branch information
DorianRec committed Jan 13, 2020
2 parents 0c2b79b + be89491 commit 572a1cc
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 154 deletions.
71 changes: 36 additions & 35 deletions src/main/java/com/treasure/hunt/game/GameEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
*/
@Requires(hider = Hider.class, searcher = Searcher.class)
public class GameEngine {
@Getter
private final Statistic statistics = new Statistic();
protected final Searcher searcher;
protected final Hider hider;
protected final Coordinate initialSearcherCoordinate;
Expand All @@ -45,6 +43,9 @@ public class GameEngine {
protected Point searcherPos;
protected Point treasurePos;

@Getter
private final Statistic statistics = new Statistic();

/**
* The constructor.
*
Expand All @@ -68,39 +69,6 @@ public GameEngine(Searcher searcher, Hider hider, Coordinate initialSearcherCoor
this.initialSearcherCoordinate = initialSearcherCoordinate;
}

/**
* @param geometryItemsList searcher path
* @param treasurePosition the position of the treasure
* @return {@code true} if the searcher located the treasure successfully. {@code false}, otherwise.
*/
protected static boolean located(List<GeometryItem<Point>> geometryItemsList, Point treasurePosition) {
assert geometryItemsList.size() > 0;

// Did the searcher move ?
if (geometryItemsList.size() == 1) {
return geometryItemsList.get(0).getObject().distance(treasurePosition) <= 1;
} else {
Point lastPoint = null;
Point point;
for (GeometryItem<Point> geometryItem : geometryItemsList) {
point = geometryItem.getObject();
if (lastPoint == null) {
lastPoint = point;
} else {
// Check the gap of each move-segment and treasurePos
LineSegment lineSegment = new LineSegment(new Coordinate(lastPoint.getX(), lastPoint.getY()),
new Coordinate(point.getX(), point.getY()));
// Usage of distancePerpendicular is completely incorrect here, since the line will be infinite
if (lineSegment.distance(new Coordinate(treasurePosition.getX(), treasurePosition.getY())) <= 1) {
return true;
}
lastPoint = point;
}
}
}
return false;
}

/**
* initialize searcher and treasure positions.
*
Expand Down Expand Up @@ -178,6 +146,39 @@ protected void searcherMove() {
searcherPos = lastMovement.getEndPoint();
}

/**
* @param geometryItemsList searcher path
* @param treasurePosition the position of the treasure
* @return {@code true}, if the searcher located the treasure successfully. {@code false}, otherwise.
*/
protected static boolean located(List<GeometryItem<Point>> geometryItemsList, Point treasurePosition) {
assert geometryItemsList.size() > 0;

// Did the searcher move ?
if (geometryItemsList.size() == 1) {
return geometryItemsList.get(0).getObject().distance(treasurePosition) <= 1;
} else {
Point lastPoint = null;
Point point;
for (GeometryItem<Point> geometryItem : geometryItemsList) {
point = geometryItem.getObject();
if (lastPoint == null) {
lastPoint = point;
} else {
// Check the gap of each move-segment and treasurePos
LineSegment lineSegment = new LineSegment(new Coordinate(lastPoint.getX(), lastPoint.getY()),
new Coordinate(point.getX(), point.getY()));
// Usage of distancePerpendicular is completely incorrect here, since the line will be infinite
if (lineSegment.distance(new Coordinate(treasurePosition.getX(), treasurePosition.getY())) <= 1) {
return true;
}
lastPoint = point;
}
}
}
return false;
}

/**
* Verifies whether the performed {@link Movement} {@code movement} by the {@link Searcher} followed the rules.
*
Expand Down
34 changes: 16 additions & 18 deletions src/main/java/com/treasure/hunt/io/FileService.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,6 @@ public void load(Label logLabel) {
});
}

private boolean askUserWhetherToLoadWrongVersion(String oldVersion) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Proceed loading wrong version");
alert.setHeaderText("The file was record with a different version than your program is running. Loading it might cause unexpected behaviour.");
alert.setContentText("Version of file was " + (oldVersion == null ? "development" : oldVersion));

Optional<ButtonType> option = alert.showAndWait();

ButtonType buttonType = option.get();
if (buttonType == ButtonType.OK) {
return true;
} else if (buttonType == ButtonType.CANCEL) {
return false;
} else {
return false;
}
}

public void save(Label logLabel, GameManager gameManager) {
if (gameManager == null) {
logLabel.setText("No game manager to save");
Expand Down Expand Up @@ -140,5 +122,21 @@ public static class GameManagerWithVersion {
GameManager gameManager;
}

private boolean askUserWhetherToLoadWrongVersion(String oldVersion) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Proceed loading wrong version");
alert.setHeaderText("The file was record with a different version than your program is running. Loading it might cause unexpected behaviour.");
alert.setContentText("Version of file was " + (oldVersion == null ? "development" : oldVersion));

Optional<ButtonType> option = alert.showAndWait();

ButtonType buttonType = option.get();
if (buttonType == ButtonType.OK) {
return true;
} else if (buttonType == ButtonType.CANCEL) {
return false;
} else {
return false;
}
}
}
39 changes: 19 additions & 20 deletions src/main/java/com/treasure/hunt/jts/awt/PointTransformation.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public class PointTransformation implements org.locationtech.jts.awt.PointTransf
* The scale translates the source coordinates multiplicative in {@link PointTransformation#transform(Coordinate)}.
*/
@Getter
DoubleProperty scaleProperty = new SimpleDoubleProperty(1);
private DoubleProperty scaleProperty = new SimpleDoubleProperty(1);
/**
* The offset translates the source coordinates additive in {@link PointTransformation#transform(Coordinate)}.
*/
@Getter
ObjectProperty<Vector2D> offsetProperty = new SimpleObjectProperty<>(new Vector2D(400, 400));
private ObjectProperty<Vector2D> offsetProperty = new SimpleObjectProperty<>(new Vector2D(400, 400));

@Setter
@Getter
Expand Down Expand Up @@ -78,15 +78,6 @@ public Coordinate transform(Coordinate src) {
return new Coordinate(scaleProperty.get() * src.x + offsetProperty.get().getX(), scaleProperty.get() * -src.y + offsetProperty.get().getY());
}

/**
* Method to retrieve the Vector from the upper left boundary point to the lower right boundary point.
*
* @return vector from upper left to lower right boundary point
*/
private Vector2D getMainDiagonalVector() {
return getUpperLeftBoundary().subtract(getLowerRightBoundary());
}

/**
* Get the length of the diagonal of the boundary rectangle
*
Expand Down Expand Up @@ -143,15 +134,6 @@ public void setBoundarySize(double width, double height) {
setBoundarySize(new Vector2D(width, height));
}

/**
* Set the offset based on the boundary representation.
*
* @param location upper left position vector of the boundary rectangle
*/
private void setBoundaryLocation(Vector2D location) {
setOffset(JTSUtils.negateX(location).multiply(scaleProperty.get()));
}

/**
* Get the boundary rectangle width.
*
Expand Down Expand Up @@ -198,4 +180,21 @@ public void scaleOffset(double gamma, Vector2D point) {
setOffset(point.add(direction.multiply(newScale / scaleProperty.get())));
}

/**
* Method to retrieve the Vector from the upper left boundary point to the lower right boundary point.
*
* @return vector from upper left to lower right boundary point
*/
private Vector2D getMainDiagonalVector() {
return getUpperLeftBoundary().subtract(getLowerRightBoundary());
}

/**
* Set the offset based on the boundary representation.
*
* @param location upper left position vector of the boundary rectangle
*/
private void setBoundaryLocation(Vector2D location) {
setOffset(JTSUtils.negateX(location).multiply(scaleProperty.get()));
}
}
11 changes: 4 additions & 7 deletions src/main/java/com/treasure/hunt/strategy/geom/GeometryItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
public class GeometryItem<T> {
@NonNull
@Getter
T object;
GeometryType geometryType;
GeometryStyle geometryStyle;
private T object;
@NonNull
private GeometryType geometryType;
private GeometryStyle geometryStyle;

public GeometryItem(T object, GeometryType geometryType, GeometryStyle geometryStyle) {
assert (object != null);
Expand All @@ -29,10 +30,6 @@ public GeometryItem(T object, GeometryType geometryType, GeometryStyle geometryS
this.geometryStyle = geometryStyle;
}

public GeometryItem(T object) {
this(object, GeometryType.STANDARD, GeometryStyle.getDefaults(GeometryType.STANDARD));
}

public GeometryItem(T object, GeometryType geometryType) {
this(object, geometryType, GeometryStyle.getDefaults(geometryType));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class GeometryStyle {

private Color fillColor;

int zIndex = 0;
private int zIndex = 0;

public GeometryStyle(boolean visible, Color outlineColor) {
this(visible, false, outlineColor, Color.black, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
* @author dorianreineccius
*/
public class Movement {
private List<GeometryItem<Point>> points = new ArrayList<>();
protected List<GeometryItem<?>> additionalGeometryItems = new ArrayList<>();
/**
* Earlier added items that are now removed from display
*/
@Getter
private List<GeometryItem> toBeRemoved = new ArrayList<>();
private List<GeometryItem<Point>> points = new ArrayList<>();

public Movement() {
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/treasure/hunt/view/CanvasController.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,6 @@ public void drawShapes() {
});
}

private void deleteShapes() {
if (gameManager == null) {
return;
}
canvas.getGraphicsContext2D().clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
}

public void onCanvasClicked(MouseEvent mouseEvent) {
if (gameManager == null) {
return;
Expand Down Expand Up @@ -121,4 +114,11 @@ public void setGameManager(ObjectProperty<GameManager> gameManager) {

});
}

private void deleteShapes() {
if (gameManager == null) {
return;
}
canvas.getGraphicsContext2D().clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
}
}
50 changes: 25 additions & 25 deletions src/main/java/com/treasure/hunt/view/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,31 @@ public void initialize() {
listenToGameMangerLoad();
}

public void onStartButtonClicked() {
Class<? extends Searcher> searcherClass = searcherList.getSelectionModel().getSelectedItem();
Class<? extends Hider> hiderClass = hiderList.getSelectionModel().getSelectedItem();
Class<? extends GameEngine> gameEngineClass = gameEngineList.getSelectionModel().getSelectedItem();

assert searcherClass != null;
assert hiderClass != null;
assert gameEngineClass != null;
try {
initGameManager(new GameManager(searcherClass, hiderClass, gameEngineClass));
} catch (Exception e) {
log.error("Something important crashed", e);
logLabel.setText("Could not create game");
}
}

public void initGameUI() {
canvasController.drawShapes();
addWidgets();
}

public void onLoadGame(ActionEvent actionEvent) {
FileService.getInstance().load(logLabel);
}

private void listenToGameMangerLoad() {
EventBusUtils.GAME_MANAGER_LOADED_EVENT.addListener(loadedGameManager -> {
Platform.runLater(() -> {
Expand Down Expand Up @@ -316,22 +341,6 @@ private void insertWidget(boolean leftToolbar, String buttonText, Pane widgetBox
}
}

public void onStartButtonClicked() {
Class<? extends Searcher> searcherClass = searcherList.getSelectionModel().getSelectedItem();
Class<? extends Hider> hiderClass = hiderList.getSelectionModel().getSelectedItem();
Class<? extends GameEngine> gameEngineClass = gameEngineList.getSelectionModel().getSelectedItem();

assert searcherClass != null;
assert hiderClass != null;
assert gameEngineClass != null;
try {
initGameManager(new GameManager(searcherClass, hiderClass, gameEngineClass));
} catch (Exception e) {
log.error("Something important crashed", e);
logLabel.setText("Could not create game");
}
}

private void initGameManager(GameManager gameManagerInstance) {
boolean initialize = gameManager.isNull().get();

Expand All @@ -343,13 +352,4 @@ private void initGameManager(GameManager gameManagerInstance) {
initGameUI();
}
}

public void initGameUI() {
canvasController.drawShapes();
addWidgets();
}

public void onLoadGame(ActionEvent actionEvent) {
FileService.getInstance().load(logLabel);
}
}
Loading

0 comments on commit 572a1cc

Please sign in to comment.