update
This commit is contained in:
@@ -172,7 +172,7 @@ public class Facade implements IFacade {
|
||||
|
||||
try {
|
||||
Coordinate jumpStep = worm.jumpStep(t);
|
||||
return new double[]{jumpStep.item1, jumpStep.item2};
|
||||
return jumpStep.toArray();
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
throw new ModelException(e);
|
||||
@@ -1036,6 +1036,6 @@ public class Facade implements IFacade {
|
||||
*/
|
||||
@Override
|
||||
public void castSpell(World world) throws ModelException {
|
||||
|
||||
world.castSpell();
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,11 @@
|
||||
package worms.model;
|
||||
|
||||
import worms.util.Coordinate;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -13,8 +15,12 @@ public class Bazooka extends Projectile {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setHitPoints(int value) throws IllegalArgumentException {
|
||||
if (value > 7 || value % 2 != 1) throw new IllegalArgumentException();
|
||||
protected void setHitPoints(int value) {
|
||||
if (value > 7) value = 7;
|
||||
else if (value % 2 != 1) {
|
||||
if (value == 0) value++;
|
||||
else value--;
|
||||
}
|
||||
super.hitPoints = value;
|
||||
}
|
||||
|
||||
|
@@ -3,18 +3,35 @@ package worms.model;
|
||||
import be.kuleuven.cs.som.annotate.Raw;
|
||||
import worms.util.Coordinate;
|
||||
|
||||
import static java.lang.Math.PI;
|
||||
import static java.lang.Math.pow;
|
||||
import static java.lang.Math.round;
|
||||
import static java.lang.Math.*;
|
||||
|
||||
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 location
|
||||
* @param radius
|
||||
*
|
||||
* @post ...
|
||||
* |setWorld(world)
|
||||
* @post ...
|
||||
@@ -32,17 +49,34 @@ public abstract class GameObject {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param world
|
||||
*
|
||||
* @return ...
|
||||
* |result == !world.hasActiveGame() && !world.isTerminated()
|
||||
* @param location
|
||||
* @param radius
|
||||
* @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) {
|
||||
return !world.hasActiveGame() && !world.isTerminated();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return ...
|
||||
* |result == this.world
|
||||
*/
|
||||
@@ -51,9 +85,7 @@ public abstract class GameObject {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param world
|
||||
*
|
||||
* @post ...
|
||||
* |if world == null
|
||||
* | this.world = null
|
||||
@@ -70,12 +102,6 @@ public abstract class GameObject {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private World world;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return ...
|
||||
* |result == this.terminated
|
||||
*/
|
||||
@@ -93,18 +119,6 @@ public abstract class GameObject {
|
||||
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
|
||||
* the location of the worm expresses the place of the game object
|
||||
@@ -115,9 +129,20 @@ public abstract class GameObject {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return ...
|
||||
* |result == this.location.toArray()
|
||||
* @param location
|
||||
* @throws IllegalArgumentException ...
|
||||
* |!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() {
|
||||
return this.location.toArray();
|
||||
@@ -126,15 +151,13 @@ public abstract class GameObject {
|
||||
/**
|
||||
* set the location of the worm to the given location
|
||||
*
|
||||
* @param location
|
||||
* the new location for the game object
|
||||
* @param location 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
|
||||
* |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);
|
||||
|
||||
@@ -142,29 +165,6 @@ public abstract class GameObject {
|
||||
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
|
||||
* the radius of the game object expresses half of the
|
||||
@@ -175,9 +175,7 @@ public abstract class GameObject {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param radius
|
||||
*
|
||||
* @post ...
|
||||
* |this.radius = radius
|
||||
*/
|
||||
@@ -189,8 +187,7 @@ public abstract class GameObject {
|
||||
/**
|
||||
* Check whether the given radius is a valid radius for the worm
|
||||
*
|
||||
* @param radius
|
||||
* the radius to check
|
||||
* @param radius the radius to check
|
||||
* @return True if and only if the radius is bigger then the minimum radius
|
||||
* (or equal) and the radius is a number
|
||||
* |result == (radius >= getMinRadius() && !Double.isNaN(radius))
|
||||
@@ -201,11 +198,8 @@ public abstract class GameObject {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @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()) &&
|
||||
@@ -231,16 +225,8 @@ public abstract class GameObject {
|
||||
!getWorld().isPassable(location));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected double mass;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return ...
|
||||
* |result == this.mass
|
||||
* @return ... |result == this.mass
|
||||
*/
|
||||
public double getMass() {
|
||||
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)
|
||||
*
|
||||
* @param radius
|
||||
* part of the formula to calculate the mass
|
||||
* @param radius part of the formula to calculate the mass
|
||||
* @post the new mass of the worm is equal to
|
||||
* 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)));
|
||||
}
|
||||
}
|
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;
|
||||
|
||||
import worms.util.Coordinate;
|
||||
|
||||
public abstract class Projectile extends GameObject {
|
||||
|
||||
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.mass = mass;
|
||||
this.force = force;
|
||||
@@ -43,4 +45,37 @@ public abstract class Projectile extends GameObject {
|
||||
public double getOrientation() {
|
||||
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;
|
||||
|
||||
import worms.util.Coordinate;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -15,8 +17,9 @@ public class Rifle extends Projectile {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setHitPoints(int value) throws IllegalArgumentException {
|
||||
if (value > 10 || value % 2 != 0) throw new IllegalArgumentException();
|
||||
protected void setHitPoints(int value) {
|
||||
if (value > 10) value = 10;
|
||||
else if (value % 2 != 0) value--;
|
||||
super.hitPoints = value;
|
||||
}
|
||||
|
||||
|
@@ -571,8 +571,8 @@ public class World {
|
||||
item2.terminate();
|
||||
}
|
||||
else if (item1 instanceof Projectile && item2 instanceof Projectile) {
|
||||
// ((Projectile) item1).increaseHitPoints(2);
|
||||
// ((Projectile) item2).increaseHitPoints(2);
|
||||
((Projectile) item1).incrementHitPoints(2);
|
||||
((Projectile) item2).incrementHitPoints(2);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException();
|
||||
|
@@ -13,6 +13,12 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
/**
|
||||
* 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.
|
||||
* |isValidLocation(getLocation())
|
||||
* @invar The orientation of the worm must be a valid location.
|
||||
@@ -27,14 +33,7 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
* |isValidName(getName())
|
||||
* @invar The value of the hit points of the worm must be a valid value for hit points.
|
||||
* isValidValueHitPoints(getHitPoints())
|
||||
*
|
||||
* @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 {
|
||||
|
||||
@@ -44,19 +43,12 @@ public class Worm extends GameObject {
|
||||
/**
|
||||
* 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.
|
||||
* |new.getWorld() == world
|
||||
* @post The new location of the worm is equal to the given location.
|
||||
@@ -80,21 +72,21 @@ public class Worm extends GameObject {
|
||||
/**
|
||||
* 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.
|
||||
* |new.getWorld() == world
|
||||
* @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()
|
||||
* @post The new value of hit points of the worm is equal to the start value for hit points.
|
||||
* |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
|
||||
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 worm is looking.
|
||||
*/
|
||||
@Basic @Raw
|
||||
@Basic
|
||||
@Raw
|
||||
public double getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
@@ -175,8 +155,7 @@ public class Worm extends GameObject {
|
||||
/**
|
||||
* Set the orientation of the worm to the given orientation.
|
||||
*
|
||||
* @param orientation
|
||||
* The new orientation of the worm.
|
||||
* @param orientation The new orientation of the worm.
|
||||
* @pre The given orientation must be a valid orientation for any worm.
|
||||
* |isValidOrientation(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.
|
||||
*
|
||||
* @param newOrientation
|
||||
* The orientation to check.
|
||||
* @param newOrientation The orientation to check.
|
||||
* @return True if and only if the orientation is bigger then and smaller then 2pi.
|
||||
* |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.
|
||||
*
|
||||
* @param minRadius
|
||||
* The radius to check.
|
||||
* @param minRadius The radius to check.
|
||||
* @return True if and only if the radius is a number and the radius is bigger then 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.
|
||||
*
|
||||
* @param radius
|
||||
* The new radius for the worm.
|
||||
* @param radius 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.
|
||||
* |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 {
|
||||
if (!canHaveAsRadius(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
|
||||
* of half of the width of the worm.
|
||||
*/
|
||||
@Basic @Raw
|
||||
@Basic
|
||||
@Raw
|
||||
public double getMinRadius() {
|
||||
return this.minRadius;
|
||||
}
|
||||
@@ -259,8 +236,7 @@ public class Worm extends GameObject {
|
||||
/**
|
||||
* Check whether the given radius is a valid radius for the worm.
|
||||
*
|
||||
* @param radius
|
||||
* The radius to check.
|
||||
* @param radius The radius to check.
|
||||
* @return True if and only if the radius is bigger then the minimum radius
|
||||
* (or equal) and the radius is a number.
|
||||
* |result == (radius >= getMinRadius() && !Double.isNaN(radius))
|
||||
@@ -274,7 +250,8 @@ public class Worm extends GameObject {
|
||||
* Return the mass of the worm.
|
||||
* The mass of the worm expresses the weight of the worm.
|
||||
*/
|
||||
@Basic @Raw
|
||||
@Basic
|
||||
@Raw
|
||||
public double getMass() {
|
||||
return this.mass;
|
||||
}
|
||||
@@ -283,7 +260,6 @@ public class Worm extends GameObject {
|
||||
// endregion
|
||||
|
||||
|
||||
|
||||
// region ActionPoints
|
||||
//===================================================================================
|
||||
|
||||
@@ -291,7 +267,8 @@ public class Worm extends GameObject {
|
||||
* Return the current action points of the worm.
|
||||
* The action points identifies the energy of the worm.
|
||||
*/
|
||||
@Basic @Raw
|
||||
@Basic
|
||||
@Raw
|
||||
public long getActionPoints() {
|
||||
return this.actionPoints;
|
||||
}
|
||||
@@ -300,7 +277,8 @@ public class Worm extends GameObject {
|
||||
* Return the maximum of action points of the worm.
|
||||
* The maximum action points identifies the maximum energy of the worm.
|
||||
*/
|
||||
@Basic @Raw
|
||||
@Basic
|
||||
@Raw
|
||||
public long getMaxActionPoints() {
|
||||
return this.maxActionPoints;
|
||||
}
|
||||
@@ -308,8 +286,7 @@ public class Worm extends GameObject {
|
||||
/**
|
||||
* Set the current points of the worm to the given points.
|
||||
*
|
||||
* @param actionPoints
|
||||
* The new points for the worm.
|
||||
* @param actionPoints The new points for the worm.
|
||||
* @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
|
||||
* the current points are equal to 0. If the given points is between the
|
||||
@@ -333,8 +310,7 @@ public class Worm extends GameObject {
|
||||
/**
|
||||
* Substract the current points of the worm.
|
||||
*
|
||||
* @param delta
|
||||
* The value which should be decreased.
|
||||
* @param delta The value which should be decreased.
|
||||
* @post The current points are set to the old current points minus the given value.
|
||||
* |setActionPoints(getActionPoints() - delta)
|
||||
*/
|
||||
@@ -356,8 +332,7 @@ public class Worm extends GameObject {
|
||||
/**
|
||||
* Set the maximum of points to the given maximum of points.
|
||||
*
|
||||
* @param maxActionPoints
|
||||
* The new maximum of points for the worm.
|
||||
* @param maxActionPoints The new maximum of points for the worm.
|
||||
* @post The new maximum points is set to the given maximum points (as an integer).
|
||||
* |this.maxPoints = round(maxActionPoints)
|
||||
* @post When the maximum points change, the current points should change too.
|
||||
@@ -372,8 +347,7 @@ public class Worm extends GameObject {
|
||||
/**
|
||||
* Substract the current points of the worm.
|
||||
*
|
||||
* @param value
|
||||
* The value which should be subtracted.
|
||||
* @param value The value which should be subtracted.
|
||||
* @post The current points are set to the old current points minus the given value.
|
||||
* |setActionPoints(getActionPoints() - value)
|
||||
*/
|
||||
@@ -385,8 +359,7 @@ public class Worm extends GameObject {
|
||||
/**
|
||||
* Substract the current points of the worm.
|
||||
*
|
||||
* @param angle
|
||||
* The angle needed to calculate the new current points.
|
||||
* @param angle The angle needed to calculate the new current points.
|
||||
* @post The current points are set to the old current points minus
|
||||
* the angle (in degrees) divided by 6.
|
||||
* |setActionPoints(getActionPoints() - (long) ceil(toDegrees(angle) / 6))
|
||||
@@ -400,7 +373,6 @@ public class Worm extends GameObject {
|
||||
// endregion
|
||||
|
||||
|
||||
|
||||
// region name
|
||||
//===================================================================================
|
||||
|
||||
@@ -408,7 +380,9 @@ public class Worm extends GameObject {
|
||||
* Return the name of the worm.
|
||||
* The name of the worm expresses the identity of the worm.
|
||||
*/
|
||||
@Basic @Immutable @Raw
|
||||
@Basic
|
||||
@Immutable
|
||||
@Raw
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
@@ -416,8 +390,7 @@ public class Worm extends GameObject {
|
||||
/**
|
||||
* Check whether the given name is a valid name for all worms.
|
||||
*
|
||||
* @param name
|
||||
* The name to check.
|
||||
* @param name The name to check.
|
||||
* @return -1 if and only if the given name is longer then 2,
|
||||
* the first letter is uppercase and the name only exists
|
||||
* of letters, " ", " ' " and " "" ".
|
||||
@@ -446,13 +419,11 @@ public class Worm extends GameObject {
|
||||
/**
|
||||
* Set the name of the worm tot the given name.
|
||||
*
|
||||
* @param name
|
||||
* The new name for the worm.
|
||||
* @param name 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.
|
||||
* |new.getName() == name
|
||||
* @throws IllegalNameException
|
||||
* The given name is not a valid name for any worm.
|
||||
* |! isValidName(name)
|
||||
*/
|
||||
@Raw
|
||||
public void setName(String name) throws IllegalNameException {
|
||||
@@ -473,13 +444,14 @@ public class Worm extends GameObject {
|
||||
// endregion
|
||||
|
||||
|
||||
|
||||
// region move
|
||||
//===================================================================================
|
||||
|
||||
/**
|
||||
* 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
|
||||
* radius and surroundings.
|
||||
* |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())))
|
||||
* @post Let the worm eat if necessary.
|
||||
* |checkEat()
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* The cost of the step is bigger then the worms current action points.
|
||||
* |cost > getActionPoints()
|
||||
*/
|
||||
public void move() throws IllegalArgumentException {
|
||||
|
||||
@@ -514,11 +482,8 @@ public class Worm extends GameObject {
|
||||
/**
|
||||
* Gives the biggest step possible for the worm.
|
||||
*
|
||||
* @param direction
|
||||
* The direction of the worm.
|
||||
* @param maxDistance
|
||||
* The maximum distance the worm can move.
|
||||
*
|
||||
* @param direction The direction of the worm.
|
||||
* @param maxDistance The maximum distance the worm can move.
|
||||
* @return The furthest possible location for the given direction and maximum distance.
|
||||
* The new location has to be passable.
|
||||
* |result == (0 <= new.getLocation() <= maxDistance) && (world.isPassable(new.getLocation(), radius))
|
||||
@@ -586,11 +551,8 @@ public class Worm extends GameObject {
|
||||
/**
|
||||
* Gives the distance between two coordinates.
|
||||
*
|
||||
* @param start
|
||||
* The start coordinate of the equation.
|
||||
* @param end
|
||||
* The end coordinate of the equation.
|
||||
*
|
||||
* @param start The start 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
|
||||
* the square root of the square of the displacement of the x coordinate plus the
|
||||
* 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.
|
||||
*
|
||||
* @param basicWorm
|
||||
* The worm who has moved.
|
||||
* @param worm
|
||||
* The worms who has clashed with the basicworm.
|
||||
*
|
||||
* @param basicWorm The worm who has moved.
|
||||
* @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
|
||||
* 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.
|
||||
@@ -623,8 +582,7 @@ public class Worm extends GameObject {
|
||||
if (w1.getMass() > basicWorm.getMass()) {
|
||||
largestWorm = w1;
|
||||
smallestWorm = basicWorm;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
largestWorm = basicWorm;
|
||||
smallestWorm = w1;
|
||||
}
|
||||
@@ -646,8 +604,7 @@ public class Worm extends GameObject {
|
||||
/**
|
||||
* Turns the worm with the given angle.
|
||||
*
|
||||
* @param angle
|
||||
* The angle that must be added to the orientation.
|
||||
* @param angle The angle that must be added to the orientation.
|
||||
* @pre The angle to add must be between 0 and 2pi (including 0).
|
||||
* |0 <= angle < 2pi
|
||||
* @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.
|
||||
*
|
||||
* @param angle
|
||||
* The angle to be checked.
|
||||
* @param angle The angle to be checked.
|
||||
* @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.
|
||||
* |result == ( (0 <= angle) && (angle < (2 * PI)) &&
|
||||
| (!Double.isNaN(angle)) &&
|
||||
| (getActionPoints() - (long) ceil(toDegrees(angle) / 6) >= 0) )
|
||||
* | (!Double.isNaN(angle)) &&
|
||||
* | (getActionPoints() - (long) ceil(toDegrees(angle) / 6) >= 0) )
|
||||
*/
|
||||
private boolean canTurn(double angle) {
|
||||
double currentAngle = getOrientation();
|
||||
@@ -691,7 +647,7 @@ public class Worm extends GameObject {
|
||||
|
||||
/**
|
||||
* This constant contains the gravity.
|
||||
* */
|
||||
*/
|
||||
public static final double G = 5.0;
|
||||
|
||||
/**
|
||||
@@ -702,6 +658,9 @@ public class Worm extends GameObject {
|
||||
/**
|
||||
* 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
|
||||
* jump time multiplied with the cosinus of the orientation
|
||||
* |new.getLocation().getX() = old.getLocation.getX() + jumpVelocity * jumpTime * cos(getOrientation())
|
||||
@@ -716,11 +675,6 @@ public class Worm extends GameObject {
|
||||
* | terminate();
|
||||
* @post Let the worm eat if necessary.
|
||||
* |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 {
|
||||
|
||||
@@ -750,8 +704,7 @@ public class Worm extends GameObject {
|
||||
* @return The time the worm will jump. The distance divided by the velocity multiplied
|
||||
* with the cosinus of the orientation.
|
||||
* |jumpDistance(this.jumpVelocity) / (this.jumpVelocity * Math.cos(this.orientation))
|
||||
* @throws IllegalStateException
|
||||
* Orientation is bigger then pi or action points is equal to 0.
|
||||
* @throws IllegalStateException Orientation is bigger then pi or action points is equal to 0.
|
||||
* |getOrientation() >= PI || getActionPoints() == 0
|
||||
*/
|
||||
public double jumpTime() {
|
||||
@@ -762,16 +715,14 @@ public class Worm extends GameObject {
|
||||
/**
|
||||
* Gives the location after a jump.
|
||||
*
|
||||
* @param deltaTime
|
||||
* The total time the worm should jump.
|
||||
* @param deltaTime 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
|
||||
* 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
|
||||
* with the second power of delta time.
|
||||
* |Coordinate.create(getLocation().getX() + this.jumpVelocity() * cos(getOrientation()) * deltaTime,
|
||||
|getLocation().getY() + this.jumpVelocity() * sin(getOrientation()) * deltaTime - 0.5 * G * pow(deltaTime, 2))
|
||||
* @throws IllegalArgumentException()
|
||||
* If the deltaTime is not a number or bigger then jumpTime or smaller then 0.
|
||||
* |getLocation().getY() + this.jumpVelocity() * sin(getOrientation()) * deltaTime - 0.5 * G * pow(deltaTime, 2))
|
||||
* @throws IllegalArgumentException() If the deltaTime is not a number or bigger then jumpTime or smaller then 0.
|
||||
* |if (Double.isNaN(deltaTime) || deltaTime > this.jumpTime() || deltaTime < 0)
|
||||
*/
|
||||
public Coordinate jumpStep(double deltaTime) {
|
||||
@@ -874,8 +825,7 @@ public class Worm extends GameObject {
|
||||
/**
|
||||
* Return the distance the worm will jump.
|
||||
*
|
||||
* @param v
|
||||
* The velocity of the jump.
|
||||
* @param v The velocity of the jump.
|
||||
* @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.
|
||||
* |(pow(v, 2) * sin(2 * getOrientation())) / G
|
||||
@@ -887,9 +837,7 @@ public class Worm extends GameObject {
|
||||
/**
|
||||
* Returns of the jump distance valid is.
|
||||
*
|
||||
* @param distance
|
||||
* The distance of the jump.
|
||||
*
|
||||
* @param distance The distance of the jump.
|
||||
* @return True if and only if the absolute value of the distance bigger or equal is
|
||||
* to the radius.
|
||||
* |result == (abs(distance) >= getRadius())
|
||||
@@ -917,15 +865,10 @@ public class Worm extends GameObject {
|
||||
/**
|
||||
* Decreases the hit points of the attacked worm (chosen by a coin).
|
||||
*
|
||||
* @param newLocation
|
||||
* The new location of the jumped worm.
|
||||
* @param oldLocation
|
||||
* The old location 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.
|
||||
*
|
||||
* @param newLocation The new location of the jumped worm.
|
||||
* @param oldLocation The old location 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
|
||||
* 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()))
|
||||
@@ -940,8 +883,7 @@ public class Worm extends GameObject {
|
||||
if (coin == 1) {
|
||||
attackedWorm = worm1;
|
||||
attacker = wormB;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
attackedWorm = wormB;
|
||||
attacker = worm1;
|
||||
}
|
||||
@@ -963,7 +905,8 @@ public class Worm extends GameObject {
|
||||
* Return the current hit points of the worm.
|
||||
* The hit points identifies the strength of the worm.
|
||||
*/
|
||||
@Basic @Raw
|
||||
@Basic
|
||||
@Raw
|
||||
public long getHitPoints() {
|
||||
return this.hitPoints;
|
||||
}
|
||||
@@ -971,8 +914,7 @@ public class Worm extends GameObject {
|
||||
/**
|
||||
* Set the current hit points of the worm to the given points.
|
||||
*
|
||||
* @param hitPoints
|
||||
* The new points for the worm.
|
||||
* @param hitPoints The new points for the worm.
|
||||
* @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.
|
||||
* |if (hitpoints <= 0)
|
||||
@@ -995,8 +937,7 @@ public class Worm extends GameObject {
|
||||
/**
|
||||
* Decrease the hit points with the given value.
|
||||
*
|
||||
* @param value
|
||||
* The value that should be decreased.
|
||||
* @param value The value that should be decreased.
|
||||
* @post The current hit points should be decreased with the given value.
|
||||
* |new.getHitPoints() == old.getHitPoints() - value
|
||||
*/
|
||||
@@ -1007,8 +948,7 @@ public class Worm extends GameObject {
|
||||
/**
|
||||
* Increment the hit points with the given value.
|
||||
*
|
||||
* @param value
|
||||
* The value that schould be added.
|
||||
* @param value The value that schould be added.
|
||||
* @post The current hit points should be increaseed with the given value.
|
||||
* |new.getHitPoints() == old.getHitPoints() + value
|
||||
*/
|
||||
@@ -1017,7 +957,6 @@ public class Worm extends GameObject {
|
||||
}
|
||||
|
||||
|
||||
|
||||
//===================================================================================
|
||||
// endregion
|
||||
|
||||
@@ -1078,11 +1017,8 @@ public class Worm extends GameObject {
|
||||
/**
|
||||
* Changes the hit points of the clashing worms.
|
||||
*
|
||||
* @param fallingWorm
|
||||
* The worm who has fallen.
|
||||
* @param worm
|
||||
* The worm on which the falling worm has fallen.
|
||||
*
|
||||
* @param fallingWorm The worm who 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
|
||||
* stationary worm.
|
||||
* |new.getHitPoints() == old.getHitPoints() + stationaryWorm.getHitPoints()/2
|
||||
@@ -1103,6 +1039,7 @@ public class Worm extends GameObject {
|
||||
|
||||
// region team
|
||||
//===================================================================================
|
||||
|
||||
/**
|
||||
* Return the current team 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.
|
||||
*
|
||||
* @param team
|
||||
* The new team for the worm.
|
||||
* @param team The new team for the worm.
|
||||
* @post The current team of the worm is set to the given team.
|
||||
* |new.getTeam() == team
|
||||
*/
|
||||
@@ -1138,9 +1074,7 @@ public class Worm extends GameObject {
|
||||
/**
|
||||
* The worm eats food and grows.
|
||||
*
|
||||
* @param food
|
||||
* The food the worm has eaten.
|
||||
*
|
||||
* @param food The food the worm has eaten.
|
||||
* @post The eaten food is terminated.
|
||||
* |food.terminate();
|
||||
* @post The worm's radius is increased with 10%.
|
||||
@@ -1239,7 +1173,6 @@ public class Worm extends GameObject {
|
||||
}
|
||||
|
||||
|
||||
|
||||
// region firing and projectiles
|
||||
//===================================================================================
|
||||
|
||||
@@ -1248,45 +1181,37 @@ public class Worm extends GameObject {
|
||||
private long hitpointsProj;
|
||||
private double forceProj;
|
||||
|
||||
public void fire() {
|
||||
public Projectile fire() {
|
||||
if (getActionPoints() >= 30 && getWorld() != null) {
|
||||
Random r = new Random();
|
||||
int random = r.nextInt((1) + 1);
|
||||
locationProj[0] = cos(getOrientation()) * getRadius();
|
||||
locationProj[1] = sin(getOrientation()) * getRadius();
|
||||
|
||||
int random = ThreadLocalRandom.current().nextInt(2);
|
||||
Coordinate projLocation = Coordinate.create(cos(getOrientation()) * getRadius(), sin(getOrientation()) * getRadius());
|
||||
|
||||
if (random == 0) {
|
||||
propertiesRifle();
|
||||
decreaseActionPoints(10);
|
||||
}
|
||||
else {
|
||||
propertiesBazooka();
|
||||
return new Rifle(getWorld(), projLocation,getOrientation());
|
||||
} else {
|
||||
double force = Bazooka.calcForce(getActionPoints());
|
||||
decreaseActionPoints(25);
|
||||
}
|
||||
//new Projectile(this.getWorld(), locationProj, massProj, hitpointsProj, forceProj);
|
||||
return new Bazooka(getWorld(), projLocation, force, getOrientation());
|
||||
}
|
||||
}
|
||||
|
||||
public void propertiesRifle() {
|
||||
massProj = 10;
|
||||
forceProj = 1.5;
|
||||
Random r = new Random();
|
||||
hitpointsProj = 0 + r.nextInt((10-0)/2) *2;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void propertiesBazooka() {
|
||||
massProj = 300;
|
||||
forceProj = 2.5 + getActionPoints()/8;
|
||||
Random r = new Random();
|
||||
hitpointsProj = 0 + r.nextInt((10-0)/(2+1)) *(2+1);
|
||||
}
|
||||
// public void hitByRifle() {
|
||||
// decreaseHitPoints(hitpointsProj);
|
||||
// }
|
||||
//
|
||||
// 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
|
||||
}
|
||||
|
Reference in New Issue
Block a user