I'm currently working on a project to make a simple 2d platformer in Java for uni, and the way we've been suggested to handle levels is to create an abstract level class, and then other classes implementing it for each individual level, so:
abstract class GameLevel {}
class Level1 extends GameLevel {}
class Level2 extends GameLevel {}
etc...
And then in my main class, I have a variable to keep track of the current level number, and code to move on to the next level, which essentially is:
public void goNextLevel() {
world.stop();
if (level == FINAL_LEVEL) {
// win code
} else {
level++;
world = new Level/*next level number*/();
}
}
And I was wondering if there was a way to take the variable containing the level number and add it on to the end of the class call, to save having to have a stack of if else statements.
Thanks for any help in advance
edit: The reason I'm not keen on putting all of it in one class and then using a variable in that to change the level is that each level has to have a relatively large number of entities, which each take a few lines to set up, and adding all of the levels in one file would lead to hundreds of lines of code which would be difficult to maintain