added move

This commit is contained in:
Leen Dereu
2018-02-27 11:37:24 +01:00
parent 83ae8d18fb
commit da56d42f23

View File

@@ -151,4 +151,27 @@ public class Worm {
this.maxPoints = (int) Math.round(maxPoints); this.maxPoints = (int) Math.round(maxPoints);
setPoints(this.points); setPoints(this.points);
} }
/**
*
* @param NumberSteps
*
* @post ...
* |new.CoordX = CoordX + NumberSteps * distanceX
*
* @post
* |new.CoordY = CoordY + NumberSteps * distanceY
*
* @throws IllegalArgumentException
* when the total of steps is lower then zero
* |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);
}
} }