From 82e1cfa8d402299ae950019631465d2e4b2238e2 Mon Sep 17 00:00:00 2001 From: Leen Dereu Date: Tue, 27 Feb 2018 12:26:43 +0100 Subject: [PATCH] added turn --- src/Worm.java | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/Worm.java b/src/Worm.java index a975a1b..f35a646 100644 --- a/src/Worm.java +++ b/src/Worm.java @@ -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; + } }