Added world and updated facade

This commit is contained in:
2018-04-03 11:21:15 +02:00
parent 9ad5255561
commit aa00b97ef0
4 changed files with 165 additions and 9 deletions

View File

@@ -2,10 +2,12 @@ package worms.facade;
import worms.model.Food; import worms.model.Food;
import worms.model.Team; import worms.model.Team;
import worms.model.World;
import worms.model.Worm; import worms.model.Worm;
import worms.util.IllegalNameException; import worms.util.IllegalNameException;
import worms.util.ModelException; import worms.util.ModelException;
import worms.util.Coordinate; import worms.util.Coordinate;
import worms.util.MustNotImplementException;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.Collection; import java.util.Collection;
@@ -794,4 +796,86 @@ public class Facade implements IFacade {
public double getMass(Worm worm) throws ModelException { public double getMass(Worm worm) throws ModelException {
return worm.getMass(); return worm.getMass();
} }
/**
* Create a new team for the given world with given name and with no members yet.
*/
@Override
public Team createTeam(World world, String name) throws ModelException, MustNotImplementException {
return null;
}
/**
* Terminate the given team.
*/
@Override
public void terminate(Team team) throws ModelException, MustNotImplementException {
}
/**
* Check whether the given portion of food is terminated.
*/
@Override
public boolean isTerminated(Team team) throws ModelException, MustNotImplementException {
return false;
}
/**
* Return the name of the given team.
*/
@Override
public String getName(Team team) throws ModelException, MustNotImplementException {
return null;
}
/**
* Return the team to which this worm belongs.
*/
@Override
public Team getTeam(Worm worm) throws ModelException {
return null;
}
/**
* Return the number of worms in the given team.
*/
@Override
public int getNbWormsOfTeam(Team team) throws ModelException, MustNotImplementException {
return 0;
}
/**
* Return a list of all the worms in the given team, sorted alphabetically.
* This method must run in linear time.
*/
@Override
public List<Worm> getAllWormsOfTeam(Team team) throws ModelException, MustNotImplementException {
return null;
}
/**
* Add the given worms to the given team.]
*/
@Override
public void addWormsToTeam(Team team, Worm... worms) throws ModelException, MustNotImplementException {
}
/**
* Remove the given worms from the given team.
*/
@Override
public void removeWormsFromTeam(Team team, Worm... worms) throws ModelException, MustNotImplementException {
}
/**
* Merge the given teams.
* - All the worms of the supplying team are transferred to the receiving team.
*/
@Override
public void mergeTeams(Team recevingTeam, Team supplyingTeam) throws ModelException, MustNotImplementException {
}
} }

View File

@@ -1,4 +0,0 @@
package worms.facade;
public class World {
}

View File

@@ -0,0 +1,76 @@
package worms.model;
import java.util.ArrayList;
public class World {
private boolean terminated = false;
public World(double width, double height, boolean[][] map) {
if (!isValidDimension(width) || !isValidDimension(height)) throw new IllegalArgumentException();
this.width = width;
this.height = height;
this.map = map;
}
// region Dimensions
//===================================================================================
public static boolean isValidDimension(double dimension) {
return dimension >= 0.0 && dimension <= Double.MAX_VALUE;
}
public double getWidth() {
return width;
}
public double getHeight() {
return height;
}
private final double width;
private final double height;
// ===================================================================================
// endregion
// region map
//===================================================================================
public boolean[][] getMap() {
return map;
}
public boolean isPassable(double[] location) {
if (location[0] >= getMap()[0].length || location[0] < 0.0 ||
location[1] >= getMap().length || location[1] < 0.0) {
return true;
}
return this.map[(int) Math.round(location[0])][(int) Math.round(location[1])];
}
public boolean isPassable(double[] center, double radius) {
return false;
}
public boolean isTerminated() {
return terminated;
}
public void terminate() {
setTerminated(true);
}
private final boolean[][] map;
private void setTerminated(boolean terminated) {
this.terminated = terminated;
}
// ===================================================================================
// endregion
}

View File

@@ -597,8 +597,8 @@ public class Worm {
long total = 1 + (new Random().nextLong() * (10 - 1)); long total = 1 + (new Random().nextLong() * (10 - 1));
long loseSmallest = (long) (total / (largestWorm.getOrientation() / (smallestWorm.getOrientation() + largestWorm.getOrientation()))); long loseSmallest = (long) (total / (largestWorm.getOrientation() / (smallestWorm.getOrientation() + largestWorm.getOrientation())));
long loseLargest = total - loseSmallest; long loseLargest = total - loseSmallest;
smallestWorm.decreaseHitPoints(loseSmallest); smallestWorm.incrementHitPoints(loseSmallest);
largestWorm.decreaseHitPoints(loseLargest); largestWorm.incrementHitPoints(loseLargest);
} }
//=================================================================================== //===================================================================================
@@ -771,7 +771,7 @@ public class Worm {
// region hitPoints // region hitPoints
//=================================================================================== //===================================================================================
@Basic @Raw @Basic @Raw
public long getHitPoints() { public long getHitPoints() {
return this.hitPoints; return this.hitPoints;
@@ -780,13 +780,13 @@ public class Worm {
@Raw @Raw
private void setHitPoints(long hitPoints) { private void setHitPoints(long hitPoints) {
if (hitPoints <= 0) if (hitPoints <= 0)
//TODO worm sterft + weghalen van gamewereld // TODO worm sterft + weghalen van gamewereld
this.hitPoints = hitPoints; this.hitPoints = hitPoints;
} }
private long hitPoints; private long hitPoints;
public void decreaseHitPoints(long value) { public void incrementHitPoints(long value) {
setHitPoints(getHitPoints() - value); setHitPoints(getHitPoints() - value);
} }