Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
games submitted by our members
Games in WIP (500)
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 976 times)
0 Members and 1 Guest are viewing this topic.
Offline elwiz

Senior Newbie




Bom-Shackalack, Jatack!


« Posted 2004-03-08 09: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.

Regards
Offline princec

JGO Kernel


Medals: 282
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2004-03-08 11: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:
1  
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 11: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 Member





« Reply #3 - Posted 2004-03-10 06: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
1  
2  
3  
4  
5  
6  
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 16: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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (50 views)
2014-04-15 18:08:23

BurntPizza (46 views)
2014-04-15 03:46:01

UprightPath (62 views)
2014-04-14 17:39:50

UprightPath (44 views)
2014-04-14 17:35:47

Porlus (61 views)
2014-04-14 15:48:38

tom_mai78101 (85 views)
2014-04-10 04:04:31

BurntPizza (143 views)
2014-04-08 23:06:04

tom_mai78101 (242 views)
2014-04-05 13:34:39

trollwarrior1 (201 views)
2014-04-04 12:06:45

CJLetsGame (208 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org 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‑gaming.org
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!