Conversation
This is needed if you want to jar package this code (for example).
|
Just curious about the changes, sorry if I am not very technically deep with Java. |
|
I don't think so. Actually I've generally found that maven makes it easier to import into different IDEs because many of them can understand it. I use IntelliJ for example and it recognises maven projects and sets them up automatically when you import. |
src/PlayLevel.java
Outdated
| 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)); | ||
| MarioGame game = new MarioGame(); |
There was a problem hiding this comment.
Indentation needs fixing
| try { | ||
| content = new String(Files.readAllBytes(Paths.get(filepath))); | ||
| } catch (IOException e) { | ||
| try (Reader r = new InputStreamReader(PlayLevel.class.getResourceAsStream(filepath))) { |
There was a problem hiding this comment.
Just wondering what this change is for?
There was a problem hiding this comment.
The previous version of the code tried to read level files from file paths. This means that you could only use it if you were running the Java code from a particular working directory in the source tree. If you tried to run it somewhere else, or packaged the code in a jar file then it can't load the level. Instead, what this does is load it as a resource - what you do is tell the system which is compiling your code that the levels folder is a resource folder (the maven config does this) and then when the code is built these are copied into the right place and packaged appropriately so that whenever the code is run (either directly or in a jar file) it can find the resources.
(Obviously the previous approach works find for you already so there's no imperative to accept this - but if you want the maven packaging then you should also do this too)
No description provided.