Hello,
I am working on a project and I’m not totally sure how to best structure and organize the hierarchy of its classes. It’s a simple turn-based game where your units can attack enemy units.
The structure is something like this.
There’s a main class which acts as a manager: it handles turns, score and also has a list of your squadrons and the enemy’s squadrons. Squadrons are classes that hold a group of units together.
Now, the thing is: say a click on one of my units and order it to attack an enemy unit, what exactly should happen in this case? My thought is to retrieve the manager and tell him who I want to attack, but I’m not sure this is the right approach.
- Should a unit have a reference to the manager?
- And if it should, is it correct to retrieve by searching for it (Camera.main.getComponent() ) or should it be passed from the manager to the squadron and then from the squadron to the unit?
- Should it tell its squadron it wants to attack instead?
I really want to try to keep the code as bulletproof as possible from the start to try to learn something more about how to organize my projects. Thank you for your time and help!