Territory loading refactoring
Overall
Java modules also prevent code from accessing resources in other modules if they are not opened. This results in bugs when the methods to load a territory file are used which are confusing to students. Therefore, these methods were removed and replaced with a helper method on SimpleHamsterGame
, which should always be in the correct module. Also added checks so that it is clear that only files from resources can be loaded via this (no absolute paths to other files)
Changes
-
initialize(String)
now treats the string as the territory content - methods for loading a territory from a file on HamsterGame, Territory etc. are removed
- fixed load methods on Territory
- initialize on HamsterGame now directly calls methods on Territory, duplicates removed
- refactored
startGame
on HamsterGame into two methods without a boolean flag - moved territories/*.ter from core to main, because they are used there. Also renamed to _territories because only one module can have a territories package, and this should be the module the students use
- removed throws IOException where no IOException could ever be thrown
- made constructor of Territory package-private because it should only be used by the HamsterGame class (everythign else might result in bugs)
- bugfix: if territory is reloaded, old hamsters are removed
- made
doRun
on SimpleHamsterGame public because it will be used by the launcher App classes
Breaking Changes
-
initialize(String)
on HamsterGame now has a different meaning (territory content instead of file path) -
startGame
now does not take a boolean any more -
Territory
constructor is package-private