diff --git a/OGP1718-Worms/src/worms/facade/Facade.java b/OGP1718-Worms/src/worms/facade/Facade.java index 457d753..4fdd205 100644 --- a/OGP1718-Worms/src/worms/facade/Facade.java +++ b/OGP1718-Worms/src/worms/facade/Facade.java @@ -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); } } diff --git a/OGP1718-Worms/src/worms/model/Worm.java b/OGP1718-Worms/src/worms/model/Worm.java index 765990a..0bddf6c 100644 --- a/OGP1718-Worms/src/worms/model/Worm.java +++ b/OGP1718-Worms/src/worms/model/Worm.java @@ -13,26 +13,25 @@ import java.util.concurrent.ThreadLocalRandom; /** * A class with the specifications of the worm * - * @author Arthur Bols and Leen Dereu - *

- * Arthur Bols 1e bachelor Informatica - * Leen Dereu 1e bachelor Informatica - *

+ * @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. - * |isValidOrientation(getOrientation()) - * @invar The radius of the worm mus be a valid radius. - * |isValidMinRadius(getRadius()) - * @invar The mass of the worm must bef a valid mass. - * |isValidMass(getMass()) - * @invar The value of the action points of the worm must be a valid value for action points. - * |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()) + * + * @invar The location of the worm must be a valid location. + * |isValidLocation(getLocation()) + * @invar The orientation of the worm must be a valid location. + * |isValidOrientation(getOrientation()) + * @invar The radius of the worm mus be a valid radius. + * |isValidMinRadius(getRadius()) + * @invar The mass of the worm must bef a valid mass. + * |isValidMass(getMass()) + * @invar The value of the action points of the worm must be a valid value for action points. + * |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 3.0 */ 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 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 + * |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 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. - * |new.getName() == name + * |new.getName() == name * @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 + * |new.getTeam() == team */ @Raw 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 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) + * + * @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. * |!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. - * |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 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) + * |isValidOrientation(orientation) + * * @post The new orientation of the worm must be equal to the given orientation. - * |new.getOrientation() == orientation + * |new.getOrientation() == orientation */ @Raw private void setOrientation(double orientation) { - if (!isValidOrientation(orientation)) throw new IllegalArgumentException(); + assert isValidOrientation(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. * * @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) { 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. * * @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)) + * |result == ((!Double.isNaN(radius)) && (radius > 0)) */ public static boolean isValidMinRadius(double minRadius) { 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. * * @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. * |! canHaveAsMinRadius(radius) - * @post The new radius of the worm is equal to the given radius. - * |new.getRadius() == 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(); - * |else if (actionPoints < 0) - * | actionPoints = 0; - * |this.actionPoints = actionPoints; + * 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() + * |else if (actionPoints < 0) + * | 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) {