Documentatie tot move (part 1 verbeteren)

This commit is contained in:
Leen Dereu
2018-04-16 19:44:28 +02:00
parent 35fb734030
commit dc5c5f361f
2 changed files with 113 additions and 91 deletions

View File

@@ -3,7 +3,11 @@ package worms.model;
import worms.util.Coordinate; import worms.util.Coordinate;
public class Food extends GameObject { public class Food extends GameObject {
/**
*
* @param world
* @param location
*/
public Food(World world, double[] location) { public Food(World world, double[] location) {
super(world, location, 0.2); super(world, location, 0.2);

View File

@@ -24,8 +24,10 @@ import java.util.concurrent.ThreadLocalRandom;
* |isValidValueActionPoints(getActionPoints()) * |isValidValueActionPoints(getActionPoints())
* @invar The name of the worm must be a valid name. * @invar The name of the worm must be a valid name.
* |isValidName(getName()) * |isValidName(getName())
* @invar The value of the hit points of the worm must be a valid value for hit points.
* isValidValueHitPoints(getHitPoints())
* *
* @version 1.0 * @version 2.0
* @author Arthur Bols and Leen Dereu * @author Arthur Bols and Leen Dereu
* *
* Arthur Bols 1e bachelor Informatica * Arthur Bols 1e bachelor Informatica
@@ -39,26 +41,33 @@ public class Worm extends GameObject {
//=================================================================================== //===================================================================================
/** /**
*initialize the new worm with given location, orientation, name and radius *Initialize the new worm with given location, orientation, name and radius.
* *
* @param world * @param world
* The world this worm belongs to * The world this worm belongs to.
* @param location * @param location
* the location for the new worm * The location for the new worm.
* @param direction
* The direction for the new worm.
* @param name * @param name
* the name for the new worm * The name for the new worm.
* @param radius * @param radius
* the radius for the new worm * The radius for the new worm.
* @param team * @param team
* The team of the new worm * The team of the new worm.
* @post the new location of the worm is equal to the given 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 * |new.getLocation() == location
* @post the new orientation of the worm is equal to the given orientation * @post The new direction of the worm is equal to the given direction.
* |new.getOrientation() == orientation * |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.
* |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) {
@@ -70,38 +79,49 @@ public class Worm extends GameObject {
/** /**
*initialize the new worm with given location, orientation, name, radius and minimum radius *initialize the new worm with given location, orientation, name, radius and minimum radius
* *
* @param world
* The world for the new worm.
* @param location * @param location
* the location for the new worm * The location for the new worm.
* @param orientation * @param orientation
* the orientation for the new worm * The orientation for the new worm.
* @param name * @param name
* the name for the new worm * The name for the new worm.
* @param radius * @param radius
* the radius for the new worm * The radius for the new worm.
* @param minRadius * @param minRadius
* the minimum radius the new worm can have * The minimum radius the new worm can have.
* @post the new location of the worm is equal to the given location * @param team
* The team for 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.
* |new.getLocation() == location * |new.getLocation() == location
* @post the new orientation of the worm is equal to the given orientation * @post The new orientation of the worm is equal to the given orientation.
* |new.getOrientation() == orientation * |new.getOrientation() == orientation
* @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 minimum radius of the worm is equal to the given minimum radius * @post The new minimum radius of the worm is equal to the given minimum radius.
* |new.getMinRadius() == minRadius * |new.getMinRadius() == minRadius
* @post actionpoints en hitpoints * @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
*
* @throws IllegalArgumentException * @throws IllegalArgumentException
* the given location is not a valid location for a worm * The given location is not a valid location for a worm.
* |!isValidLocation(location) * |!isValidLocation(location)
* @throws IllegalArgumentException * @throws IllegalArgumentException
* the given minimum radius is not a valid minimum radius for a worm * The given minimum radius is not a valid minimum radius for a worm.
* |!isValidMinRadius(minRadius) * |!isValidMinRadius(minRadius)
* @throws IllegalArgumentException * @throws IllegalArgumentException
* the given radius can not be a minimum radius for a worm * The given radius can not be a minimum radius for a worm.
* |!canHaveAsMinRadius(radius) * |!canHaveAsMinRadius(radius)
* @throws IllegalNameException * @throws IllegalNameException
* the given name is not a valid name for a worm * The given name is not a valid name for a worm.
* |isValidName(name) * |isValidName(name)
*/ */
@Raw @Raw
@@ -137,9 +157,9 @@ public class Worm extends GameObject {
//=================================================================================== //===================================================================================
/** /**
* Return the orientation of the worm * Return the orientation of the worm.
* the orientation of a worm expresses the direction in which * The orientation of a worm expresses the direction in which
* the worm is looking * the worm is looking.
*/ */
@Basic @Raw @Basic @Raw
public double getOrientation() { public double getOrientation() {
@@ -147,18 +167,18 @@ public class Worm extends GameObject {
} }
/** /**
* this variable contains the orientation of the worm * This variable contains the orientation of the worm.
*/ */
private double orientation; private double orientation;
/** /**
* set the orientation of the worm to the given orientation * Set the orientation of the worm to the given orientation.
* *
* @param orientation * @param orientation
* the new orientation of the worm * 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
@@ -168,11 +188,11 @@ public class Worm extends GameObject {
} }
/** /**
*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 * @param newOrientation
* the orientation to check * 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 and smaller then 2pi.
* |result == ( newOrientation >= 0 && newOrientation < 2 * PI ) * |result == ( newOrientation >= 0 && newOrientation < 2 * PI )
*/ */
public static boolean isValidOrientation(double newOrientation) { public static boolean isValidOrientation(double newOrientation) {
@@ -186,14 +206,12 @@ public class Worm extends GameObject {
// region Shape mass/radius // region Shape mass/radius
//=================================================================================== //===================================================================================
/** /**
* 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 * @param minRadius
* the radius to check * 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) {
@@ -201,14 +219,14 @@ public class Worm extends GameObject {
} }
/** /**
* set the radius of the worm to the given radius * Set the radius of the worm to the given radius.
* *
* @param radius * @param radius
* the new radius for the worm * The new radius for the worm.
* @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
* @throws IllegalArgumentException * @throws IllegalArgumentException
* the given radius is not a valid radius for any worm * The given radius is not a valid radius for any worm.
* |! canHaveAsMinRadius(radius) * |! canHaveAsMinRadius(radius)
*/ */
@Raw @Override @Raw @Override
@@ -223,9 +241,9 @@ public class Worm extends GameObject {
} }
/** /**
* Return the minimum radius the worm can have * Return the minimum radius the worm can have.
* the minimum radius of the worm expresses the minimum length * The minimum radius of the worm expresses the minimum length
* of half of the width of the worm * of half of the width of the worm.
*/ */
@Basic @Raw @Basic @Raw
public double getMinRadius() { public double getMinRadius() {
@@ -233,17 +251,17 @@ public class Worm extends GameObject {
} }
/** /**
* This variable contains the minimum value of the radius * This variable contains the minimum value of the radius.
*/ */
private final double minRadius; private final double minRadius;
/** /**
* 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 * @param radius
* the radius to check * The radius to check.
* @return True if and only if the radius is bigger then the minimum radius * @return True if and only if the radius is bigger then the minimum radius
* (or equal) and the radius is a number * (or equal) and the radius is a number.
* |result == (radius >= getMinRadius() && !Double.isNaN(radius)) * |result == (radius >= getMinRadius() && !Double.isNaN(radius))
*/ */
@Raw @Raw
@@ -252,8 +270,8 @@ public class Worm extends GameObject {
} }
/** /**
* Return the mass of the worm * Return the mass of the worm.
* the mass of the worm expresses the weight of the worm * The mass of the worm expresses the weight of the worm.
*/ */
@Basic @Raw @Basic @Raw
public double getMass() { public double getMass() {
@@ -269,8 +287,8 @@ public class Worm extends GameObject {
//=================================================================================== //===================================================================================
/** /**
* Return the current action points of the worm * Return the current action points of the worm.
* the action points identifies the energy of the worm * The action points identifies the energy of the worm.
*/ */
@Basic @Raw @Basic @Raw
public long getActionPoints() { public long getActionPoints() {
@@ -278,8 +296,8 @@ public class Worm extends GameObject {
} }
/** /**
* Return the maximum of action points of the worm * Return the maximum of action points of the worm.
* the maximum action points identifies the maximum energy of the worm * The maximum action points identifies the maximum energy of the worm.
*/ */
@Basic @Raw @Basic @Raw
public long getMaxActionPoints() { public long getMaxActionPoints() {
@@ -287,14 +305,14 @@ public class Worm extends GameObject {
} }
/** /**
* set the current points of the worm to the given points * Set the current points of the worm to the given points.
* *
* @param actionPoints * @param actionPoints
* the new points for the worm * 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)
@@ -312,11 +330,11 @@ public class Worm extends GameObject {
} }
/** /**
*substract the current points of the worm * Substract the current points of the worm.
* *
* @param delta * @param delta
* the value which should be decreased * 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) * |setActionPoints(getActionPoints() - delta)
*/ */
public void decreaseActionPoints (long delta) { public void decreaseActionPoints (long delta) {
@@ -325,23 +343,23 @@ public class Worm extends GameObject {
} }
/** /**
* this variable contains the current action points of the worm * This variable contains the current action points of the worm.
*/ */
private long actionPoints; private long actionPoints;
/** /**
* this variable contains the maximum action points a worm can have * This variable contains the maximum action points a worm can have.
*/ */
private long maxActionPoints; private long maxActionPoints;
/** /**
* set the maximum of points to the given maximum of points * Set the maximum of points to the given maximum of points.
* *
* @param maxActionPoints * @param maxActionPoints
* the new maximum of points for the worm * 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.maxPoints = 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(getActionPoints)
*/ */
@Raw @Raw
@@ -351,11 +369,11 @@ public class Worm extends GameObject {
} }
/** /**
* substract the current points of the worm * Substract the current points of the worm.
* *
* @param value * @param value
* the value which should be subtracted * The value which should be subtracted.
* @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() - value) * |setActionPoints(getActionPoints() - value)
*/ */
private void subtractActionPoints (long value) { private void subtractActionPoints (long value) {
@@ -364,12 +382,12 @@ public class Worm extends GameObject {
} }
/** /**
* substract the current points of the worm * Substract the current points of the worm.
* *
* @param angle * @param angle
* the angle needed to calculate the new current points * The angle needed to calculate the new current points.
* @post the current points are set to the old current points minus * @post The current points are set to the old current points minus
* the angle (in degrees) divided by 6 * the angle (in degrees) divided by 6.
* |setActionPoints(getActionPoints() - (long) ceil(toDegrees(angle) / 6)) * |setActionPoints(getActionPoints() - (long) ceil(toDegrees(angle) / 6))
*/ */
private void subtractActionPoints (double angle) { private void subtractActionPoints (double angle) {
@@ -386,8 +404,8 @@ public class Worm extends GameObject {
//=================================================================================== //===================================================================================
/** /**
* Return the name of the worm * Return the name of the worm.
* the name of the worm expresses the identity of the worm * The name of the worm expresses the identity of the worm.
*/ */
@Basic @Immutable @Raw @Basic @Immutable @Raw
public String getName() { public String getName() {
@@ -395,13 +413,13 @@ public class Worm extends GameObject {
} }
/** /**
* 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 * @param name
* the name to check * The name to check.
* @return -1 if and only if the given name is longer then 2, * @return -1 if and only if the given name is longer then 2,
* the first letter is uppercase and the name only exists * the first letter is uppercase and the name only exists
* of letters, " ", " ' " and " "" " * of letters, " ", " ' " and " "" ".
* |for (i = 0; i < name.length(); i++) * |for (i = 0; i < name.length(); i++)
* |result == (name.length() > 2 && Character.isUpperCase(name.charAt(0) * |result == (name.length() > 2 && Character.isUpperCase(name.charAt(0)
* |&& Character.isLetter(name.charAt(i)) && * |&& Character.isLetter(name.charAt(i)) &&
@@ -425,14 +443,14 @@ public class Worm extends GameObject {
} }
/** /**
* set the name of the worm tot the given name * Set the name of the worm tot the given name.
* *
* @param name * @param name
* the new name for the worm * The new name for the worm.
* @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
* @throws IllegalNameException * @throws IllegalNameException
* the given name is not a valid name for any worm * The given name is not a valid name for any worm.
* |! isValidName(name) * |! isValidName(name)
*/ */
@Raw @Raw
@@ -446,7 +464,7 @@ public class Worm extends GameObject {
} }
/** /**
* this variable contains the name of the worm * This variable contains the name of the worm.
*/ */
private String name; private String name;