Search in sources :

Example 56 with LionEngineException

use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.

the class StateAnimationUtil method loadStates.

/**
 * Load all existing animations defined in the xml file.
 *
 * @param states The states values.
 * @param factory The factory reference.
 * @param provider The featurable reference.
 * @param setup The setup reference.
 */
public static void loadStates(StateAnimationBased[] states, StateFactory factory, FeatureProvider provider, Setup setup) {
    final AnimationConfig configAnimations = AnimationConfig.imports(setup);
    for (final StateAnimationBased type : states) {
        try {
            final Animation animation = configAnimations.getAnimation(type.getAnimationName());
            final State state = UtilReflection.create(type.getStateClass(), UtilReflection.getParamTypes(provider, animation), provider, animation);
            factory.addState(state);
        } catch (final NoSuchMethodException exception) {
            throw new LionEngineException(exception);
        }
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) State(com.b3dgs.lionengine.game.State) Animation(com.b3dgs.lionengine.Animation) AnimationConfig(com.b3dgs.lionengine.game.AnimationConfig)

Example 57 with LionEngineException

use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.

the class XmlTest method testWrongWriteXml.

/**
 * Test wrong write in xml file.
 *
 * @throws IOException If error.
 */
private void testWrongWriteXml() throws IOException {
    try {
        new Xml("child").save(Medias.create(Constant.EMPTY_STRING));
        Assert.fail();
    } catch (final LionEngineException exception) {
        // Success
        Assert.assertNotNull(exception);
    }
    final File file = File.createTempFile("foo", null);
    file.deleteOnExit();
    if (file.mkdir()) {
        try {
            new Xml("child").save(Medias.create(file.getPath()));
            Assert.fail();
        } catch (final LionEngineException exception) {
            // Success
            Assert.assertNotNull(exception);
        } finally {
            UtilFolder.deleteDirectory(file);
        }
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) File(java.io.File)

Example 58 with LionEngineException

use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.

the class SpriteParallaxedTest method testParallaxFailure.

/**
 * Test parallax sprite failure.
 */
@Test
public void testParallaxFailure() {
    try {
        final SpriteParallaxed spriteC = Drawable.loadSpriteParallaxed(media, 0, 60, 100);
        Assert.assertNotNull(spriteC);
        Assert.fail();
    } catch (final LionEngineException exception) {
        // Success
        Assert.assertNotNull(exception);
    }
    try {
        final SpriteParallaxed spriteC = Drawable.loadSpriteParallaxed(media, LINES, 60, 0);
        Assert.assertNotNull(spriteC);
        Assert.fail();
    } catch (final LionEngineException exception) {
        // Success
        Assert.assertNotNull(exception);
    }
    try {
        final SpriteParallaxed spriteC = Drawable.loadSpriteParallaxed(media, LINES, 0, 60);
        Assert.assertNotNull(spriteC);
        Assert.fail();
    } catch (final LionEngineException exception) {
        // Success
        Assert.assertNotNull(exception);
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) SpriteParallaxed(com.b3dgs.lionengine.graphic.SpriteParallaxed) Test(org.junit.Test)

Example 59 with LionEngineException

use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.

the class ProducerModelTest method testEnumFail.

/**
 * Test with enum fail.
 *
 * @throws NoSuchFieldException If error.
 * @throws IllegalArgumentException If error.
 * @throws IllegalAccessException If error.
 */
@Test
public void testEnumFail() throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
    final ProducerModel producer = new ProducerModel(services);
    final Field field = producer.getClass().getDeclaredField("state");
    UtilReflection.setAccessible(field, true);
    field.set(producer, ProducerState.values()[5]);
    try {
        producer.update(1.0);
        Assert.fail();
    } catch (final LionEngineException exception) {
        Assert.assertEquals("Unknown enum: FAIL", exception.getMessage());
    }
}
Also used : Field(java.lang.reflect.Field) LionEngineException(com.b3dgs.lionengine.LionEngineException) Test(org.junit.Test)

Example 60 with LionEngineException

use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.

the class ServerImpl method start.

@Override
public void start(String name, int port) {
    if (!started) {
        try {
            serverSocket = new ServerSocket(port);
            clientConnectionListener = new ClientConnecter(serverSocket, this);
            clientConnectionListener.start();
            this.port = port;
            bandwidthTimer.start();
            started = true;
        } catch (final IOException exception) {
            throw new LionEngineException(exception, "Cannot create the server !");
        }
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException)

Aggregations

LionEngineException (com.b3dgs.lionengine.LionEngineException)75 IOException (java.io.IOException)13 File (java.io.File)8 OutputStream (java.io.OutputStream)7 ArrayList (java.util.ArrayList)7 XmlReader (com.b3dgs.lionengine.XmlReader)6 Field (java.lang.reflect.Field)6 Test (org.junit.Test)6 Media (com.b3dgs.lionengine.Media)5 Configurer (com.b3dgs.lionengine.game.Configurer)4 UtilFile (com.b3dgs.lionengine.UtilFile)3 Graphic (com.b3dgs.lionengine.graphic.Graphic)3 UtilFile (com.b3dgs.lionengine.util.UtilFile)3 DisplayMode (java.awt.DisplayMode)3 BufferedImage (java.awt.image.BufferedImage)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 AfterAll (org.junit.jupiter.api.AfterAll)3 Animation (com.b3dgs.lionengine.Animation)2 AnimationConfig (com.b3dgs.lionengine.game.AnimationConfig)2 Feature (com.b3dgs.lionengine.game.Feature)2