From d1617e9cf3214948d8d1c328d86bea3dc7bc52a1 Mon Sep 17 00:00:00 2001 From: Arthur Bols Date: Fri, 9 Mar 2018 22:30:42 +0100 Subject: [PATCH] small improvements --- OGP1718-Worms/src/worms/model/Worm.java | 96 +++++++++++++------------ 1 file changed, 49 insertions(+), 47 deletions(-) diff --git a/OGP1718-Worms/src/worms/model/Worm.java b/OGP1718-Worms/src/worms/model/Worm.java index 7e0835f..9e8cdb7 100644 --- a/OGP1718-Worms/src/worms/model/Worm.java +++ b/OGP1718-Worms/src/worms/model/Worm.java @@ -295,6 +295,7 @@ public class Worm { return this.actionPoints; } + @Basic public long getMaxActionPoints() { return this.maxActionPoints; } @@ -410,10 +411,41 @@ public class Worm { * Return the name of the worm * the name of the worm expresses the identity of the worm */ + @Basic public String getName() { return this.name; } + /** + * 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))) + */ + public static int isValidName (String name) { + + if (name.length() < 2 || !Character.isUpperCase(name.charAt(0))) { + return 0; + } + String allowedCharacters = "'\" "; + + for (int i = 0; i < name.length(); i++) { + if (!Character.isLetter(name.charAt(i))) { + if (allowedCharacters.indexOf(name.charAt(i)) == -1) { + return i; + } + } + } + return -1; + } + /** * set the name of the worm tot the given name * @@ -434,46 +466,16 @@ public class Worm { this.name = name; } - /** - * 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))) - */ - public static int isValidName (String name) { - - if (name.length() < 2 || !Character.isUpperCase(name.charAt(0))) { - return 0; - } - String allowedCharacters = "'\" "; - - for (int i = 0; i < name.length(); i++) { - if (!Character.isLetter(name.charAt(i))) { - if (allowedCharacters.indexOf(name.charAt(i)) == -1) { - return i; - } - } - } - return -1; - } - /** * this variable contains the name of the worm */ private String name; - //=================================================================================== // endregion + // region move //=================================================================================== @@ -551,7 +553,7 @@ public class Worm { /** * * @param angle - * @return + * @return ... */ private boolean canTurn(double angle) { return 0 <= angle && angle < (2 * PI) && @@ -596,21 +598,10 @@ public class Worm { this.actionPoints = 0; } - /** - * Return a boolean whether the worm can jump or not - * - * @return True if and only if the action actionPoints is bigger then 0 and the orientation - * is lower then pi - * |result == this.actionPoints > 0 && this.orientation < Math.PI - */ - private boolean canJump() { - return this.actionPoints > 0 && this.orientation < PI; - } - /** * Return the time the worm will jump - * - * @return the time the worm will jump. The distance divided by the velocity multiplied + * + * @return the time the worm will jump. The distance divided by the velocity multiplied * with the cosinus of the orientation * |jumpDistance(this.jumpVelocity) / (this.jumpVelocity * Math.cos(this.orientation)) */ @@ -623,7 +614,7 @@ public class Worm { } /** - * + * * @param deltaTime ... * @return Tuple */ @@ -634,7 +625,18 @@ public class Worm { return Tuple.create(this.location.item1 + this.jumpVelocity() * cos(this.orientation) * deltaTime, this.location.item2 + this.jumpVelocity() * sin(this.orientation) * deltaTime - 0.5 * G * pow(deltaTime, 2)); } - + + /** + * Return a boolean whether the worm can jump or not + * + * @return True if and only if the action actionPoints is bigger then 0 and the orientation + * is lower then pi + * |result == this.actionPoints > 0 && this.orientation < Math.PI + */ + private boolean canJump() { + return this.actionPoints > 0 && this.orientation < PI; + } + /** * Return the distance the worm will jump *