Help me draw a map

Has anyone ever played Risk? or the full campaign mode from Shogun: Total War?

What I'd really like to be able to do, it to be able to have a map drawn to a window, and for the program to be able to tell what the boundries of each country are, so if I click on England, it will know the difference between that country, the sea surrounding it, and the many other countries around the world.

Now, I have succeeded this in part, by creating countries with straight borders and using the coordinates of all the points of each country could mathmatically work out where the user had clicked, but what if I wanted to use an actual map of the world with squiggly borders?

I'm not really asking for someone to tell me how to do it, just point me in the right direction because I don't have a clue :(

[820 byte] By [Dan-Forevera] at [2007-9-29 21:47:46]
# 1

There have been threads on this before, but I can't think of suitable search terms. In the case of both the games you describe, the map is political, so you could just draw each country in a different colour and have a map from the colour value to the country. If you draw it as a BufferedImage, it's easy enough to work out the co-ords of the click and get the colour. (For physical maps, this approach can be adapted to have a second image, off-screen, which you use for the lookup).

YATArchivista at 2007-7-16 2:07:40 > top of Java-index,Other Topics,Algorithms...
# 2
hmm, I might try that buffered image approach...Thanks :)
Dan-Forevera at 2007-7-16 2:07:40 > top of Java-index,Other Topics,Algorithms...
# 3
You might try searching for something like "sprite collision testing."
rkconnera at 2007-7-16 2:07:40 > top of Java-index,Other Topics,Algorithms...
# 4
Also even easier you may look at the Polygon class.You could setup Polygons for each country, and thensimply use the .contains() method to see which oneit is in.
rkconnera at 2007-7-16 2:07:40 > top of Java-index,Other Topics,Algorithms...
# 5
http://www.bsc-eoc.org/links/links.jspThat's a JSP page (obviously) that has a map pretty much like what you described. You could have a look at its HTML and see what it does.
DrClapa at 2007-7-16 2:07:40 > top of Java-index,Other Topics,Algorithms...
# 6

Hello Dan-Forever.

If you have every country as a polygone. And you have all the coordinates of every corner in those polygones then you can take the point clicked and draw a line from it and one line through it like a T with the clicked point beeing the point where the two meet. You then check every two coordinates building up a line (polygone by polygone) in your map, and check if your two lines cross it. If the total sum of crossings are odd this means your dot where inside that polygone, if not it means the clicked dot where outside of that polygone. When one polygones been checked you take the next one and so on.

JungleSorea at 2007-7-16 2:07:40 > top of Java-index,Other Topics,Algorithms...
# 7
you're right
shahutma at 2007-7-16 2:07:40 > top of Java-index,Other Topics,Algorithms...
# 8
apasal lak anor tak leh masuk?heran!heran!heran!orang lain boleh lak!!!!
shahutma at 2007-7-16 2:07:40 > top of Java-index,Other Topics,Algorithms...
# 9
dah bole dah....hahahaha
manggis6460a at 2007-7-16 2:07:40 > top of Java-index,Other Topics,Algorithms...
# 10

> Hello Dan-Forever.

> If you have every country as a polygone. And you have

> all the coordinates of every corner in those polygones

> then you can take the point clicked and draw a line

> [snip]

Or.... you could just call [url=http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Polygon.html#contains(int,%20int)]Polygon.contains()[/url] as I said.

rkconnera at 2007-7-16 2:07:40 > top of Java-index,Other Topics,Algorithms...
# 11
hehe.. yes that is the easiest way. I just thought while the question is in algorithms I齦l give an algorithmic approach.
JungleSorea at 2007-7-16 2:07:40 > top of Java-index,Other Topics,Algorithms...
# 12
Dan, I was looking forward to create a risk java version game, It took me a while to figure it out, since risk in Brazil is called "War". If you'd like to share some info: carvalho.vinicius@superig.com.br
vccarvalhoa at 2007-7-16 2:07:40 > top of Java-index,Other Topics,Algorithms...