added turn
This commit is contained in:
@@ -149,25 +149,42 @@ public class Worm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param NumberSteps
|
* @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
|
* |new.CoordX = CoordX + NumberSteps * distanceX
|
||||||
*
|
* @post the new y-coordinate schould be the old one plus the number of steps multiplied
|
||||||
* @post
|
* 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 zero
|
* 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 = getRadius() * Math.cos(getOrientation());
|
double distanceX = getRadius() * Math.cos(getOrientation());
|
||||||
double distanceY = getRadius() * Math.sin(getOrientation());
|
double distanceY = getRadius() * Math.sin(getOrientation());
|
||||||
setCoordX(getCoordX() + NumberSteps * distanceX);
|
setCoordX(getCoordX() + numberSteps * distanceX);
|
||||||
setCoordY(getCoordY() + NumberSteps * distanceY);
|
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user