Documentatie World

This commit is contained in:
Leen Dereu
2018-05-23 13:19:46 +02:00
parent c5f55f29fb
commit be9e8ae8f9

View File

@@ -8,25 +8,24 @@ import java.util.stream.Collectors;
public class World {
/**
*
* @param width
* @param height
* @param map
*
* @post ...
* new.width = width
* |new.width = width
* @post ...
* new.height = height
* |new.height = height
* @post ...
* new.map = map
* |new.map = map
* @post ...
* new.legthX = width / map[0].length
* |new.legthX = width / map[0].length
* @post ...
* new.lengthY = height / map.length
* |new.lengthY = height / map.length
* @post ...
* new.game = false
* |new.game = false
* @post ...
* new.gameObjets = new HashSet<>()
* |new.gameObjets = new HashSet<>()
*/
public World(double width, double height, boolean[][] map) {
@@ -43,7 +42,7 @@ public class World {
}
// region game
// region game (Total)
//===================================================================================
public boolean hasActiveGame() {
@@ -120,11 +119,10 @@ public class World {
// endregion
// region Dimensions
// region Dimensions (Total)
//===================================================================================
/**
*
* @param dimension
*
* @return ...
@@ -135,7 +133,6 @@ public class World {
}
/**
*
* @return ...
* |result == width
*/
@@ -144,7 +141,6 @@ public class World {
}
/**
*
* @return ...
* |result == height
*/
@@ -152,14 +148,8 @@ public class World {
return height;
}
/**
*
*/
private final double width;
/**
*
*/
private final double height;
// ===================================================================================
@@ -167,11 +157,10 @@ public class World {
// region map
// region map (Total)
//===================================================================================
/**
*
* @return ...
* |result == map
*/
@@ -180,7 +169,6 @@ public class World {
}
/**
*
* @return ...
* result = this.terminated
*/
@@ -189,6 +177,8 @@ public class World {
}
/**
* @post ...
* |teams.clear()
* @post ...
* |this.terminated = true
*/
@@ -202,32 +192,25 @@ public class World {
this.terminated = true;
}
/**
*
*/
private final boolean[][] map;
/**
*
*/
private boolean terminated = false;
// ===================================================================================
// endregion
// region passable
// region passable (Total)
//===================================================================================
/**
*
* @param location
*
* @return ...
* |false if:
* |true if:
* | Math.floor(location[0] / lengthX) >= getMap()[0].length ||
* | location[0] < 0.0 || location[1] / lengthY >= getMap().length || location[1] < 0.0
* |various:
* | result == this.map[(int) Math.floor(location[1] / lengthY)][(int) Math.floor(location[0] / lengthX)]
* | result == this.map[map.length - 1 - (int) Math.floor(location[1] / lengthY)][(int) Math.floor(location[0] / lengthX)]
*/
public boolean isPassable(double[] location) {
@@ -240,7 +223,6 @@ public class World {
}
/**
*
* @param location
*
* @return ...
@@ -263,7 +245,6 @@ public class World {
}
/**
*
* @param center
* @param radius
*
@@ -271,11 +252,13 @@ public class World {
* |for (double i = 0; i < 2 * Math.PI; i += Math.PI / 180)
* | double lenX = center[0] + radius * Math.cos(i)
* | double lenY = center[1] + radius * Math.sin(i)
* | if (i < 1.58 && i > 1.57)
* | lenY -= 0.0000000001
* | else if (i < 0.79 && i > 0.78 )
* | if (center[0] + radius == lenX)
* | lenX -= 0.0000000001
* |result == isPassable(lenX, lenY)
* | if (center[1] + radius == lenY)
* | lenY -= 0.0000000001
* | if (!isPassable(lenX, lenY))
* | result == false
* |result == true
*/
public boolean isPassable(double[] center, double radius) {
@@ -304,7 +287,6 @@ public class World {
}
/**
*
* @return ...
* |result == isAdjacent(Coordinate.create(center), radius)
*/
@@ -313,7 +295,6 @@ public class World {
}
/**
*
* @param center ...
* @param radius ...
*
@@ -330,7 +311,6 @@ public class World {
}
/**
*
* @return ...
* |result == this.lengtX
*/
@@ -339,7 +319,6 @@ public class World {
}
/**
*
* @return ...
* |result == this.lengthY
*/
@@ -347,18 +326,11 @@ public class World {
return this.lengthY;
}
/**
*
*/
private final double lengthX;
/**
*
*/
private final double lengthY;
/**
*
* @param x
* @param y
*
@@ -373,8 +345,6 @@ public class World {
*/
private boolean isPassable(double x, double y) {
int xCoord = (int) Math.floor(x / lengthX);
int yCoord = map.length - 1 - (int) Math.floor(y / lengthY);
@@ -392,11 +362,10 @@ public class World {
// endregion
// region objects
// region objects (Defensive)
//===================================================================================
/**
*
* @return ...
* |result == new ArrayList<>(getGameObjects())
*/
@@ -405,9 +374,16 @@ public class World {
return new ArrayList<>(getGameObjects());
}
private Set<Team> teams = new HashSet<>();
/**
* @param team
* @throws IllegalStateException ...
* |team.size() == 10
* @throws IllegalArgumentException ...
* |! teams.add(team)
*/
public void addTeam(Team team) {
if (teams.size() == 10) throw new IllegalStateException("Maximum 10 teams");
@@ -416,17 +392,14 @@ public class World {
}
/**
*
* @return ...
* |result == teams
* |result == HashSet<>(teams)
*/
public Set<Team> getAllTeams() {
return new HashSet<>(teams);
}
/**
*
* @return ...
* |result == this.gameObjects
*/
@@ -435,17 +408,30 @@ public class World {
}
/**
*
* @param obj
*
* @post obj.setWorld(this)
* @post ...
* |obj.setWorld(this)
* @post ...
* |if (!obj.isValidLocation(obj.getLocation()))
* |obj.setWorld(null)
* @post ...
* |if (Worm.class.isInstance(obj) && (!obj.isValidLocation(obj.getLocation())
* | || !isAdjacent(obj.getLocation(), obj.getRadius()) ))
* |obj.setWorld(null)
* @post ...
* |getGameObjects().add(obj)
*
* @throws IllegalStateException
* ...
* @throws IllegalStateException ...
* |hasActiveGame()
* @throws IllegalArgumentException
* ...
* |!getGameObjects().add(obj)
* @throws IllegalArgumentException ...
* |obj == null || getGameObjects().contains(obj) || obj.isTerminated() ||
* | obj.getWorld() != null
* @throws IllegalArgumentException ...
* |! obj.isValidLocation(obj.getLocation())
* @throws IllegalArgumentException ...
* |Worm.class.isInstance(obj) && (!obj.isValidLocation(obj.getLocation()) ||
* | !isAdjacent(obj.getLocation(), obj.getRadius()))
*/
public void add(GameObject obj) throws IllegalStateException, IllegalArgumentException {
if (hasActiveGame()) throw new IllegalStateException();
@@ -466,9 +452,11 @@ public class World {
}
/**
*
* @param obj
*
* @post ...
* |obj.setWorld(null)
*
* @throws IllegalArgumentException
* ...
* |!getGameObjects().remove(obj)
@@ -480,11 +468,10 @@ public class World {
}
/**
*
* @param obj
*
* @return ...
* |getGameObjects().contains(obj)
* |result == getGameObjects().contains(obj)
*
* @throws NullPointerException
*/
@@ -493,10 +480,8 @@ public class World {
}
/**
*
* @return ...
* |lis.add(worm) for each worm
* |result == list (ArrayList<>())
* |result == getGameObjectsByClass(Worm.class)
*/
@SuppressWarnings("unchecked")
public List<Worm> getWormList() {
@@ -505,10 +490,8 @@ public class World {
}
/**
*
* @return ...
* |list.add(food) for each food
* |result == list (ArrayList<>())
* |result == getGameObjectsByClass(Food.class)
*/
@SuppressWarnings("unchecked")
public List<Food> getFoodList() {
@@ -516,14 +499,17 @@ public class World {
return getGameObjectsByClass(Food.class);
}
/**
* @param cl
* @param <T>
*
* @return ...
* |result == getGameObjects().stream().filter(cl::isInstance).map(cl::cast).collect(Collectors.toList())
*/
public <T extends GameObject> List<T> getGameObjectsByClass(Class<T> cl) {
return getGameObjects().stream().filter(cl::isInstance).map(cl::cast).collect(Collectors.toList());
}
/**
*
*/
private Set<GameObject> gameObjects;
@@ -531,7 +517,7 @@ public class World {
// endregion
// region Wizard
// region Wizard (Defensive)
//===================================================================================
public void castSpell() {