diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000000..2616a0151f --- /dev/null +++ b/pom.xml @@ -0,0 +1,65 @@ + + 4.0.0 + com.github.amidos2006 + mario-ai-framework + jar + 1.0.0-SNAPSHOT + + Mario-AI-Framework + The Mario AI framework is a framework for using AI methods with a version of Super Mario Bros. + + https://github.com/amidos2006/Mario-AI-Framework + + + + Mario-AI-Framework License + https://github.com/amidos2006/Mario-AI-Framework#copyrights + repo + + + + + UTF-8 + + + + + amidos2006 + Ahmed Khalifa + ahmed@akhalifa.com + http://www.akhalifa.com + + + + + https://github.com/amidos2006/Mario-AI-Framework + scm:git:git@github.com:amidos2006/Mario-AI-Framework.git + HEAD + + + + src + + + levels + + + img + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 8 + 8 + + + + + diff --git a/src/PlayLevel.java b/src/PlayLevel.java index 890cb3dcf7..7b85ba8e93 100644 --- a/src/PlayLevel.java +++ b/src/PlayLevel.java @@ -1,4 +1,7 @@ import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringWriter; import java.nio.file.Files; import java.nio.file.Paths; @@ -23,17 +26,22 @@ public static void printResults(MarioResult result) { } public static String getLevel(String filepath) { - String content = ""; - try { - content = new String(Files.readAllBytes(Paths.get(filepath))); - } catch (IOException e) { + try (Reader r = new InputStreamReader(PlayLevel.class.getResourceAsStream(filepath))) { + StringWriter writer = new StringWriter(); + char[] buf = new char[1024]; + int read; + while ((read = r.read(buf)) != -1) { + writer.write(buf, 0, read); } - return content; + return writer.toString(); + } catch (IOException e) { + return ""; + } } public static void main(String[] args) { MarioGame game = new MarioGame(); - // printResults(game.playGame(getLevel("../levels/original/lvl-1.txt"), 200, 0)); - printResults(game.runGame(new agents.robinBaumgarten.Agent(), getLevel("./levels/original/lvl-1.txt"), 20, 0, true)); + // printResults(game.playGame(getLevel("/original/lvl-1.txt"), 200, 0)); + printResults(game.runGame(new agents.robinBaumgarten.Agent(), getLevel("/original/lvl-1.txt"), 20, 0, true)); } } diff --git a/src/engine/helper/Assets.java b/src/engine/helper/Assets.java index 7581d463f0..73d8252d03 100755 --- a/src/engine/helper/Assets.java +++ b/src/engine/helper/Assets.java @@ -46,7 +46,7 @@ public static void init(GraphicsConfiguration gc) { private static Image getImage(GraphicsConfiguration gc, String imageName) throws IOException { BufferedImage source = null; try { - source = ImageIO.read(Assets.class.getResourceAsStream(imageName)); + source = ImageIO.read(Assets.class.getResourceAsStream("/"+imageName)); } catch (Exception e) { }