I have a package levels and classes level_default, level_hard... which each have some methods like Load();, MoveEvent();, TouchEvent();...
I want to store somehow the selected level class in a variable called lets say myLevel
So that then I can use for example myLevel.Load(); to call the load method from that specific stored level.
So far, I've been using switch loops to call the required method from the selected level.
( ... case "1": levels.level_default.load(); break; case "2": levels.level_hard.load(); ...)
But how can It be done like this so I can just select the level, and use its methods without needing to check all the time what level I'm using to call the method from that level?
Leveland define the methods in it. Then make the subclassesDefault,Hard... which extendLevel. Then you can have an object ofLeveland initialize it like -Level lev = new Hard();( orDefault, as you want it). That way you would just have to call the method onlev, and it would automatically call the required methods from the specific class.