Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (404)
games submitted by our members
Games in WIP (289)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Problem with polymorphism and different classes  (Read 404 times)
0 Members and 1 Guest are viewing this topic.
Offline Kurten

Junior Member


Medals: 2


-w-


« Posted 2011-03-29 13:46:41 »

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
Offline kevglass
« League of Dukes »

JGO Kernel


Medals: 54
Projects: 20


Mentally unstable, best avoided.


« Reply #1 - Posted 2011-03-29 13:50:51 »

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

Offline Kurten

Junior Member


Medals: 2


-w-


« Reply #2 - Posted 2011-03-29 13:56:53 »

Thank you so much, that solved the problem! Cheesy 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!
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (32 views)
2013-05-17 21:29:12

alaslipknot (40 views)
2013-05-16 21:24:48

gouessej (70 views)
2013-05-16 00:53:38

gouessej (69 views)
2013-05-16 00:17:58

theagentd (78 views)
2013-05-15 15:01:13

theagentd (73 views)
2013-05-15 15:00:54

StreetDoggy (113 views)
2013-05-14 15:56:26

kutucuk (137 views)
2013-05-12 17:10:36

kutucuk (137 views)
2013-05-12 15:36:09

UnluckyDevil (145 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.065 seconds with 21 queries.