Problem with polymorphism and different classes

Hello guys, im currently working on a game that needs to modify values for different classes to use. Basically like one superclass handing out variables to other classes that uses them for different things. Examples of these are coordinates for graphics and mousepointer coordinates. I have created 3 classes called MainEngine, GraphicalEngine and GameLogic. MainEngine starts up the program, creating objects for GraphicalEngine and GameLogic. However, GraphicalEngine also needs to acces the values of GameLogic, i solved this by declaring 1 object for GameLogic in MainEngine and one in GraphicalEngine. It does not work as i suspected though. The values modified by MainEngine and the ones accessed by GraphicalEngine are two different enteties it seems. I suspect it is because MainEngine declares one GameLogic Object and GraphicalEngine another. I need some way of forcing them to use the same versions of the variables without declaring polymorphic versions of them. Do you guys have any ideas?

//Kurten

How about passing the instance of GameLogic that the MainEngine create to the GraphicsEngine in the constructor when the MainEngine creates it.

This way they will share the single instance of the GameLogic and you’re defining a contract of GraphicsEngine which says to exist it must have a GameLogic to display - which seems to make sense based on your model.

Kev

Thank you so much, that solved the problem! :smiley: It fixed the graphics coordinates and it enabled me to use mousemotion listening correctly again! Im very, very, very grateful for the quick reply and the awesome advice!