This commit is contained in:
Leen Dereu
2018-02-27 12:43:36 +01:00

View File

@@ -1,3 +1,4 @@
import be.kuleuven.cs.som.annotate.*;
public class Worm { public class Worm {
@@ -97,7 +98,7 @@ public class Worm {
/** /**
* @param orientation * @param orientation
* *
*/ */
public void setOrientation(double orientation) { public void setOrientation(double orientation) {
@@ -153,39 +154,39 @@ public class Worm {
this.maxPoints = (int) Math.round(maxPoints); this.maxPoints = (int) Math.round(maxPoints);
setPoints(this.points); setPoints(this.points);
} }
/** /**
* @param NumberSteps * @param numberSteps ...
* the number of steps the worm should take * the number of steps the worm should take
* *
* @post the new x-coordinate schould be the old one plus the number of steps multiplied * @post the new x-coordinate schould be the old one plus the number of steps multiplied
* with the distance of a step in the x-orientation * with the distance of a step in the x-orientation
* |new.CoordX = CoordX + NumberSteps * distanceX * |new.CoordX = CoordX + NumberSteps * distanceX
* @post the new y-coordinate schould be the old one plus the number of steps multiplied * @post the new y-coordinate schould be the old one plus the number of steps multiplied
* with the distance of a step in the y-orientation * with the distance of a step in the y-orientation
* |new.CoordY = CoordY + NumberSteps * distanceY * |new.CoordY = CoordY + NumberSteps * distanceY
* *
* @throws IllegalArgumentException * @throws IllegalArgumentException
* when the total of steps is lower then 0 * when the total of steps is lower then 0
* |NumberSteps < 0 * |NumberSteps < 0
*/ */
public void move(int numberSteps) { public void move(int numberSteps) {
if (numberSteps < 0) if (numberSteps < 0)
throw new IllegalArgumentException(); throw new IllegalArgumentException();
double distanceX = this.radius * Math.cos(this.orientation); double distanceX = this.radius * Math.cos(this.orientation);
double distanceY = this.radius * Math.sin(this.orientation); double distanceY = this.radius * Math.sin(this.orientation);
setCoordX(this.coordX + numberSteps * distanceX); setCoordX(this.coordX + numberSteps * distanceX);
setCoordY(this.coordY + numberSteps * distanceY); setCoordY(this.coordY + numberSteps * distanceY);
} }
/** /**
* @param angleToAdd * @param angleToAdd
* the angle that must be added to the orientation * the angle that must be added to the orientation
* *
* @pre the angle to add must be between 0 and 2pi (including 0) * @pre the angle to add must be between 0 and 2pi (including 0)
* |0 <= angleToAdd < 2pi * |0 <= angleToAdd < 2pi
* *
* @post the new orientation is the old orientation plus the given angle * @post the new orientation is the old orientation plus the given angle
* |new.orientation = orientation + angleToAdd * |new.orientation = orientation + angleToAdd
* @post the resulting angle (= the new orientation) must be between 0 and 2pi (including 0) * @post the resulting angle (= the new orientation) must be between 0 and 2pi (including 0)