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 {
|
public Worm createWorm(World world, double[] location, double direction, double radius, String name, Team team) throws ModelException {
|
||||||
try {
|
try {
|
||||||
return new Worm(world, location, direction, radius, name, team);
|
return new Worm(world, location, direction, radius, name, team);
|
||||||
} catch(IllegalArgumentException e) {
|
} catch(IllegalArgumentException | AssertionError e) {
|
||||||
throw new ModelException(e);
|
throw new ModelException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -13,26 +13,25 @@ import java.util.concurrent.ThreadLocalRandom;
|
|||||||
/**
|
/**
|
||||||
* A class with the specifications of the worm
|
* A class with the specifications of the worm
|
||||||
*
|
*
|
||||||
* @author Arthur Bols and Leen Dereu
|
* @authors Arthur Bols and Leen Dereu (1ste bachelor informatica)
|
||||||
* <p>
|
*
|
||||||
* Arthur Bols 1e bachelor Informatica
|
|
||||||
* Leen Dereu 1e bachelor Informatica
|
|
||||||
* <p>
|
|
||||||
* URL: https://github.com/KUL-ogp/ogp1718-project-bols-dereu
|
* 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 location of the worm must be a valid location.
|
||||||
* @invar The orientation of the worm must be a valid location.
|
* |isValidLocation(getLocation())
|
||||||
* |isValidOrientation(getOrientation())
|
* @invar The orientation of the worm must be a valid location.
|
||||||
* @invar The radius of the worm mus be a valid radius.
|
* |isValidOrientation(getOrientation())
|
||||||
* |isValidMinRadius(getRadius())
|
* @invar The radius of the worm mus be a valid radius.
|
||||||
* @invar The mass of the worm must bef a valid mass.
|
* |isValidMinRadius(getRadius())
|
||||||
* |isValidMass(getMass())
|
* @invar The mass of the worm must bef a valid mass.
|
||||||
* @invar The value of the action points of the worm must be a valid value for action points.
|
* |isValidMass(getMass())
|
||||||
* |isValidValueActionPoints(getActionPoints())
|
* @invar The value of the action points of the worm must be a valid value for action points.
|
||||||
* @invar The name of the worm must be a valid name.
|
* |isValidValueActionPoints(getActionPoints())
|
||||||
* |isValidName(getName())
|
* @invar The name of the worm must be a valid name.
|
||||||
* @invar The value of the hit points of the worm must be a valid value for hit points.
|
* |isValidName(getName())
|
||||||
* isValidValueHitPoints(getHitPoints())
|
* @invar The value of the hit points of the worm must be a valid value for hit points.
|
||||||
|
* |isValidValueHitPoints(getHitPoints())
|
||||||
|
*
|
||||||
* @version 3.0
|
* @version 3.0
|
||||||
*/
|
*/
|
||||||
public class Worm extends GameObject implements IJumpable{
|
public class Worm extends GameObject implements IJumpable{
|
||||||
@@ -49,18 +48,19 @@ public class Worm extends GameObject implements IJumpable{
|
|||||||
* @param name The name for the new worm.
|
* @param name The name for the new worm.
|
||||||
* @param radius The radius for the new worm.
|
* @param radius The radius for the new worm.
|
||||||
* @param team The team of the new worm.
|
* @param team The team of the new worm.
|
||||||
|
*
|
||||||
* @post The new world of the worm is equal to the given world.
|
* @post The new world of the worm is equal to the given world.
|
||||||
* |new.getWorld() == world
|
* |new.getWorld() == world
|
||||||
* @post The new location of the worm is equal to the given location.
|
* @post The new location of the worm is equal to the given location.
|
||||||
* |new.getLocation() == location
|
* |new.getLocation() == location
|
||||||
* @post The new direction of the worm is equal to the given direction.
|
* @post The new direction of the worm is equal to the given direction.
|
||||||
* |new.getDirection() == direction
|
* |new.getDirection() == direction
|
||||||
* @post The new name of the worm is equal to the given name.
|
* @post The new name of the worm is equal to the given name.
|
||||||
* |new.getName() == name
|
* |new.getName() == name
|
||||||
* @post The new radius of the worm is equal to the given radius.
|
* @post The new radius of the worm is equal to the given radius.
|
||||||
* |new.getRadius() == radius
|
* |new.getRadius() == radius
|
||||||
* @post The new team of the worm is equal to the given team.
|
* @post The new team of the worm is equal to the given team.
|
||||||
* |new.getTeam() == team
|
* |new.getTeam() == team
|
||||||
*/
|
*/
|
||||||
@Raw
|
@Raw
|
||||||
public Worm(World world, double[] location, double direction, double radius, String name, Team team) {
|
public Worm(World world, double[] location, double direction, double radius, String name, Team team) {
|
||||||
@@ -79,30 +79,32 @@ public class Worm extends GameObject implements IJumpable{
|
|||||||
* @param radius The radius for the new worm.
|
* @param radius The radius for the new worm.
|
||||||
* @param minRadius The minimum radius the new worm can have.
|
* @param minRadius The minimum radius the new worm can have.
|
||||||
* @param team The team for the new worm.
|
* @param team The team for the new worm.
|
||||||
* @throws IllegalArgumentException The given location is not a valid location for a worm.
|
*
|
||||||
* |!isValidLocation(location)
|
* @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.
|
||||||
|
* |new.getLocation() == location
|
||||||
|
* @post The new orientation of the worm is equal to the given orientation.
|
||||||
|
* |new.getOrientation() == orientation
|
||||||
|
* @post The new name of the worm is equal to the given name.
|
||||||
|
* |new.getName() == name
|
||||||
|
* @post The new radius of the worm is equal to the given radius.
|
||||||
|
* |new.getRadius() == radius
|
||||||
|
* @post The new minimum radius of the worm is equal to the given minimum radius.
|
||||||
|
* |new.getMinRadius() == minRadius
|
||||||
|
* @post The new value of action points of the worm is equal to the maximum possible value of action points.
|
||||||
|
* |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.
|
* @throws IllegalArgumentException The given minimum radius is not a valid minimum radius for a worm.
|
||||||
* |!isValidMinRadius(minRadius)
|
* |!isValidMinRadius(minRadius)
|
||||||
* @throws IllegalArgumentException The given radius can not be a minimum radius for a worm.
|
* @throws IllegalArgumentException The given radius can not be a minimum radius for a worm.
|
||||||
* |!canHaveAsMinRadius(radius)
|
* |!canHaveAsMinRadius(radius)
|
||||||
* @throws IllegalNameException The given name is not a valid name for a worm.
|
* @throws IllegalNameException The given name is not a valid name for a worm.
|
||||||
* |isValidName(name)
|
* |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.
|
|
||||||
* |new.getLocation() == location
|
|
||||||
* @post The new orientation of the worm is equal to the given orientation.
|
|
||||||
* |new.getOrientation() == orientation
|
|
||||||
* @post The new name of the worm is equal to the given name.
|
|
||||||
* |new.getName() == name
|
|
||||||
* @post The new radius of the worm is equal to the given radius.
|
|
||||||
* |new.getRadius() == radius
|
|
||||||
* @post The new minimum radius of the worm is equal to the given minimum radius.
|
|
||||||
* |new.getMinRadius() == minRadius
|
|
||||||
* @post The new value of action points of the worm is equal to the maximum possible value of action points.
|
|
||||||
* |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
|
|
||||||
*/
|
*/
|
||||||
@Raw
|
@Raw
|
||||||
public Worm(World world, double[] location, double orientation, String name, double radius, double minRadius, Team team)
|
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.
|
* Set the orientation of the worm to the given orientation.
|
||||||
*
|
*
|
||||||
* @param orientation The new orientation of the worm.
|
* @param orientation The new orientation of the worm.
|
||||||
|
*
|
||||||
* @pre The given orientation must be a valid orientation for any worm.
|
* @pre The given orientation must be a valid orientation for any worm.
|
||||||
* |isValidOrientation(orientation)
|
* |isValidOrientation(orientation)
|
||||||
|
*
|
||||||
* @post The new orientation of the worm must be equal to the given orientation.
|
* @post The new orientation of the worm must be equal to the given orientation.
|
||||||
* |new.getOrientation() == orientation
|
* |new.getOrientation() == orientation
|
||||||
*/
|
*/
|
||||||
@Raw
|
@Raw
|
||||||
private void setOrientation(double orientation) {
|
private void setOrientation(double orientation) {
|
||||||
if (!isValidOrientation(orientation)) throw new IllegalArgumentException();
|
assert isValidOrientation(orientation);
|
||||||
this.orientation = orientation;
|
this.orientation = orientation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,8 +177,9 @@ public class Worm extends GameObject implements IJumpable{
|
|||||||
* Check whether the given orientation is a valid orientation for the worm.
|
* Check whether the given orientation is a valid orientation for the worm.
|
||||||
*
|
*
|
||||||
* @param newOrientation The orientation to check.
|
* @param newOrientation The orientation to check.
|
||||||
* @return True if and only if the orientation is bigger then and smaller then 2pi.
|
*
|
||||||
* |result == ( newOrientation >= 0 && newOrientation < 2 * PI )
|
* @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) {
|
public static boolean isValidOrientation(double newOrientation) {
|
||||||
return newOrientation >= 0 && newOrientation < 2 * PI;
|
return newOrientation >= 0 && newOrientation < 2 * PI;
|
||||||
@@ -191,8 +196,9 @@ public class Worm extends GameObject implements IJumpable{
|
|||||||
* Check whether the given radius is a valid minimum radius for the worm.
|
* Check whether the given radius is a valid minimum radius for the worm.
|
||||||
*
|
*
|
||||||
* @param minRadius The radius to check.
|
* @param minRadius The radius to check.
|
||||||
|
*
|
||||||
* @return True if and only if the radius is a number and the radius is bigger then 0.
|
* @return True if and only if the radius is a number and the radius is bigger then 0.
|
||||||
* |result == ((!Double.isNaN(radius)) && (radius > 0))
|
* |result == ((!Double.isNaN(radius)) && (radius > 0))
|
||||||
*/
|
*/
|
||||||
public static boolean isValidMinRadius(double minRadius) {
|
public static boolean isValidMinRadius(double minRadius) {
|
||||||
return !Double.isNaN(minRadius) && minRadius > 0;
|
return !Double.isNaN(minRadius) && minRadius > 0;
|
||||||
@@ -202,10 +208,14 @@ public class Worm extends GameObject implements IJumpable{
|
|||||||
* Set the radius of the worm to the given radius.
|
* Set the radius of the worm to the given radius.
|
||||||
*
|
*
|
||||||
* @param radius The new radius for the worm.
|
* @param radius The new radius for the worm.
|
||||||
|
*
|
||||||
|
* @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.
|
* @throws IllegalArgumentException The given radius is not a valid radius for any worm.
|
||||||
* |! canHaveAsMinRadius(radius)
|
* |! canHaveAsMinRadius(radius)
|
||||||
* @post The new radius of the worm is equal to the given radius.
|
|
||||||
* |new.getRadius() == radius
|
|
||||||
*/
|
*/
|
||||||
@Raw
|
@Raw
|
||||||
@Override
|
@Override
|
||||||
@@ -228,17 +238,22 @@ public class Worm extends GameObject implements IJumpable{
|
|||||||
* Check whether the given radius is a valid radius for the worm.
|
* Check whether the given radius is a valid radius for the worm.
|
||||||
*
|
*
|
||||||
* @param radius The radius to check.
|
* @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.
|
* @return If the world is not equal to null, the result is true if and only if the radius is a number, the radius
|
||||||
* |result == (radius >= getMinRadius() && !Double.isNaN(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
|
@Raw
|
||||||
private boolean canHaveAsRadius(double radius) {
|
private boolean canHaveAsRadius(double radius) {
|
||||||
if (this.world != null) {
|
if (this.world != null) {
|
||||||
return !Double.isNaN(radius) && radius >= this.minRadius && !Double.isInfinite(radius) && this.world.isPassable(this.location, radius);
|
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.
|
* Set the current points of the worm to the given points.
|
||||||
*
|
*
|
||||||
* @param actionPoints The new points for the worm.
|
* @param actionPoints The new points for the worm.
|
||||||
|
*
|
||||||
* @post If the given points are bigger then the maximum points, the current points
|
* @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
|
* 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
|
* 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.
|
* maximum points and 0, the current points is equal to the given points.
|
||||||
* |if (actionPoints > getMaxActionPoints())
|
* |if (actionPoints > getMaxActionPoints())
|
||||||
* | actionPoints = getMaxActionPoints();
|
* | actionPoints = getMaxActionPoints()
|
||||||
* |else if (actionPoints < 0)
|
* |else if (actionPoints < 0)
|
||||||
* | actionPoints = 0;
|
* | actionPoints = 0
|
||||||
* |this.actionPoints = actionPoints;
|
* |this.actionPoints = actionPoints
|
||||||
*/
|
*/
|
||||||
@Raw
|
@Raw
|
||||||
public void setActionPoints(long actionPoints) {
|
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
|
@Raw
|
||||||
public void incrementActionPoints(long delta) {
|
public void incrementActionPoints(long delta) {
|
||||||
setActionPoints(this.actionPoints + 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.
|
* @param delta The value which should be decreased.
|
||||||
|
*
|
||||||
* @post The current points are set to the old current points minus the given value.
|
* @post The current points are set to the old current points minus the given value.
|
||||||
* |setActionPoints(getActionPoints() - delta)
|
* |new.getActionPoints() == old.getActionPoints() - delta
|
||||||
*/
|
*/
|
||||||
@Raw
|
@Raw
|
||||||
public void decrementActionPoints(long delta) {
|
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.
|
* @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.
|
* @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))
|
* |new.getActionPoints() == old.getActionPoints() - (long) ceil(toDegrees(angle) / 6))
|
||||||
*/
|
*/
|
||||||
private void decreaseActionPointsByAngle(double angle) {
|
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.
|
* Set the maximum of points to the given maximum of points.
|
||||||
*
|
*
|
||||||
* @param maxActionPoints The new maximum of points for the worm.
|
* @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).
|
* @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.
|
* @post When the maximum points change, the current points should change too.
|
||||||
* |setActionPoints(getActionPoints)
|
* |setActionPoints(this.actionPoints)
|
||||||
*/
|
*/
|
||||||
@Raw
|
@Raw
|
||||||
private void setMaxActionPoints(double maxActionPoints) {
|
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.
|
* Check whether the given name is a valid name for all worms.
|
||||||
*
|
*
|
||||||
* @param name The name to check.
|
* @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
|
* @return ...
|
||||||
* of letters, " ", " ' " and " "" ".
|
* |
|
||||||
* |for (i = 0; i < name.length(); i++)
|
*
|
||||||
* |result == (name.length() > 2 && Character.isUpperCase(name.charAt(0)
|
* @throws IllegalArgumentException ...
|
||||||
* |&& Character.isLetter(name.charAt(i)) &&
|
* |
|
||||||
* |allowedCharacters.indexOf(name.charAt(i)))
|
|
||||||
*/
|
*/
|
||||||
public static int isValidName(String name) {
|
public static int isValidName(String name) {
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user