Commit 6f424fa3 authored by Lucas Delcros's avatar Lucas Delcros

added test for water spawning

parent a0ebf39a
......@@ -38,8 +38,9 @@ public class Map implements Serializable {
public Map() {}
public Map(Tile[][] m,Surface[] rooms, Surface[] corridors,/* Surface[] doors,*/ MapPoint positionPlayerAtStart,MapPoint stairsPosition) {
public Map(Tile[][] m,Surface[] rooms, Surface[] corridors,/* Surface[] doors,*/ Entity[] entities , MapPoint positionPlayerAtStart,MapPoint stairsPosition) {
map = m;
this.entities = entities;
this.positionPlayerAtStart=positionPlayerAtStart;
this.stairsPosition=stairsPosition;
this.rooms=rooms;
......@@ -168,25 +169,6 @@ public class Map implements Serializable {
public Entity[] getEntities() {
return(entities);
}
public void generateEntities() {
MapPatterns.read();
int nbRooms=rooms.length;
Random r=new Random();
int nbEntities=-1;
while(nbEntities<nbRooms/2 || nbEntities>3*nbRooms) {
nbEntities=(int) (nbRooms*(1+r.nextGaussian()));
}
entities=new Entity[nbEntities];
for(int i=0;i<nbEntities;i++) {
int room=r.nextInt(nbRooms);
int ii=rooms[room].i1+r.nextInt(rooms[room].height);
int jj=rooms[room].j1+r.nextInt(rooms[room].width);
int posY=ii*Point.TileScale;
int posX=jj*Point.TileScale;
entities[i]= SpeciesArray.create(posX,posY,100,"Ronflex","Monster "+i);
}
}
public void addSomeCorridors() {
int nbRooms=rooms.length;
Random r=new Random();
......
......@@ -5,6 +5,9 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import core.gamestate.Entity;
import core.gamestate.SpeciesArray;
import core.zone.Point;
import map_generation.tiles.TileBuilder;
import map_generation.tiles.TileType;
......@@ -21,10 +24,9 @@ public final class MapBuilder implements Serializable{
private ArrayList<Surface> rooms;
private ArrayList<Surface> corridors;
private ArrayList<Surface> doors;
private Entity[] entities;
private MapPoint positionPlayerAtStart;
private MapPoint stairsPosition;
// private ArrayList<int[]> positionEntitiesAtStart;
// private Entity[] typeEntities;
private int height = 0, width = 0;
public MapBuilder() {
......@@ -146,7 +148,24 @@ public final class MapBuilder implements Serializable{
if(!s.isOnSurface(positionPlayerAtStart) && !s.isOnSurface(stairsPosition))fillSurfaceWith(map, s, TileType.WATER);
}
}
private void generateEntities(TileBuilder[][] tb) {
MapPatterns.read();
int nbRooms=rooms.size();
Random r=new Random();
int nbEntities=-1;
while(nbEntities<nbRooms/2 || nbEntities>3*nbRooms) {
nbEntities=(int) (nbRooms*(1+r.nextGaussian()));
}
entities=new Entity[nbEntities];
for(int i=0;i<nbEntities;i++) {
int room=r.nextInt(nbRooms);
int ii=rooms.get(room).i1+r.nextInt(rooms.get(room).height);
int jj=rooms.get(room).j1+r.nextInt(rooms.get(room).width);
int posY=ii*Point.TileScale;
int posX=jj*Point.TileScale;
if(tb[ii][jj].getType() != TileType.WATER) entities[i]= SpeciesArray.create(posX,posY,100,"Ronflex","Monster "+i);
}
}
/**
* Build the map
......@@ -167,12 +186,13 @@ public final class MapBuilder implements Serializable{
fillSurfaceWith(map, corridor, TileType.GROUND);
}
generateEntities(map);
map[stairsPosition.getI()][stairsPosition.getJ()].setType(TileType.STAIRS);
//TODO uses doors
//Surface[] doors = this.doors.toArray(new Surface[this.doors.size()]);
Surface[] rooms = this.rooms.toArray(new Surface[this.rooms.size()]);
Surface[] corridors = this.corridors.toArray(new Surface[this.corridors.size()]);
return new Map(TileBuilder.buildTiles(map), rooms, corridors/*, doors*/, positionPlayerAtStart, stairsPosition);
return new Map(TileBuilder.buildTiles(map), rooms, corridors/*, doors*/, entities, positionPlayerAtStart, stairsPosition);
}
}
......@@ -19,7 +19,6 @@ public class MapGeneration implements Serializable {
}
//System.out.println("NbCheck : "+nbCheck);
//map.addSomeCorridors();
map.generateEntities();
return(map);
}
}
package map_generation.tests;
//import static org.junit.Assert.*;
//import map_generation.map.SurfacesMapGeneration;
//import map_generation.map.Map;
import static org.junit.Assert.*;
import map_generation.map.Map;
import map_generation.map.SurfacesMapGeneration;
import map_generation.tiles.TileType;
//import org.junit.Test;
import org.junit.Test;
import core.gamestate.Entity;
import core.zone.Point;
public class MapTests {
// @Test
@Test
public void testEveryRoomIsReachable() {
//Map map = SurfacesMapGeneration.roomsRandomGeneration(20, 500);
// assertTrue("Some rooms are not reachable !", map.check());
Map map = SurfacesMapGeneration.roomsRandomGeneration(20, 500);
assertTrue("Some rooms are not reachable !", map.check());
}
@Test
public void testNoEntitiesOnWater(){
Map map = SurfacesMapGeneration.roomsRandomGeneration(20, 500);
for(Entity entity : map.getEntities()){
Point pt = Point.construct(entity.getX(), entity.getY());
assertFalse("An entity has spawn on water !",map.getTileAt(pt.toMapPoint()).getType() == TileType.WATER);
}
}
@Test
public void testPlayerNotOnWater(){
Map map = SurfacesMapGeneration.roomsRandomGeneration(20, 500);
assertFalse("The player has spawn on water !", map.getTileAt(map.getPositionPlayerStart()).getType() == TileType.WATER);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment