Search in sources :

Example 1 with Tiled

use of com.b3dgs.lionengine.game.Tiled in project lionengine by b3dgs.

the class ExtractorModelTest method testRemoveListener.

/**
 * Test the remove listener.
 */
@Test
void testRemoveListener() {
    final AtomicBoolean check = new AtomicBoolean();
    final Extractor extractor = new ExtractorModel(services, setup);
    final ExtractorListener listener = new ExtractorListenerVoid() {

        @Override
        public void notifyStartGoToRessources(String type, Tiled resourceLocation) {
            check.set(true);
        }
    };
    extractor.addListener(listener);
    extractor.prepare(new FeaturableModel(services, setup));
    extractor.startExtraction();
    assertTrue(check.get());
    extractor.removeListener(listener);
    check.set(false);
    extractor.startExtraction();
    assertFalse(check.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Tiled(com.b3dgs.lionengine.game.Tiled) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Test(org.junit.jupiter.api.Test)

Example 2 with Tiled

use of com.b3dgs.lionengine.game.Tiled 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)

Aggregations

Tiled (com.b3dgs.lionengine.game.Tiled)2 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)2 Test (org.junit.jupiter.api.Test)2 Featurable (com.b3dgs.lionengine.game.feature.Featurable)1 Identifiable (com.b3dgs.lionengine.game.feature.Identifiable)1 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1