Hello, I'm trying to put together a simple javascript/dhtml implementation of Pacman in an oop style (as far as js will let me) but I've come up against the same problem I always do (kind of the point of the exercise). I end up with aggregated objects that need to query objects that they have no access to. I am obviously designing my code incorrectly - can anyone offer any advice. I will use the Pacman example (obviously not faithful to the origninal )
I basically have Agents (ghosts and the pacman) which share an interface but differ in their methods of altering their x and y properties.
A Renderer object is responsible for display and is handed a Map on instantiation which contains a TileList of Tiles. Tiles being either Wall or Passage implementations of the Tile interface.
The Main loop updates and gets the Agents' positions and hands them to the Renderer which then flips its rendering to reflect the new positions.
The problem comes when your Agents need to know whether they are allowed to move to a particular location - they need to have their own movement logic but are bound by the logic of the Map also. This more or less describes the general case of my recurring problem
Would I get the Agents to request a position and check it with the Map before allowing or denying? Seems a little long winded and un-encapsulated?
Thanks for any comments
tom
I basically have Agents (ghosts and the pacman) which share an interface but differ in their methods of altering their x and y properties.
A Renderer object is responsible for display and is handed a Map on instantiation which contains a TileList of Tiles. Tiles being either Wall or Passage implementations of the Tile interface.
The Main loop updates and gets the Agents' positions and hands them to the Renderer which then flips its rendering to reflect the new positions.
The problem comes when your Agents need to know whether they are allowed to move to a particular location - they need to have their own movement logic but are bound by the logic of the Map also. This more or less describes the general case of my recurring problem
Would I get the Agents to request a position and check it with the Map before allowing or denying? Seems a little long winded and un-encapsulated?
Thanks for any comments
tom