Hello everyone,
This is a rather simple problem and so I am hoping for some simple answers!
The game I'm currently developing has a cell grid that you can place units in with some rules governing whether or not you can place units into the cells. I have an array of Units, whereby the indices represent the cells. If a cell is occupied, the value corresponding to the cell index in the array should have the unit assigned or otherwise be null. An example of a placement rule is that units can't be placed into a cell that is already occupied.
Keeping in mind that the array should be kept up to date with regards to which cells are occupied, WHERE should I manage the positioning of the units into the cells when moved, the assignment of the units to the cell array and the placement rules?
My original thought was to have it all managed in a grid service, where I would just say, GridService.PlaceUnit(Unit, Cell). The grid service would check if it could place the unit in the cell, and if it could, it would position it there and then set the cell as occupied by the unit. However, the problem I see with this is that the grid service would be manipulating the position data of my unit externally which is apparently a no-no.
I have problems like this all the time, I don't know how to divide my responsibilities between classes.
Could someone please give me some guidance on how to solve these issues? Perhaps some principles? I'm desperate!
Cheers.