Documentatie Worm
This commit is contained in:
@@ -688,7 +688,7 @@ public class Facade implements IFacade {
|
||||
public Worm createWorm(World world, double[] location, double direction, double radius, String name, Team team) throws ModelException {
|
||||
try {
|
||||
return new Worm(world, location, direction, radius, name, team);
|
||||
} catch(IllegalArgumentException e) {
|
||||
} catch(IllegalArgumentException | AssertionError e) {
|
||||
throw new ModelException(e);
|
||||
}
|
||||
}
|
||||
|
@@ -13,12 +13,10 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
/**
|
||||
* A class with the specifications of the worm
|
||||
*
|
||||
* @author Arthur Bols and Leen Dereu
|
||||
* <p>
|
||||
* Arthur Bols 1e bachelor Informatica
|
||||
* Leen Dereu 1e bachelor Informatica
|
||||
* <p>
|
||||
* @authors Arthur Bols and Leen Dereu (1ste bachelor informatica)
|
||||
*
|
||||
* URL: https://github.com/KUL-ogp/ogp1718-project-bols-dereu
|
||||
*
|
||||
* @invar The location of the worm must be a valid location.
|
||||
* |isValidLocation(getLocation())
|
||||
* @invar The orientation of the worm must be a valid location.
|
||||
@@ -32,7 +30,8 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
* @invar The name of the worm must be a valid name.
|
||||
* |isValidName(getName())
|
||||
* @invar The value of the hit points of the worm must be a valid value for hit points.
|
||||
* isValidValueHitPoints(getHitPoints())
|
||||
* |isValidValueHitPoints(getHitPoints())
|
||||
*
|
||||
* @version 3.0
|
||||
*/
|
||||
public class Worm extends GameObject implements IJumpable{
|
||||
@@ -49,6 +48,7 @@ public class Worm extends GameObject implements IJumpable{
|
||||
* @param name The name for the new worm.
|
||||
* @param radius The radius for the new worm.
|
||||
* @param team The team of the new worm.
|
||||
*
|
||||
* @post The new world of the worm is equal to the given world.
|
||||
* |new.getWorld() == world
|
||||
* @post The new location of the worm is equal to the given location.
|
||||
@@ -79,14 +79,7 @@ public class Worm extends GameObject implements IJumpable{
|
||||
* @param radius The radius for the new worm.
|
||||
* @param minRadius The minimum radius the new worm can have.
|
||||
* @param team The team for the new worm.
|
||||
* @throws IllegalArgumentException The given location is not a valid location for a worm.
|
||||
* |!isValidLocation(location)
|
||||
* @throws IllegalArgumentException The given minimum radius is not a valid minimum radius for a worm.
|
||||
* |!isValidMinRadius(minRadius)
|
||||
* @throws IllegalArgumentException The given radius can not be a minimum radius for a worm.
|
||||
* |!canHaveAsMinRadius(radius)
|
||||
* @throws IllegalNameException The given name is not a valid name for a worm.
|
||||
* |isValidName(name)
|
||||
*
|
||||
* @post The new world of the worm is equal to the given world.
|
||||
* |new.getWorld() == world
|
||||
* @post The new location of the worm is equal to the given location.
|
||||
@@ -103,6 +96,15 @@ public class Worm extends GameObject implements IJumpable{
|
||||
* |new.getActionPoints() == getMaxActionPoints()
|
||||
* @post The new value of hit points of the worm is equal to the start value for hit points.
|
||||
* |new.getHitPoints() == startHitPoints
|
||||
* @post The new team of the worm is equal to the given team.
|
||||
* |new.getTeam() == team
|
||||
*
|
||||
* @throws IllegalArgumentException The given minimum radius is not a valid minimum radius for a worm.
|
||||
* |!isValidMinRadius(minRadius)
|
||||
* @throws IllegalArgumentException The given radius can not be a minimum radius for a worm.
|
||||
* |!canHaveAsMinRadius(radius)
|
||||
* @throws IllegalNameException The given name is not a valid name for a worm.
|
||||
* |isValidName(name)
|
||||
*/
|
||||
@Raw
|
||||
public Worm(World world, double[] location, double orientation, String name, double radius, double minRadius, Team team)
|
||||
@@ -158,14 +160,16 @@ public class Worm extends GameObject implements IJumpable{
|
||||
* Set the orientation of the worm to the given orientation.
|
||||
*
|
||||
* @param orientation The new orientation of the worm.
|
||||
*
|
||||
* @pre The given orientation must be a valid orientation for any worm.
|
||||
* |isValidOrientation(orientation)
|
||||
*
|
||||
* @post The new orientation of the worm must be equal to the given orientation.
|
||||
* |new.getOrientation() == orientation
|
||||
*/
|
||||
@Raw
|
||||
private void setOrientation(double orientation) {
|
||||
if (!isValidOrientation(orientation)) throw new IllegalArgumentException();
|
||||
assert isValidOrientation(orientation);
|
||||
this.orientation = orientation;
|
||||
}
|
||||
|
||||
@@ -173,7 +177,8 @@ public class Worm extends GameObject implements IJumpable{
|
||||
* Check whether the given orientation is a valid orientation for the worm.
|
||||
*
|
||||
* @param newOrientation The orientation to check.
|
||||
* @return True if and only if the orientation is bigger then and smaller then 2pi.
|
||||
*
|
||||
* @return True if and only if the orientation is bigger then 0 and smaller then 2pi.
|
||||
* |result == ( newOrientation >= 0 && newOrientation < 2 * PI )
|
||||
*/
|
||||
public static boolean isValidOrientation(double newOrientation) {
|
||||
@@ -191,6 +196,7 @@ public class Worm extends GameObject implements IJumpable{
|
||||
* Check whether the given radius is a valid minimum radius for the worm.
|
||||
*
|
||||
* @param minRadius 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))
|
||||
*/
|
||||
@@ -202,10 +208,14 @@ public class Worm extends GameObject implements IJumpable{
|
||||
* Set the radius of the worm to the given radius.
|
||||
*
|
||||
* @param radius The new radius for the worm.
|
||||
* @throws IllegalArgumentException The given radius is not a valid radius for any worm.
|
||||
* |! canHaveAsMinRadius(radius)
|
||||
*
|
||||
* @post The new radius of the worm is equal to the given radius.
|
||||
* |new.getRadius() == radius
|
||||
* @post The new maximum of action points is equal to the mass of the worm.
|
||||
* |new.getMaxActionPoints() == this.mass
|
||||
*
|
||||
* @throws IllegalArgumentException The given radius is not a valid radius for any worm.
|
||||
* |! canHaveAsMinRadius(radius)
|
||||
*/
|
||||
@Raw
|
||||
@Override
|
||||
@@ -228,17 +238,22 @@ public class Worm extends GameObject implements IJumpable{
|
||||
* 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 >= getMinRadius() && !Double.isNaN(radius))
|
||||
*
|
||||
* @return If the world is not equal to null, the result is true if and only if the radius is a number, the radius
|
||||
* is bigger or equal to the minimum radius, the radius is not a infinite number and the location (with radius)
|
||||
* is passable. If the world is equal to null, the result is true if and only if the radius is a number,
|
||||
* the radius is bigger or equal to the minimum radius and the radius is not a infinite number.
|
||||
* |if (this.world != null)
|
||||
* | result == !Double.isNaN(radius) && radius >= this.minRadius && !Double.isInfinite(radius) &&
|
||||
* | this.world.isPassable(this.location, radius)
|
||||
* |result == !Double.isNaN(radius) && radius >= this.minRadius && !Double.isInfinite(radius)
|
||||
*/
|
||||
@Raw
|
||||
private boolean canHaveAsRadius(double radius) {
|
||||
if (this.world != null) {
|
||||
return !Double.isNaN(radius) && radius >= this.minRadius && !Double.isInfinite(radius) && this.world.isPassable(this.location, radius);
|
||||
} else {
|
||||
return !Double.isNaN(radius) && radius >= this.minRadius && !Double.isInfinite(radius);
|
||||
}
|
||||
return !Double.isNaN(radius) && radius >= this.minRadius && !Double.isInfinite(radius);
|
||||
}
|
||||
|
||||
//===================================================================================
|
||||
@@ -272,15 +287,16 @@ public class Worm extends GameObject implements IJumpable{
|
||||
* 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 (actionPoints > getMaxActionPoints())
|
||||
* | actionPoints = getMaxActionPoints();
|
||||
* | actionPoints = getMaxActionPoints()
|
||||
* |else if (actionPoints < 0)
|
||||
* | actionPoints = 0;
|
||||
* |this.actionPoints = actionPoints;
|
||||
* | actionPoints = 0
|
||||
* |this.actionPoints = actionPoints
|
||||
*/
|
||||
@Raw
|
||||
public void setActionPoints(long actionPoints) {
|
||||
@@ -293,18 +309,26 @@ public class Worm extends GameObject implements IJumpable{
|
||||
}
|
||||
|
||||
|
||||
// TODO add documentatie
|
||||
/**
|
||||
* Increments the action points with the given delta.
|
||||
*
|
||||
* @param delta The value by which the action points should be increment.
|
||||
*
|
||||
* @post The action points are set to the old action points incremented with the given delta.
|
||||
* |new.getActionPoints() == old.getActionPoints() + delta
|
||||
*/
|
||||
@Raw
|
||||
public void incrementActionPoints(long delta) {
|
||||
setActionPoints(this.actionPoints + delta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Substract the current points of the worm.
|
||||
* Decrements the action points with the given delta.
|
||||
*
|
||||
* @param delta The value which should be decreased.
|
||||
*
|
||||
* @post The current points are set to the old current points minus the given value.
|
||||
* |setActionPoints(getActionPoints() - delta)
|
||||
* |new.getActionPoints() == old.getActionPoints() - delta
|
||||
*/
|
||||
@Raw
|
||||
public void decrementActionPoints(long delta) {
|
||||
@@ -313,12 +337,12 @@ public class Worm extends GameObject implements IJumpable{
|
||||
}
|
||||
|
||||
/**
|
||||
* Substract the current points of the worm.
|
||||
* Decrease the current action points of the worm involving the given angle.
|
||||
*
|
||||
* @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.
|
||||
* |setActionPoints(getActionPoints() - (long) ceil(toDegrees(angle) / 6))
|
||||
*
|
||||
* @post The current points are set to the old current points minus the angle (in degrees) divided by 6.
|
||||
* |new.getActionPoints() == old.getActionPoints() - (long) ceil(toDegrees(angle) / 6))
|
||||
*/
|
||||
private void decreaseActionPointsByAngle(double angle) {
|
||||
|
||||
@@ -336,10 +360,11 @@ public class Worm extends GameObject implements IJumpable{
|
||||
* Set the maximum of points to the given maximum of points.
|
||||
*
|
||||
* @param maxActionPoints 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 = round(maxActionPoints)
|
||||
* |this.maxActionPoints = round(maxActionPoints)
|
||||
* @post When the maximum points change, the current points should change too.
|
||||
* |setActionPoints(getActionPoints)
|
||||
* |setActionPoints(this.actionPoints)
|
||||
*/
|
||||
@Raw
|
||||
private void setMaxActionPoints(double maxActionPoints) {
|
||||
@@ -372,16 +397,16 @@ public class Worm extends GameObject implements IJumpable{
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Documentatie vanaf hier verder afwerken!!
|
||||
* Check whether the given name is a valid name for all worms.
|
||||
*
|
||||
* @param name The name to check.
|
||||
* @return -1 if and only if the given name is longer then 2,
|
||||
* the first letter is uppercase and the name only exists
|
||||
* of letters, " ", " ' " and " "" ".
|
||||
* |for (i = 0; i < name.length(); i++)
|
||||
* |result == (name.length() > 2 && Character.isUpperCase(name.charAt(0)
|
||||
* |&& Character.isLetter(name.charAt(i)) &&
|
||||
* |allowedCharacters.indexOf(name.charAt(i)))
|
||||
*
|
||||
* @return ...
|
||||
* |
|
||||
*
|
||||
* @throws IllegalArgumentException ...
|
||||
* |
|
||||
*/
|
||||
public static int isValidName(String name) {
|
||||
|
||||
|
Reference in New Issue
Block a user