Merge branch 'master' of gitlab.principis.be:OGP/worms
This commit is contained in:
@@ -176,7 +176,7 @@ public class Facade implements IFacade {
|
||||
Coordinate jumpStep = worm.jumpStep(t);
|
||||
return jumpStep.toArray();
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
catch (IllegalArgumentException | IllegalStateException e) {
|
||||
throw new ModelException(e);
|
||||
}
|
||||
}
|
||||
@@ -927,7 +927,7 @@ public class Facade implements IFacade {
|
||||
public Team createTeam(World world, String name) throws ModelException, MustNotImplementException {
|
||||
try {
|
||||
return new Team(name, world);
|
||||
} catch(IllegalNameException e) {
|
||||
} catch(IllegalNameException | IllegalStateException e) {
|
||||
throw new ModelException(e.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -1011,7 +1011,11 @@ public class Facade implements IFacade {
|
||||
*/
|
||||
@Override
|
||||
public void mergeTeams(Team receivingTeam, Team supplyingTeam) throws ModelException, MustNotImplementException {
|
||||
try {
|
||||
Team.mergeTeams(receivingTeam, supplyingTeam);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new ModelException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -82,46 +82,44 @@ public abstract class Projectile extends GameObject {
|
||||
|
||||
private double jumpVelocity() {
|
||||
// wat met de action points?
|
||||
// double force = 5 * Worm.getActionPoints() + getMass() * G;
|
||||
// return force/getMass() * FORCE_TIME;
|
||||
return 0.0;
|
||||
double force = 5 * Worm.getActionPoints() + getMass() * G;
|
||||
return force/getMass() * FORCE_TIME;
|
||||
}
|
||||
|
||||
private double getJumpTime(double jumpTimeStep) {
|
||||
// // TODO zie naar worm hoe dit moet, implementatie moet wel anders!
|
||||
// //wat met parameter jumpTimeStep?
|
||||
//
|
||||
// double v = jumpVelocity();
|
||||
// double time = 0;
|
||||
// double a = getOrientation();
|
||||
// Coordinate loc = getLocation();
|
||||
// World world = getWorld();
|
||||
// double radius = getRadius();
|
||||
// Coordinate newLoc;
|
||||
//
|
||||
// while (true) {
|
||||
// time += 0.05;
|
||||
// double x = loc.getX() + v * time * cos(a);
|
||||
// double y = loc.getY() + v * time * sin(a) - (G * time * time) / 2.0;
|
||||
// newLoc = Coordinate.create(x, y);
|
||||
// if (! world.isPassable(newLoc, radius) || x < 0 || y < 0 || x > world.getWidth() || y > world.getHeight()) {
|
||||
// while (true) {
|
||||
// time -= 0.01;
|
||||
// newLoc = Coordinate.create(loc.getX() + v * time * cos(a), loc.getY() + v * time * sin(a) - (G * time * time) / 2.0);
|
||||
// if (newLoc.getX() < 0 || newLoc.getY() < 0 || newLoc.getX() > getWorld().getWidth() ||
|
||||
// newLoc.getY() > world.getHeight() || world.isAdjacent(newLoc, radius)) {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// if ((int) round(time) == 10) {
|
||||
// throw new RuntimeException();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return time;
|
||||
return 0.0;
|
||||
// TODO zie naar worm hoe dit moet, implementatie moet wel anders!
|
||||
//wat met parameter jumpTimeStep?
|
||||
|
||||
double v = jumpVelocity();
|
||||
double time = 0;
|
||||
double a = getOrientation();
|
||||
Coordinate loc = getLocation();
|
||||
World world = getWorld();
|
||||
double radius = getRadius();
|
||||
Coordinate newLoc;
|
||||
|
||||
while (true) {
|
||||
time += 0.05;
|
||||
double x = loc.getX() + v * time * cos(a);
|
||||
double y = loc.getY() + v * time * sin(a) - (G * time * time) / 2.0;
|
||||
newLoc = Coordinate.create(x, y);
|
||||
if (! world.isPassable(newLoc, radius) || x < 0 || y < 0 || x > world.getWidth() || y > world.getHeight()) {
|
||||
while (true) {
|
||||
time -= 0.01;
|
||||
newLoc = Coordinate.create(loc.getX() + v * time * cos(a), loc.getY() + v * time * sin(a) - (G * time * time) / 2.0);
|
||||
if (newLoc.getX() < 0 || newLoc.getY() < 0 || newLoc.getX() > getWorld().getWidth() ||
|
||||
newLoc.getY() > world.getHeight() || world.isAdjacent(newLoc, radius)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ((int) round(time) == 10) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
private boolean canJump() {
|
||||
@@ -131,25 +129,25 @@ public abstract class Projectile extends GameObject {
|
||||
}
|
||||
|
||||
public void jump() throws IllegalStateException {
|
||||
// // TODO zie naar worm hoe dit moet, implementatie moet wel anders!
|
||||
// // wat meegeven met getJumpTime() ?
|
||||
// // wat met action points?
|
||||
//
|
||||
// if (!canJump())
|
||||
// throw new IllegalStateException();
|
||||
//
|
||||
// double v = jumpVelocity();
|
||||
// double t = getJumpTime();
|
||||
// double a = getOrientation();
|
||||
//
|
||||
// Coordinate newLocation = Coordinate.create(getLocation().getX() + v * t * cos(a), getLocation().getY() + v * t * sin(a) - (G * t * t) / 2.0);
|
||||
//
|
||||
// if (! isValidLocation(newLocation)) {
|
||||
// terminate();
|
||||
// return;
|
||||
// }
|
||||
// setLocation(newLocation);
|
||||
// //Worm.setActionPoints(0);
|
||||
// TODO zie naar worm hoe dit moet, implementatie moet wel anders!
|
||||
// wat meegeven met getJumpTime() ?
|
||||
// wat met action points?
|
||||
|
||||
if (!canJump())
|
||||
throw new IllegalStateException();
|
||||
|
||||
double v = jumpVelocity();
|
||||
double t = getJumpTime();
|
||||
double a = getOrientation();
|
||||
|
||||
Coordinate newLocation = Coordinate.create(getLocation().getX() + v * t * cos(a), getLocation().getY() + v * t * sin(a) - (G * t * t) / 2.0);
|
||||
|
||||
if (! isValidLocation(newLocation)) {
|
||||
terminate();
|
||||
return;
|
||||
}
|
||||
setLocation(newLocation);
|
||||
//Worm.setActionPoints(0);
|
||||
}
|
||||
|
||||
private static Coordinate calcLocation(Coordinate wormLocation, double wormOrientation, double wormRadius, double mass) {
|
||||
|
@@ -82,6 +82,7 @@ public class Team {
|
||||
Collection<Worm> worms = getAllWormsOfTeam();
|
||||
|
||||
for (Worm w : worm) {
|
||||
if (w == null) return false;
|
||||
if (!names.add(w.getName())) return false;
|
||||
if (worms.contains(w)) return false;
|
||||
if (worms.size() == 0 && !w.isTerminated()) continue;
|
||||
@@ -173,8 +174,8 @@ public class Team {
|
||||
}
|
||||
|
||||
Worm[] supWorms = supplyingTeam.getAllWormsOfTeam().toArray(new Worm[0]);
|
||||
receivingTeam.addWorm(supWorms);
|
||||
supplyingTeam.removeWormsFromTeam(supWorms);
|
||||
receivingTeam.addWorm(supWorms);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -192,6 +192,8 @@ public class World {
|
||||
Set<GameObject> gameObjectList = new HashSet<>(getGameObjects());
|
||||
gameObjectList.forEach(g -> g.terminate());
|
||||
|
||||
this.teams.clear();
|
||||
|
||||
this.terminated = true;
|
||||
}
|
||||
|
||||
@@ -558,7 +560,7 @@ public class World {
|
||||
|
||||
|
||||
if (item1 instanceof Worm && item2 instanceof Worm) {
|
||||
if (((Worm) item1).getTeam().getName().equals(((Worm) item2).getTeam().getName())) {
|
||||
if ((((Worm) item1).getTeam() != null && ((Worm) item2).getTeam() != null) && ((Worm) item1).getTeam().getName().equals(((Worm) item2).getTeam().getName())) {
|
||||
long hitpoints = (long) Math.floor((((Worm) item1).getHitPoints() + ((Worm) item2).getHitPoints()) / 2);
|
||||
((Worm) item1).setHitPoints(hitpoints);
|
||||
((Worm) item2).setHitPoints(hitpoints);
|
||||
@@ -567,24 +569,27 @@ public class World {
|
||||
Worm lgWorm = (Worm) item1;
|
||||
Worm smWorm = (Worm) item2;
|
||||
|
||||
if (item1.getRadius() < item2.getRadius()) {
|
||||
if (lgWorm.getRadius() < smWorm.getRadius()) {
|
||||
lgWorm = (Worm) item2;
|
||||
smWorm = (Worm) item1;
|
||||
}
|
||||
|
||||
long lgHitPoints = lgWorm.getHitPoints();
|
||||
long lgHitPoints = lgWorm.getActionPoints();
|
||||
if (lgHitPoints < 5) {
|
||||
lgWorm.setHitPoints(0);
|
||||
smWorm.incrementHitPoints(lgHitPoints);
|
||||
lgWorm.setActionPoints(0);
|
||||
smWorm.incrementActionPoints(smWorm.getActionPoints() + lgHitPoints);
|
||||
} else {
|
||||
smWorm.incrementHitPoints(5);
|
||||
lgWorm.decreaseHitPoints(5);
|
||||
smWorm.incrementActionPoints(5);
|
||||
lgWorm.decreaseActionPoints(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (item1 instanceof Worm && item2 instanceof Food) {
|
||||
((Worm) item1).eat((Food) item2, false);
|
||||
}
|
||||
else if(item1 instanceof Food && item2 instanceof Worm) {
|
||||
((Worm) item2).eat((Food) item1, false);
|
||||
}
|
||||
else if (item1 instanceof Worm && item2 instanceof Projectile ||
|
||||
item1 instanceof Projectile && item2 instanceof Worm) {
|
||||
// TODO hit by projectile, projectile gets random hit points
|
||||
|
@@ -323,6 +323,10 @@ public class Worm extends GameObject {
|
||||
setActionPoints(getActionPoints() - delta);
|
||||
}
|
||||
|
||||
public void incrementActionPoints(long delta) {
|
||||
setActionPoints(getActionPoints() + delta);
|
||||
}
|
||||
|
||||
/**
|
||||
* This variable contains the current action points of the worm.
|
||||
*/
|
||||
@@ -966,7 +970,10 @@ public class Worm extends GameObject {
|
||||
* |new.getHitPoints() == old.getHitPoints() + value
|
||||
*/
|
||||
public void incrementHitPoints(long value) {
|
||||
setHitPoints(getHitPoints() + value);
|
||||
|
||||
double current = getHitPoints();
|
||||
if (current + value < 0) setHitPoints(0);
|
||||
else setHitPoints(getHitPoints() + value);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user