Sign in to follow this  

[java] Game similar to Risk

This topic is 2843 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I want to make a game similar to Risk. However, I still have no idea how to make each land as a click-able button. I know how to draw the map using pgdraw import. I am fairly new to java and am still learning new things everyday. However, before I start the project, I want to have everything planned out. So currently I do not know how to make say a hexagon shape drawn using pgdraw in to an object that is click-able. Perhaps there is another way to make a map as well? Anyone know what I need/know to do this type of game. I realize its not an over night process, so its not one of those new ideas that burns up in a few days, I have been thinking about this game for a long time now and been studying programming for 2 years now. Last year I learned Visual Basic, this year learning Java, but our curriculum doesn't cover everything I wish it would especially the graphics part, which is why I am here. :D

Share this post


Link to post
Share on other sites
You need to take care of click detection. If you are drawing your map to a JPanel you then put a MouseListener attached to that panel and map the mouse coordinates to where on the map the player may have clicked. If you want a real risk style map then one option is to colour each land mass differently and check the mouse coordinates against colour. Or you could create an internal set of coordinates for each area and check bounds. A third option is to use something like InkScape to create an SVG file that you can then load. Since SVG files are vector graphics you could load each land mass as a java.awt.Shape object(such as GeneralPath) then call Shape.contains(x, y) on the mouse. The third option is the hardest to implement since you would have to find or write a loader for SVG files that convert to the Java Shape interface.

Share this post


Link to post
Share on other sites
Thanks CaptainJester for your quick response. I think I am interested the most in the third option(I like challenges :D), however, I have a few concerns. See, I want to be able to change the color of each land mass. Also, I want to change what is being displayed in each land mass(small graphics). Would I be able to do that with SVG graphics? If I could, could you go a little more in depth about the loader for the SVG files. In the second to last sentence you mentioned that all you need to do is load each land mass as java.awt.shape . Then you set the land mass's coordinates. Where does the loader come in to play(perhaps when the game loads, but wouldn't that be already taken care of when you load it in as java.awt.shape)? I am a bit lost in that area.

Share this post


Link to post
Share on other sites
You need to write the code to load and interpret the SVG files. All the shapes are stored as a set of vectors. You can convert that to screen coordinates. For each shape in the SVG file you create a corresponding shape in your code. Shape is an interface that encapsulates a variety of classes, include Rectangle, Ellipse, GeneralPath, etc. Look in the API docs under java.awt.Shape to see what is available. When you have your list of shapes you can draw the outline of the shape or fill them in or do a fill then draw over the same area in a different colour to create a border.

The spec is over at http://www.w3.org/TR/SVG/. I think Slick has an implementation in its code base and its open source. http://slick.cokeandcode.com/

Share this post


Link to post
Share on other sites
here is what i did for my risk like game.

you have two image files for the map. one is the map with only the country borders drawn, all else is white (or any other solitary color). the other image has each country filled in with a unique color.

you never draw the image where each country is a unique color. you use that as basically a look up table. so that when you get the mouse position over the real map, you look up that same mouse position in the unique color image and based on the color under the mouse you know which country the mouse is over.

the other image with all countries white and only the border drawn...well when a user selects a country as their own or conquers it or any reason to color it a different color, you merely do a floodfill algorithm on that country to the new color you want it to be. and continue to use this image as the one that you are drawing to the screen.

Share this post


Link to post
Share on other sites

This topic is 2843 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this