Search in sources :

Example 41 with MapTile

use of com.b3dgs.lionengine.game.feature.tile.map.MapTile in project lionengine by b3dgs.

the class FovableModelTest method testFovable.

/**
 * Test the fovable model.
 */
@Test
void testFovable() {
    final MapTile map = UtilMap.createMap(7);
    services.add(map);
    final Setup setup = new Setup(config);
    final Fovable fovable = new FovableModel(services, setup);
    final Featurable featurable = new FeaturableModel(services, setup);
    final Transformable transformable = featurable.addFeatureAndGet(new TransformableModel(services, setup));
    transformable.teleport(1, 2);
    transformable.setSize(3, 4);
    fovable.prepare(featurable);
    fovable.setFov(5);
    assertEquals(1, fovable.getInTileX());
    assertEquals(2, fovable.getInTileY());
    assertEquals(3, fovable.getInTileWidth());
    assertEquals(4, fovable.getInTileHeight());
    assertEquals(5, fovable.getInTileFov());
    assertTrue(fovable.canUpdate());
    fovable.setCanUpdate(() -> false);
    assertFalse(fovable.canUpdate());
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Transformable(com.b3dgs.lionengine.game.feature.Transformable) UtilTransformable(com.b3dgs.lionengine.game.feature.UtilTransformable) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Test(org.junit.jupiter.api.Test)

Example 42 with MapTile

use of com.b3dgs.lionengine.game.feature.tile.map.MapTile in project lionengine by b3dgs.

the class MapTileCircuitModelTest method testResolution.

/**
 * Test the map circuit resolution.
 */
@Test
void testResolution() {
    final MapTile map = createMap(TILE_GROUND);
    final MapTileGroup mapGroup = map.getFeature(MapTileGroup.class);
    final MapTileCircuit mapCircuit = map.getFeature(MapTileCircuitModel.class);
    map.setTile(5, 6, TILE_ROAD);
    map.setTile(5, 4, TILE_ROAD);
    map.setTile(5, 5, TILE_ROAD);
    map.setTile(4, 5, TILE_ROAD);
    map.setTile(6, 5, TILE_ROAD);
    mapCircuit.resolve(map.getTile(5, 5));
    assertEquals(ROAD, mapGroup.getGroup(map.getTile(5, 5)));
}
Also used : MapTileGroup(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Test(org.junit.jupiter.api.Test)

Example 43 with MapTile

use of com.b3dgs.lionengine.game.feature.tile.map.MapTile in project lionengine by b3dgs.

the class MapGeneratorTest method testGenerator.

/**
 * Test the map generator.
 */
@Test
void testGenerator() {
    final MapTile generated = generator.generateMap(parameters, Arrays.asList(Medias.create("forest.png")), Medias.create("sheets.xml"), Medias.create("groups.xml"));
    append.append(generated, 0, 0);
    mapViewer.render(g);
    assertEquals(16, map.getTileWidth());
    assertEquals(16, map.getTileHeight());
    assertEquals(64, map.getInTileWidth());
    assertEquals(48, map.getInTileHeight());
    for (int tx = 0; tx < map.getInTileWidth(); tx++) {
        for (int ty = 0; ty < map.getInTileHeight(); ty++) {
            assertNotNull(map.getTile(tx, ty));
        }
    }
}
Also used : MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Test(org.junit.jupiter.api.Test) FactoryGraphicTest(com.b3dgs.lionengine.graphic.FactoryGraphicTest)

Example 44 with MapTile

use of com.b3dgs.lionengine.game.feature.tile.map.MapTile in project lionengine by b3dgs.

the class MapTilePersisterModelTest method testSaveLoad.

/**
 * Test the save and load map from file.
 *
 * @throws IOException If error.
 */
@Test
void testSaveLoad() throws IOException {
    final MapTile map = UtilMapTilePersister.createMap();
    assertEquals(map.getInTileWidth() * (map.getInTileHeight() - 1), map.getTilesNumber());
    final Media level = Medias.create("level");
    UtilMapTilePersister.saveMap(map, level);
    final MapTile mapLoaded = UtilMapTilePersister.loadMap(level);
    assertEquals(map.getTileWidth(), mapLoaded.getTileWidth());
    assertEquals(map.getTileHeight(), mapLoaded.getTileHeight());
    assertEquals(map.getInTileWidth(), mapLoaded.getInTileWidth());
    assertEquals(map.getInTileHeight(), mapLoaded.getInTileHeight());
    assertEquals(map.getWidth(), mapLoaded.getWidth());
    assertEquals(map.getHeight(), mapLoaded.getHeight());
    for (int x = 0; x < mapLoaded.getInTileWidth(); x++) {
        for (int y = 0; y < mapLoaded.getInTileHeight(); y++) {
            final Tile tile = mapLoaded.getTile(x, y);
            if (y == 0) {
                assertNull(tile);
            } else {
                assertNotNull(tile);
                assertEquals(x * y, tile.getNumber());
                assertEquals(x * mapLoaded.getTileWidth(), tile.getX());
                assertEquals(y * mapLoaded.getTileHeight(), tile.getY());
            }
        }
    }
    assertEquals(map.getTilesNumber(), mapLoaded.getTilesNumber());
    assertTrue(level.getFile().delete());
}
Also used : Media(com.b3dgs.lionengine.Media) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Tile(com.b3dgs.lionengine.game.feature.tile.Tile) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Test(org.junit.jupiter.api.Test)

Example 45 with MapTile

use of com.b3dgs.lionengine.game.feature.tile.map.MapTile in project lionengine by b3dgs.

the class MapTilePersisterModelTest method testConstructor.

/**
 * Test the constructor with services with map.
 */
@Test
void testConstructor() {
    final MapTile map = new MapTileGame();
    final MapTilePersister mapPersister = new MapTilePersisterModel();
    assertNotNull(mapPersister);
    mapPersister.prepare(map);
}
Also used : MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Test(org.junit.jupiter.api.Test)

Aggregations

MapTile (com.b3dgs.lionengine.game.feature.tile.map.MapTile)58 Test (org.junit.jupiter.api.Test)34 Media (com.b3dgs.lionengine.Media)15 Tile (com.b3dgs.lionengine.game.feature.tile.Tile)11 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)10 Collection (java.util.Collection)9 MapTileGroup (com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup)8 MapTileGroupModel (com.b3dgs.lionengine.game.feature.tile.map.MapTileGroupModel)7 MapTileTransition (com.b3dgs.lionengine.game.feature.tile.map.transition.MapTileTransition)6 Test (org.junit.Test)6 HashMap (java.util.HashMap)4 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)3 Setup (com.b3dgs.lionengine.game.feature.Setup)3 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)3 Featurable (com.b3dgs.lionengine.game.feature.Featurable)2 Transformable (com.b3dgs.lionengine.game.feature.Transformable)2 UtilTransformable (com.b3dgs.lionengine.game.feature.UtilTransformable)2 FileReading (com.b3dgs.lionengine.io.FileReading)2 FileWriting (com.b3dgs.lionengine.io.FileWriting)2 HashSet (java.util.HashSet)2