4

i want to start coding a game project which is called "Risk" and my first aim is build the map correctly. So logically, each territory should be a JButton but JButton's are rectangular oriented. Moreover, i know that every territory should be a component so i can use mouse event listeners for each of them. well my question is

  • should i try to draw each territory with using coordinates, lines, shapes etc ? or
  • is there any way to draw and combine each territory regularly ?

On the other hand, this is the link for the map of the game.

Map of Risk

quartaela
  • 2,579
  • 16
  • 63
  • 99

2 Answers2

4

try to make fixed territories, so you mustn't have headaches with resizing your actual territory, only change the color of the territory you occupied recently, like in Dune2 was, if you know that game. And I think, definitively you should, and put that jbutton under the numbers on your map (or what will be definitively better, if you replace numbers with territory name and you'd put that button under that). I hope, my answer answered your doubts :)

Citrus
  • 1,162
  • 1
  • 16
  • 38
  • 4
    +1 for Dune2 reference. – Sotirios Delimanolis Feb 27 '13 at 21:56
  • thanks dude, mah favrit game was on my very very first PC :D – Citrus Feb 27 '13 at 21:57
  • heheh yeah i know Dune2D. however, how can i handle with the custom shapes ? – quartaela Feb 27 '13 at 22:02
  • and by the way [link](http://play-dune.com/) here it is ;) – Citrus Feb 27 '13 at 22:02
  • Wow, I can't right click to move! That game has not aged well. – mattboy Feb 27 '13 at 22:06
  • for example i'm talking about a map like this http://redux.dune2k.com/img/screen7.jpg – quartaela Feb 27 '13 at 22:07
  • 1
    draw the stuff with shapes at first, so it should be fixed for the whole game. Then you divide territories between players and change the color of the territory to the color of the player. After that you can occupy new territories, which means you only change the fill color of the teritory. Easy deal I think, I would make it in this way, so it does not mean that this is the best or the most optimal, but for me this is the most straightforward thing that I would do. – Citrus Feb 27 '13 at 22:07
  • i guess i understood your answer but in my opinion it will look a little bit amateur :D however i appreciated for your reply. thanks for it – quartaela Feb 28 '13 at 12:18
  • dude, be a lazy programmer and you dont run into problems, like I does few years back :D – Citrus Feb 28 '13 at 15:48
  • and Dune 2 wasn't lame, was it? :D – Citrus Feb 28 '13 at 18:04
4

I feel like it's going to be a lot of work. The easy way out would be to just put JButtons under the numbers.

If you still feel inclined to make irregularly shaped clickable areas, I suggest creating instances of Polygon (java.awt) for each country. They are made using arrays of x and y points that define the corners. Conveniently enough, there is a Polygon.contains(x, y) method that lets you know if (x, y) is in your polygon. If you use a larger JPanel that covers the entire map and get the mouse location relative to the JPanel, you can notify each country whether or not the mouse is inside it.

Levster
  • 146
  • 1
  • 2
    Every implementation of `Shape`, including `Polygon`, has `contains()`, so even a `GeneralPath` comprised of lines and curves is possible. – trashgod Feb 28 '13 at 02:53