Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (756)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Advice for a simple "Risk" game  (Read 1923 times)
0 Members and 1 Guest are viewing this topic.
Offline elwiz

Senior Newbie

Bom-Shackalack, Jatack!

« Posted 2004-03-08 08:36:51 »

I'm a rookie in Java, recently finished my first course and are about to start a second one (concentrating in Network, JDBC and Swing).

However, coding is the best way to improve skills, so I was thinking of start coding a simple game, something like "Risk".

However, how would I create that playable Map? Should I use an "ugly" map that I don't show that catches mouseclicks, or is there a more clever solution?

Also, If anyone knows of source somewhere that could be useful to have a look at, please let me know.

Offline princec

« JGO Spiffy Duke »

Medals: 1030
Projects: 3
Exp: 20 years

Eh? Who? What? ... Me?

« Reply #1 - Posted 2004-03-08 10:49:55 »

A nice way to do the map with proper irregular outlines is to use an indexing map behind the actual drawn map.

The indexing map "pixels" point directly into an array of the territories (reality is you could do it with just an array of bytes rather than an image).

So to look up the territory clicked on the map graphic you'd do:
territory = territories[indexMap[WIDTH * mouseEvent.getY() + mouseEvent.getX()]];

where territory 0 might be "the sea", and all the others point to the various other Risk territories.

You can then paint them in PSP or the Gimp or something and save as a raw indexed image.

Cas Smiley

Cas Smiley

Offline elwiz

Senior Newbie

Bom-Shackalack, Jatack!

« Reply #2 - Posted 2004-03-08 10:55:20 »

Now that sounds like a great advice! Time to bail out from work and do some more serious stuff Wink
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline sma

Junior Devvie

« Reply #3 - Posted 2004-03-10 05:48:56 »

Probing the color (read byte value) of some image would be one solution.  The other would be to use polygons to describe the field borders and then iterate a list of polygon objects, testing whether they contain the click position.

That's not as fast as the bitmap solution, but it should be fast enough for your purpose and you could easily add a "map editor" to your game to let the user create custom maps by providing the borders.

I think, the original Risk has ~50 fields, a loop like
Polygon[] fieldBorders;
for (int i = 0; i  <fieldBorders.length; i++) {
  if (fieldBorders[i].contains(mouseX, mouseY))
    return i;

should be fast enough.  If not, you could make use of the fact that countries are grouped by continent and check for the continents first. This should reduce the test to 6 continents and ~10 fields. However, I don't think this would be necessary.

The polygon solution has one additional advantage. You could easily highlight the field under the mouse and/or the field the user clicked.

If you have an image as map because that looks better, you can still draw a polygon over that image, using a translucent color, for example new Color(255, 255, 0, 128).

.: Truth Until Paradox!
Offline elwiz

Senior Newbie

Bom-Shackalack, Jatack!

« Reply #4 - Posted 2004-03-14 15:11:02 »

Sounds interesting, i haven't had the time to try it out yet, any of the solutions. Have to finish my course first.
I've always been thinking about how to do this solutions though, some year ago I started out with the same idea of a game in Python, but never managed to get a good one.
(I was thinking of using SVG graphics but never found a module to render it
Sad  )
Pages: [1]
  ignore  |  Print  

DesertCoockie (56 views)
2018-05-13 18:23:11

nelsongames (88 views)
2018-04-24 18:15:36

nelsongames (78 views)
2018-04-24 18:14:32

ivj94 (763 views)
2018-03-24 14:47:39

ivj94 (95 views)
2018-03-24 14:46:31

ivj94 (647 views)
2018-03-24 14:43:53

Solater (108 views)
2018-03-17 05:04:08

nelsongames (189 views)
2018-03-05 17:56:34

Gornova (430 views)
2018-03-02 22:15:33

buddyBro (1090 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!