added move
This commit is contained in:
@@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user