Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

about preparing the map of Risk game with swing in java [closed]

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

like image 754
quartaela Avatar asked Feb 17 '23 09:02

quartaela


2 Answers

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 :)

like image 80
Citrus Avatar answered Apr 28 '23 09:04

Citrus


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.

like image 42
Levster Avatar answered Apr 28 '23 09:04

Levster