diff --git a/OGP1718-Worms/src/worms/facade/Facade.java b/OGP1718-Worms/src/worms/facade/Facade.java index 296c3b5..ba3e4a3 100644 --- a/OGP1718-Worms/src/worms/facade/Facade.java +++ b/OGP1718-Worms/src/worms/facade/Facade.java @@ -2,6 +2,9 @@ package worms.facade; import worms.internal.gui.game.IActionHandler; import worms.model.*; +import worms.model.Food; +import worms.model.Projectile; +import worms.model.Worm; import worms.programs.IProgramFactory; import worms.util.IllegalNameException; import worms.util.ModelException; @@ -9,7 +12,6 @@ import worms.util.Coordinate; import worms.util.MustNotImplementException; import java.math.BigInteger; -import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Set; @@ -294,7 +296,7 @@ public class Facade implements IFacade { */ @Override public boolean isTerminated(Projectile projectile) throws ModelException { - return false; + return projectile.isTerminated(); } /** @@ -304,7 +306,7 @@ public class Facade implements IFacade { */ @Override public double getOrientation(Projectile projectile) throws ModelException { - return 0; + return projectile.getOrientation(); } /** @@ -316,7 +318,7 @@ public class Facade implements IFacade { */ @Override public double[] getLocation(Projectile projectile) throws ModelException { - return new double[0]; + return projectile.getLocationArray(); } /** @@ -326,7 +328,7 @@ public class Facade implements IFacade { */ @Override public double getRadius(Projectile projectile) { - return 0; + return projectile.getRadius(); } /** @@ -336,7 +338,7 @@ public class Facade implements IFacade { */ @Override public int getNbHitPoints(Projectile projectile) throws ModelException { - return 0; + return projectile.getHitPoints(); } /** diff --git a/OGP1718-Worms/src/worms/model/Bazooka.java b/OGP1718-Worms/src/worms/model/Bazooka.java new file mode 100644 index 0000000..bd97be3 --- /dev/null +++ b/OGP1718-Worms/src/worms/model/Bazooka.java @@ -0,0 +1,26 @@ +package worms.model; + +import java.util.concurrent.ThreadLocalRandom; + +public class Bazooka extends Projectile { + protected Bazooka(World world, double[] location, double force, double orientation) { + super(world, location, 300, force, orientation); + } + + @Override + protected int getRandomHitPoints() { + return ThreadLocalRandom.current().nextInt(15) / 2; + } + + @Override + protected void setHitPoints(int value) throws IllegalArgumentException { + if (value > 7 || value % 2 != 1) throw new IllegalArgumentException(); + super.hitPoints = value; + } + + public static double calcForce(double actionPoints) { + double hp = 2.5 + actionPoints / 8.0; + if (hp > 9.5) return 9.5; + return hp; + } +} diff --git a/OGP1718-Worms/src/worms/model/Food.java b/OGP1718-Worms/src/worms/model/Food.java index c445642..8fb03bb 100644 --- a/OGP1718-Worms/src/worms/model/Food.java +++ b/OGP1718-Worms/src/worms/model/Food.java @@ -1,7 +1,5 @@ package worms.model; -import worms.util.Coordinate; - public class Food extends GameObject { /** diff --git a/OGP1718-Worms/src/worms/model/GameObject.java b/OGP1718-Worms/src/worms/model/GameObject.java index dac6ba1..a1a1cb3 100644 --- a/OGP1718-Worms/src/worms/model/GameObject.java +++ b/OGP1718-Worms/src/worms/model/GameObject.java @@ -24,7 +24,7 @@ public abstract class GameObject { * @post ... * |setRadius(radius) */ - GameObject(World world, double[] location, double radius) { + protected GameObject(World world, double[] location, double radius) { setWorld(world); world.add(this); setLocation(location); @@ -163,7 +163,7 @@ public abstract class GameObject { /** * This variable contains the radius of the game object */ - double radius; + protected double radius; /** * Return the radius of the game object @@ -181,7 +181,7 @@ public abstract class GameObject { * @post ... * |this.radius = radius */ - void setRadius(double radius) { + protected void setRadius(double radius) { if (!canHaveAsRadius(radius)) throw new IllegalArgumentException(); this.radius = radius; } @@ -215,7 +215,7 @@ public abstract class GameObject { * | !(location.getY() - radius < 0 && * | !getWorld().isPassable(location)) */ - boolean isValidLocation(Coordinate location) { + protected boolean isValidLocation(Coordinate location) { double radius = getRadius(); if (world == null) { @@ -235,7 +235,7 @@ public abstract class GameObject { /** * */ - double mass; + protected double mass; /** * diff --git a/OGP1718-Worms/src/worms/model/Projectile.java b/OGP1718-Worms/src/worms/model/Projectile.java index eff8345..ac4101d 100644 --- a/OGP1718-Worms/src/worms/model/Projectile.java +++ b/OGP1718-Worms/src/worms/model/Projectile.java @@ -1,53 +1,46 @@ package worms.model; -public class Projectile extends GameObject { - private static double rho = 7800; - private double hitpoints; - private double force; - private Type type; - - public Projectile(World world, double[] location, double mass, double hitpoints, double force, Projectile.Type type) { +public abstract class Projectile extends GameObject { + + private static final int rho = 7800; + + + protected Projectile (World world, double location[], double mass, double force, double orientation) { super(world, location, calcRadius(mass)); - setHitPoints(hitpoints); - setMass(mass); - setForce(force); - - this.type = type; - } - - public static double calcRadius(double mass) { - return Math.cbrt(mass/(4/3*Math.PI*rho)); - } - - public void setHitPoints(double value) { - this.hitpoints = value; - } - - public void setRandomHitPoints() { - - } - - public double getHitPoints() { - return this.hitpoints; - } - - public void increaseHitPoints(double value) { - - this.hitpoints += value; - if (this.type == Type.RIFLE && this.hitpoints > 10) this.hitpoints = 10; - else if (this.type == Type.BAZOOKA && this.hitpoints > 7) this.hitpoints = 7; - } - - public void setMass(double mass) { - this.mass = mass; - } - - public void setForce(double force) { + super.mass = mass; this.force = force; + this.orientation = orientation; + this.hitPoints = getRandomHitPoints(); } - public enum Type { - RIFLE, - BAZOOKA; + + public static double calcRadius(double mass) { + return Math.pow(((mass / 1000.0 / rho) * (3.0 / (4.0 * Math.PI))), 1.0 / 3.0); + } + + public double getForce() { + return this.force; + } + private final double force; + + + protected int hitPoints; + + protected abstract int getRandomHitPoints(); + + public int getHitPoints() { + return this.hitPoints; + } + + protected abstract void setHitPoints(int value) throws IllegalArgumentException; + + public void incrementHitPoints(int value) { + setHitPoints(this.hitPoints + value); + } + + private final double orientation; + + public double getOrientation() { + return orientation; } } \ No newline at end of file diff --git a/OGP1718-Worms/src/worms/model/Rifle.java b/OGP1718-Worms/src/worms/model/Rifle.java new file mode 100644 index 0000000..337acde --- /dev/null +++ b/OGP1718-Worms/src/worms/model/Rifle.java @@ -0,0 +1,23 @@ +package worms.model; + +import java.util.concurrent.ThreadLocalRandom; + +public class Rifle extends Projectile { + + + public Rifle(World world, double[] location, double orientation) { + super(world, location, 10, 1.5, orientation); + } + + @Override + protected int getRandomHitPoints() { + return ThreadLocalRandom.current().nextInt(6) * 2; + } + + @Override + protected void setHitPoints(int value) throws IllegalArgumentException { + if (value > 10 || value % 2 != 0) throw new IllegalArgumentException(); + super.hitPoints = value; + } + +} diff --git a/OGP1718-Worms/src/worms/model/World.java b/OGP1718-Worms/src/worms/model/World.java index 6a0e1e3..d1c1c78 100644 --- a/OGP1718-Worms/src/worms/model/World.java +++ b/OGP1718-Worms/src/worms/model/World.java @@ -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).increaseHitPoints(2); +// ((Projectile) item2).increaseHitPoints(2); } else { throw new IllegalArgumentException(); diff --git a/OGP1718-Worms/src/worms/model/Worm.java b/OGP1718-Worms/src/worms/model/Worm.java index bfe54ef..e29507b 100644 --- a/OGP1718-Worms/src/worms/model/Worm.java +++ b/OGP1718-Worms/src/worms/model/Worm.java @@ -1242,6 +1242,7 @@ public class Worm extends GameObject { // region firing and projectiles //=================================================================================== + private double[] locationProj; private double massProj; private long hitpointsProj; @@ -1250,9 +1251,9 @@ public class Worm extends GameObject { public void fire() { if (getActionPoints() >= 30 && getWorld() != null) { Random r = new Random(); - int random = r.nextInt((1 - 0) + 1); - locationProj[0] = cos(getOrientation())*getRadius(); - locationProj[1] = sin(getOrientation())*getRadius(); + int random = r.nextInt((1) + 1); + locationProj[0] = cos(getOrientation()) * getRadius(); + locationProj[1] = sin(getOrientation()) * getRadius(); if (random == 0) { propertiesRifle(); decreaseActionPoints(10); @@ -1261,7 +1262,7 @@ public class Worm extends GameObject { propertiesBazooka(); decreaseActionPoints(25); } - new Projectile(this.getWorld(), locationProj, massProj, hitpointsProj, forceProj); + //new Projectile(this.getWorld(), locationProj, massProj, hitpointsProj, forceProj); } } diff --git a/OGP1718-Worms/tests/worms/model/Part3_FullFacadeTest.java b/OGP1718-Worms/tests/worms/model/Part3_FullFacadeTest.java index 050b8d6..9babc9b 100755 --- a/OGP1718-Worms/tests/worms/model/Part3_FullFacadeTest.java +++ b/OGP1718-Worms/tests/worms/model/Part3_FullFacadeTest.java @@ -12,7 +12,6 @@ import org.junit.*; import worms.facade.Facade; import worms.facade.IFacade; import worms.internal.gui.game.IActionHandler; -import worms.programs.IProgramFactory; import worms.programs.ProgramFactory; import worms.programs.ProgramParser; import worms.util.*; diff --git a/OGP1718-Worms/tests/worms/model/PartialPart2FacadeTest.java b/OGP1718-Worms/tests/worms/model/PartialPart2FacadeTest.java index a55a1f2..c22b57d 100755 --- a/OGP1718-Worms/tests/worms/model/PartialPart2FacadeTest.java +++ b/OGP1718-Worms/tests/worms/model/PartialPart2FacadeTest.java @@ -7,7 +7,6 @@ import org.junit.Test; import worms.facade.Facade; import worms.facade.IFacade; -import worms.model.Worm; public class PartialPart2FacadeTest { diff --git a/docs/samenvatting part 3.md b/docs/samenvatting part 3.md index d4193f1..2b865a7 100644 --- a/docs/samenvatting part 3.md +++ b/docs/samenvatting part 3.md @@ -57,6 +57,7 @@ Eten kost 8 action points als niet genoeg -> niet eten - hitpoints bepalen impact op doelwit - mogen gedeeltelijk of volledig op impassable - **NIET** adjacent +- radius hangt van massa af #### locatie