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,27 +3,44 @@ 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 {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param world
|
||||
* @param location
|
||||
* @param radius
|
||||
*
|
||||
* @post ...
|
||||
* |setWorld(world)
|
||||
* @post ...
|
||||
* |world.add(this)
|
||||
* @post ...
|
||||
* |setLocation(location)
|
||||
* @post ...
|
||||
* |setRadius(radius)
|
||||
*/
|
||||
/**
|
||||
* 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 ...
|
||||
* |world.add(this)
|
||||
* @post ...
|
||||
* |setLocation(location)
|
||||
* @post ...
|
||||
* |setRadius(radius)
|
||||
*/
|
||||
protected GameObject(World world, double[] location, double radius) {
|
||||
setWorld(world);
|
||||
world.add(this);
|
||||
@@ -32,33 +49,48 @@ 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
|
||||
* @return ...
|
||||
* |result == this.world
|
||||
*/
|
||||
public World getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param world
|
||||
*
|
||||
* @post ...
|
||||
* |if world == null
|
||||
* | this.world = null
|
||||
* |else:
|
||||
* | this.world = world
|
||||
* |if world == null
|
||||
* | this.world = null
|
||||
* |else:
|
||||
* | this.world = world
|
||||
*/
|
||||
public void setWorld(World world) {
|
||||
if (world == null) {
|
||||
@@ -70,14 +102,8 @@ public abstract class GameObject {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private World world;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return ...
|
||||
* |result == this.terminated
|
||||
* @return ...
|
||||
* |result == this.terminated
|
||||
*/
|
||||
public boolean isTerminated() {
|
||||
return this.terminated;
|
||||
@@ -85,39 +111,38 @@ public abstract class GameObject {
|
||||
|
||||
/**
|
||||
* @post ...
|
||||
* |this.terminated = true
|
||||
* |getWorld().remove(this)
|
||||
* |this.terminated = true
|
||||
* |getWorld().remove(this)
|
||||
*/
|
||||
public void terminate() {
|
||||
this.terminated = true;
|
||||
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
|
||||
* in the play area
|
||||
* the location of the worm expresses the place of the game object
|
||||
* in the play area
|
||||
*/
|
||||
Coordinate getLocation() {
|
||||
return this.location;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @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
|
||||
* @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)
|
||||
* @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
|
||||
*/
|
||||
void setLocation(double[] location) throws IllegalArgumentException {
|
||||
protected void setLocation(double[] location) throws IllegalArgumentException {
|
||||
|
||||
Coordinate locationCoordinate = Coordinate.create(location);
|
||||
|
||||
@@ -142,44 +165,19 @@ 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
|
||||
* width of the game object
|
||||
* the radius of the game object expresses half of the
|
||||
* width of the game object
|
||||
*/
|
||||
public double getRadius(){
|
||||
public double getRadius() {
|
||||
return this.radius;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param radius
|
||||
*
|
||||
* @post ...
|
||||
* |this.radius = radius
|
||||
* |this.radius = radius
|
||||
*/
|
||||
protected void setRadius(double radius) {
|
||||
if (!canHaveAsRadius(radius)) throw new IllegalArgumentException();
|
||||
@@ -189,11 +187,10 @@ 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))
|
||||
* (or equal) and the radius is a number
|
||||
* |result == (radius >= getMinRadius() && !Double.isNaN(radius))
|
||||
*/
|
||||
@Raw
|
||||
private boolean canHaveAsRadius(double radius) {
|
||||
@@ -201,19 +198,16 @@ public abstract class GameObject {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param location
|
||||
*
|
||||
* @return ...
|
||||
* |if (world == null)
|
||||
* | result == !Double.isNaN(location.getX()) && !Double.isNaN(location.getY())
|
||||
* |result == !Double.isNaN(location.getX()) &&
|
||||
* | !Double.isNaN(location.getY()) &&
|
||||
* | !(location.getX() - radius < 0) &&
|
||||
* | !(location.getX() + radius > getWorld().getWidth()) &&
|
||||
* | !(location.getY() + radius > getWorld().getHeight()) &&
|
||||
* | !(location.getY() - radius < 0 &&
|
||||
* | !getWorld().isPassable(location))
|
||||
* @return ... |if (world == null)
|
||||
* | result == !Double.isNaN(location.getX()) && !Double.isNaN(location.getY())
|
||||
* |result == !Double.isNaN(location.getX()) &&
|
||||
* | !Double.isNaN(location.getY()) &&
|
||||
* | !(location.getX() - radius < 0) &&
|
||||
* | !(location.getX() + radius > getWorld().getWidth()) &&
|
||||
* | !(location.getY() + radius > getWorld().getHeight()) &&
|
||||
* | !(location.getY() - radius < 0 &&
|
||||
* | !getWorld().isPassable(location))
|
||||
*/
|
||||
protected boolean isValidLocation(Coordinate location) {
|
||||
double radius = getRadius();
|
||||
@@ -228,19 +222,11 @@ public abstract class GameObject {
|
||||
!(location.getX() + radius > getWorld().getWidth()) &&
|
||||
!(location.getY() + radius > getWorld().getHeight()) &&
|
||||
!(location.getY() - radius < 0 &&
|
||||
!getWorld().isPassable(location));
|
||||
!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
|
||||
* @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))
|
||||
* @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();
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user