improved world
This commit is contained in:
@@ -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
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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<Team> getAllTeams() {
|
||||
|
||||
Set<Team> teams = new HashSet<Team>();
|
||||
Set<Team> 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<Worm> getWormList() {
|
||||
|
||||
List<Worm> 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<Food> getFoodList() {
|
||||
List<Food> 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 <T extends GameObject> List<T> getGameObjectsByClass(Class<T> cl) {
|
||||
|
||||
return (List<T>) 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<GameObject> 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
|
||||
|
||||
}
|
||||
|
@@ -1156,7 +1156,15 @@ public class Worm extends GameObject {
|
||||
|
||||
double radius = getRadius();
|
||||
double changeRadius = radius * 0.1;
|
||||
|
||||
if (food.isPoisonous()) {
|
||||
changeRadius *= -1;
|
||||
radius *= 0.9;
|
||||
} else {
|
||||
radius *= 1.1;
|
||||
}
|
||||
|
||||
|
||||
setRadius(radius);
|
||||
|
||||
World world = getWorld();
|
||||
|
Reference in New Issue
Block a user