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