Search in sources :

Example 11 with TransformableModel

use of com.b3dgs.lionengine.game.feature.TransformableModel in project lionengine by b3dgs.

the class ExtractorModelTest method testCannotExtract.

/**
 * Test the extractor cannot extract.
 */
@Test
void testCannotExtract() {
    final ObjectExtractor object = new ObjectExtractor(services, setup, false, true);
    object.addFeature(new TransformableModel(services, setup));
    final Extractor extractor = new ExtractorModel(services, setup);
    extractor.setCapacity(1);
    extractor.setExtractionSpeed(50.0);
    extractor.setDropOffSpeed(50.0);
    extractor.prepare(object);
    final AtomicReference<String> goTo = new AtomicReference<>();
    final AtomicReference<String> skip = new AtomicReference<>();
    extractor.addListener(UtilExtractable.createListener(goTo, skip, skip, skip, skip, skip));
    extractor.setResource("wood", 1, 2, 1, 1);
    extractor.startExtraction();
    extractor.update(1.0);
    assertFalse(extractor.isExtracting());
    assertNotNull(goTo.get());
    extractor.update(1.0);
    assertFalse(extractor.isExtracting());
    assertNotNull(goTo.get());
    object.getFeature(Identifiable.class).notifyDestroyed();
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) AtomicReference(java.util.concurrent.atomic.AtomicReference) Identifiable(com.b3dgs.lionengine.game.feature.Identifiable) Test(org.junit.jupiter.api.Test)

Example 12 with TransformableModel

use of com.b3dgs.lionengine.game.feature.TransformableModel in project lionengine by b3dgs.

the class ExtractorModelTest method testExtractorExtractableNoResource.

/**
 * Test the extractor with extractable without resource.
 */
@Test
void testExtractorExtractableNoResource() {
    final ObjectExtractorSelf object = new ObjectExtractorSelf(services, setup);
    object.addFeature(new TransformableModel(services, setup));
    final Extractor extractor = new ExtractorModel(services, setup);
    extractor.setCapacity(6);
    extractor.setExtractionSpeed(50.0);
    extractor.setDropOffSpeed(100.0);
    extractor.prepare(object);
    extractor.addListener(object);
    assertNull(extractor.getResourceLocation());
    assertNull(extractor.getResourceType());
    final Extractable extractable = UtilExtractable.createExtractable(services, setup);
    extractable.setResourcesQuantity(0);
    extractor.setResource(extractable);
    assertFalse(extractor.isExtracting());
    extractor.startExtraction();
    assertFalse(extractor.isExtracting());
    assertEquals(1, object.flag.get());
    extractor.update(1.0);
    assertTrue(extractor.isExtracting());
    assertEquals(2, object.flag.get());
    extractor.update(1.0);
    assertTrue(extractor.isExtracting());
    assertEquals(2, object.flag.get());
    object.getFeature(Identifiable.class).notifyDestroyed();
    extractable.getFeature(Identifiable.class).notifyDestroyed();
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Identifiable(com.b3dgs.lionengine.game.feature.Identifiable) Test(org.junit.jupiter.api.Test)

Example 13 with TransformableModel

use of com.b3dgs.lionengine.game.feature.TransformableModel in project lionengine by b3dgs.

the class MapTilePathModelTest method createObject.

/**
 * Create object test.
 *
 * @return The object test.
 */
private Pathfindable createObject() {
    final FeaturableModel object = new FeaturableModel(services, setup);
    final Transformable transformable = object.addFeatureAndGet(new TransformableModel(services, setup));
    transformable.setSize(1, 1);
    return object.addFeatureAndGet(new PathfindableModel(services, setup));
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Transformable(com.b3dgs.lionengine.game.feature.Transformable) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel)

Example 14 with TransformableModel

use of com.b3dgs.lionengine.game.feature.TransformableModel in project lionengine by b3dgs.

the class ExtractorModelTest method testExtractor.

/**
 * Test the extractor.
 */
@Test
void testExtractor() {
    final Featurable object = new FeaturableModel(services, setup);
    object.addFeature(new TransformableModel(services, setup));
    final ExtractorModel extractor = new ExtractorModel(services, setup);
    extractor.recycle();
    extractor.setCapacity(6);
    extractor.setExtractionSpeed(50.0);
    extractor.setDropOffSpeed(100.0);
    extractor.prepare(object);
    final AtomicReference<String> goTo = new AtomicReference<>();
    final AtomicReference<String> startExtract = new AtomicReference<>();
    final AtomicReference<String> extracted = new AtomicReference<>();
    final AtomicReference<String> carry = new AtomicReference<>();
    final AtomicReference<String> startDrop = new AtomicReference<>();
    final AtomicReference<String> endDrop = new AtomicReference<>();
    extractor.addListener(UtilExtractable.createListener(goTo, startExtract, extracted, carry, startDrop, endDrop));
    assertNull(extractor.getResourceLocation());
    assertNull(extractor.getResourceType());
    extractor.setResource("wood", 1, 2, 1, 1);
    final Tiled location = extractor.getResourceLocation();
    assertEquals(1.0, location.getInTileX());
    assertEquals(2.0, location.getInTileY());
    assertEquals(1.0, location.getInTileWidth());
    assertEquals(1.0, location.getInTileHeight());
    assertEquals("wood", extractor.getResourceType());
    assertFalse(extractor.isExtracting());
    extractor.startExtraction();
    assertFalse(extractor.isExtracting());
    assertEquals("wood", goTo.get());
    extractor.update(1.0);
    assertTrue(extractor.isExtracting());
    assertEquals("wood", startExtract.get());
    assertNotEquals("wood", extracted.get());
    extractor.update(1.0);
    assertTrue(extractor.isExtracting());
    assertEquals("wood", extracted.get());
    extractor.update(1.0);
    extractor.update(1.0);
    extractor.update(1.0);
    extractor.update(1.0);
    extractor.update(1.0);
    assertTrue(extractor.isExtracting());
    assertEquals("wood", carry.get());
    extractor.update(1.0);
    assertFalse(extractor.isExtracting());
    assertEquals("wood", startDrop.get());
    extractor.update(1.0);
    extractor.update(1.0);
    extractor.update(1.0);
    assertTrue(extractor.isExtracting());
    assertEquals("wood", endDrop.get());
    object.getFeature(Identifiable.class).notifyDestroyed();
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Tiled(com.b3dgs.lionengine.game.Tiled) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) AtomicReference(java.util.concurrent.atomic.AtomicReference) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Identifiable(com.b3dgs.lionengine.game.feature.Identifiable) Test(org.junit.jupiter.api.Test)

Example 15 with TransformableModel

use of com.b3dgs.lionengine.game.feature.TransformableModel in project lionengine by b3dgs.

the class ExtractableModelTest method testConfigWithNode.

/**
 * Test the extraction config with node.
 */
@Test
void testConfigWithNode() {
    final MapTile map = new MapTileGame();
    map.create(16, 16, 4, 4);
    services.add(map);
    final Featurable featurable = new FeaturableModel(services, setup);
    featurable.addFeatureAndGet(new TransformableModel(services, setup)).teleport(16, 32);
    final Media media = UtilExtractable.createMedia();
    final Extractable extractable = new ExtractableModel(services, new Setup(media));
    extractable.prepare(featurable);
    assertEquals(10, extractable.getResourceQuantity());
    assertEquals("gold", extractable.getResourceType());
    assertEquals(1, extractable.getInTileX());
    assertEquals(2, extractable.getInTileY());
    assertEquals(1, extractable.getInTileWidth());
    assertEquals(2, extractable.getInTileHeight());
    extractable.getFeature(Identifiable.class).notifyDestroyed();
    assertTrue(media.getFile().delete());
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) Media(com.b3dgs.lionengine.Media) 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) Identifiable(com.b3dgs.lionengine.game.feature.Identifiable) Test(org.junit.jupiter.api.Test)

Aggregations

TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)37 Test (org.junit.jupiter.api.Test)20 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)19 Transformable (com.b3dgs.lionengine.game.feature.Transformable)17 Setup (com.b3dgs.lionengine.game.feature.Setup)12 Featurable (com.b3dgs.lionengine.game.feature.Featurable)11 Identifiable (com.b3dgs.lionengine.game.feature.Identifiable)10 UtilSetup (com.b3dgs.lionengine.game.feature.UtilSetup)9 Media (com.b3dgs.lionengine.Media)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 AnimatableModel (com.b3dgs.lionengine.game.feature.AnimatableModel)5 Services (com.b3dgs.lionengine.game.feature.Services)5 UtilTransformable (com.b3dgs.lionengine.game.feature.UtilTransformable)5 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)5 Medias (com.b3dgs.lionengine.Medias)4 Handler (com.b3dgs.lionengine.game.feature.Handler)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Animation (com.b3dgs.lionengine.Animation)3 UtilAssert.assertEquals (com.b3dgs.lionengine.UtilAssert.assertEquals)3 UtilAssert.assertTrue (com.b3dgs.lionengine.UtilAssert.assertTrue)3