Merge branch 'master' of gitlab.principis.be:OGP/worms
This commit is contained in:
@@ -27,7 +27,15 @@ public class Worm {
|
||||
|
||||
// jumping
|
||||
private Tuple<Double, Double> oldLocation;
|
||||
|
||||
/**
|
||||
* this variable contains the velocity of the jump of the worm
|
||||
*/
|
||||
private double jumpVelocity;
|
||||
|
||||
/**
|
||||
* this variable contains the duration of the jump of the worm
|
||||
*/
|
||||
private double jumpTime;
|
||||
|
||||
/**
|
||||
@@ -152,6 +160,15 @@ public class Worm {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
/**
|
||||
* check whether the given location is a valid location for the worm
|
||||
*
|
||||
* @param location
|
||||
* the location to check
|
||||
* @return True if and only if the location is not equal to null and the coordinates of
|
||||
* the worm are numbers
|
||||
* |result == (location != null) && (!Double.isNaN(location.item1)) && (!Double.isNaN(location.item2))
|
||||
*/
|
||||
private boolean isValidLocation(Tuple<Double, Double>location) {
|
||||
return location != null && !Double.isNaN(location.item1) && !Double.isNaN(location.item2);
|
||||
}
|
||||
@@ -226,6 +243,15 @@ public class Worm {
|
||||
setMass(radius);
|
||||
}
|
||||
|
||||
/**
|
||||
* check whether the given radius is a valid radius for the worm
|
||||
*
|
||||
* @param radius
|
||||
* the radius to check
|
||||
* @return True if and only if the radius is bigger then the minimum radius
|
||||
* (or equal) and the radius is a number
|
||||
* |result == (radius >= this.minimumRadius && !Double.isNaN(radius))
|
||||
*/
|
||||
private boolean isValidRadius(double radius) {
|
||||
return radius >= this.minimumRadius && !Double.isNaN(radius);
|
||||
}
|
||||
@@ -239,6 +265,14 @@ public class Worm {
|
||||
return this.minimumRadius;
|
||||
}
|
||||
|
||||
/**
|
||||
* check whether the given radius is a valid minimum radius for the worm
|
||||
*
|
||||
* @param radius
|
||||
* the radius to check
|
||||
* @return True if and only if the radius is a number and the radius is bigger then 0
|
||||
* |result == ((!Double.isNaN(radius)) && (radius > 0))
|
||||
*/
|
||||
private boolean isValidMinimumRadius(double radius) {
|
||||
return !Double.isNaN(radius) && radius > 0;
|
||||
}
|
||||
@@ -277,6 +311,10 @@ public class Worm {
|
||||
// region ActionPoints
|
||||
//===================================================================================
|
||||
|
||||
/**
|
||||
* Return the current action points of the worm
|
||||
* the action points identifies the energy of the worm
|
||||
*/
|
||||
public long getActionPoints() {
|
||||
return this.actionPoints;
|
||||
}
|
||||
@@ -285,6 +323,21 @@ public class Worm {
|
||||
return this.maxActionPoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the current points of the worm to the given points
|
||||
*
|
||||
* @param actionPoints
|
||||
* the new points for the worm
|
||||
* @post if the given points are bigger then the maximum points, the current points
|
||||
* are equal to the maximum points. If the given points are lower then 0
|
||||
* the current points are equal to 0. If the given points is between the
|
||||
* maximum points and 0, the current points is equal to the given points
|
||||
* |if (points > this.maxPoints)
|
||||
* | points = this.maxPoints
|
||||
* |else if (points < 0)
|
||||
* | points = 0
|
||||
* |this.points = points
|
||||
*/
|
||||
public void setActionPoints(long actionPoints) {
|
||||
|
||||
this.actionPoints = toValidActionPoints(actionPoints);
|
||||
@@ -307,10 +360,43 @@ public class Worm {
|
||||
return actionPoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the maximum of points to the given maximum of points
|
||||
*
|
||||
* @param maxPoints
|
||||
* the new maximum of points for the worm
|
||||
* @post the new maximum points is set to the given maximum points (as an integer)
|
||||
* |this.maxPoints = (int) ceil(maxPoints)
|
||||
* @post when the maximum points change, the current points should change too
|
||||
* |setPoints(this.points)
|
||||
*/
|
||||
private void setMaxPoints(double maxPoints) {
|
||||
this.maxActionPoints = (int) ceil(maxPoints);
|
||||
setActionPoints(this.actionPoints);
|
||||
}
|
||||
|
||||
/**
|
||||
* substract the current points of the worm
|
||||
*
|
||||
* @param value
|
||||
* the value which should be substracted
|
||||
* @post the current points are set to the old current points minus the given value
|
||||
* |setPoints(this.points - value)
|
||||
*/
|
||||
private void subtractActionPoints (long value) {
|
||||
|
||||
setActionPoints(this.actionPoints - value);
|
||||
}
|
||||
|
||||
/**
|
||||
* substract the current points of the worm
|
||||
*
|
||||
* @param angle
|
||||
* the angle needed to calculate the new current points
|
||||
* @post the current points are set to the old current points minus
|
||||
* the angle (in degrees) divided by 6
|
||||
* |setPoints(this.points - (int) ceil(toDegrees(angle) / 6))
|
||||
*/
|
||||
private void subtractActionPoints (double angle) {
|
||||
|
||||
setActionPoints(this.actionPoints - (long) ceil(toDegrees(angle) / 6));
|
||||
|
Reference in New Issue
Block a user