Search in sources :

Example 31 with TransformableModel

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

the class ExtractorModelTest method testConfig.

/**
 * Test the extractor config.
 */
@Test
void testConfig() {
    final ObjectExtractor object = new ObjectExtractor(services, setup, true, true);
    object.addFeature(new TransformableModel(services, setup));
    final Media media = UtilSetup.createConfig(ExtractorModelTest.class);
    final Xml xml = new Xml(media);
    xml.add(ExtractorConfig.exports(new ExtractorConfig(1.0, 2.0, 5)));
    xml.save(media);
    final ExtractorModel extractor = new ExtractorModel(services, new Setup(media));
    extractor.recycle();
    assertEquals(5, extractor.getExtractionCapacity());
    assertEquals(1.0, extractor.getExtractionSpeed());
    assertEquals(2.0, extractor.getDropOffSpeed());
    extractor.prepare(object);
    assertEquals(5, extractor.getExtractionCapacity());
    assertEquals(1.0, extractor.getExtractionSpeed());
    assertEquals(2.0, extractor.getDropOffSpeed());
    object.getFeature(Identifiable.class).notifyDestroyed();
    assertTrue(media.getFile().delete());
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Setup(com.b3dgs.lionengine.game.feature.Setup) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup) Identifiable(com.b3dgs.lionengine.game.feature.Identifiable) Test(org.junit.jupiter.api.Test)

Example 32 with TransformableModel

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

the class ExtractorModelTest method testExtractorExtractable.

/**
 * Test the extractor with extractable.
 */
@Test
void testExtractorExtractable() {
    final ObjectExtractorSelf object = new ObjectExtractorSelf(services, setup);
    object.addFeature(new TransformableModel(services, setup));
    final Extractor extractor = new ExtractorModel(services, setup);
    extractor.setCapacity(2);
    extractor.setExtractionSpeed(25.0);
    extractor.setDropOffSpeed(100.0);
    extractor.prepare(object);
    extractor.addListener(object);
    assertNull(extractor.getResourceLocation());
    assertNull(extractor.getResourceType());
    final Extractable extractable = UtilExtractable.createExtractable(services, setup);
    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);
    extractor.update(1.0);
    assertTrue(extractor.isExtracting());
    assertEquals(5, object.flag.get());
    extractor.update(1.0);
    extractor.update(1.0);
    extractor.update(1.0);
    extractor.update(1.0);
    extractor.update(1.0);
    extractor.update(1.0);
    extractor.update(1.0);
    extractor.update(1.0);
    extractor.update(1.0);
    assertFalse(extractor.isExtracting());
    assertEquals(6, object.flag.get());
    extractor.update(1.0);
    assertTrue(extractor.isExtracting());
    assertEquals(2, object.flag.get());
    extractor.update(1.0);
    extractor.update(1.0);
    extractor.update(1.0);
    extractor.update(1.0);
    extractor.update(1.0);
    extractor.update(1.0);
    extractor.update(1.0);
    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 33 with TransformableModel

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

the class ExtractorModelTest method testCannotCarry.

/**
 * Test the extractor cannot carry.
 */
@Test
void testCannotCarry() {
    final ObjectExtractor object = new ObjectExtractor(services, setup, true, false);
    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> drop = new AtomicReference<>();
    final AtomicReference<String> skip = new AtomicReference<>();
    extractor.addListener(UtilExtractable.createListener(skip, skip, skip, skip, drop, skip));
    extractor.setResource("wood", 1, 2, 1, 1);
    extractor.startExtraction();
    extractor.update(1.0);
    assertTrue(extractor.isExtracting());
    extractor.update(1.0);
    extractor.update(1.0);
    assertTrue(extractor.isExtracting());
    assertNull(drop.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 34 with TransformableModel

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

the class UtilExtractable method createExtractable.

/**
 * Create extractable.
 *
 * @param services The services reference (must not be <code>null</code>).
 * @param setup The setup reference (must not be <code>null</code>).
 * @return The extractable.
 */
public static Extractable createExtractable(Services services, Setup setup) {
    services.add(new MapTileGame());
    final Featurable featurable = new FeaturableModel(services, setup);
    featurable.addFeature(new TransformableModel(services, setup));
    final Extractable extractable = new ExtractableModel(services, setup);
    extractable.setResourcesQuantity(10);
    extractable.setResourcesType("wood");
    extractable.prepare(featurable);
    return extractable;
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Featurable(com.b3dgs.lionengine.game.feature.Featurable)

Example 35 with TransformableModel

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

the class ExtractableModelTest method testExtract.

/**
 * Test the extraction.
 */
@Test
void testExtract() {
    services.add(new MapTileGame());
    final Featurable featurable = new FeaturableModel(services, setup);
    featurable.addFeature(new TransformableModel(services, setup));
    final Extractable extractable = new ExtractableModel(services, setup);
    extractable.prepare(featurable);
    extractable.setResourcesQuantity(10);
    assertEquals(10, extractable.getResourceQuantity());
    extractable.extractResource(5);
    assertEquals(5, extractable.getResourceQuantity());
    extractable.getFeature(Identifiable.class).notifyDestroyed();
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) 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