my question is in relation to the decoupling of classes when handling array of display objects.
lets assume were making a PacMan game, in my main.as file I would call constructLevel.as to build the different portions(graphics) of the level.
Now lets say the “food” that pacman eats is in an array, foodArray, now would it be better to keep foodArray inside main.as so main can easily access it, or would it be better to have foodArray in constructLevel.
in the first scenerio, constructLevel requires the appropriate variables to exist in main.as, in this case foodArray. In the other case however, main would always need to reference constructLevel.foodArray to grab data, still the same coupling as before but the data has shifted from main to contructLevel
the third solution would be to create a blackBoard which encapsulates all the data.
I’m not sure what the best practice in this case is.
I would go this way… Create the classes: Level, LevelConstructor. So that the LevelConstructor would build the Level objects and return them.
So, from the main class, we create a new level like this:
In this case, we have foodArray and all other details of the level in a newLevel object.
By doing this, we separate the level data and the level building algorithms. The levelConstructor object may have any number of properties and methods for building the levels, anything that your game requires.