Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (623)
Games in Android Showcase (176)
games submitted by our members
Games in WIP (676)
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 728 times)
0 Members and 1 Guest are viewing this topic.
Offline Kurten

Junior Devvie

Medals: 3
Exp: 3 years


« Posted 2011-03-29 11: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?

Offline kevglass

« JGO Spiffy Duke »

Medals: 272
Projects: 25
Exp: 18 years

Coder, Trainee Pixel Artist, Game Reviewer

« Reply #1 - Posted 2011-03-29 11: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.


Offline Kurten

Junior Devvie

Medals: 3
Exp: 3 years


« Reply #2 - Posted 2011-03-29 11: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.

BurntPizza (22 views)
2015-10-07 02:11:23

KaiHH (23 views)
2015-10-06 20:22:20

KaiHH (11 views)
2015-10-06 19:41:59

BurntPizza (24 views)
2015-10-06 19:04:48

basil_ (44 views)
2015-09-30 17:04:40

shadowstryker (22 views)
2015-09-29 15:55:06

TheSpaceHedgehog (28 views)
2015-09-29 01:58:48

GamerC4 (54 views)
2015-09-24 21:10:38

GamerC4 (71 views)
2015-09-24 21:09:48

htuy (28 views)
2015-09-24 04:57:24
Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11

Rendering resources
by Roquen
2015-08-17 12:42:29

Rendering resources
by Roquen
2015-08-17 09:36:56

Rendering resources
by Roquen
2015-08-13 07:40:51

Networking Resources
by Roquen
2015-08-13 07:40:43

List of Learning Resources
by gouessej
2015-07-09 11:29:36 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
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!