views:

561

answers:

2

Dear all,

I'm trying to implement a small-scale strategy, taking turns game implemented in Java, GUI is made with JFace and SWT.

My challenge is to write a GUI implementation of the world map, where countries will act as clickable buttons. However, countries have no fixed boundaries, no rectangular shape, and simply no way I can think of to be described in a grid layout.

This is my first time trying to implement a project of this type, please advise

Best regards, Paul

+3  A: 

If it's a tile based map (like at Civilization) or it's displayed as pixmap, you could save the ownership of each tile/pixel in a two-dimensional array. Just display the map a a simple, clickable pixmap in a canvas an add a MouseListener. If you get a click event at the coordinates (X,Y), you can just get your country like:

Country clickedCountry = myCountriesOnMap[X][Y];

... in your Listener implementing the MouseListener interface. myCountriesOnMap would be of type Country[][].

Of course, you will need an algorithm that will resolve the ownership for each tile/pixel at startup or if a territory gets conquered (I don't know, if this may happen). May be you will have to define your countries as polygons (like you would do it for a HTML map). I cannot help you on this, as I haven't done anything similar jet, but I'm sure you will find something on Google.

Greetings

Sacher

craesh
A: 

Try to use the OpenStreetMap data. It contains exact country borders and good image export possibilities.

The Key:border tag will show you all borders. You could extract it and calculate your clickable areas.

furtelwart