I've been working on a game in my spare time. I'm pretty much done defining the primitives and until today everything was pretty well segmented and encapsulated but now it's come time to implement path finding (and other ways for the objects to interact with each other). Here path finding requires at minimum a knowledge of the map, a knowledge of where units are in the map and which types of terrain are passable by the unit whose path is being found.
There are three ways I've thought to implement this
- Implement it in some high level class that knows about all of these things already (i.e. a game state object)
- Implement it in some specific method inside one of the "involved" classes (like unit or map) and pass in all relevant state
- Implement it in some function which is completely separate (because no state needs to be retained) and again pass in all of the relevant data
I want to get your opinion on which of these makes sense (or if there are others I haven't thought of). I like The first one the most because it only couples the objects at a high level and doesn't require exposing objects to state they don't (otherwise) need to know about. I don't like number 2 because it doesn't do those things and number 3 I'm neutral on at this point; it doesn't seem necessarily better or worse than number 1.
If number 2 is in fact the winner I have concerns about how much complexity will be propagated up to this high level game class.