fixed annotations
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package worms.model;
|
||||
|
||||
import be.kuleuven.cs.som.annotate.Basic;
|
||||
import be.kuleuven.cs.som.annotate.Raw;
|
||||
import worms.util.Coordinate;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
@@ -24,7 +26,8 @@ public class Bazooka extends Projectile {
|
||||
* @post ...
|
||||
* |new.getForce() == calcForce(worm.getActionPoints())
|
||||
*/
|
||||
protected Bazooka(Worm worm) {
|
||||
@Raw
|
||||
public Bazooka(Worm worm) {
|
||||
super(worm, 300, calcForce(worm.getActionPoints()));
|
||||
}
|
||||
|
||||
@@ -35,6 +38,7 @@ public class Bazooka extends Projectile {
|
||||
* |result == nb
|
||||
*/
|
||||
@Override
|
||||
@Raw
|
||||
protected int getRandomHitPoints() {
|
||||
int nb =ThreadLocalRandom.current().nextInt(15) / 2;
|
||||
nb += (nb % 2 == 0 ? 1:0);
|
||||
@@ -46,7 +50,9 @@ public class Bazooka extends Projectile {
|
||||
* |result == this.hitPoints * (int) this.force
|
||||
*
|
||||
*/
|
||||
@Basic
|
||||
@Override
|
||||
@Raw
|
||||
protected int getImpactHitPoints() {
|
||||
return this.hitPoints * (int) this.force;
|
||||
}
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package worms.model;
|
||||
|
||||
import be.kuleuven.cs.som.annotate.Basic;
|
||||
import be.kuleuven.cs.som.annotate.Raw;
|
||||
import worms.util.Coordinate;
|
||||
|
||||
/**
|
||||
@@ -23,6 +25,7 @@ public class Food extends GameObject {
|
||||
* @post ...
|
||||
* |setMass(getRadius(), 150)
|
||||
*/
|
||||
@Raw
|
||||
public Food(World world, double[] location) {
|
||||
super(world, location, 0.2);
|
||||
|
||||
@@ -35,6 +38,8 @@ public class Food extends GameObject {
|
||||
* @return ...
|
||||
* |result == this.poisonous
|
||||
*/
|
||||
@Basic
|
||||
@Raw
|
||||
public boolean isPoisonous() {
|
||||
return this.poisonous;
|
||||
}
|
||||
@@ -43,6 +48,7 @@ public class Food extends GameObject {
|
||||
* @post ...
|
||||
* |poisonous == true
|
||||
*/
|
||||
@Raw
|
||||
public void poison() {
|
||||
this.poisonous = true;
|
||||
}
|
||||
@@ -51,6 +57,7 @@ public class Food extends GameObject {
|
||||
* @post ...
|
||||
* |poisonous == false
|
||||
*/
|
||||
@Raw
|
||||
public void heal() {
|
||||
this.poisonous = false;
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package worms.model;
|
||||
|
||||
import be.kuleuven.cs.som.annotate.Basic;
|
||||
import be.kuleuven.cs.som.annotate.Raw;
|
||||
import worms.util.Coordinate;
|
||||
|
||||
@@ -28,7 +29,8 @@ public abstract class GameObject {
|
||||
* @post ...
|
||||
* |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);
|
||||
|
||||
}
|
||||
@@ -51,7 +53,8 @@ public abstract class GameObject {
|
||||
* @throws IllegalArgumentException ...
|
||||
* |!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");
|
||||
setLocation(location);
|
||||
setRadius(radius);
|
||||
@@ -70,6 +73,8 @@ public abstract class GameObject {
|
||||
* @return ...
|
||||
* |result == this.world
|
||||
*/
|
||||
@Basic
|
||||
@Raw
|
||||
public World getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
@@ -155,10 +160,10 @@ public abstract class GameObject {
|
||||
|
||||
if (!isValidLocation(location)) {
|
||||
if (!(location.getX() - radius < 0) ||
|
||||
!(location.getX() + radius > getWorld().getWidth()) ||
|
||||
!(location.getY() + radius > getWorld().getHeight()) ||
|
||||
!(location.getX() + radius > this.world.getWidth()) ||
|
||||
!(location.getY() + radius > this.world.getHeight()) ||
|
||||
!(location.getY() - radius < 0)) {
|
||||
world.remove(this);
|
||||
this.world.remove(this);
|
||||
} else throw new IllegalArgumentException();
|
||||
}
|
||||
this.location = location;
|
||||
@@ -188,7 +193,6 @@ public abstract class GameObject {
|
||||
* | getWorld().isPassable(location)
|
||||
*/
|
||||
protected boolean isValidLocation(Coordinate location) {
|
||||
double radius = getRadius();
|
||||
|
||||
if (world == null) {
|
||||
return !Double.isNaN(location.getX()) &&
|
||||
@@ -196,10 +200,10 @@ public abstract class GameObject {
|
||||
}
|
||||
return !Double.isNaN(location.getX()) &&
|
||||
!Double.isNaN(location.getY()) &&
|
||||
!(location.getX() - radius < 0) &&
|
||||
!(location.getX() + radius > getWorld().getWidth()) &&
|
||||
!(location.getY() + radius > getWorld().getHeight()) &&
|
||||
!(location.getY() - radius < 0) && getWorld().isPassable(location);
|
||||
!(location.getX() - this.radius < 0) &&
|
||||
!(location.getX() + this.radius > this.world.getWidth()) &&
|
||||
!(location.getY() + this.radius > this.world.getHeight()) &&
|
||||
!(location.getY() - this.radius < 0) && this.world.isPassable(location);
|
||||
}
|
||||
|
||||
protected Coordinate location;
|
||||
@@ -215,6 +219,8 @@ public abstract class GameObject {
|
||||
* @return ...
|
||||
* |result == this.radius
|
||||
*/
|
||||
@Basic
|
||||
@Raw
|
||||
public double getRadius() {
|
||||
return this.radius;
|
||||
}
|
||||
@@ -228,6 +234,7 @@ public abstract class GameObject {
|
||||
* @throws IllegalArgumentException ...
|
||||
* |!canHaveAsRadius(radius)
|
||||
*/
|
||||
@Raw
|
||||
protected void setRadius(double radius) {
|
||||
if (!canHaveAsRadius(radius)) throw new IllegalArgumentException();
|
||||
this.radius = radius;
|
||||
@@ -241,6 +248,7 @@ public abstract class GameObject {
|
||||
* @return ...
|
||||
* |result == !Double.isNaN(radius) && radius > 0
|
||||
*/
|
||||
@Basic
|
||||
@Raw
|
||||
private boolean canHaveAsRadius(double radius) {
|
||||
return !Double.isNaN(radius) && radius > 0;
|
||||
@@ -257,6 +265,8 @@ public abstract class GameObject {
|
||||
* @return ...
|
||||
* |result == this.mass
|
||||
*/
|
||||
@Basic
|
||||
@Raw
|
||||
public double getMass() {
|
||||
return this.mass;
|
||||
}
|
||||
@@ -268,6 +278,7 @@ public abstract class GameObject {
|
||||
* @post ...
|
||||
* |new.getMass() == rho * (4.0 / 3.0 * PI * pow(radius, 3.0)
|
||||
*/
|
||||
@Raw
|
||||
protected void setMass(double radius, double rho) {
|
||||
|
||||
this.mass = rho * (4.0 / 3.0 * PI * pow(radius, 3.0));
|
||||
@@ -352,6 +363,8 @@ public abstract class GameObject {
|
||||
* @return ...
|
||||
* |result == this.terminated
|
||||
*/
|
||||
@Basic
|
||||
@Raw
|
||||
public boolean isTerminated() {
|
||||
return this.terminated;
|
||||
}
|
||||
@@ -363,6 +376,7 @@ public abstract class GameObject {
|
||||
* |if (this.world != null)
|
||||
* | this.world.remove(this)
|
||||
*/
|
||||
@Basic
|
||||
public void terminate() {
|
||||
this.terminated = true;
|
||||
if (this.world != null) {
|
||||
|
@@ -1,5 +1,7 @@
|
||||
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.programs.Expression;
|
||||
import worms.programs.Procedure;
|
||||
@@ -12,20 +14,6 @@ import static java.lang.Math.toDegrees;
|
||||
|
||||
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) {
|
||||
this.main = main;
|
||||
@@ -36,17 +24,12 @@ public class Program {
|
||||
public Worm getWorm() {
|
||||
return this.worm;
|
||||
}
|
||||
|
||||
public Map<String, Object> getVariables() {
|
||||
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;
|
||||
|
||||
@@ -92,6 +75,13 @@ public class Program {
|
||||
return printList;
|
||||
}
|
||||
|
||||
protected void setWorm(Worm worm) {
|
||||
this.worm = worm;
|
||||
}
|
||||
protected void setActionHandler(IActionHandler actionHandler) {
|
||||
this.actionHandler = actionHandler;
|
||||
}
|
||||
|
||||
private boolean breakLoop = false;
|
||||
|
||||
@SuppressWarnings({"unchecked", "SuspiciousMethodCalls"})
|
||||
@@ -239,11 +229,6 @@ public class Program {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private class CallStackNode {
|
||||
private Iterator<Statement> statementIterator;
|
||||
private Statement lastStatement;
|
||||
@@ -253,5 +238,20 @@ public class Program {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package worms.model;
|
||||
|
||||
import be.kuleuven.cs.som.annotate.Basic;
|
||||
import be.kuleuven.cs.som.annotate.Raw;
|
||||
import worms.util.Coordinate;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
@@ -25,6 +27,7 @@ public class Rifle extends Projectile {
|
||||
* @post ...
|
||||
* |new.getForce() == 1.5
|
||||
*/
|
||||
@Raw
|
||||
public Rifle(Worm worm) {
|
||||
super(worm, 10, 1.5);
|
||||
}
|
||||
@@ -34,6 +37,7 @@ public class Rifle extends Projectile {
|
||||
* |result == ThreadLocalRandom.current().nextInt(1,6) * 2
|
||||
*/
|
||||
@Override
|
||||
@Raw
|
||||
protected int getRandomHitPoints() {
|
||||
return ThreadLocalRandom.current().nextInt(1,6) * 2;
|
||||
}
|
||||
@@ -42,7 +46,9 @@ public class Rifle extends Projectile {
|
||||
* @return ...
|
||||
* |result == this.hitPoints
|
||||
*/
|
||||
@Basic
|
||||
@Override
|
||||
@Raw
|
||||
protected int getImpactHitPoints() {
|
||||
return this.hitPoints;
|
||||
}
|
||||
|
@@ -3,6 +3,8 @@ package worms.model;
|
||||
import java.util.*;
|
||||
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.TeamComparator;
|
||||
|
||||
@@ -31,6 +33,7 @@ public class Team {
|
||||
* |if (world != null)
|
||||
* | world.addTeam(this)
|
||||
*/
|
||||
@Raw
|
||||
public Team (String name, World world) {
|
||||
setName(name);
|
||||
this.wormCollection = new TreeSet<>(new TeamComparator());
|
||||
@@ -51,6 +54,7 @@ public class Team {
|
||||
* | result == false
|
||||
* |result == this.getName().equals((Team) obj).getName())
|
||||
*/
|
||||
@Basic
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof Team)) return false;
|
||||
@@ -168,6 +172,7 @@ public class Team {
|
||||
* @throws IllegalArgumentException If the worm is equal to null.
|
||||
* |worm == null
|
||||
*/
|
||||
@Basic
|
||||
public boolean containsWorm(Worm worm) throws IllegalArgumentException {
|
||||
if (worm == null) throw new IllegalArgumentException();
|
||||
return this.wormCollection.contains(worm);
|
||||
@@ -179,6 +184,7 @@ public class Team {
|
||||
* @return All the worms of the team in a List.
|
||||
* |result == ArrayList<>(this.wormCollection)
|
||||
*/
|
||||
@Basic
|
||||
public List<Worm> getAllWormsList() {
|
||||
return new ArrayList<>(this.wormCollection);
|
||||
}
|
||||
@@ -189,6 +195,7 @@ public class Team {
|
||||
* @return The number of worms in the team.
|
||||
* |result == getAllWormsOfTeam().size()
|
||||
*/
|
||||
@Basic
|
||||
public int getNbWorms() {
|
||||
return this.wormCollection.size();
|
||||
}
|
||||
@@ -243,7 +250,7 @@ public class Team {
|
||||
*
|
||||
* @throws IllegalStateException If the minimum mass is equal to null.
|
||||
* |minMass == null
|
||||
*/
|
||||
*/
|
||||
private double getMinMassTeam() throws IllegalStateException {
|
||||
Worm minMass = this.wormCollection.stream().min(Comparator.comparingDouble(Worm::getMass)).orElse(null);
|
||||
if (minMass == null) {
|
||||
@@ -266,6 +273,8 @@ public class Team {
|
||||
* @return The name of the team.
|
||||
* |result == this.name
|
||||
*/
|
||||
@Basic
|
||||
@Raw
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
@@ -309,6 +318,7 @@ public class Team {
|
||||
* @post The variable terminated is set to true.
|
||||
* |new.terminated = true
|
||||
*/
|
||||
@Raw
|
||||
public void terminate() {
|
||||
|
||||
removeWormsFromTeam(this.wormCollection.toArray(new Worm[0]));
|
||||
@@ -322,6 +332,8 @@ public class Team {
|
||||
* @return Of the team is terminated or not
|
||||
* |result == this.terminated
|
||||
*/
|
||||
@Basic
|
||||
@Raw
|
||||
public boolean isTerminated() {
|
||||
return this.terminated;
|
||||
}
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package worms.model;
|
||||
|
||||
import be.kuleuven.cs.som.annotate.Basic;
|
||||
import be.kuleuven.cs.som.annotate.Raw;
|
||||
import worms.util.Coordinate;
|
||||
|
||||
import java.util.*;
|
||||
@@ -36,6 +38,7 @@ public class World {
|
||||
* @post ...
|
||||
* |new.gameObjets = new HashSet<>()
|
||||
*/
|
||||
@Raw
|
||||
public World(double width, double height, boolean[][] map) {
|
||||
|
||||
if (!isValidDimension(width) || !isValidDimension(height) || map == null || map.length == 0) throw new IllegalArgumentException();
|
||||
@@ -55,6 +58,8 @@ public class World {
|
||||
* @return ...
|
||||
* result = this.terminated
|
||||
*/
|
||||
@Basic
|
||||
@Raw
|
||||
public boolean isTerminated() {
|
||||
return this.terminated;
|
||||
}
|
||||
@@ -84,7 +89,8 @@ public class World {
|
||||
|
||||
// region game (Total)
|
||||
//===================================================================================
|
||||
|
||||
@Basic
|
||||
@Raw
|
||||
public boolean hasActiveGame() {
|
||||
return this.game;
|
||||
}
|
||||
@@ -101,6 +107,7 @@ public class World {
|
||||
|
||||
}
|
||||
|
||||
@Raw
|
||||
public void finishGame() {
|
||||
this.game = false;
|
||||
}
|
||||
@@ -168,6 +175,8 @@ public class World {
|
||||
* @return ...
|
||||
* |result == dimension >= 0.0 && dimension <= Double.MAX_VALUE
|
||||
*/
|
||||
@Basic
|
||||
@Raw
|
||||
public static boolean isValidDimension(double dimension) {
|
||||
return dimension >= 0.0 && dimension <= Double.MAX_VALUE;
|
||||
}
|
||||
@@ -176,6 +185,8 @@ public class World {
|
||||
* @return ...
|
||||
* |result == width
|
||||
*/
|
||||
@Basic
|
||||
@Raw
|
||||
public double getWidth() {
|
||||
return width;
|
||||
}
|
||||
@@ -184,6 +195,8 @@ public class World {
|
||||
* @return ...
|
||||
* |result == height
|
||||
*/
|
||||
@Basic
|
||||
@Raw
|
||||
public double getHeight() {
|
||||
return height;
|
||||
}
|
||||
@@ -197,6 +210,8 @@ public class World {
|
||||
* @return ...
|
||||
* |result == this.lengtX
|
||||
*/
|
||||
@Basic
|
||||
@Raw
|
||||
public double getLengthX() {
|
||||
return this.lengthX;
|
||||
}
|
||||
@@ -205,6 +220,8 @@ public class World {
|
||||
* @return ...
|
||||
* |result == this.lengthY
|
||||
*/
|
||||
@Basic
|
||||
@Raw
|
||||
public double getLengthY() {
|
||||
return this.lengthY;
|
||||
}
|
||||
@@ -225,6 +242,8 @@ public class World {
|
||||
* @return ...
|
||||
* |result == map
|
||||
*/
|
||||
@Basic
|
||||
@Raw
|
||||
public boolean[][] getMap() {
|
||||
return map;
|
||||
}
|
||||
@@ -384,9 +403,10 @@ public class World {
|
||||
* @return ...
|
||||
* |result == new ArrayList<>(getGameObjects())
|
||||
*/
|
||||
@Basic
|
||||
public Collection<Object> getAllItems() {
|
||||
|
||||
return new ArrayList<>(getGameObjects());
|
||||
return new ArrayList<>(this.gameObjects);
|
||||
}
|
||||
|
||||
private Set<Team> teams = new HashSet<>();
|
||||
@@ -410,6 +430,7 @@ public class World {
|
||||
* @return ...
|
||||
* |result == HashSet<>(teams)
|
||||
*/
|
||||
@Basic
|
||||
public Set<Team> getAllTeams() {
|
||||
return new HashSet<>(teams);
|
||||
}
|
||||
@@ -418,6 +439,8 @@ public class World {
|
||||
* @return ...
|
||||
* |result == this.gameObjects
|
||||
*/
|
||||
@Basic
|
||||
@Raw
|
||||
public Set<GameObject> getGameObjects() {
|
||||
return this.gameObjects;
|
||||
}
|
||||
@@ -489,6 +512,7 @@ public class World {
|
||||
*
|
||||
* @throws NullPointerException
|
||||
*/
|
||||
@Basic
|
||||
public boolean hasAsGameObject(GameObject obj) {
|
||||
return getGameObjects().contains(obj);
|
||||
}
|
||||
@@ -497,6 +521,7 @@ public class World {
|
||||
* @return ...
|
||||
* |result == getGameObjectsByClass(Worm.class)
|
||||
*/
|
||||
@Basic
|
||||
public List<Worm> getWormList() {
|
||||
|
||||
return getGameObjectsByClass(Worm.class);
|
||||
@@ -506,6 +531,7 @@ public class World {
|
||||
* @return ...
|
||||
* |result == getGameObjectsByClass(Food.class)
|
||||
*/
|
||||
@Basic
|
||||
public List<Food> getFoodList() {
|
||||
|
||||
return getGameObjectsByClass(Food.class);
|
||||
@@ -518,6 +544,7 @@ public class World {
|
||||
* @return ...
|
||||
* |result == getGameObjects().stream().filter(cl::isInstance).map(cl::cast).collect(Collectors.toList())
|
||||
*/
|
||||
@Basic
|
||||
public <T extends GameObject> List<T> getGameObjectsByClass(Class<T> cl) {
|
||||
return getGameObjects().stream().filter(cl::isInstance).map(cl::cast).collect(Collectors.toList());
|
||||
}
|
||||
|
@@ -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.
|
||||
* |result == ( newOrientation >= 0 && newOrientation < 2 * PI )
|
||||
*/
|
||||
@Basic
|
||||
public static boolean isValidOrientation(double newOrientation) {
|
||||
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.
|
||||
* |result == ((!Double.isNaN(radius)) && (radius > 0))
|
||||
*/
|
||||
@Basic
|
||||
public static boolean isValidMinRadius(double minRadius) {
|
||||
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.
|
||||
* |new.getActionPoints() == old.getActionPoints() - (long) ceil(toDegrees(angle) / 6))
|
||||
*/
|
||||
@Raw
|
||||
private void decreaseActionPointsByAngle(double angle) {
|
||||
|
||||
setActionPoints(this.actionPoints - (long) ceil(toDegrees(angle) / 6));
|
||||
@@ -367,7 +370,7 @@ public class Worm extends GameObject implements IJumpable{
|
||||
* |setActionPoints(this.actionPoints)
|
||||
*/
|
||||
@Raw
|
||||
private void setMaxActionPoints(double maxActionPoints) {
|
||||
public void setMaxActionPoints(double maxActionPoints) {
|
||||
this.maxActionPoints = round(maxActionPoints);
|
||||
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.
|
||||
*/
|
||||
@Basic
|
||||
@Immutable
|
||||
@Raw
|
||||
public String getName() {
|
||||
return this.name;
|
||||
@@ -415,6 +417,7 @@ public class Worm extends GameObject implements IJumpable{
|
||||
* @throws IllegalArgumentException If the name is equal to null.
|
||||
* |name == null
|
||||
*/
|
||||
@Raw
|
||||
public static int isValidName(String name) {
|
||||
|
||||
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)
|
||||
* | && this.actionPoints - (long) Math.abs(ceil(toDegrees(angle) / 6)) >= 0
|
||||
*/
|
||||
@Raw
|
||||
protected boolean canTurn(double angle) {
|
||||
double currentAngle = this.orientation;
|
||||
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.
|
||||
* |result == getActionPoints() > 0 && getOrientation() <= PI
|
||||
*/
|
||||
@Raw
|
||||
private boolean canJump() {
|
||||
return this.actionPoints > 0 && this.orientation <= PI;
|
||||
}
|
||||
@@ -970,6 +975,7 @@ public class Worm extends GameObject implements IJumpable{
|
||||
* |force = 5 * getActionPoints() + getMass() * G
|
||||
* |result == force / getMass() * FORCE_TIME
|
||||
*/
|
||||
@Raw
|
||||
private double jumpVelocity() {
|
||||
|
||||
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.
|
||||
* |new.getHitPoints() == old.getHitPoints() - value
|
||||
*/
|
||||
@Raw
|
||||
public void decreaseHitPoints(long value) {
|
||||
setHitPoints(this.hitPoints - value);
|
||||
}
|
||||
@@ -1086,6 +1093,7 @@ public class Worm extends GameObject implements IJumpable{
|
||||
* | new.getHitPoints() == 0
|
||||
* |new.getHitPoints() == old.getHitPoints() + value
|
||||
*/
|
||||
@Raw
|
||||
public void incrementHitPoints(long value) {
|
||||
|
||||
long current = this.hitPoints;
|
||||
@@ -1177,6 +1185,7 @@ public class Worm extends GameObject implements IJumpable{
|
||||
* | double[] center = {this.location.getX(), this.location.getY()}
|
||||
* |result == !this.world.isAdjacent(center, this.radius);
|
||||
*/
|
||||
@Raw
|
||||
public boolean canFall() {
|
||||
double[] center = {this.location.getX(), this.location.getY()};
|
||||
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.
|
||||
* The team identifies the partners of the worm.
|
||||
*/
|
||||
@Raw
|
||||
@Basic
|
||||
public Team getTeam() {
|
||||
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.
|
||||
* |new.getTeam() == team
|
||||
*/
|
||||
@Raw
|
||||
public void setTeam(Team team) {
|
||||
this.team = team;
|
||||
}
|
||||
@@ -1282,6 +1294,8 @@ public class Worm extends GameObject implements IJumpable{
|
||||
}
|
||||
}
|
||||
|
||||
@Basic
|
||||
@Raw
|
||||
public Boolean canEat() {
|
||||
return this.actionPoints >= 8;
|
||||
}
|
||||
@@ -1321,6 +1335,8 @@ public class Worm extends GameObject implements IJumpable{
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Basic
|
||||
@Raw
|
||||
public Boolean canFire() {
|
||||
return this.actionPoints >= 30 && this.world != null;
|
||||
}
|
||||
@@ -1343,6 +1359,8 @@ public class Worm extends GameObject implements IJumpable{
|
||||
program.setActionHandler(actionHandler);
|
||||
}
|
||||
|
||||
@Basic
|
||||
@Raw
|
||||
public worms.model.Program getProgram() {
|
||||
return program;
|
||||
}
|
||||
@@ -1364,7 +1382,6 @@ public class Worm extends GameObject implements IJumpable{
|
||||
super.terminate();
|
||||
if (team != null) {
|
||||
team.removeWormsFromTeam(this);
|
||||
team = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user