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