added turn

This commit is contained in:
Leen Dereu
2018-02-27 12:26:43 +01:00
parent 3545ff3894
commit 82e1cfa8d4

View File

@@ -149,25 +149,42 @@ public class Worm {
}
/**
*
* @param NumberSteps
*
* @post ...
* @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
* |new.CoordX = CoordX + NumberSteps * distanceX
*
* @post
* @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
* |new.CoordY = CoordY + NumberSteps * distanceY
*
* @throws IllegalArgumentException
* when the total of steps is lower then zero
* when the total of steps is lower then 0
* |NumberSteps < 0
*/
public void move(int NumberSteps) {
if (NumberSteps < 0)
public void move(int numberSteps) {
if (numberSteps < 0)
throw new IllegalArgumentException();
double distanceX = getRadius() * Math.cos(getOrientation());
double distanceY = getRadius() * Math.sin(getOrientation());
setCoordX(getCoordX() + NumberSteps * distanceX);
setCoordY(getCoordY() + NumberSteps * distanceY);
setCoordX(getCoordX() + numberSteps * distanceX);
setCoordY(getCoordY() + numberSteps * distanceY);
}
/**
* @param angleToAdd
* the angle that must be added to the orientation
*
* @pre the angle to add must be between 0 and 2pi (including 0)
* |0 <= angleToAdd < 2pi
*
* @post the new orientation is the old orientation plus the given angle
* |new.orientation = orientation + angleToAdd
* @post the resulting angle (= the new orientation) must be between 0 and 2pi (including 0)
* |0 <= new.orientation < 2pi
*/
public void turn(double angleToAdd) {
assert 0 <= angleToAdd && angleToAdd < 2 * Math.PI;
}
}