Strategy game programming in Java, how the map and unit classes should work/relate each other.

Posted by Gabriel A. Zorrilla on Stack Overflow See other posts from Stack Overflow or by Gabriel A. Zorrilla
Published on 2010-04-19T01:45:53Z Indexed on 2010/04/19 1:53 UTC
Read the original article Hit count: 292

Filed under:
|

As a way of learning Java i'm doing a little strategy game. You have a game map and military units.

The gamemap and the units are Jpanels which are binded together in another class called GameWindow, which has a JLayeredPane where the gamepap is below the units. Every time i click a unit (and therefore, the JPane) I can get the unit's information. The problem comes when i want to move a unit... each unit is self drawn inside it's Jpanel, how do i represent the change in position over the gamemap?

I'm thinking about reloading the whole game window based on a position change of a unit (because the JPAnels that represent the units are created in the GameWindow, not drawn in the gamemap).

Another more elegant option, should be repainting the whole map, with the units. But that way the units would lose it's status of objects (no more JPAnels, just being drawn in the gamemap paint() method), and how would i tell if one unit is clicked?

I dont know how people with more experience in games handle the class structure in strategy games. I believe i have the right structure (map, game units, each one an object) but I'm having difficulties making it work together.

Here is a snapshot of the map with a couple of units: alt text

© Stack Overflow or respective owner

Related posts about java

Related posts about game-development