Skip to main content
gamedev.net
🔒 Locked

[java] Help on Java implementation of a Hex map

Started by EEder 4 replies 3.6k views
Original Post
EEder
EEder
(This is a duplicate post of the same message on the Isometric/Hex/Land main forum... I figured i''d throw it here too so I can get the response from the local java trolls ) Hey there - I''m new to Gamedev.net, but based on the insane amount of substance here and the very responsive users in the forums (and my upcoming programming experiences), I plan to be much more frequent. The game that me (and my co-partners) are working on is basically a war game/country simulation. For a map, we''ve decided (tenatively... we''re still kinda up in the air) about going with a hex map. We''ve thought of how this ties in to the game, and it seems to work. We''ve thought about coding (our language of practice will be JAVA for the purposes of this game). Implementing a hex map in Java has been problematic for us as of now. We''re still thinking rather high level, conceptual right now, but any suggestions are welcome. How, exactly, does one implement a hex map in Java? OR in any other language, for that matter (although Java would be most pertinent and relative)? We thought of crazy things like an 6-linked list, the mother of all two/dimensional arrays with only certain element used... Anyway, any help here woudl be really appreciated. I''m not asking for source code, of course, but a kick in the right direction (or maybe even an example) would be great. Thanks -Brad
stilltjack
stilltjack
Howdy,
That can be more complex then you think. I''d recommend looking over the book, isometric game programming. At least it will get you started.
dave
CaptainJester
CaptainJester
I answered your post in the Isometric forum. I would not suggest double posting, it is frowned upon.

---
Make it work.
Make it fast.

"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
nonnus29
nonnus29
Check out the articles section on this site;

http://www.gamedev.net/reference/articles/article747.asp

This is an excellent article by the author of Iso game programming. Its not written for a particular graphics library and the code is in c, but its very informative. As long as you can copy bitmaps you can do these techniques. Try GameFrame4JavA on java nerds site.
Petr Stedry
Petr Stedry
Hi,

I know that any solution that creates/uses too many (but what is too much actually with 2+GHz CPUs) objects will run the fastest it could if done otherwise.

But consider having a structure - HexPlate. The plate would consist of Hex object (hexes ).

A Hex would need to have:
6 "links" to other Hex objects
1 "link" to the object it actually contains

The HexPlate.
You should start with an interface, that can EXTEND Collection. Also think about using an Iterator.
Having an iterator may not seem as a good idea in the beginning, but it helps in the long run.
The class can then be customized to return different iterator implementations that can for example modify direction and/or other characteristics.

Try it and you see.

But don't forget that OOP is about describing the solution with terms that are identical/analoguous to the terms of the problem. So try not to dive deep into arrays or ints, but try to use abstraction, generalization.

and don't forget to ...

have a nice day


[edited by - Petr Stedry on April 12, 2002 5:56:41 AM]
Petr Stedry
davidsporn
davidsporn
Hi,

To be more efficient, I would store your map in a grid of size (I,J) (J rows, I columns)


---- I --->
| 0-0-...-0-0
| 0-0-...-0-0
J ...
| 0-0-...-0-0
V 0-0-...-0-0



Then an element (i,j) of such grid would be connected to following elements :

(i-1,j-1)
(i,j-1)
(i-1,j)
(i+1,j)
(i,j+1)
(i+1,j+1)

0-0
0-X-0
0-0



In some case it''s more convenient to use coordinate (i,j), in others it''s more convenient to use item index (j*I + i) so you should choose the implementation (1D or 2D arrays) that minimize the need for convertion, or the one that you prefer

----
David Sporn AKA Sporniket

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.