diff --git a/OGP1718-Worms/src/worms/model/Food.java b/OGP1718-Worms/src/worms/model/Food.java index 8b18b42..bde6246 100644 --- a/OGP1718-Worms/src/worms/model/Food.java +++ b/OGP1718-Worms/src/worms/model/Food.java @@ -3,7 +3,11 @@ package worms.model; import worms.util.Coordinate; public class Food extends GameObject { - + /** + * + * @param world + * @param location + */ public Food(World world, double[] location) { super(world, location, 0.2); diff --git a/OGP1718-Worms/src/worms/model/Worm.java b/OGP1718-Worms/src/worms/model/Worm.java index 9dd4b94..8cb3743 100644 --- a/OGP1718-Worms/src/worms/model/Worm.java +++ b/OGP1718-Worms/src/worms/model/Worm.java @@ -25,8 +25,10 @@ import java.util.concurrent.ThreadLocalRandom; * |isValidValueActionPoints(getActionPoints()) * @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()) * - * @version 1.0 + * @version 2.0 * @author Arthur Bols and Leen Dereu * * Arthur Bols 1e bachelor Informatica @@ -40,26 +42,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 - * The world this worm belongs to + * The world this worm belongs to. * @param location - * the location for the new worm + * The location for the new worm. + * @param direction + * The direction for the new worm. * @param name - * the name for the new worm + * The name for the new worm. * @param radius - * the radius for the new worm + * The radius for the new worm. * @param team - * The team of the new worm - * @post the new location of the worm is equal to the given location + * 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. * |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 + * @post The new direction of the worm is equal to the given direction. + * |new.getDirection() == direction + * @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 + * @post The new radius of the worm is equal to the given radius. * |new.getRadius() == radius + * @post The new team of the worm is equal to the given team. + * |new.getTeam() == team */ @Raw public Worm(World world, double[] location, double direction, double radius, String name, Team team) { @@ -71,38 +80,49 @@ public class Worm extends GameObject { /** *initialize the new worm with given location, orientation, name, radius and minimum radius * + * @param world + * The world for the new worm. * @param location - * the location for the new worm + * The location for the new worm. * @param orientation - * the orientation for the new worm + * The orientation for the new worm. * @param name - * the name for the new worm + * The name for the new worm. * @param radius - * the radius for the new worm + * The radius for the new worm. * @param minRadius - * the minimum radius the new worm can have - * @post the new location of the worm is equal to the given location + * The minimum radius the new worm can have. + * @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 - * @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 - * @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 - * @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 - * @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 - * @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 - * the given location is not a valid location for a worm + * 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 + * 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 + * 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 + * The given name is not a valid name for a worm. * |isValidName(name) */ @Raw @@ -138,9 +158,9 @@ public class Worm extends GameObject { //=================================================================================== /** - * Return the orientation of the worm - * the orientation of a worm expresses the direction in which - * the worm is looking + * Return the orientation of the worm. + * The orientation of a worm expresses the direction in which + * the worm is looking. */ @Basic @Raw public double getOrientation() { @@ -148,18 +168,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; /** - * 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 - * @pre the given orientation must be a valid orientation for any worm + * 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 + * @post The new orientation of the worm must be equal to the given orientation. * |new.getOrientation() == orientation */ @Raw @@ -169,11 +189,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 - * the orientation to check - * @return True if and only if the orientation is bigger then and smaller then 2pi + * 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 ) */ public static boolean isValidOrientation(double newOrientation) { @@ -187,14 +207,12 @@ public class Worm extends GameObject { // 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 - * the radius to check - * @return True if and only if the radius is a number and the radius is bigger then 0 + * 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)) */ public static boolean isValidMinRadius(double minRadius) { @@ -202,14 +220,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 - * the new radius for the worm - * @post the new radius of the worm is equal to the given radius + * The new radius for the worm. + * @post The new radius of the worm is equal to the given radius. * |new.getRadius() == radius * @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) */ @Raw @Override @@ -224,9 +242,9 @@ public class Worm extends GameObject { } /** - * Return the minimum radius the worm can have - * the minimum radius of the worm expresses the minimum length - * of half of the width of the worm + * Return the minimum radius the worm can have. + * The minimum radius of the worm expresses the minimum length + * of half of the width of the worm. */ @Basic @Raw public double getMinRadius() { @@ -234,17 +252,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; /** - * 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 + * 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 + * (or equal) and the radius is a number. * |result == (radius >= getMinRadius() && !Double.isNaN(radius)) */ @Raw @@ -253,8 +271,8 @@ public class Worm extends GameObject { } /** - * Return the mass of the worm - * the mass of the worm expresses the weight of the worm + * Return the mass of the worm. + * The mass of the worm expresses the weight of the worm. */ @Basic @Raw public double getMass() { @@ -270,8 +288,8 @@ public class Worm extends GameObject { //=================================================================================== /** - * Return the current action points of the worm - * the action points identifies the energy of the worm + * Return the current action points of the worm. + * The action points identifies the energy of the worm. */ @Basic @Raw public long getActionPoints() { @@ -279,8 +297,8 @@ public class Worm extends GameObject { } /** - * Return the maximum of action points of the worm - * the maximum action points identifies the maximum energy of the worm + * Return the maximum of action points of the worm. + * The maximum action points identifies the maximum energy of the worm. */ @Basic @Raw public long getMaxActionPoints() { @@ -288,14 +306,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 - * the new points for the worm - * @post if the given points are bigger then the maximum points, the current points + * 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 + * maximum points and 0, the current points is equal to the given points. * |if (actionPoints > getMaxActionPoints()) * | actionPoints = getMaxActionPoints(); * |else if (actionPoints < 0) @@ -313,11 +331,11 @@ public class Worm extends GameObject { } /** - *substract the current points of the worm + * Substract the current points of the worm. * * @param delta - * the value which should be decreased - * @post the current points are set to the old current points minus the given value + * The value which should be decreased. + * @post The current points are set to the old current points minus the given value. * |setActionPoints(getActionPoints() - delta) */ public void decreaseActionPoints (long delta) { @@ -326,23 +344,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; /** - * 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; /** - * 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 - * @post the new maximum points is set to the given maximum points (as an integer) + * 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) - * @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) */ @Raw @@ -352,11 +370,11 @@ public class Worm extends GameObject { } /** - * substract the current points of the worm + * Substract the current points of the worm. * * @param value - * the value which should be subtracted - * @post the current points are set to the old current points minus the given value + * The value which should be subtracted. + * @post The current points are set to the old current points minus the given value. * |setActionPoints(getActionPoints() - value) */ private void subtractActionPoints (long value) { @@ -365,12 +383,12 @@ public class Worm extends GameObject { } /** - * substract the current points of the worm + * 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 + * 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)) */ private void subtractActionPoints (double angle) { @@ -387,8 +405,8 @@ public class Worm extends GameObject { //=================================================================================== /** - * Return the name of the worm - * the name of the worm expresses the identity of the worm + * Return the name of the worm. + * The name of the worm expresses the identity of the worm. */ @Basic @Immutable @Raw public String getName() { @@ -396,13 +414,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 - * the name to check + * 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 " "" " + * of letters, " ", " ' " and " "" ". * |for (i = 0; i < name.length(); i++) * |result == (name.length() > 2 && Character.isUpperCase(name.charAt(0) * |&& Character.isLetter(name.charAt(i)) && @@ -426,14 +444,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 - * the new name for the worm - * @post the new name of the worm is equal to the given name + * The new name for the worm. + * @post The new name of the worm is equal to the given name. * |new.getName() == name * @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) */ @Raw @@ -447,7 +465,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;