Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (429)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (466)
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 515 times)
0 Members and 1 Guest are viewing this topic.
Offline Kurten

Junior Member


Medals: 2
Exp: 3 years


-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

JGO Kernel


Medals: 85
Projects: 22


Coder, Trainee Pixel Artist, Game Reviewer


« 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
Exp: 3 years


-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.

 

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

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (80 views)
2014-04-15 18:08:23

BurntPizza (72 views)
2014-04-15 03:46:01

UprightPath (83 views)
2014-04-14 17:39:50

UprightPath (67 views)
2014-04-14 17:35:47

Porlus (83 views)
2014-04-14 15:48:38

tom_mai78101 (107 views)
2014-04-10 04:04:31

BurntPizza (167 views)
2014-04-08 23:06:04

tom_mai78101 (263 views)
2014-04-05 13:34:39

trollwarrior1 (213 views)
2014-04-04 12:06:45

CJLetsGame (222 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org 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‑gaming.org
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!