diff --git a/OGP1718-Worms/src/worms/facade/Facade.java b/OGP1718-Worms/src/worms/facade/Facade.java index 538136c..b9ec1b4 100644 --- a/OGP1718-Worms/src/worms/facade/Facade.java +++ b/OGP1718-Worms/src/worms/facade/Facade.java @@ -2,6 +2,7 @@ package worms.facade; import worms.model.Worm; import worms.util.ModelException; +import worms.util.Tuple; public class Facade implements IFacade { /** @@ -13,18 +14,19 @@ public class Facade implements IFacade { * (in meter) * @param direction The direction of the new worm (in radians) * @param radius The radius of the new worm (in meter) - * @param name + * @param name ... */ @Override public Worm createWorm(double[] location, double direction, double radius, String name) throws ModelException { - return null; + + return new Worm(Tuple.create(location), direction, name, radius); } /** * Moves the given worm by the given number of steps. * - * @param worm - * @param nbSteps + * @param worm ... + * @param nbSteps ... */ @Override public void move(Worm worm, int nbSteps) throws ModelException { @@ -34,8 +36,8 @@ public class Facade implements IFacade { /** * Turns the given worm by the given angle. * - * @param worm - * @param angle + * @param worm ... + * @param angle ... */ @Override public void turn(Worm worm, double angle) throws ModelException { @@ -45,7 +47,7 @@ public class Facade implements IFacade { /** * Makes the given worm jump. * - * @param worm + * @param worm ... */ @Override public void jump(Worm worm) throws ModelException { @@ -56,7 +58,7 @@ public class Facade implements IFacade { * Returns the total amount of time (in seconds) that a jump of the given worm * would take. * - * @param worm + * @param worm ... */ @Override public double getJumpTime(Worm worm) throws ModelException { @@ -66,8 +68,8 @@ public class Facade implements IFacade { /** * Returns the location on the jump trajectory of the given worm after a time t. * - * @param worm - * @param t + * @param worm ... + * @param t ... * @return An array with two elements, with the first element being the * x-coordinate and the second element the y-coordinate. */ @@ -79,7 +81,7 @@ public class Facade implements IFacade { /** * Returns the x-coordinate of the current location of the given worm. * - * @param worm + * @param worm ... */ @Override public double getX(Worm worm) throws ModelException { @@ -89,7 +91,7 @@ public class Facade implements IFacade { /** * Returns the y-coordinate of the current location of the given worm. * - * @param worm + * @param worm ... */ @Override public double getY(Worm worm) throws ModelException { @@ -99,7 +101,7 @@ public class Facade implements IFacade { /** * Returns the current orientation of the given worm (in radians). * - * @param worm + * @param worm ... */ @Override public double getOrientation(Worm worm) throws ModelException { @@ -109,7 +111,7 @@ public class Facade implements IFacade { /** * Returns the radius of the given worm. * - * @param worm + * @param worm ... */ @Override public double getRadius(Worm worm) throws ModelException { @@ -119,8 +121,8 @@ public class Facade implements IFacade { /** * Sets the radius of the given worm to the given value. * - * @param worm - * @param newRadius + * @param worm ... + * @param newRadius ... */ @Override public void setRadius(Worm worm, double newRadius) throws ModelException { @@ -130,7 +132,7 @@ public class Facade implements IFacade { /** * Returns the current number of action points of the given worm. * - * @param worm + * @param worm ... */ @Override public long getNbActionPoints(Worm worm) throws ModelException { @@ -141,8 +143,8 @@ public class Facade implements IFacade { * Decreases the current number of action points of the given worm with the * given delta. * - * @param worm - * @param delta + * @param worm ... + * @param delta ... */ @Override public void decreaseNbActionPoints(Worm worm, long delta) throws ModelException { @@ -152,7 +154,7 @@ public class Facade implements IFacade { /** * Returns the maximum number of action points of the given worm. * - * @param worm + * @param worm ... */ @Override public long getMaxNbActionPoints(Worm worm) throws ModelException { @@ -162,7 +164,7 @@ public class Facade implements IFacade { /** * Returns the name the given worm. * - * @param worm + * @param worm ... */ @Override public String getName(Worm worm) throws ModelException { @@ -172,8 +174,8 @@ public class Facade implements IFacade { /** * Renames the given worm. * - * @param worm - * @param newName + * @param worm ... + * @param newName ... */ @Override public void rename(Worm worm, String newName) throws ModelException { @@ -183,7 +185,7 @@ public class Facade implements IFacade { /** * Returns the mass of the given worm. * - * @param worm + * @param worm ... */ @Override public double getMass(Worm worm) throws ModelException { diff --git a/OGP1718-Worms/src/worms/util/Tuple.java b/OGP1718-Worms/src/worms/util/Tuple.java index 5aca4da..3646ebb 100644 --- a/OGP1718-Worms/src/worms/util/Tuple.java +++ b/OGP1718-Worms/src/worms/util/Tuple.java @@ -1,7 +1,9 @@ package worms.util; +import be.kuleuven.cs.som.annotate.Immutable; +import be.kuleuven.cs.som.annotate.Value; + import java.util.Objects; -import be.kuleuven.cs.som.annotate.*; /** @@ -11,7 +13,7 @@ import be.kuleuven.cs.som.annotate.*; * @param second element type * * - * @version 1.0 + * @version 1.1 * @author Arthur Bols & Leen Dereu */ @Value @@ -45,6 +47,13 @@ public class Tuple { return new Tuple<>(item1, item2); } + @Immutable + public static Tuple create(double[] arr) { + if (arr == null || arr.length > 2) + throw new IllegalArgumentException("Invalid parameter arr"); + return new Tuple<>(arr[0], arr[1]); + } + @Override public boolean equals(Object o) { if (this == o) return true;