From 76bc41cba35f6c6a64a2c44fe0d5f76f19215413 Mon Sep 17 00:00:00 2001 From: Leen Dereu Date: Mon, 16 Apr 2018 21:04:28 +0200 Subject: [PATCH] Documentatie move methode --- OGP1718-Worms/src/worms/model/World.java | 3 ++ OGP1718-Worms/src/worms/model/Worm.java | 51 +++++++++++++----------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/OGP1718-Worms/src/worms/model/World.java b/OGP1718-Worms/src/worms/model/World.java index 43e945b..0fb2618 100644 --- a/OGP1718-Worms/src/worms/model/World.java +++ b/OGP1718-Worms/src/worms/model/World.java @@ -5,6 +5,8 @@ import worms.util.Coordinate; import java.util.*; import java.util.stream.Collectors; +import org.omg.PortableServer.ServantActivatorOperations; + public class World { public World(double width, double height, boolean[][] map) { @@ -44,6 +46,7 @@ public class World { throw new IllegalStateException("No worms"); } + getWormList().get(this.activeWorm).setActionPoints((long) getWormList().get(this.activeWorm).getMass()); this.activeWorm++; if (this.activeWorm == getWormList().size()) { this.activeWorm = 0; diff --git a/OGP1718-Worms/src/worms/model/Worm.java b/OGP1718-Worms/src/worms/model/Worm.java index 4cbf6c4..a123702 100644 --- a/OGP1718-Worms/src/worms/model/Worm.java +++ b/OGP1718-Worms/src/worms/model/Worm.java @@ -320,7 +320,7 @@ public class Worm extends GameObject { * |this.actionPoints = actionPoints; */ @Raw - private void setActionPoints(long actionPoints) { + public void setActionPoints(long actionPoints) { if (actionPoints > getMaxActionPoints()) actionPoints = getMaxActionPoints(); else if (actionPoints < 0) @@ -477,28 +477,19 @@ public class Worm extends GameObject { //=================================================================================== /** - * move the worm for the given number of steps - * - * @post the x-coordinate of the new location of the worm should be the location of - * the old x-coordinate plus the number of steps multiplied with the distance - * that the x-coordinate should move (distance is equal to the radius multiplied - * with the cosinus of the orientation) - * |distanceX = this.radius * cos(getOrientation()) - * |new.xCoordinate = getLocation().getX() + numberSteps * distanceX - * @post the y-coordinate of the new location of the worm should be the location of - * the old y-coordinate plus the number of steps multiplied with the distance - * that the y-coordinate should move (distance is equal to the radius multiplied - * with the sinus of the orientation) - * |distanceY = this.radius * sin(getOrientation()) - * |new.yCoordinate = getLocation().getY() + numberSteps * distanceY - * @post the current value of action actionPoints has changed. The current value of action actionPoints - * minus the cost of moving (abs(cos(theta)) + abs(4 sin(theta))) - * |cost = (long) ceil(abs(cos(getOrientation())) + abs(4 * sin(getOrientation()))) * numberSteps - * |subtractActionPoints(cost) + * Move the worm for the given number of steps. + * + * @post The newlocation of the worm is the furthest possible step the worm can take. Depending on its + * radius and surroundings. + * |new.getLocation() = FurthestLocationInDirection + * @post The action points of the worm are substrated with the cost of the step. This cost is equal to + * the absolute value of the distance multiplied with the cosinus of the new direction plus the absolute + * value of 4 multiplied with the distance and the sinus of the new direction. + * |new.getActionPoints() == old.getActionPoints() - (abs(distance * cos(new.getOrientation()) + abs(4 * distance * sin(new.getOrientation()))) + * * @throws IllegalArgumentException - * when the total of steps is lower then 0 or when the cost of action point is more - * then the current value of action point - * |NumberSteps < 0 || cost > this.actionPoints + * The cost of the step is bigger then the worms current action points. + * |cost > getActionPoints() */ public void move() throws IllegalArgumentException { @@ -516,8 +507,16 @@ public class Worm extends GameObject { } /** - * - * @return + * Gives the biggest step possible for the worm. + * + * @param direction + * The direction of the worm. + * @param maxDistance + * The maximum distance the worm can move. + * + * @return The furthest possible location for the given direction and maximum distance. + * The new location has to be passable. + * |result == (0 <= new.getLocation() <= maxDistance) && (world.isPassable(new.getLocation(), radius)) */ public Coordinate getFurthestLocationInDirection(double direction, double maxDistance) { Coordinate currentLocation = getLocation(); @@ -548,6 +547,10 @@ public class Worm extends GameObject { return nextLoc; } + /** + * + * @return + */ public double getFurthestLocationDirection() { Coordinate location = getLocation(); double direction = getOrientation();