diff --git a/OGP1718-Worms/src/worms/model/Food.java b/OGP1718-Worms/src/worms/model/Food.java index 379a8a1..306a5fe 100644 --- a/OGP1718-Worms/src/worms/model/Food.java +++ b/OGP1718-Worms/src/worms/model/Food.java @@ -2,31 +2,29 @@ package worms.model; import static java.lang.Math.*; -public class Food { - // region location - //=================================================================================== - - - //=================================================================================== - // endregion +public class Food extends GameObject { + + public Food(World world, double[] location) { + setWorld(world); + setLocation(location); + } // region shape //=================================================================================== - - final double radius = 0.20; - - public double getMass() { - return this.mass; - } - - public void setMass() { + + private final double radius = 0.20; + + @Override + public double getRadius() { + return this.radius; + } + + @Override + public void setMass(double radius) { final double rho = 150; - double m = rho * (4/3 * PI * pow(radius, 3)); - this.mass = m; + this.mass = rho * (4/3 * PI * pow(radius, 3)); } - public double mass; - //=================================================================================== // endregion diff --git a/OGP1718-Worms/src/worms/model/GameObject.java b/OGP1718-Worms/src/worms/model/GameObject.java index 90aeb4c..33f8383 100644 --- a/OGP1718-Worms/src/worms/model/GameObject.java +++ b/OGP1718-Worms/src/worms/model/GameObject.java @@ -3,21 +3,15 @@ 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; - public abstract class GameObject { -// public GameObject(World world, Coordinate location, double radius) { -// -// this.world = world; -// this.location = location; -// this.radius = radius; -// } private World world; + /** + * + * @return World + */ public World getWorld() { return this.world; } @@ -26,10 +20,17 @@ public abstract class GameObject { } + /** + * + * @return + */ public boolean isTerminated() { return this.terminated; } + /** + * Terminate the worm + */ public void terminate() { this.terminated = true; } @@ -66,7 +67,16 @@ public abstract class GameObject { * the given location is not a valid location for a game object * |! isValidLocation(location) */ + void setLocation(double[] location) throws IllegalArgumentException { + + Coordinate locationCoordinate = Coordinate.create(location); + + if (!isValidLocation(locationCoordinate)) throw new IllegalArgumentException(); + this.location = locationCoordinate; + } + void setLocation(Coordinate location) throws IllegalArgumentException { + if (!isValidLocation(location)) throw new IllegalArgumentException(); this.location = location; } @@ -85,7 +95,7 @@ public abstract class GameObject { public double getRadius(){ return this.radius; } - abstract void setRadius(double radius); + //abstract void setRadius(double radius); boolean isValidLocation(Coordinate location) { double radius = getRadius(); @@ -94,11 +104,12 @@ public abstract class GameObject { !(location.getCoordinateX() - radius < 0) && !(location.getCoordinateX() + radius > getWorld().getWidth()) && !(location.getCoordinateY() + radius > getWorld().getHeight()) && - !(location.getCoordinateY() - radius < 0); + !(location.getCoordinateY() - radius < 0 && + !getWorld().isPassable(location)); } - private double mass; + double mass; public double getMass() { return this.mass; } diff --git a/OGP1718-Worms/src/worms/model/World.java b/OGP1718-Worms/src/worms/model/World.java index f0cd562..9318362 100644 --- a/OGP1718-Worms/src/worms/model/World.java +++ b/OGP1718-Worms/src/worms/model/World.java @@ -1,5 +1,7 @@ package worms.model; +import worms.util.Coordinate; + import java.util.*; public class World { @@ -132,6 +134,10 @@ public class World { return this.map[(int) Math.floor(location[1] / lengthY)][(int) Math.floor(location[0] / lengthX)]; } + public boolean isPassable(Coordinate location) { + return this.isPassable(location.toArray()); + } + /** * * @param center ... @@ -223,6 +229,7 @@ public class World { for(Worm worm: getWormList()) { teams.add(worm.getTeam()); } + return teams; } diff --git a/OGP1718-Worms/src/worms/model/Worm.java b/OGP1718-Worms/src/worms/model/Worm.java index 9cdee2e..a57e96a 100644 --- a/OGP1718-Worms/src/worms/model/Worm.java +++ b/OGP1718-Worms/src/worms/model/Worm.java @@ -212,7 +212,7 @@ public class Worm extends GameObject { * the given radius is not a valid radius for any worm * |! canHaveAsMinRadius(radius) */ - @Raw @Override + @Raw public void setRadius(double radius) throws IllegalArgumentException { if (!canHaveAsRadius(radius)) throw new IllegalArgumentException("Invalid radius"); @@ -800,4 +800,20 @@ public class Worm extends GameObject { //=================================================================================== // endregion + + + // region team + //=================================================================================== + public Team getTeam() { + return this.team; + } + + public void setTeam(Team team) { + this.team = team; + } + + private Team team; + + // =================================================================================== + // endregion }