fixed annotations

This commit is contained in:
2018-05-25 04:25:05 +02:00
parent 4cf6e67a78
commit cc277a045f
8 changed files with 132 additions and 43 deletions

View File

@@ -1,5 +1,7 @@
package worms.model; package worms.model;
import be.kuleuven.cs.som.annotate.Basic;
import be.kuleuven.cs.som.annotate.Raw;
import worms.util.Coordinate; import worms.util.Coordinate;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
@@ -24,7 +26,8 @@ public class Bazooka extends Projectile {
* @post ... * @post ...
* |new.getForce() == calcForce(worm.getActionPoints()) * |new.getForce() == calcForce(worm.getActionPoints())
*/ */
protected Bazooka(Worm worm) { @Raw
public Bazooka(Worm worm) {
super(worm, 300, calcForce(worm.getActionPoints())); super(worm, 300, calcForce(worm.getActionPoints()));
} }
@@ -35,6 +38,7 @@ public class Bazooka extends Projectile {
* |result == nb * |result == nb
*/ */
@Override @Override
@Raw
protected int getRandomHitPoints() { protected int getRandomHitPoints() {
int nb =ThreadLocalRandom.current().nextInt(15) / 2; int nb =ThreadLocalRandom.current().nextInt(15) / 2;
nb += (nb % 2 == 0 ? 1:0); nb += (nb % 2 == 0 ? 1:0);
@@ -46,7 +50,9 @@ public class Bazooka extends Projectile {
* |result == this.hitPoints * (int) this.force * |result == this.hitPoints * (int) this.force
* *
*/ */
@Basic
@Override @Override
@Raw
protected int getImpactHitPoints() { protected int getImpactHitPoints() {
return this.hitPoints * (int) this.force; return this.hitPoints * (int) this.force;
} }

View File

@@ -1,5 +1,7 @@
package worms.model; package worms.model;
import be.kuleuven.cs.som.annotate.Basic;
import be.kuleuven.cs.som.annotate.Raw;
import worms.util.Coordinate; import worms.util.Coordinate;
/** /**
@@ -23,6 +25,7 @@ public class Food extends GameObject {
* @post ... * @post ...
* |setMass(getRadius(), 150) * |setMass(getRadius(), 150)
*/ */
@Raw
public Food(World world, double[] location) { public Food(World world, double[] location) {
super(world, location, 0.2); super(world, location, 0.2);
@@ -35,6 +38,8 @@ public class Food extends GameObject {
* @return ... * @return ...
* |result == this.poisonous * |result == this.poisonous
*/ */
@Basic
@Raw
public boolean isPoisonous() { public boolean isPoisonous() {
return this.poisonous; return this.poisonous;
} }
@@ -43,6 +48,7 @@ public class Food extends GameObject {
* @post ... * @post ...
* |poisonous == true * |poisonous == true
*/ */
@Raw
public void poison() { public void poison() {
this.poisonous = true; this.poisonous = true;
} }
@@ -51,6 +57,7 @@ public class Food extends GameObject {
* @post ... * @post ...
* |poisonous == false * |poisonous == false
*/ */
@Raw
public void heal() { public void heal() {
this.poisonous = false; this.poisonous = false;
} }

View File

@@ -1,5 +1,6 @@
package worms.model; package worms.model;
import be.kuleuven.cs.som.annotate.Basic;
import be.kuleuven.cs.som.annotate.Raw; import be.kuleuven.cs.som.annotate.Raw;
import worms.util.Coordinate; import worms.util.Coordinate;
@@ -28,7 +29,8 @@ public abstract class GameObject {
* @post ... * @post ...
* |setRadius(radius) * |setRadius(radius)
*/ */
protected GameObject(World world, double[] location, double radius) { @Raw
public GameObject(World world, double[] location, double radius) {
this(world, Coordinate.create(location), radius); this(world, Coordinate.create(location), radius);
} }
@@ -51,7 +53,8 @@ public abstract class GameObject {
* @throws IllegalArgumentException ... * @throws IllegalArgumentException ...
* |!isValidLocation(location) * |!isValidLocation(location)
*/ */
protected GameObject(World world, Coordinate location, double radius) { @Raw
public GameObject(World world, Coordinate location, double radius) {
if (!isValidLocation(location)) throw new IllegalArgumentException("Illegal location"); if (!isValidLocation(location)) throw new IllegalArgumentException("Illegal location");
setLocation(location); setLocation(location);
setRadius(radius); setRadius(radius);
@@ -70,6 +73,8 @@ public abstract class GameObject {
* @return ... * @return ...
* |result == this.world * |result == this.world
*/ */
@Basic
@Raw
public World getWorld() { public World getWorld() {
return this.world; return this.world;
} }
@@ -155,10 +160,10 @@ public abstract class GameObject {
if (!isValidLocation(location)) { if (!isValidLocation(location)) {
if (!(location.getX() - radius < 0) || if (!(location.getX() - radius < 0) ||
!(location.getX() + radius > getWorld().getWidth()) || !(location.getX() + radius > this.world.getWidth()) ||
!(location.getY() + radius > getWorld().getHeight()) || !(location.getY() + radius > this.world.getHeight()) ||
!(location.getY() - radius < 0)) { !(location.getY() - radius < 0)) {
world.remove(this); this.world.remove(this);
} else throw new IllegalArgumentException(); } else throw new IllegalArgumentException();
} }
this.location = location; this.location = location;
@@ -188,7 +193,6 @@ public abstract class GameObject {
* | getWorld().isPassable(location) * | getWorld().isPassable(location)
*/ */
protected boolean isValidLocation(Coordinate location) { protected boolean isValidLocation(Coordinate location) {
double radius = getRadius();
if (world == null) { if (world == null) {
return !Double.isNaN(location.getX()) && return !Double.isNaN(location.getX()) &&
@@ -196,10 +200,10 @@ public abstract class GameObject {
} }
return !Double.isNaN(location.getX()) && return !Double.isNaN(location.getX()) &&
!Double.isNaN(location.getY()) && !Double.isNaN(location.getY()) &&
!(location.getX() - radius < 0) && !(location.getX() - this.radius < 0) &&
!(location.getX() + radius > getWorld().getWidth()) && !(location.getX() + this.radius > this.world.getWidth()) &&
!(location.getY() + radius > getWorld().getHeight()) && !(location.getY() + this.radius > this.world.getHeight()) &&
!(location.getY() - radius < 0) && getWorld().isPassable(location); !(location.getY() - this.radius < 0) && this.world.isPassable(location);
} }
protected Coordinate location; protected Coordinate location;
@@ -215,6 +219,8 @@ public abstract class GameObject {
* @return ... * @return ...
* |result == this.radius * |result == this.radius
*/ */
@Basic
@Raw
public double getRadius() { public double getRadius() {
return this.radius; return this.radius;
} }
@@ -228,6 +234,7 @@ public abstract class GameObject {
* @throws IllegalArgumentException ... * @throws IllegalArgumentException ...
* |!canHaveAsRadius(radius) * |!canHaveAsRadius(radius)
*/ */
@Raw
protected void setRadius(double radius) { protected void setRadius(double radius) {
if (!canHaveAsRadius(radius)) throw new IllegalArgumentException(); if (!canHaveAsRadius(radius)) throw new IllegalArgumentException();
this.radius = radius; this.radius = radius;
@@ -241,6 +248,7 @@ public abstract class GameObject {
* @return ... * @return ...
* |result == !Double.isNaN(radius) && radius > 0 * |result == !Double.isNaN(radius) && radius > 0
*/ */
@Basic
@Raw @Raw
private boolean canHaveAsRadius(double radius) { private boolean canHaveAsRadius(double radius) {
return !Double.isNaN(radius) && radius > 0; return !Double.isNaN(radius) && radius > 0;
@@ -257,6 +265,8 @@ public abstract class GameObject {
* @return ... * @return ...
* |result == this.mass * |result == this.mass
*/ */
@Basic
@Raw
public double getMass() { public double getMass() {
return this.mass; return this.mass;
} }
@@ -268,6 +278,7 @@ public abstract class GameObject {
* @post ... * @post ...
* |new.getMass() == rho * (4.0 / 3.0 * PI * pow(radius, 3.0) * |new.getMass() == rho * (4.0 / 3.0 * PI * pow(radius, 3.0)
*/ */
@Raw
protected void setMass(double radius, double rho) { protected void setMass(double radius, double rho) {
this.mass = rho * (4.0 / 3.0 * PI * pow(radius, 3.0)); this.mass = rho * (4.0 / 3.0 * PI * pow(radius, 3.0));
@@ -352,6 +363,8 @@ public abstract class GameObject {
* @return ... * @return ...
* |result == this.terminated * |result == this.terminated
*/ */
@Basic
@Raw
public boolean isTerminated() { public boolean isTerminated() {
return this.terminated; return this.terminated;
} }
@@ -363,6 +376,7 @@ public abstract class GameObject {
* |if (this.world != null) * |if (this.world != null)
* | this.world.remove(this) * | this.world.remove(this)
*/ */
@Basic
public void terminate() { public void terminate() {
this.terminated = true; this.terminated = true;
if (this.world != null) { if (this.world != null) {

View File

@@ -1,5 +1,7 @@
package worms.model; package worms.model;
import be.kuleuven.cs.som.annotate.Basic;
import be.kuleuven.cs.som.annotate.Raw;
import worms.internal.gui.game.IActionHandler; import worms.internal.gui.game.IActionHandler;
import worms.programs.Expression; import worms.programs.Expression;
import worms.programs.Procedure; import worms.programs.Procedure;
@@ -12,20 +14,6 @@ import static java.lang.Math.toDegrees;
public class Program { public class Program {
private final Map<String, Statement> procMap;
private final Map<String, Object> varMap = new HashMap<>();
private final List<Object> printList = new ArrayList<>();
private Stack<Statement.Type> currentType = new Stack<>();
private int inLoop = 0;
private int inProcedure = 0;
private boolean breakProcedure = false;
private boolean enoughAP = true;
private IActionHandler actionHandler;
private Worm worm;
private final Statement main;
public Program(List<Procedure> proc, Statement main) { public Program(List<Procedure> proc, Statement main) {
this.main = main; this.main = main;
@@ -36,17 +24,12 @@ public class Program {
public Worm getWorm() { public Worm getWorm() {
return this.worm; return this.worm;
} }
public Map<String, Object> getVariables() { public Map<String, Object> getVariables() {
return this.varMap; return this.varMap;
} }
protected void setWorm(Worm worm) {
this.worm = worm;
}
protected void setActionHandler(IActionHandler actionHandler) {
this.actionHandler = actionHandler;
}
protected void execute() { public void execute() {
enoughAP = true; enoughAP = true;
@@ -92,6 +75,13 @@ public class Program {
return printList; return printList;
} }
protected void setWorm(Worm worm) {
this.worm = worm;
}
protected void setActionHandler(IActionHandler actionHandler) {
this.actionHandler = actionHandler;
}
private boolean breakLoop = false; private boolean breakLoop = false;
@SuppressWarnings({"unchecked", "SuspiciousMethodCalls"}) @SuppressWarnings({"unchecked", "SuspiciousMethodCalls"})
@@ -239,11 +229,6 @@ public class Program {
} }
private class CallStackNode { private class CallStackNode {
private Iterator<Statement> statementIterator; private Iterator<Statement> statementIterator;
private Statement lastStatement; private Statement lastStatement;
@@ -253,5 +238,20 @@ public class Program {
lastStatement = ls; lastStatement = ls;
} }
} }
private final Map<String, Statement> procMap;
private final Map<String, Object> varMap = new HashMap<>();
private final List<Object> printList = new ArrayList<>();
private Stack<Statement.Type> currentType = new Stack<>();
private int inLoop = 0;
private int inProcedure = 0;
private boolean breakProcedure = false;
private boolean enoughAP = true;
private IActionHandler actionHandler;
private Worm worm;
private final Statement main;
} }

View File

@@ -1,5 +1,7 @@
package worms.model; package worms.model;
import be.kuleuven.cs.som.annotate.Basic;
import be.kuleuven.cs.som.annotate.Raw;
import worms.util.Coordinate; import worms.util.Coordinate;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
@@ -25,6 +27,7 @@ public class Rifle extends Projectile {
* @post ... * @post ...
* |new.getForce() == 1.5 * |new.getForce() == 1.5
*/ */
@Raw
public Rifle(Worm worm) { public Rifle(Worm worm) {
super(worm, 10, 1.5); super(worm, 10, 1.5);
} }
@@ -34,6 +37,7 @@ public class Rifle extends Projectile {
* |result == ThreadLocalRandom.current().nextInt(1,6) * 2 * |result == ThreadLocalRandom.current().nextInt(1,6) * 2
*/ */
@Override @Override
@Raw
protected int getRandomHitPoints() { protected int getRandomHitPoints() {
return ThreadLocalRandom.current().nextInt(1,6) * 2; return ThreadLocalRandom.current().nextInt(1,6) * 2;
} }
@@ -42,7 +46,9 @@ public class Rifle extends Projectile {
* @return ... * @return ...
* |result == this.hitPoints * |result == this.hitPoints
*/ */
@Basic
@Override @Override
@Raw
protected int getImpactHitPoints() { protected int getImpactHitPoints() {
return this.hitPoints; return this.hitPoints;
} }

View File

@@ -3,6 +3,8 @@ package worms.model;
import java.util.*; import java.util.*;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import be.kuleuven.cs.som.annotate.Basic;
import be.kuleuven.cs.som.annotate.Raw;
import worms.util.IllegalNameException; import worms.util.IllegalNameException;
import worms.util.TeamComparator; import worms.util.TeamComparator;
@@ -31,6 +33,7 @@ public class Team {
* |if (world != null) * |if (world != null)
* | world.addTeam(this) * | world.addTeam(this)
*/ */
@Raw
public Team (String name, World world) { public Team (String name, World world) {
setName(name); setName(name);
this.wormCollection = new TreeSet<>(new TeamComparator()); this.wormCollection = new TreeSet<>(new TeamComparator());
@@ -51,6 +54,7 @@ public class Team {
* | result == false * | result == false
* |result == this.getName().equals((Team) obj).getName()) * |result == this.getName().equals((Team) obj).getName())
*/ */
@Basic
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (!(obj instanceof Team)) return false; if (!(obj instanceof Team)) return false;
@@ -168,6 +172,7 @@ public class Team {
* @throws IllegalArgumentException If the worm is equal to null. * @throws IllegalArgumentException If the worm is equal to null.
* |worm == null * |worm == null
*/ */
@Basic
public boolean containsWorm(Worm worm) throws IllegalArgumentException { public boolean containsWorm(Worm worm) throws IllegalArgumentException {
if (worm == null) throw new IllegalArgumentException(); if (worm == null) throw new IllegalArgumentException();
return this.wormCollection.contains(worm); return this.wormCollection.contains(worm);
@@ -179,6 +184,7 @@ public class Team {
* @return All the worms of the team in a List. * @return All the worms of the team in a List.
* |result == ArrayList<>(this.wormCollection) * |result == ArrayList<>(this.wormCollection)
*/ */
@Basic
public List<Worm> getAllWormsList() { public List<Worm> getAllWormsList() {
return new ArrayList<>(this.wormCollection); return new ArrayList<>(this.wormCollection);
} }
@@ -189,6 +195,7 @@ public class Team {
* @return The number of worms in the team. * @return The number of worms in the team.
* |result == getAllWormsOfTeam().size() * |result == getAllWormsOfTeam().size()
*/ */
@Basic
public int getNbWorms() { public int getNbWorms() {
return this.wormCollection.size(); return this.wormCollection.size();
} }
@@ -266,6 +273,8 @@ public class Team {
* @return The name of the team. * @return The name of the team.
* |result == this.name * |result == this.name
*/ */
@Basic
@Raw
public String getName() { public String getName() {
return this.name; return this.name;
} }
@@ -309,6 +318,7 @@ public class Team {
* @post The variable terminated is set to true. * @post The variable terminated is set to true.
* |new.terminated = true * |new.terminated = true
*/ */
@Raw
public void terminate() { public void terminate() {
removeWormsFromTeam(this.wormCollection.toArray(new Worm[0])); removeWormsFromTeam(this.wormCollection.toArray(new Worm[0]));
@@ -322,6 +332,8 @@ public class Team {
* @return Of the team is terminated or not * @return Of the team is terminated or not
* |result == this.terminated * |result == this.terminated
*/ */
@Basic
@Raw
public boolean isTerminated() { public boolean isTerminated() {
return this.terminated; return this.terminated;
} }

View File

@@ -1,5 +1,7 @@
package worms.model; package worms.model;
import be.kuleuven.cs.som.annotate.Basic;
import be.kuleuven.cs.som.annotate.Raw;
import worms.util.Coordinate; import worms.util.Coordinate;
import java.util.*; import java.util.*;
@@ -36,6 +38,7 @@ public class World {
* @post ... * @post ...
* |new.gameObjets = new HashSet<>() * |new.gameObjets = new HashSet<>()
*/ */
@Raw
public World(double width, double height, boolean[][] map) { public World(double width, double height, boolean[][] map) {
if (!isValidDimension(width) || !isValidDimension(height) || map == null || map.length == 0) throw new IllegalArgumentException(); if (!isValidDimension(width) || !isValidDimension(height) || map == null || map.length == 0) throw new IllegalArgumentException();
@@ -55,6 +58,8 @@ public class World {
* @return ... * @return ...
* result = this.terminated * result = this.terminated
*/ */
@Basic
@Raw
public boolean isTerminated() { public boolean isTerminated() {
return this.terminated; return this.terminated;
} }
@@ -84,7 +89,8 @@ public class World {
// region game (Total) // region game (Total)
//=================================================================================== //===================================================================================
@Basic
@Raw
public boolean hasActiveGame() { public boolean hasActiveGame() {
return this.game; return this.game;
} }
@@ -101,6 +107,7 @@ public class World {
} }
@Raw
public void finishGame() { public void finishGame() {
this.game = false; this.game = false;
} }
@@ -168,6 +175,8 @@ public class World {
* @return ... * @return ...
* |result == dimension >= 0.0 && dimension <= Double.MAX_VALUE * |result == dimension >= 0.0 && dimension <= Double.MAX_VALUE
*/ */
@Basic
@Raw
public static boolean isValidDimension(double dimension) { public static boolean isValidDimension(double dimension) {
return dimension >= 0.0 && dimension <= Double.MAX_VALUE; return dimension >= 0.0 && dimension <= Double.MAX_VALUE;
} }
@@ -176,6 +185,8 @@ public class World {
* @return ... * @return ...
* |result == width * |result == width
*/ */
@Basic
@Raw
public double getWidth() { public double getWidth() {
return width; return width;
} }
@@ -184,6 +195,8 @@ public class World {
* @return ... * @return ...
* |result == height * |result == height
*/ */
@Basic
@Raw
public double getHeight() { public double getHeight() {
return height; return height;
} }
@@ -197,6 +210,8 @@ public class World {
* @return ... * @return ...
* |result == this.lengtX * |result == this.lengtX
*/ */
@Basic
@Raw
public double getLengthX() { public double getLengthX() {
return this.lengthX; return this.lengthX;
} }
@@ -205,6 +220,8 @@ public class World {
* @return ... * @return ...
* |result == this.lengthY * |result == this.lengthY
*/ */
@Basic
@Raw
public double getLengthY() { public double getLengthY() {
return this.lengthY; return this.lengthY;
} }
@@ -225,6 +242,8 @@ public class World {
* @return ... * @return ...
* |result == map * |result == map
*/ */
@Basic
@Raw
public boolean[][] getMap() { public boolean[][] getMap() {
return map; return map;
} }
@@ -384,9 +403,10 @@ public class World {
* @return ... * @return ...
* |result == new ArrayList<>(getGameObjects()) * |result == new ArrayList<>(getGameObjects())
*/ */
@Basic
public Collection<Object> getAllItems() { public Collection<Object> getAllItems() {
return new ArrayList<>(getGameObjects()); return new ArrayList<>(this.gameObjects);
} }
private Set<Team> teams = new HashSet<>(); private Set<Team> teams = new HashSet<>();
@@ -410,6 +430,7 @@ public class World {
* @return ... * @return ...
* |result == HashSet<>(teams) * |result == HashSet<>(teams)
*/ */
@Basic
public Set<Team> getAllTeams() { public Set<Team> getAllTeams() {
return new HashSet<>(teams); return new HashSet<>(teams);
} }
@@ -418,6 +439,8 @@ public class World {
* @return ... * @return ...
* |result == this.gameObjects * |result == this.gameObjects
*/ */
@Basic
@Raw
public Set<GameObject> getGameObjects() { public Set<GameObject> getGameObjects() {
return this.gameObjects; return this.gameObjects;
} }
@@ -489,6 +512,7 @@ public class World {
* *
* @throws NullPointerException * @throws NullPointerException
*/ */
@Basic
public boolean hasAsGameObject(GameObject obj) { public boolean hasAsGameObject(GameObject obj) {
return getGameObjects().contains(obj); return getGameObjects().contains(obj);
} }
@@ -497,6 +521,7 @@ public class World {
* @return ... * @return ...
* |result == getGameObjectsByClass(Worm.class) * |result == getGameObjectsByClass(Worm.class)
*/ */
@Basic
public List<Worm> getWormList() { public List<Worm> getWormList() {
return getGameObjectsByClass(Worm.class); return getGameObjectsByClass(Worm.class);
@@ -506,6 +531,7 @@ public class World {
* @return ... * @return ...
* |result == getGameObjectsByClass(Food.class) * |result == getGameObjectsByClass(Food.class)
*/ */
@Basic
public List<Food> getFoodList() { public List<Food> getFoodList() {
return getGameObjectsByClass(Food.class); return getGameObjectsByClass(Food.class);
@@ -518,6 +544,7 @@ public class World {
* @return ... * @return ...
* |result == getGameObjects().stream().filter(cl::isInstance).map(cl::cast).collect(Collectors.toList()) * |result == getGameObjects().stream().filter(cl::isInstance).map(cl::cast).collect(Collectors.toList())
*/ */
@Basic
public <T extends GameObject> List<T> getGameObjectsByClass(Class<T> cl) { public <T extends GameObject> List<T> getGameObjectsByClass(Class<T> cl) {
return getGameObjects().stream().filter(cl::isInstance).map(cl::cast).collect(Collectors.toList()); return getGameObjects().stream().filter(cl::isInstance).map(cl::cast).collect(Collectors.toList());
} }

View File

@@ -181,6 +181,7 @@ public class Worm extends GameObject implements IJumpable{
* @return True if and only if the orientation is bigger then 0 and smaller then 2pi. * @return True if and only if the orientation is bigger then 0 and smaller then 2pi.
* |result == ( newOrientation >= 0 && newOrientation < 2 * PI ) * |result == ( newOrientation >= 0 && newOrientation < 2 * PI )
*/ */
@Basic
public static boolean isValidOrientation(double newOrientation) { public static boolean isValidOrientation(double newOrientation) {
return newOrientation >= 0 && newOrientation < 2 * PI; return newOrientation >= 0 && newOrientation < 2 * PI;
} }
@@ -200,6 +201,7 @@ public class Worm extends GameObject implements IJumpable{
* @return True if and only if the radius is a number and the radius is bigger then 0. * @return True if and only if the radius is a number and the radius is bigger then 0.
* |result == ((!Double.isNaN(radius)) && (radius > 0)) * |result == ((!Double.isNaN(radius)) && (radius > 0))
*/ */
@Basic
public static boolean isValidMinRadius(double minRadius) { public static boolean isValidMinRadius(double minRadius) {
return !Double.isNaN(minRadius) && minRadius > 0; return !Double.isNaN(minRadius) && minRadius > 0;
} }
@@ -344,6 +346,7 @@ public class Worm extends GameObject implements IJumpable{
* @post The current points are set to the old current points minus the angle (in degrees) divided by 6. * @post The current points are set to the old current points minus the angle (in degrees) divided by 6.
* |new.getActionPoints() == old.getActionPoints() - (long) ceil(toDegrees(angle) / 6)) * |new.getActionPoints() == old.getActionPoints() - (long) ceil(toDegrees(angle) / 6))
*/ */
@Raw
private void decreaseActionPointsByAngle(double angle) { private void decreaseActionPointsByAngle(double angle) {
setActionPoints(this.actionPoints - (long) ceil(toDegrees(angle) / 6)); setActionPoints(this.actionPoints - (long) ceil(toDegrees(angle) / 6));
@@ -367,7 +370,7 @@ public class Worm extends GameObject implements IJumpable{
* |setActionPoints(this.actionPoints) * |setActionPoints(this.actionPoints)
*/ */
@Raw @Raw
private void setMaxActionPoints(double maxActionPoints) { public void setMaxActionPoints(double maxActionPoints) {
this.maxActionPoints = round(maxActionPoints); this.maxActionPoints = round(maxActionPoints);
setActionPoints(this.actionPoints); setActionPoints(this.actionPoints);
} }
@@ -390,7 +393,6 @@ public class Worm extends GameObject implements IJumpable{
* The name of the worm expresses the identity of the worm. * The name of the worm expresses the identity of the worm.
*/ */
@Basic @Basic
@Immutable
@Raw @Raw
public String getName() { public String getName() {
return this.name; return this.name;
@@ -415,6 +417,7 @@ public class Worm extends GameObject implements IJumpable{
* @throws IllegalArgumentException If the name is equal to null. * @throws IllegalArgumentException If the name is equal to null.
* |name == null * |name == null
*/ */
@Raw
public static int isValidName(String name) { public static int isValidName(String name) {
if (name == null) throw new IllegalArgumentException("Name must not be null"); if (name == null) throw new IllegalArgumentException("Name must not be null");
@@ -765,6 +768,7 @@ public class Worm extends GameObject implements IJumpable{
* |result == 0 <= angle + this.orientation && angle + this.orientation < (2 * PI) && !Double.isNaN(angle) * |result == 0 <= angle + this.orientation && angle + this.orientation < (2 * PI) && !Double.isNaN(angle)
* | && this.actionPoints - (long) Math.abs(ceil(toDegrees(angle) / 6)) >= 0 * | && this.actionPoints - (long) Math.abs(ceil(toDegrees(angle) / 6)) >= 0
*/ */
@Raw
protected boolean canTurn(double angle) { protected boolean canTurn(double angle) {
double currentAngle = this.orientation; double currentAngle = this.orientation;
return 0 <= angle + currentAngle && angle + currentAngle < (2 * PI) && return 0 <= angle + currentAngle && angle + currentAngle < (2 * PI) &&
@@ -957,6 +961,7 @@ public class Worm extends GameObject implements IJumpable{
* is lower or equal to pi. * is lower or equal to pi.
* |result == getActionPoints() > 0 && getOrientation() <= PI * |result == getActionPoints() > 0 && getOrientation() <= PI
*/ */
@Raw
private boolean canJump() { private boolean canJump() {
return this.actionPoints > 0 && this.orientation <= PI; return this.actionPoints > 0 && this.orientation <= PI;
} }
@@ -970,6 +975,7 @@ public class Worm extends GameObject implements IJumpable{
* |force = 5 * getActionPoints() + getMass() * G * |force = 5 * getActionPoints() + getMass() * G
* |result == force / getMass() * FORCE_TIME * |result == force / getMass() * FORCE_TIME
*/ */
@Raw
private double jumpVelocity() { private double jumpVelocity() {
double force = 5 * this.actionPoints + this.mass * G; double force = 5 * this.actionPoints + this.mass * G;
@@ -1071,6 +1077,7 @@ public class Worm extends GameObject implements IJumpable{
* @post The current hit points should be decreased with the given value. * @post The current hit points should be decreased with the given value.
* |new.getHitPoints() == old.getHitPoints() - value * |new.getHitPoints() == old.getHitPoints() - value
*/ */
@Raw
public void decreaseHitPoints(long value) { public void decreaseHitPoints(long value) {
setHitPoints(this.hitPoints - value); setHitPoints(this.hitPoints - value);
} }
@@ -1086,6 +1093,7 @@ public class Worm extends GameObject implements IJumpable{
* | new.getHitPoints() == 0 * | new.getHitPoints() == 0
* |new.getHitPoints() == old.getHitPoints() + value * |new.getHitPoints() == old.getHitPoints() + value
*/ */
@Raw
public void incrementHitPoints(long value) { public void incrementHitPoints(long value) {
long current = this.hitPoints; long current = this.hitPoints;
@@ -1177,6 +1185,7 @@ public class Worm extends GameObject implements IJumpable{
* | double[] center = {this.location.getX(), this.location.getY()} * | double[] center = {this.location.getX(), this.location.getY()}
* |result == !this.world.isAdjacent(center, this.radius); * |result == !this.world.isAdjacent(center, this.radius);
*/ */
@Raw
public boolean canFall() { public boolean canFall() {
double[] center = {this.location.getX(), this.location.getY()}; double[] center = {this.location.getX(), this.location.getY()};
return !this.world.isAdjacent(center, this.radius); return !this.world.isAdjacent(center, this.radius);
@@ -1194,6 +1203,8 @@ public class Worm extends GameObject implements IJumpable{
* Return the current team of the worm. * Return the current team of the worm.
* The team identifies the partners of the worm. * The team identifies the partners of the worm.
*/ */
@Raw
@Basic
public Team getTeam() { public Team getTeam() {
return this.team; return this.team;
} }
@@ -1206,6 +1217,7 @@ public class Worm extends GameObject implements IJumpable{
* @post The current team of the worm is set to the given team. * @post The current team of the worm is set to the given team.
* |new.getTeam() == team * |new.getTeam() == team
*/ */
@Raw
public void setTeam(Team team) { public void setTeam(Team team) {
this.team = team; this.team = team;
} }
@@ -1282,6 +1294,8 @@ public class Worm extends GameObject implements IJumpable{
} }
} }
@Basic
@Raw
public Boolean canEat() { public Boolean canEat() {
return this.actionPoints >= 8; return this.actionPoints >= 8;
} }
@@ -1321,6 +1335,8 @@ public class Worm extends GameObject implements IJumpable{
throw new IllegalStateException(); throw new IllegalStateException();
} }
@Basic
@Raw
public Boolean canFire() { public Boolean canFire() {
return this.actionPoints >= 30 && this.world != null; return this.actionPoints >= 30 && this.world != null;
} }
@@ -1343,6 +1359,8 @@ public class Worm extends GameObject implements IJumpable{
program.setActionHandler(actionHandler); program.setActionHandler(actionHandler);
} }
@Basic
@Raw
public worms.model.Program getProgram() { public worms.model.Program getProgram() {
return program; return program;
} }
@@ -1364,7 +1382,6 @@ public class Worm extends GameObject implements IJumpable{
super.terminate(); super.terminate();
if (team != null) { if (team != null) {
team.removeWormsFromTeam(this); team.removeWormsFromTeam(this);
team = null;
} }
} }
} }