Merge branch 'master' of gitlab.principis.be:OGP/worms

This commit is contained in:
2018-04-16 21:04:41 +02:00
2 changed files with 30 additions and 24 deletions

View File

@@ -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;

View File

@@ -321,7 +321,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)
@@ -478,28 +478,19 @@ public class Worm extends GameObject {
//===================================================================================
/**
* move the worm for the given number of steps
* 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())))
*
* @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)
* @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 {
@@ -519,8 +510,16 @@ public class Worm extends GameObject {
}
/**
* Gives the biggest step possible for the worm.
*
* @return
* @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();
@@ -551,6 +550,10 @@ public class Worm extends GameObject {
return nextLoc;
}
/**
*
* @return
*/
public double getFurthestLocationDirection() {
Coordinate location = getLocation();
double direction = getOrientation();