update
This commit is contained in:
@@ -172,7 +172,7 @@ public class Facade implements IFacade {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Coordinate jumpStep = worm.jumpStep(t);
|
Coordinate jumpStep = worm.jumpStep(t);
|
||||||
return new double[]{jumpStep.item1, jumpStep.item2};
|
return jumpStep.toArray();
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {
|
||||||
throw new ModelException(e);
|
throw new ModelException(e);
|
||||||
@@ -1036,6 +1036,6 @@ public class Facade implements IFacade {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void castSpell(World world) throws ModelException {
|
public void castSpell(World world) throws ModelException {
|
||||||
|
world.castSpell();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,11 @@
|
|||||||
package worms.model;
|
package worms.model;
|
||||||
|
|
||||||
|
import worms.util.Coordinate;
|
||||||
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
public class Bazooka extends Projectile {
|
public class Bazooka extends Projectile {
|
||||||
protected Bazooka(World world, double[] location, double force, double orientation) {
|
protected Bazooka(World world, Coordinate location, double force, double orientation) {
|
||||||
super(world, location, 300, force, orientation);
|
super(world, location, 300, force, orientation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -13,8 +15,12 @@ public class Bazooka extends Projectile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setHitPoints(int value) throws IllegalArgumentException {
|
protected void setHitPoints(int value) {
|
||||||
if (value > 7 || value % 2 != 1) throw new IllegalArgumentException();
|
if (value > 7) value = 7;
|
||||||
|
else if (value % 2 != 1) {
|
||||||
|
if (value == 0) value++;
|
||||||
|
else value--;
|
||||||
|
}
|
||||||
super.hitPoints = value;
|
super.hitPoints = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,18 +3,35 @@ package worms.model;
|
|||||||
import be.kuleuven.cs.som.annotate.Raw;
|
import be.kuleuven.cs.som.annotate.Raw;
|
||||||
import worms.util.Coordinate;
|
import worms.util.Coordinate;
|
||||||
|
|
||||||
import static java.lang.Math.PI;
|
import static java.lang.Math.*;
|
||||||
import static java.lang.Math.pow;
|
|
||||||
import static java.lang.Math.round;
|
|
||||||
|
|
||||||
public abstract class GameObject {
|
public abstract class GameObject {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This variable contains the radius of the game object
|
||||||
|
*/
|
||||||
|
protected double radius;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
*/
|
||||||
|
protected double mass;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private World world;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private boolean terminated = false;
|
||||||
|
/**
|
||||||
|
* this variable contains the location of the worm (a Coordinate)
|
||||||
|
*/
|
||||||
|
private Coordinate location;
|
||||||
|
|
||||||
|
/**
|
||||||
* @param world
|
* @param world
|
||||||
* @param location
|
* @param location
|
||||||
* @param radius
|
* @param radius
|
||||||
*
|
|
||||||
* @post ...
|
* @post ...
|
||||||
* |setWorld(world)
|
* |setWorld(world)
|
||||||
* @post ...
|
* @post ...
|
||||||
@@ -32,17 +49,34 @@ public abstract class GameObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param world
|
* @param world
|
||||||
*
|
* @param location
|
||||||
* @return ...
|
* @param radius
|
||||||
* |result == !world.hasActiveGame() && !world.isTerminated()
|
* @post ...
|
||||||
|
* |setWorld(world)
|
||||||
|
* @post ...
|
||||||
|
* |world.add(this)
|
||||||
|
* @post ...
|
||||||
|
* |setLocation(location)
|
||||||
|
* @post ...
|
||||||
|
* |setRadius(radius)
|
||||||
|
*/
|
||||||
|
protected GameObject(World world, Coordinate location, double radius) {
|
||||||
|
setWorld(world);
|
||||||
|
world.add(this);
|
||||||
|
setLocation(location);
|
||||||
|
setRadius(radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param world
|
||||||
|
* @return ... |result == !world.hasActiveGame() && !world.isTerminated()
|
||||||
*/
|
*/
|
||||||
public static boolean isValidWorld(World world) {
|
public static boolean isValidWorld(World world) {
|
||||||
return !world.hasActiveGame() && !world.isTerminated();
|
return !world.hasActiveGame() && !world.isTerminated();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @return ...
|
* @return ...
|
||||||
* |result == this.world
|
* |result == this.world
|
||||||
*/
|
*/
|
||||||
@@ -51,9 +85,7 @@ public abstract class GameObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param world
|
* @param world
|
||||||
*
|
|
||||||
* @post ...
|
* @post ...
|
||||||
* |if world == null
|
* |if world == null
|
||||||
* | this.world = null
|
* | this.world = null
|
||||||
@@ -70,12 +102,6 @@ public abstract class GameObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
*/
|
|
||||||
private World world;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @return ...
|
* @return ...
|
||||||
* |result == this.terminated
|
* |result == this.terminated
|
||||||
*/
|
*/
|
||||||
@@ -93,18 +119,6 @@ public abstract class GameObject {
|
|||||||
getWorld().remove(this);
|
getWorld().remove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private boolean terminated = false;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* this variable contains the location of the worm (a Coordinate)
|
|
||||||
*/
|
|
||||||
private Coordinate location;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the location of the game object
|
* Return the location of the game object
|
||||||
* the location of the worm expresses the place of the game object
|
* the location of the worm expresses the place of the game object
|
||||||
@@ -115,9 +129,20 @@ public abstract class GameObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @param location
|
||||||
* @return ...
|
* @throws IllegalArgumentException ...
|
||||||
* |result == this.location.toArray()
|
* |!isValidLocation(location)
|
||||||
|
* @post ...
|
||||||
|
* this.location = location
|
||||||
|
*/
|
||||||
|
protected void setLocation(Coordinate location) throws IllegalArgumentException {
|
||||||
|
|
||||||
|
if (!isValidLocation(location)) throw new IllegalArgumentException();
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return ... |result == this.location.toArray()
|
||||||
*/
|
*/
|
||||||
public double[] getLocationArray() {
|
public double[] getLocationArray() {
|
||||||
return this.location.toArray();
|
return this.location.toArray();
|
||||||
@@ -126,15 +151,13 @@ public abstract class GameObject {
|
|||||||
/**
|
/**
|
||||||
* set the location of the worm to the given location
|
* set the location of the worm to the given location
|
||||||
*
|
*
|
||||||
* @param location
|
* @param location the new location for the game object
|
||||||
* the new location for the game object
|
* @throws IllegalArgumentException the given location is not a valid location for a game object
|
||||||
|
* |! isValidLocation(location)
|
||||||
* @post the new location of the game object is equal to the given location
|
* @post the new location of the game object is equal to the given location
|
||||||
* |new.getLocation() == location
|
* |new.getLocation() == location
|
||||||
* @throws IllegalArgumentException
|
|
||||||
* the given location is not a valid location for a game object
|
|
||||||
* |! isValidLocation(location)
|
|
||||||
*/
|
*/
|
||||||
void setLocation(double[] location) throws IllegalArgumentException {
|
protected void setLocation(double[] location) throws IllegalArgumentException {
|
||||||
|
|
||||||
Coordinate locationCoordinate = Coordinate.create(location);
|
Coordinate locationCoordinate = Coordinate.create(location);
|
||||||
|
|
||||||
@@ -142,42 +165,17 @@ public abstract class GameObject {
|
|||||||
this.location = locationCoordinate;
|
this.location = locationCoordinate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param location
|
|
||||||
*
|
|
||||||
* @post ...
|
|
||||||
* this.location = location
|
|
||||||
*
|
|
||||||
* @throws IllegalArgumentException
|
|
||||||
* ...
|
|
||||||
* |!isValidLocation(location)
|
|
||||||
*/
|
|
||||||
void setLocation(Coordinate location) throws IllegalArgumentException {
|
|
||||||
|
|
||||||
if (!isValidLocation(location)) throw new IllegalArgumentException();
|
|
||||||
this.location = location;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This variable contains the radius of the game object
|
|
||||||
*/
|
|
||||||
protected double radius;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the radius of the game object
|
* Return the radius of the game object
|
||||||
* the radius of the game object expresses half of the
|
* the radius of the game object expresses half of the
|
||||||
* width of the game object
|
* width of the game object
|
||||||
*/
|
*/
|
||||||
public double getRadius(){
|
public double getRadius() {
|
||||||
return this.radius;
|
return this.radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param radius
|
* @param radius
|
||||||
*
|
|
||||||
* @post ...
|
* @post ...
|
||||||
* |this.radius = radius
|
* |this.radius = radius
|
||||||
*/
|
*/
|
||||||
@@ -189,8 +187,7 @@ public abstract class GameObject {
|
|||||||
/**
|
/**
|
||||||
* Check whether the given radius is a valid radius for the worm
|
* Check whether the given radius is a valid radius for the worm
|
||||||
*
|
*
|
||||||
* @param radius
|
* @param radius the radius to check
|
||||||
* the radius to check
|
|
||||||
* @return True if and only if the radius is bigger then the minimum radius
|
* @return True if and only if the radius is bigger then the minimum radius
|
||||||
* (or equal) and the radius is a number
|
* (or equal) and the radius is a number
|
||||||
* |result == (radius >= getMinRadius() && !Double.isNaN(radius))
|
* |result == (radius >= getMinRadius() && !Double.isNaN(radius))
|
||||||
@@ -201,11 +198,8 @@ public abstract class GameObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param location
|
* @param location
|
||||||
*
|
* @return ... |if (world == null)
|
||||||
* @return ...
|
|
||||||
* |if (world == null)
|
|
||||||
* | result == !Double.isNaN(location.getX()) && !Double.isNaN(location.getY())
|
* | result == !Double.isNaN(location.getX()) && !Double.isNaN(location.getY())
|
||||||
* |result == !Double.isNaN(location.getX()) &&
|
* |result == !Double.isNaN(location.getX()) &&
|
||||||
* | !Double.isNaN(location.getY()) &&
|
* | !Double.isNaN(location.getY()) &&
|
||||||
@@ -231,16 +225,8 @@ public abstract class GameObject {
|
|||||||
!getWorld().isPassable(location));
|
!getWorld().isPassable(location));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @return ... |result == this.mass
|
||||||
*/
|
|
||||||
protected double mass;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @return ...
|
|
||||||
* |result == this.mass
|
|
||||||
*/
|
*/
|
||||||
public double getMass() {
|
public double getMass() {
|
||||||
return this.mass;
|
return this.mass;
|
||||||
@@ -249,13 +235,12 @@ public abstract class GameObject {
|
|||||||
/**
|
/**
|
||||||
* set the mass of the worm to the given mass (dependent on the radius)
|
* set the mass of the worm to the given mass (dependent on the radius)
|
||||||
*
|
*
|
||||||
* @param radius
|
* @param radius part of the formula to calculate the mass
|
||||||
* part of the formula to calculate the mass
|
|
||||||
* @post the new mass of the worm is equal to
|
* @post the new mass of the worm is equal to
|
||||||
* rho * (4 / 3 * Math.PI * Math.pow(radius, 3))
|
* rho * (4 / 3 * Math.PI * Math.pow(radius, 3))
|
||||||
* |new.getMass() == rho * (4 / 3 * Math.PI * Math.pow(radius, 3))
|
* |new.getMass() == rho * (4 / 3 * Math.PI * Math.pow(radius, 3))
|
||||||
*/
|
*/
|
||||||
void setMass(double radius, double rho) {
|
protected void setMass(double radius, double rho) {
|
||||||
this.mass = (double) round(rho * (4.0 / 3.0 * PI * pow(radius, 3)));
|
this.mass = (double) round(rho * (4.0 / 3.0 * PI * pow(radius, 3)));
|
||||||
}
|
}
|
||||||
}
|
}
|
4
OGP1718-Worms/src/worms/model/Program.java
Normal file
4
OGP1718-Worms/src/worms/model/Program.java
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
package worms.model;
|
||||||
|
|
||||||
|
public class Program {
|
||||||
|
}
|
@@ -1,11 +1,13 @@
|
|||||||
package worms.model;
|
package worms.model;
|
||||||
|
|
||||||
|
import worms.util.Coordinate;
|
||||||
|
|
||||||
public abstract class Projectile extends GameObject {
|
public abstract class Projectile extends GameObject {
|
||||||
|
|
||||||
private static final int rho = 7800;
|
private static final int rho = 7800;
|
||||||
|
|
||||||
|
|
||||||
protected Projectile (World world, double location[], double mass, double force, double orientation) {
|
protected Projectile (World world, Coordinate location, double mass, double force, double orientation) {
|
||||||
super(world, location, calcRadius(mass));
|
super(world, location, calcRadius(mass));
|
||||||
super.mass = mass;
|
super.mass = mass;
|
||||||
this.force = force;
|
this.force = force;
|
||||||
@@ -43,4 +45,37 @@ public abstract class Projectile extends GameObject {
|
|||||||
public double getOrientation() {
|
public double getOrientation() {
|
||||||
return orientation;
|
return orientation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isValidLocation(Coordinate location) {
|
||||||
|
double radius = getRadius();
|
||||||
|
|
||||||
|
if (getWorld() == null) {
|
||||||
|
return !Double.isNaN(location.getX()) &&
|
||||||
|
!Double.isNaN(location.getY());
|
||||||
|
}
|
||||||
|
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().isAdjacent(location, radius));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Coordinate getJumpStep(double elapsedTime) {
|
||||||
|
// TODO zie naar worm hoe dit moet, implementatie moet wel anders!
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getJumpTime(double jumpTimeStep) {
|
||||||
|
|
||||||
|
// TODO zie naar worm hoe dit moet, implementatie moet wel anders!
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void jump() {
|
||||||
|
// TODO zie naar worm hoe dit moet, implementatie moet wel anders!
|
||||||
|
}
|
||||||
}
|
}
|
@@ -1,11 +1,13 @@
|
|||||||
package worms.model;
|
package worms.model;
|
||||||
|
|
||||||
|
import worms.util.Coordinate;
|
||||||
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
public class Rifle extends Projectile {
|
public class Rifle extends Projectile {
|
||||||
|
|
||||||
|
|
||||||
public Rifle(World world, double[] location, double orientation) {
|
public Rifle(World world, Coordinate location, double orientation) {
|
||||||
super(world, location, 10, 1.5, orientation);
|
super(world, location, 10, 1.5, orientation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -15,8 +17,9 @@ public class Rifle extends Projectile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setHitPoints(int value) throws IllegalArgumentException {
|
protected void setHitPoints(int value) {
|
||||||
if (value > 10 || value % 2 != 0) throw new IllegalArgumentException();
|
if (value > 10) value = 10;
|
||||||
|
else if (value % 2 != 0) value--;
|
||||||
super.hitPoints = value;
|
super.hitPoints = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -571,8 +571,8 @@ public class World {
|
|||||||
item2.terminate();
|
item2.terminate();
|
||||||
}
|
}
|
||||||
else if (item1 instanceof Projectile && item2 instanceof Projectile) {
|
else if (item1 instanceof Projectile && item2 instanceof Projectile) {
|
||||||
// ((Projectile) item1).increaseHitPoints(2);
|
((Projectile) item1).incrementHitPoints(2);
|
||||||
// ((Projectile) item2).increaseHitPoints(2);
|
((Projectile) item2).incrementHitPoints(2);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
|
@@ -13,6 +13,12 @@ import java.util.concurrent.ThreadLocalRandom;
|
|||||||
/**
|
/**
|
||||||
* A class with the specifications of the worm
|
* A class with the specifications of the worm
|
||||||
*
|
*
|
||||||
|
* @author Arthur Bols and Leen Dereu
|
||||||
|
* <p>
|
||||||
|
* Arthur Bols 1e bachelor Informatica
|
||||||
|
* Leen Dereu 1e bachelor Informatica
|
||||||
|
* <p>
|
||||||
|
* URL: https://github.com/KUL-ogp/ogp1718-project-bols-dereu
|
||||||
* @invar The location of the worm must be a valid location.
|
* @invar The location of the worm must be a valid location.
|
||||||
* |isValidLocation(getLocation())
|
* |isValidLocation(getLocation())
|
||||||
* @invar The orientation of the worm must be a valid location.
|
* @invar The orientation of the worm must be a valid location.
|
||||||
@@ -27,14 +33,7 @@ import java.util.concurrent.ThreadLocalRandom;
|
|||||||
* |isValidName(getName())
|
* |isValidName(getName())
|
||||||
* @invar The value of the hit points of the worm must be a valid value for hit points.
|
* @invar The value of the hit points of the worm must be a valid value for hit points.
|
||||||
* isValidValueHitPoints(getHitPoints())
|
* isValidValueHitPoints(getHitPoints())
|
||||||
*
|
|
||||||
* @version 3.0
|
* @version 3.0
|
||||||
* @author Arthur Bols and Leen Dereu
|
|
||||||
*
|
|
||||||
* Arthur Bols 1e bachelor Informatica
|
|
||||||
* Leen Dereu 1e bachelor Informatica
|
|
||||||
*
|
|
||||||
* URL: https://github.com/KUL-ogp/ogp1718-project-bols-dereu
|
|
||||||
*/
|
*/
|
||||||
public class Worm extends GameObject {
|
public class Worm extends GameObject {
|
||||||
|
|
||||||
@@ -42,21 +41,14 @@ public class Worm extends GameObject {
|
|||||||
//===================================================================================
|
//===================================================================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*Initialize the new worm with given location, orientation, name and radius.
|
* Initialize the new worm with given location, orientation, name and radius.
|
||||||
*
|
|
||||||
* @param world
|
|
||||||
* The world this worm belongs to.
|
|
||||||
* @param location
|
|
||||||
* The location for the new worm.
|
|
||||||
* @param direction
|
|
||||||
* The direction for the new worm.
|
|
||||||
* @param name
|
|
||||||
* The name for the new worm.
|
|
||||||
* @param radius
|
|
||||||
* The radius for the new worm.
|
|
||||||
* @param team
|
|
||||||
* The team of the new worm.
|
|
||||||
*
|
*
|
||||||
|
* @param world The world this worm belongs to.
|
||||||
|
* @param location The location for the new worm.
|
||||||
|
* @param direction The direction for the new worm.
|
||||||
|
* @param name The name for the new worm.
|
||||||
|
* @param radius The radius for the new worm.
|
||||||
|
* @param team The team of the new worm.
|
||||||
* @post The new world of the worm is equal to the given world.
|
* @post The new world of the worm is equal to the given world.
|
||||||
* |new.getWorld() == world
|
* |new.getWorld() == world
|
||||||
* @post The new location of the worm is equal to the given location.
|
* @post The new location of the worm is equal to the given location.
|
||||||
@@ -78,23 +70,23 @@ public class Worm extends GameObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*initialize the new worm with given location, orientation, name, radius and minimum radius
|
* initialize the new worm with given location, orientation, name, radius and minimum radius
|
||||||
*
|
|
||||||
* @param world
|
|
||||||
* The world for the new worm.
|
|
||||||
* @param location
|
|
||||||
* The location for the new worm.
|
|
||||||
* @param orientation
|
|
||||||
* The orientation for the new worm.
|
|
||||||
* @param name
|
|
||||||
* The name for the new worm.
|
|
||||||
* @param radius
|
|
||||||
* The radius for the new worm.
|
|
||||||
* @param minRadius
|
|
||||||
* The minimum radius the new worm can have.
|
|
||||||
* @param team
|
|
||||||
* The team for the new worm.
|
|
||||||
*
|
*
|
||||||
|
* @param world The world for the new worm.
|
||||||
|
* @param location The location for the new worm.
|
||||||
|
* @param orientation The orientation for the new worm.
|
||||||
|
* @param name The name for the new worm.
|
||||||
|
* @param radius The radius for the new worm.
|
||||||
|
* @param minRadius The minimum radius the new worm can have.
|
||||||
|
* @param team The team for the new worm.
|
||||||
|
* @throws IllegalArgumentException The given location is not a valid location for a worm.
|
||||||
|
* |!isValidLocation(location)
|
||||||
|
* @throws IllegalArgumentException The given minimum radius is not a valid minimum radius for a worm.
|
||||||
|
* |!isValidMinRadius(minRadius)
|
||||||
|
* @throws IllegalArgumentException The given radius can not be a minimum radius for a worm.
|
||||||
|
* |!canHaveAsMinRadius(radius)
|
||||||
|
* @throws IllegalNameException The given name is not a valid name for a worm.
|
||||||
|
* |isValidName(name)
|
||||||
* @post The new world of the worm is equal to the given world.
|
* @post The new world of the worm is equal to the given world.
|
||||||
* |new.getWorld() == world
|
* |new.getWorld() == world
|
||||||
* @post The new location of the worm is equal to the given location.
|
* @post The new location of the worm is equal to the given location.
|
||||||
@@ -111,19 +103,6 @@ public class Worm extends GameObject {
|
|||||||
* |new.getActionPoints() == getMaxActionPoints()
|
* |new.getActionPoints() == getMaxActionPoints()
|
||||||
* @post The new value of hit points of the worm is equal to the start value for hit points.
|
* @post The new value of hit points of the worm is equal to the start value for hit points.
|
||||||
* |new.getHitPoints() == startHitPoints
|
* |new.getHitPoints() == startHitPoints
|
||||||
*
|
|
||||||
* @throws IllegalArgumentException
|
|
||||||
* The given location is not a valid location for a worm.
|
|
||||||
* |!isValidLocation(location)
|
|
||||||
* @throws IllegalArgumentException
|
|
||||||
* The given minimum radius is not a valid minimum radius for a worm.
|
|
||||||
* |!isValidMinRadius(minRadius)
|
|
||||||
* @throws IllegalArgumentException
|
|
||||||
* The given radius can not be a minimum radius for a worm.
|
|
||||||
* |!canHaveAsMinRadius(radius)
|
|
||||||
* @throws IllegalNameException
|
|
||||||
* The given name is not a valid name for a worm.
|
|
||||||
* |isValidName(name)
|
|
||||||
*/
|
*/
|
||||||
@Raw
|
@Raw
|
||||||
public Worm(World world, double[] location, double orientation, String name, double radius, double minRadius, Team team)
|
public Worm(World world, double[] location, double orientation, String name, double radius, double minRadius, Team team)
|
||||||
@@ -162,7 +141,8 @@ public class Worm extends GameObject {
|
|||||||
* The orientation of a worm expresses the direction in which
|
* The orientation of a worm expresses the direction in which
|
||||||
* the worm is looking.
|
* the worm is looking.
|
||||||
*/
|
*/
|
||||||
@Basic @Raw
|
@Basic
|
||||||
|
@Raw
|
||||||
public double getOrientation() {
|
public double getOrientation() {
|
||||||
return orientation;
|
return orientation;
|
||||||
}
|
}
|
||||||
@@ -175,8 +155,7 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* Set the orientation of the worm to the given orientation.
|
* Set the orientation of the worm to the given orientation.
|
||||||
*
|
*
|
||||||
* @param orientation
|
* @param orientation The new orientation of the worm.
|
||||||
* The new orientation of the worm.
|
|
||||||
* @pre The given orientation must be a valid orientation for any worm.
|
* @pre The given orientation must be a valid orientation for any worm.
|
||||||
* |isValidOrientation(orientation)
|
* |isValidOrientation(orientation)
|
||||||
* @post The new orientation of the worm must be equal to the given orientation.
|
* @post The new orientation of the worm must be equal to the given orientation.
|
||||||
@@ -191,8 +170,7 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* Check whether the given orientation is a valid orientation for the worm.
|
* Check whether the given orientation is a valid orientation for the worm.
|
||||||
*
|
*
|
||||||
* @param newOrientation
|
* @param newOrientation The orientation to check.
|
||||||
* The orientation to check.
|
|
||||||
* @return True if and only if the orientation is bigger then and smaller then 2pi.
|
* @return True if and only if the orientation is bigger then and smaller then 2pi.
|
||||||
* |result == ( newOrientation >= 0 && newOrientation < 2 * PI )
|
* |result == ( newOrientation >= 0 && newOrientation < 2 * PI )
|
||||||
*/
|
*/
|
||||||
@@ -210,8 +188,7 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* Check whether the given radius is a valid minimum radius for the worm.
|
* Check whether the given radius is a valid minimum radius for the worm.
|
||||||
*
|
*
|
||||||
* @param minRadius
|
* @param minRadius The radius to check.
|
||||||
* The radius to check.
|
|
||||||
* @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))
|
||||||
*/
|
*/
|
||||||
@@ -222,15 +199,14 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* Set the radius of the worm to the given radius.
|
* Set the radius of the worm to the given radius.
|
||||||
*
|
*
|
||||||
* @param radius
|
* @param radius The new radius for the worm.
|
||||||
* The new radius for the worm.
|
* @throws IllegalArgumentException The given radius is not a valid radius for any worm.
|
||||||
|
* |! canHaveAsMinRadius(radius)
|
||||||
* @post The new radius of the worm is equal to the given radius.
|
* @post The new radius of the worm is equal to the given radius.
|
||||||
* |new.getRadius() == radius
|
* |new.getRadius() == radius
|
||||||
* @throws IllegalArgumentException
|
|
||||||
* The given radius is not a valid radius for any worm.
|
|
||||||
* |! canHaveAsMinRadius(radius)
|
|
||||||
*/
|
*/
|
||||||
@Raw @Override
|
@Raw
|
||||||
|
@Override
|
||||||
public void setRadius(double radius) throws IllegalArgumentException {
|
public void setRadius(double radius) throws IllegalArgumentException {
|
||||||
if (!canHaveAsRadius(radius))
|
if (!canHaveAsRadius(radius))
|
||||||
throw new IllegalArgumentException("Invalid radius");
|
throw new IllegalArgumentException("Invalid radius");
|
||||||
@@ -246,7 +222,8 @@ public class Worm extends GameObject {
|
|||||||
* The minimum radius of the worm expresses the minimum length
|
* The minimum radius of the worm expresses the minimum length
|
||||||
* of half of the width of the worm.
|
* of half of the width of the worm.
|
||||||
*/
|
*/
|
||||||
@Basic @Raw
|
@Basic
|
||||||
|
@Raw
|
||||||
public double getMinRadius() {
|
public double getMinRadius() {
|
||||||
return this.minRadius;
|
return this.minRadius;
|
||||||
}
|
}
|
||||||
@@ -259,8 +236,7 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* Check whether the given radius is a valid radius for the worm.
|
* Check whether the given radius is a valid radius for the worm.
|
||||||
*
|
*
|
||||||
* @param radius
|
* @param radius The radius to check.
|
||||||
* The radius to check.
|
|
||||||
* @return True if and only if the radius is bigger then the minimum radius
|
* @return True if and only if the radius is bigger then the minimum radius
|
||||||
* (or equal) and the radius is a number.
|
* (or equal) and the radius is a number.
|
||||||
* |result == (radius >= getMinRadius() && !Double.isNaN(radius))
|
* |result == (radius >= getMinRadius() && !Double.isNaN(radius))
|
||||||
@@ -274,7 +250,8 @@ public class Worm extends GameObject {
|
|||||||
* Return the mass of the worm.
|
* Return the mass of the worm.
|
||||||
* The mass of the worm expresses the weight of the worm.
|
* The mass of the worm expresses the weight of the worm.
|
||||||
*/
|
*/
|
||||||
@Basic @Raw
|
@Basic
|
||||||
|
@Raw
|
||||||
public double getMass() {
|
public double getMass() {
|
||||||
return this.mass;
|
return this.mass;
|
||||||
}
|
}
|
||||||
@@ -283,7 +260,6 @@ public class Worm extends GameObject {
|
|||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// region ActionPoints
|
// region ActionPoints
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
|
|
||||||
@@ -291,7 +267,8 @@ public class Worm extends GameObject {
|
|||||||
* Return the current action points of the worm.
|
* Return the current action points of the worm.
|
||||||
* The action points identifies the energy of the worm.
|
* The action points identifies the energy of the worm.
|
||||||
*/
|
*/
|
||||||
@Basic @Raw
|
@Basic
|
||||||
|
@Raw
|
||||||
public long getActionPoints() {
|
public long getActionPoints() {
|
||||||
return this.actionPoints;
|
return this.actionPoints;
|
||||||
}
|
}
|
||||||
@@ -300,7 +277,8 @@ public class Worm extends GameObject {
|
|||||||
* Return the maximum of action points of the worm.
|
* Return the maximum of action points of the worm.
|
||||||
* The maximum action points identifies the maximum energy of the worm.
|
* The maximum action points identifies the maximum energy of the worm.
|
||||||
*/
|
*/
|
||||||
@Basic @Raw
|
@Basic
|
||||||
|
@Raw
|
||||||
public long getMaxActionPoints() {
|
public long getMaxActionPoints() {
|
||||||
return this.maxActionPoints;
|
return this.maxActionPoints;
|
||||||
}
|
}
|
||||||
@@ -308,8 +286,7 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* Set the current points of the worm to the given points.
|
* Set the current points of the worm to the given points.
|
||||||
*
|
*
|
||||||
* @param actionPoints
|
* @param actionPoints The new points for the worm.
|
||||||
* The new points for the worm.
|
|
||||||
* @post If the given points are bigger then the maximum points, the current points
|
* @post If the given points are bigger then the maximum points, the current points
|
||||||
* are equal to the maximum points. If the given points are lower then 0
|
* are equal to the maximum points. If the given points are lower then 0
|
||||||
* the current points are equal to 0. If the given points is between the
|
* the current points are equal to 0. If the given points is between the
|
||||||
@@ -333,12 +310,11 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* Substract the current points of the worm.
|
* Substract the current points of the worm.
|
||||||
*
|
*
|
||||||
* @param delta
|
* @param delta The value which should be decreased.
|
||||||
* The value which should be decreased.
|
|
||||||
* @post The current points are set to the old current points minus the given value.
|
* @post The current points are set to the old current points minus the given value.
|
||||||
* |setActionPoints(getActionPoints() - delta)
|
* |setActionPoints(getActionPoints() - delta)
|
||||||
*/
|
*/
|
||||||
public void decreaseActionPoints (long delta) {
|
public void decreaseActionPoints(long delta) {
|
||||||
|
|
||||||
setActionPoints(getActionPoints() - delta);
|
setActionPoints(getActionPoints() - delta);
|
||||||
}
|
}
|
||||||
@@ -356,8 +332,7 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* Set the maximum of points to the given maximum of points.
|
* Set the maximum of points to the given maximum of points.
|
||||||
*
|
*
|
||||||
* @param maxActionPoints
|
* @param maxActionPoints The new maximum of points for the worm.
|
||||||
* The new maximum of points for the worm.
|
|
||||||
* @post The new maximum points is set to the given maximum points (as an integer).
|
* @post The new maximum points is set to the given maximum points (as an integer).
|
||||||
* |this.maxPoints = round(maxActionPoints)
|
* |this.maxPoints = round(maxActionPoints)
|
||||||
* @post When the maximum points change, the current points should change too.
|
* @post When the maximum points change, the current points should change too.
|
||||||
@@ -372,12 +347,11 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* Substract the current points of the worm.
|
* Substract the current points of the worm.
|
||||||
*
|
*
|
||||||
* @param value
|
* @param value The value which should be subtracted.
|
||||||
* The value which should be subtracted.
|
|
||||||
* @post The current points are set to the old current points minus the given value.
|
* @post The current points are set to the old current points minus the given value.
|
||||||
* |setActionPoints(getActionPoints() - value)
|
* |setActionPoints(getActionPoints() - value)
|
||||||
*/
|
*/
|
||||||
private void subtractActionPoints (long value) {
|
private void subtractActionPoints(long value) {
|
||||||
|
|
||||||
setActionPoints(getActionPoints() - value);
|
setActionPoints(getActionPoints() - value);
|
||||||
}
|
}
|
||||||
@@ -385,13 +359,12 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* Substract the current points of the worm.
|
* Substract the current points of the worm.
|
||||||
*
|
*
|
||||||
* @param angle
|
* @param angle The angle needed to calculate the new current points.
|
||||||
* The angle needed to calculate the new current points.
|
|
||||||
* @post The current points are set to the old current points minus
|
* @post The current points are set to the old current points minus
|
||||||
* the angle (in degrees) divided by 6.
|
* the angle (in degrees) divided by 6.
|
||||||
* |setActionPoints(getActionPoints() - (long) ceil(toDegrees(angle) / 6))
|
* |setActionPoints(getActionPoints() - (long) ceil(toDegrees(angle) / 6))
|
||||||
*/
|
*/
|
||||||
private void subtractActionPoints (double angle) {
|
private void subtractActionPoints(double angle) {
|
||||||
|
|
||||||
setActionPoints(getActionPoints() - (long) ceil(toDegrees(angle) / 6));
|
setActionPoints(getActionPoints() - (long) ceil(toDegrees(angle) / 6));
|
||||||
}
|
}
|
||||||
@@ -400,7 +373,6 @@ public class Worm extends GameObject {
|
|||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// region name
|
// region name
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
|
|
||||||
@@ -408,7 +380,9 @@ public class Worm extends GameObject {
|
|||||||
* Return the name of the worm.
|
* Return the name of the worm.
|
||||||
* The name of the worm expresses the identity of the worm.
|
* The name of the worm expresses the identity of the worm.
|
||||||
*/
|
*/
|
||||||
@Basic @Immutable @Raw
|
@Basic
|
||||||
|
@Immutable
|
||||||
|
@Raw
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
@@ -416,8 +390,7 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* Check whether the given name is a valid name for all worms.
|
* Check whether the given name is a valid name for all worms.
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name The name to check.
|
||||||
* The name to check.
|
|
||||||
* @return -1 if and only if the given name is longer then 2,
|
* @return -1 if and only if the given name is longer then 2,
|
||||||
* the first letter is uppercase and the name only exists
|
* the first letter is uppercase and the name only exists
|
||||||
* of letters, " ", " ' " and " "" ".
|
* of letters, " ", " ' " and " "" ".
|
||||||
@@ -426,7 +399,7 @@ public class Worm extends GameObject {
|
|||||||
* |&& Character.isLetter(name.charAt(i)) &&
|
* |&& Character.isLetter(name.charAt(i)) &&
|
||||||
* |allowedCharacters.indexOf(name.charAt(i)))
|
* |allowedCharacters.indexOf(name.charAt(i)))
|
||||||
*/
|
*/
|
||||||
public static int isValidName (String name) {
|
public static int isValidName(String name) {
|
||||||
|
|
||||||
if (name.length() < 2 || !Character.isUpperCase(name.charAt(0))) {
|
if (name.length() < 2 || !Character.isUpperCase(name.charAt(0))) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -446,13 +419,11 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* Set the name of the worm tot the given name.
|
* Set the name of the worm tot the given name.
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name The new name for the worm.
|
||||||
* The new name for the worm.
|
* @throws IllegalNameException The given name is not a valid name for any worm.
|
||||||
|
* |! isValidName(name)
|
||||||
* @post The new name of the worm is equal to the given name.
|
* @post The new name of the worm is equal to the given name.
|
||||||
* |new.getName() == name
|
* |new.getName() == name
|
||||||
* @throws IllegalNameException
|
|
||||||
* The given name is not a valid name for any worm.
|
|
||||||
* |! isValidName(name)
|
|
||||||
*/
|
*/
|
||||||
@Raw
|
@Raw
|
||||||
public void setName(String name) throws IllegalNameException {
|
public void setName(String name) throws IllegalNameException {
|
||||||
@@ -473,13 +444,14 @@ public class Worm extends GameObject {
|
|||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// region move
|
// region move
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move the worm for the given number of steps.
|
* Move the worm for the given number of steps.
|
||||||
*
|
*
|
||||||
|
* @throws IllegalArgumentException The cost of the step is bigger then the worms current action points.
|
||||||
|
* |cost > getActionPoints()
|
||||||
* @post The newlocation of the worm is the furthest possible step the worm can take. Depending on its
|
* @post The newlocation of the worm is the furthest possible step the worm can take. Depending on its
|
||||||
* radius and surroundings.
|
* radius and surroundings.
|
||||||
* |new.getLocation() = FurthestLocationInDirection
|
* |new.getLocation() = FurthestLocationInDirection
|
||||||
@@ -489,10 +461,6 @@ public class Worm extends GameObject {
|
|||||||
* |new.getActionPoints() == old.getActionPoints() - (abs(distance * cos(new.getOrientation()) + abs(4 * distance * sin(new.getOrientation())))
|
* |new.getActionPoints() == old.getActionPoints() - (abs(distance * cos(new.getOrientation()) + abs(4 * distance * sin(new.getOrientation())))
|
||||||
* @post Let the worm eat if necessary.
|
* @post Let the worm eat if necessary.
|
||||||
* |checkEat()
|
* |checkEat()
|
||||||
*
|
|
||||||
* @throws IllegalArgumentException
|
|
||||||
* The cost of the step is bigger then the worms current action points.
|
|
||||||
* |cost > getActionPoints()
|
|
||||||
*/
|
*/
|
||||||
public void move() throws IllegalArgumentException {
|
public void move() throws IllegalArgumentException {
|
||||||
|
|
||||||
@@ -514,11 +482,8 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* Gives the biggest step possible for the worm.
|
* Gives the biggest step possible for the worm.
|
||||||
*
|
*
|
||||||
* @param direction
|
* @param direction The direction of the worm.
|
||||||
* The direction of the worm.
|
* @param maxDistance The maximum distance the worm can move.
|
||||||
* @param maxDistance
|
|
||||||
* The maximum distance the worm can move.
|
|
||||||
*
|
|
||||||
* @return The furthest possible location for the given direction and maximum distance.
|
* @return The furthest possible location for the given direction and maximum distance.
|
||||||
* The new location has to be passable.
|
* The new location has to be passable.
|
||||||
* |result == (0 <= new.getLocation() <= maxDistance) && (world.isPassable(new.getLocation(), radius))
|
* |result == (0 <= new.getLocation() <= maxDistance) && (world.isPassable(new.getLocation(), radius))
|
||||||
@@ -531,7 +496,7 @@ public class Worm extends GameObject {
|
|||||||
if (step > radius) step = radius;
|
if (step > radius) step = radius;
|
||||||
Coordinate nextLoc = currentLocation;
|
Coordinate nextLoc = currentLocation;
|
||||||
|
|
||||||
while(getDistance(currentLocation, nextLoc) < maxDistance) {
|
while (getDistance(currentLocation, nextLoc) < maxDistance) {
|
||||||
|
|
||||||
nextLoc = Coordinate.create(round((nextLoc.getX() + 0.1 * cos(direction)) * 100.0) / 100.0,
|
nextLoc = Coordinate.create(round((nextLoc.getX() + 0.1 * cos(direction)) * 100.0) / 100.0,
|
||||||
round((nextLoc.getY() + step * sin(direction)) * 100.0) / 100.0);
|
round((nextLoc.getY() + step * sin(direction)) * 100.0) / 100.0);
|
||||||
@@ -586,11 +551,8 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* Gives the distance between two coordinates.
|
* Gives the distance between two coordinates.
|
||||||
*
|
*
|
||||||
* @param start
|
* @param start The start coordinate of the equation.
|
||||||
* The start coordinate of the equation.
|
* @param end The end coordinate of the equation.
|
||||||
* @param end
|
|
||||||
* The end coordinate of the equation.
|
|
||||||
*
|
|
||||||
* @return the distance between the two given coordinates. The distance is equal to
|
* @return the distance between the two given coordinates. The distance is equal to
|
||||||
* the square root of the square of the displacement of the x coordinate plus the
|
* the square root of the square of the displacement of the x coordinate plus the
|
||||||
* square of the displacement of the y coordinate.
|
* square of the displacement of the y coordinate.
|
||||||
@@ -604,11 +566,8 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* The clashing worms their hit points are reduced.
|
* The clashing worms their hit points are reduced.
|
||||||
*
|
*
|
||||||
* @param basicWorm
|
* @param basicWorm The worm who has moved.
|
||||||
* The worm who has moved.
|
* @param worm The worms who has clashed with the basicworm.
|
||||||
* @param worm
|
|
||||||
* The worms who has clashed with the basicworm.
|
|
||||||
*
|
|
||||||
* @post All the worms that clashed their hitpoints are reduced. There is a random integer between
|
* @post All the worms that clashed their hitpoints are reduced. There is a random integer between
|
||||||
* 1 and 10 (= N). The lose of the smalles worm is equal to N divided by the orientation of the largest
|
* 1 and 10 (= N). The lose of the smalles worm is equal to N divided by the orientation of the largest
|
||||||
* worm that is divided by the orientation of the smallest worm plus the orientatie of the largest one.
|
* worm that is divided by the orientation of the smallest worm plus the orientatie of the largest one.
|
||||||
@@ -619,12 +578,11 @@ public class Worm extends GameObject {
|
|||||||
public void collision(Worm basicWorm, Worm... worm) {
|
public void collision(Worm basicWorm, Worm... worm) {
|
||||||
Worm largestWorm;
|
Worm largestWorm;
|
||||||
Worm smallestWorm;
|
Worm smallestWorm;
|
||||||
for (Worm w1: worm) {
|
for (Worm w1 : worm) {
|
||||||
if (w1.getMass() > basicWorm.getMass()) {
|
if (w1.getMass() > basicWorm.getMass()) {
|
||||||
largestWorm = w1;
|
largestWorm = w1;
|
||||||
smallestWorm = basicWorm;
|
smallestWorm = basicWorm;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
largestWorm = basicWorm;
|
largestWorm = basicWorm;
|
||||||
smallestWorm = w1;
|
smallestWorm = w1;
|
||||||
}
|
}
|
||||||
@@ -646,8 +604,7 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* Turns the worm with the given angle.
|
* Turns the worm with the given angle.
|
||||||
*
|
*
|
||||||
* @param angle
|
* @param angle The angle that must be added to the orientation.
|
||||||
* The angle that must be added to the orientation.
|
|
||||||
* @pre The angle to add must be between 0 and 2pi (including 0).
|
* @pre The angle to add must be between 0 and 2pi (including 0).
|
||||||
* |0 <= angle < 2pi
|
* |0 <= angle < 2pi
|
||||||
* @post The new orientation is the old orientation plus the given angle.
|
* @post The new orientation is the old orientation plus the given angle.
|
||||||
@@ -667,13 +624,12 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* Return a boolean reflecting whether the worm can accept the given angle to turn.
|
* Return a boolean reflecting whether the worm can accept the given angle to turn.
|
||||||
*
|
*
|
||||||
* @param angle
|
* @param angle The angle to be checked.
|
||||||
* The angle to be checked.
|
|
||||||
* @return True if and only if the given angle is between 0 (including) and 2pi,
|
* @return True if and only if the given angle is between 0 (including) and 2pi,
|
||||||
* the angle is a number and the current number of action points is high enough to turn.
|
* the angle is a number and the current number of action points is high enough to turn.
|
||||||
* |result == ( (0 <= angle) && (angle < (2 * PI)) &&
|
* |result == ( (0 <= angle) && (angle < (2 * PI)) &&
|
||||||
| (!Double.isNaN(angle)) &&
|
* | (!Double.isNaN(angle)) &&
|
||||||
| (getActionPoints() - (long) ceil(toDegrees(angle) / 6) >= 0) )
|
* | (getActionPoints() - (long) ceil(toDegrees(angle) / 6) >= 0) )
|
||||||
*/
|
*/
|
||||||
private boolean canTurn(double angle) {
|
private boolean canTurn(double angle) {
|
||||||
double currentAngle = getOrientation();
|
double currentAngle = getOrientation();
|
||||||
@@ -691,7 +647,7 @@ public class Worm extends GameObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This constant contains the gravity.
|
* This constant contains the gravity.
|
||||||
* */
|
*/
|
||||||
public static final double G = 5.0;
|
public static final double G = 5.0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -702,6 +658,9 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* Let the worm jump.
|
* Let the worm jump.
|
||||||
*
|
*
|
||||||
|
* @throws IllegalStateException if the current action actionPoints is equal to 0 or the orientation is more then
|
||||||
|
* pi the worm can not jump
|
||||||
|
* |!canJump()
|
||||||
* @post the new x coordinate is equal to the old x coordinate plus the jump velocity multiplied with the
|
* @post the new x coordinate is equal to the old x coordinate plus the jump velocity multiplied with the
|
||||||
* jump time multiplied with the cosinus of the orientation
|
* jump time multiplied with the cosinus of the orientation
|
||||||
* |new.getLocation().getX() = old.getLocation.getX() + jumpVelocity * jumpTime * cos(getOrientation())
|
* |new.getLocation().getX() = old.getLocation.getX() + jumpVelocity * jumpTime * cos(getOrientation())
|
||||||
@@ -716,11 +675,6 @@ public class Worm extends GameObject {
|
|||||||
* | terminate();
|
* | terminate();
|
||||||
* @post Let the worm eat if necessary.
|
* @post Let the worm eat if necessary.
|
||||||
* |checkEat()
|
* |checkEat()
|
||||||
*
|
|
||||||
* @throws IllegalStateException
|
|
||||||
* if the current action actionPoints is equal to 0 or the orientation is more then
|
|
||||||
* pi the worm can not jump
|
|
||||||
* |!canJump()
|
|
||||||
*/
|
*/
|
||||||
public void jump() throws IllegalStateException {
|
public void jump() throws IllegalStateException {
|
||||||
|
|
||||||
@@ -750,8 +704,7 @@ public class Worm extends GameObject {
|
|||||||
* @return The time the worm will jump. The distance divided by the velocity multiplied
|
* @return The time the worm will jump. The distance divided by the velocity multiplied
|
||||||
* with the cosinus of the orientation.
|
* with the cosinus of the orientation.
|
||||||
* |jumpDistance(this.jumpVelocity) / (this.jumpVelocity * Math.cos(this.orientation))
|
* |jumpDistance(this.jumpVelocity) / (this.jumpVelocity * Math.cos(this.orientation))
|
||||||
* @throws IllegalStateException
|
* @throws IllegalStateException Orientation is bigger then pi or action points is equal to 0.
|
||||||
* Orientation is bigger then pi or action points is equal to 0.
|
|
||||||
* |getOrientation() >= PI || getActionPoints() == 0
|
* |getOrientation() >= PI || getActionPoints() == 0
|
||||||
*/
|
*/
|
||||||
public double jumpTime() {
|
public double jumpTime() {
|
||||||
@@ -762,16 +715,14 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* Gives the location after a jump.
|
* Gives the location after a jump.
|
||||||
*
|
*
|
||||||
* @param deltaTime
|
* @param deltaTime The total time the worm should jump.
|
||||||
* The total time the worm should jump.
|
|
||||||
* @return Coordinate with the new location of the worm. The new x-coordinate is the old x-coordinate plus the jump velocity
|
* @return Coordinate with the new location of the worm. The new x-coordinate is the old x-coordinate plus the jump velocity
|
||||||
* multiplied with the cosinus of the orientation multiplied with delta time. The new y-coordinate is the old y-coordinate plus
|
* multiplied with the cosinus of the orientation multiplied with delta time. The new y-coordinate is the old y-coordinate plus
|
||||||
* the jump velocity multiplied with the sinus of the orientation multiplied with delta time minus 0,5 times the gravity multiplied
|
* the jump velocity multiplied with the sinus of the orientation multiplied with delta time minus 0,5 times the gravity multiplied
|
||||||
* with the second power of delta time.
|
* with the second power of delta time.
|
||||||
* |Coordinate.create(getLocation().getX() + this.jumpVelocity() * cos(getOrientation()) * deltaTime,
|
* |Coordinate.create(getLocation().getX() + this.jumpVelocity() * cos(getOrientation()) * deltaTime,
|
||||||
|getLocation().getY() + this.jumpVelocity() * sin(getOrientation()) * deltaTime - 0.5 * G * pow(deltaTime, 2))
|
* |getLocation().getY() + this.jumpVelocity() * sin(getOrientation()) * deltaTime - 0.5 * G * pow(deltaTime, 2))
|
||||||
* @throws IllegalArgumentException()
|
* @throws IllegalArgumentException() If the deltaTime is not a number or bigger then jumpTime or smaller then 0.
|
||||||
* If the deltaTime is not a number or bigger then jumpTime or smaller then 0.
|
|
||||||
* |if (Double.isNaN(deltaTime) || deltaTime > this.jumpTime() || deltaTime < 0)
|
* |if (Double.isNaN(deltaTime) || deltaTime > this.jumpTime() || deltaTime < 0)
|
||||||
*/
|
*/
|
||||||
public Coordinate jumpStep(double deltaTime) {
|
public Coordinate jumpStep(double deltaTime) {
|
||||||
@@ -810,7 +761,7 @@ public class Worm extends GameObject {
|
|||||||
double radius = getRadius();
|
double radius = getRadius();
|
||||||
Coordinate newLoc;
|
Coordinate newLoc;
|
||||||
|
|
||||||
while(true) {
|
while (true) {
|
||||||
|
|
||||||
t += 0.05;
|
t += 0.05;
|
||||||
double x = loc.getX() + v * t * cos(a);
|
double x = loc.getX() + v * t * cos(a);
|
||||||
@@ -874,8 +825,7 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* Return the distance the worm will jump.
|
* Return the distance the worm will jump.
|
||||||
*
|
*
|
||||||
* @param v
|
* @param v The velocity of the jump.
|
||||||
* The velocity of the jump.
|
|
||||||
* @return The distance the worm will jump. The distance is equal to the velocity powered by 2 multiplied
|
* @return The distance the worm will jump. The distance is equal to the velocity powered by 2 multiplied
|
||||||
* with the sinus of 2 times the orientation en this divided with the gravity.
|
* with the sinus of 2 times the orientation en this divided with the gravity.
|
||||||
* |(pow(v, 2) * sin(2 * getOrientation())) / G
|
* |(pow(v, 2) * sin(2 * getOrientation())) / G
|
||||||
@@ -887,9 +837,7 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* Returns of the jump distance valid is.
|
* Returns of the jump distance valid is.
|
||||||
*
|
*
|
||||||
* @param distance
|
* @param distance The distance of the jump.
|
||||||
* The distance of the jump.
|
|
||||||
*
|
|
||||||
* @return True if and only if the absolute value of the distance bigger or equal is
|
* @return True if and only if the absolute value of the distance bigger or equal is
|
||||||
* to the radius.
|
* to the radius.
|
||||||
* |result == (abs(distance) >= getRadius())
|
* |result == (abs(distance) >= getRadius())
|
||||||
@@ -917,22 +865,17 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* Decreases the hit points of the attacked worm (chosen by a coin).
|
* Decreases the hit points of the attacked worm (chosen by a coin).
|
||||||
*
|
*
|
||||||
* @param newLocation
|
* @param newLocation The new location of the jumped worm.
|
||||||
* The new location of the jumped worm.
|
* @param oldLocation The old location of the jumped worm.
|
||||||
* @param oldLocation
|
* @param worm1 The jumped worm.
|
||||||
* The old location of the jumped worm.
|
* @param worm2 The worms who stand on the same place (or parial) of the jumped worm.
|
||||||
* @param worm1
|
|
||||||
* The jumped worm.
|
|
||||||
* @param worm2
|
|
||||||
* The worms who stand on the same place (or parial) of the jumped worm.
|
|
||||||
*
|
|
||||||
* @post the attacked worms hit points are decreased with random value between 1 and 10 multiplied
|
* @post the attacked worms hit points are decreased with random value between 1 and 10 multiplied
|
||||||
* with the rate of the radius of the attacker and the radius of the attacked worm.
|
* with the rate of the radius of the attacker and the radius of the attacked worm.
|
||||||
* |new.attackedWorm.getHitPoints() == old.attackedWorm.getHitPoints() - 10 * ((attacker.getRadius())/(attackedWorm.getRadius()))
|
* |new.attackedWorm.getHitPoints() == old.attackedWorm.getHitPoints() - 10 * ((attacker.getRadius())/(attackedWorm.getRadius()))
|
||||||
*/
|
*/
|
||||||
public void fight(Coordinate newLocation, Coordinate oldLocation, Worm worm1, Worm... worm2) {
|
public void fight(Coordinate newLocation, Coordinate oldLocation, Worm worm1, Worm... worm2) {
|
||||||
if (! worm1.isTerminated() && newLocation != oldLocation) {
|
if (!worm1.isTerminated() && newLocation != oldLocation) {
|
||||||
for (Worm wormB: worm2) {
|
for (Worm wormB : worm2) {
|
||||||
Worm attackedWorm;
|
Worm attackedWorm;
|
||||||
Worm attacker;
|
Worm attacker;
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
@@ -940,12 +883,11 @@ public class Worm extends GameObject {
|
|||||||
if (coin == 1) {
|
if (coin == 1) {
|
||||||
attackedWorm = worm1;
|
attackedWorm = worm1;
|
||||||
attacker = wormB;
|
attacker = wormB;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
attackedWorm = wormB;
|
attackedWorm = wormB;
|
||||||
attacker = worm1;
|
attacker = worm1;
|
||||||
}
|
}
|
||||||
double N = 10 * ceil((attacker.getRadius())/(attackedWorm.getRadius()));
|
double N = 10 * ceil((attacker.getRadius()) / (attackedWorm.getRadius()));
|
||||||
long loseAttackedWorm = (long) rand.nextInt((((int) N) - 1) + 1) + 1;
|
long loseAttackedWorm = (long) rand.nextInt((((int) N) - 1) + 1) + 1;
|
||||||
attackedWorm.decreaseHitPoints(loseAttackedWorm);
|
attackedWorm.decreaseHitPoints(loseAttackedWorm);
|
||||||
}
|
}
|
||||||
@@ -963,7 +905,8 @@ public class Worm extends GameObject {
|
|||||||
* Return the current hit points of the worm.
|
* Return the current hit points of the worm.
|
||||||
* The hit points identifies the strength of the worm.
|
* The hit points identifies the strength of the worm.
|
||||||
*/
|
*/
|
||||||
@Basic @Raw
|
@Basic
|
||||||
|
@Raw
|
||||||
public long getHitPoints() {
|
public long getHitPoints() {
|
||||||
return this.hitPoints;
|
return this.hitPoints;
|
||||||
}
|
}
|
||||||
@@ -971,8 +914,7 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* Set the current hit points of the worm to the given points.
|
* Set the current hit points of the worm to the given points.
|
||||||
*
|
*
|
||||||
* @param hitPoints
|
* @param hitPoints The new points for the worm.
|
||||||
* The new points for the worm.
|
|
||||||
* @post If the given points are equal or lower then zero, the worm should be dead.
|
* @post If the given points are equal or lower then zero, the worm should be dead.
|
||||||
* Otherwise the current hit points are set to the given points.
|
* Otherwise the current hit points are set to the given points.
|
||||||
* |if (hitpoints <= 0)
|
* |if (hitpoints <= 0)
|
||||||
@@ -995,8 +937,7 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* Decrease the hit points with the given value.
|
* Decrease the hit points with the given value.
|
||||||
*
|
*
|
||||||
* @param value
|
* @param value The value that should be decreased.
|
||||||
* The value that should be decreased.
|
|
||||||
* @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
|
||||||
*/
|
*/
|
||||||
@@ -1007,8 +948,7 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* Increment the hit points with the given value.
|
* Increment the hit points with the given value.
|
||||||
*
|
*
|
||||||
* @param value
|
* @param value The value that schould be added.
|
||||||
* The value that schould be added.
|
|
||||||
* @post The current hit points should be increaseed with the given value.
|
* @post The current hit points should be increaseed with the given value.
|
||||||
* |new.getHitPoints() == old.getHitPoints() + value
|
* |new.getHitPoints() == old.getHitPoints() + value
|
||||||
*/
|
*/
|
||||||
@@ -1017,7 +957,6 @@ public class Worm extends GameObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
@@ -1072,17 +1011,14 @@ public class Worm extends GameObject {
|
|||||||
*/
|
*/
|
||||||
public boolean canFall() {
|
public boolean canFall() {
|
||||||
double[] center = {getLocation().getX(), getLocation().getY()};
|
double[] center = {getLocation().getX(), getLocation().getY()};
|
||||||
return ! getWorld().isAdjacent(center, getRadius());
|
return !getWorld().isAdjacent(center, getRadius());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes the hit points of the clashing worms.
|
* Changes the hit points of the clashing worms.
|
||||||
*
|
*
|
||||||
* @param fallingWorm
|
* @param fallingWorm The worm who has fallen.
|
||||||
* The worm who has fallen.
|
* @param worm The worm on which the falling worm has fallen.
|
||||||
* @param worm
|
|
||||||
* The worm on which the falling worm has fallen.
|
|
||||||
*
|
|
||||||
* @post the falling worm his hit points are incremented with half of the hit points of the
|
* @post the falling worm his hit points are incremented with half of the hit points of the
|
||||||
* stationary worm.
|
* stationary worm.
|
||||||
* |new.getHitPoints() == old.getHitPoints() + stationaryWorm.getHitPoints()/2
|
* |new.getHitPoints() == old.getHitPoints() + stationaryWorm.getHitPoints()/2
|
||||||
@@ -1090,8 +1026,8 @@ public class Worm extends GameObject {
|
|||||||
* |new.getHitPoints() == old.getHitPoints() - old.getHitPoints()/2
|
* |new.getHitPoints() == old.getHitPoints() - old.getHitPoints()/2
|
||||||
*/
|
*/
|
||||||
public void collisionFall(Worm fallingWorm, Worm... worm) {
|
public void collisionFall(Worm fallingWorm, Worm... worm) {
|
||||||
for (Worm stationaryWorm: worm) {
|
for (Worm stationaryWorm : worm) {
|
||||||
long value = stationaryWorm.getHitPoints()/2;
|
long value = stationaryWorm.getHitPoints() / 2;
|
||||||
fallingWorm.incrementHitPoints(value);
|
fallingWorm.incrementHitPoints(value);
|
||||||
stationaryWorm.decreaseHitPoints(value);
|
stationaryWorm.decreaseHitPoints(value);
|
||||||
}
|
}
|
||||||
@@ -1103,6 +1039,7 @@ public class Worm extends GameObject {
|
|||||||
|
|
||||||
// region team
|
// region team
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
@@ -1114,8 +1051,7 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* Set the current team of the worm to the given team.
|
* Set the current team of the worm to the given team.
|
||||||
*
|
*
|
||||||
* @param team
|
* @param team The new team for the worm.
|
||||||
* The new team for the worm.
|
|
||||||
* @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
|
||||||
*/
|
*/
|
||||||
@@ -1138,9 +1074,7 @@ public class Worm extends GameObject {
|
|||||||
/**
|
/**
|
||||||
* The worm eats food and grows.
|
* The worm eats food and grows.
|
||||||
*
|
*
|
||||||
* @param food
|
* @param food The food the worm has eaten.
|
||||||
* The food the worm has eaten.
|
|
||||||
*
|
|
||||||
* @post The eaten food is terminated.
|
* @post The eaten food is terminated.
|
||||||
* |food.terminate();
|
* |food.terminate();
|
||||||
* @post The worm's radius is increased with 10%.
|
* @post The worm's radius is increased with 10%.
|
||||||
@@ -1231,7 +1165,7 @@ public class Worm extends GameObject {
|
|||||||
|
|
||||||
World world = getWorld();
|
World world = getWorld();
|
||||||
List<Food> foodList = world.getFoodList();
|
List<Food> foodList = world.getFoodList();
|
||||||
for (Food food: foodList) {
|
for (Food food : foodList) {
|
||||||
if (getDistance(food.getLocation(), this.getLocation()) < this.getRadius() + food.getRadius()) {
|
if (getDistance(food.getLocation(), this.getLocation()) < this.getRadius() + food.getRadius()) {
|
||||||
eat(food);
|
eat(food);
|
||||||
}
|
}
|
||||||
@@ -1239,7 +1173,6 @@ public class Worm extends GameObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// region firing and projectiles
|
// region firing and projectiles
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
|
|
||||||
@@ -1248,45 +1181,37 @@ public class Worm extends GameObject {
|
|||||||
private long hitpointsProj;
|
private long hitpointsProj;
|
||||||
private double forceProj;
|
private double forceProj;
|
||||||
|
|
||||||
public void fire() {
|
public Projectile fire() {
|
||||||
if (getActionPoints() >= 30 && getWorld() != null) {
|
if (getActionPoints() >= 30 && getWorld() != null) {
|
||||||
Random r = new Random();
|
|
||||||
int random = r.nextInt((1) + 1);
|
int random = ThreadLocalRandom.current().nextInt(2);
|
||||||
locationProj[0] = cos(getOrientation()) * getRadius();
|
Coordinate projLocation = Coordinate.create(cos(getOrientation()) * getRadius(), sin(getOrientation()) * getRadius());
|
||||||
locationProj[1] = sin(getOrientation()) * getRadius();
|
|
||||||
if (random == 0) {
|
if (random == 0) {
|
||||||
propertiesRifle();
|
|
||||||
decreaseActionPoints(10);
|
decreaseActionPoints(10);
|
||||||
}
|
return new Rifle(getWorld(), projLocation,getOrientation());
|
||||||
else {
|
} else {
|
||||||
propertiesBazooka();
|
double force = Bazooka.calcForce(getActionPoints());
|
||||||
decreaseActionPoints(25);
|
decreaseActionPoints(25);
|
||||||
}
|
return new Bazooka(getWorld(), projLocation, force, getOrientation());
|
||||||
//new Projectile(this.getWorld(), locationProj, massProj, hitpointsProj, forceProj);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void propertiesRifle() {
|
return null;
|
||||||
massProj = 10;
|
|
||||||
forceProj = 1.5;
|
|
||||||
Random r = new Random();
|
|
||||||
hitpointsProj = 0 + r.nextInt((10-0)/2) *2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void propertiesBazooka() {
|
// public void hitByRifle() {
|
||||||
massProj = 300;
|
// decreaseHitPoints(hitpointsProj);
|
||||||
forceProj = 2.5 + getActionPoints()/8;
|
// }
|
||||||
Random r = new Random();
|
//
|
||||||
hitpointsProj = 0 + r.nextInt((10-0)/(2+1)) *(2+1);
|
// public void hitByBazooka() {
|
||||||
}
|
// decreaseHitPoints(hitpointsProj * (long) forceProj);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// TODO We gaan maar 1 hit function gebruiken
|
||||||
|
|
||||||
|
|
||||||
public void hitByRifle() {
|
|
||||||
decreaseHitPoints(hitpointsProj);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void hitByBazooka() {
|
|
||||||
decreaseHitPoints(hitpointsProj * (long) forceProj);
|
|
||||||
}
|
|
||||||
// ===================================================================================
|
// ===================================================================================
|
||||||
// endregion
|
// endregion
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user