diff --git a/OGP1718-Worms/src/worms/facade/Facade.java b/OGP1718-Worms/src/worms/facade/Facade.java index a1ff374..296c3b5 100644 --- a/OGP1718-Worms/src/worms/facade/Facade.java +++ b/OGP1718-Worms/src/worms/facade/Facade.java @@ -274,7 +274,7 @@ public class Facade implements IFacade { */ @Override public boolean isPoisonous(Food food) throws ModelException { - return false; + return food.isPoisonous(); } /** @@ -284,7 +284,7 @@ public class Facade implements IFacade { */ @Override public void poison(Food food) throws ModelException { - + food.poison(); } /** @@ -402,28 +402,6 @@ public class Facade implements IFacade { return null; } -// /** -// * Returns the x-coordinate of the current location of the given worm. -// * -// * @param worm -// * the worm who is going to move -// */ -// @Override -// public double getX(Worm worm) throws ModelException { -// return worm.getLocation().item1; -// } -// -// /** -// * Returns the y-coordinate of the current location of the given worm. -// * -// * @param worm -// * the worm who is going to move -// */ -// @Override -// public double getY(Worm worm) throws ModelException { -// return worm.getLocation().item2; -// } - /** * Create a new world with given width and given height. * The passable map is a rectangular matrix indicating which parts of the terrain @@ -1049,7 +1027,7 @@ public class Facade implements IFacade { } /** - * Have the wizard cast a spell over two randomly slected game objects in the given + * Have the wizard cast a spell over two randomly selected game objects in the given * world. * * @param world diff --git a/OGP1718-Worms/src/worms/model/Food.java b/OGP1718-Worms/src/worms/model/Food.java index 130dca3..ea40d67 100644 --- a/OGP1718-Worms/src/worms/model/Food.java +++ b/OGP1718-Worms/src/worms/model/Food.java @@ -24,4 +24,16 @@ public class Food extends GameObject { final double rho = 150; setMass(getRadius(), rho); } + + + + public boolean isPoisonous() { + return this.poisonous; + } + + public void poison() { + this.poisonous = true; + } + + private boolean poisonous = false; } diff --git a/OGP1718-Worms/src/worms/model/World.java b/OGP1718-Worms/src/worms/model/World.java index d058d84..29e38b9 100644 --- a/OGP1718-Worms/src/worms/model/World.java +++ b/OGP1718-Worms/src/worms/model/World.java @@ -3,6 +3,7 @@ package worms.model; import worms.util.Coordinate; import java.util.*; +import java.util.stream.Collectors; public class World { @@ -381,7 +382,7 @@ public class World { */ public Set getAllTeams() { - Set teams = new HashSet(); + Set teams = new HashSet<>(); for(Worm worm: getWormList()) { teams.add(worm.getTeam()); } @@ -448,15 +449,10 @@ public class World { * |lis.add(worm) for each worm * |result == list (ArrayList<>()) */ + @SuppressWarnings("unchecked") public List getWormList() { - List list = new ArrayList<>(); - for (GameObject x : getGameObjects()) { - if (x.getClass().equals(Worm.class)) { - list.add((Worm) x); - } - } - return list; + return getGameObjectsByClass(Worm.class); } /** @@ -465,14 +461,11 @@ public class World { * |list.add(food) for each food * |result == list (ArrayList<>()) */ + @SuppressWarnings("unchecked") public List getFoodList() { - List list = new ArrayList<>(); - for (GameObject x : getGameObjects()) { - if (x.getClass().equals(Food.class)) { - list.add((Food) x); - } - } - return list; + + return getGameObjectsByClass(Food.class); + } /** @@ -493,6 +486,12 @@ public class World { return list; } + @SuppressWarnings("unchecked") + public List getGameObjectsByClass(Class cl) { + + return (List) getGameObjects().stream().filter(x -> x.getClass().equals(cl)).collect(Collectors.toList()); + } + /** * */ @@ -502,4 +501,59 @@ public class World { // =================================================================================== // endregion + + // region Wizard + //=================================================================================== + + public void castSpell() { + + Set gameObjects = getGameObjects(); + int size = gameObjects.size(); + int nb1 = new Random().nextInt(size); + int nb2 = new Random().nextInt(size); + + GameObject item1 = null; + GameObject item2 = null; + + int i = 0; + for(GameObject g: gameObjects) { + + if (i == nb1) item1 = g; + if (i == nb2) item2 = g; + + if (item1 != null && item2 != null) break; + i++; + } + + + if (item1 instanceof Worm && item2 instanceof Worm) { + System.out.println("test"); + } + else if (item1 instanceof Worm && item2 instanceof Food || + item1 instanceof Food && item2 instanceof Worm) { + System.out.println("test"); + } + else if (item1 instanceof Worm && item2 instanceof Projectile || + item1 instanceof Projectile && item2 instanceof Worm) { + System.out.println("test"); + } + else if (item1 instanceof Food && item2 instanceof Food) { + System.out.println("test"); + } + else if (item1 instanceof Food && item2 instanceof Projectile || + item1 instanceof Projectile && item2 instanceof Food) { + System.out.println("test"); + } + else if (item1 instanceof Projectile && item2 instanceof Projectile) { + System.out.println("test"); + } + else { + throw new IllegalArgumentException(); + } + } + + + // =================================================================================== + // endregion + } diff --git a/OGP1718-Worms/src/worms/model/Worm.java b/OGP1718-Worms/src/worms/model/Worm.java index 44e1851..a408ec9 100644 --- a/OGP1718-Worms/src/worms/model/Worm.java +++ b/OGP1718-Worms/src/worms/model/Worm.java @@ -1156,7 +1156,15 @@ public class Worm extends GameObject { double radius = getRadius(); double changeRadius = radius * 0.1; - radius *= 1.1; + + if (food.isPoisonous()) { + changeRadius *= -1; + radius *= 0.9; + } else { + radius *= 1.1; + } + + setRadius(radius); World world = getWorld();