.NETGURU
Creating a Hex Map
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.vb.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Niels Jensen
Hi All,

I'm desperately looking for help regarding the following:

I need to make a hexmap in it's own scrollable window on a form, when I
say hex map I mean a graphical hexagon surrounded by other hexagons the
same size. The program I'm writing imports region information i.e 10,13
would be a hexagon, 10 hex columns to the right and 13 hex rows down
from hex 1,1.

I have some source code for a Delphi add-in but having had zero
experience with Delphi, it's not a good place to start.

Can anyone point me in the right direction?

Please...

Niels
Reply to this message...
 
    
One Handed Man \( OHM - Terry Burns \)
This is simple a vector drawing is it not, you could create an array for
each hexegon containing Six Points, these co-ordinates are then used to draw
a path on the graphics area of your control/form.

Dim myHexagon(8) As Point
Dim clientArea As Graphics

myHexagon(0) = New Point(50, 10)
myHexagon(1) = New Point(60, 10)
myHexagon(2) = New Point(70, 20)
myHexagon(3) = New Point(70, 30)
myHexagon(4) = New Point(60, 40)
myHexagon(5) = New Point(50, 40)
myHexagon(6) = New Point(40, 30)
myHexagon(7) = New Point(40, 20)
myHexagon(8) = New Point(50, 10)

clientArea = Me.CreateGraphics
clientArea.DrawLines(New Pen(Color.Red), myHexagon)

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Niels Jensen" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Niels Jensen
One Handed Man ( OHM - Terry Burns ) wrote:

[Original message clipped]

research - btw that's an octagon - a hexagon has six sides ;)

Niels
Reply to this message...
 
    
One Handed Man \( OHM - Terry Burns \)
LOL, sorry, a moment of madness !, I allways wondered why I wasn't any good
at DIY

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Niels Jensen" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Gerald Hernandez
Intriguing. Sounds like a fun little project.
I would start out by asking what do you want to do with the map once you
have it. It sounds like a game map, but the question is more involved than
that.
Do you want to be able to graphically select hex cells?
Do you want to draw something else contained with the cells?
Do you want all sides to be equal like a regular circular inscribed polygon?
Or could the height/width aspect ratio be different?
Is the master grid a fixed size, or you want it to be dynamic?
Would the grid be rotatable?
What dotNet drawing methods are you familiar with?

The "easiest" solution would be based upon what you want to do with it.
If it is just draw a hex picture map, you could just create a cell block and
tile it. But not of much use.
If you want "intelligence", then you should probably go the vector route and
create hex cell Objects that render themselves to an intelligent "hex grid"
control.

Like most things, there are numerous ways to do this, but "begin with the
end in mind" to get the best results.

Gerald

"Niels Jensen" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Niels Jensen
Gerald Hernandez wrote:
[Original message clipped]

based turn report into the program which will then draw out the map to
give me a graphical representation.

> Do you want to be able to graphically select hex cells?
Yup - this will definitely be handy as that way you could click on a hex
and see which units are in it

> Do you want to draw something else contained with the cells?
Yes again - each hex will have different terrain features such as
mountains or desert. Each hex can also contain thins like towns or
player built buildings

[Original message clipped]


[Original message clipped]

but not necessarily needed
> What dotNet drawing methods are you familiar with?
Here's the problem :) - next to nothing - yet. But with the help of the
net and other reference material I tend to pick these things up v.quickly

[Original message clipped]

Thanks Gerald - you've definitely given me things to think about. now
to start looking for the material i need :)

Niels
Reply to this message...
 
    
Gerald Hernandez
I'm giving this some thought.
To get everything you want might be quite complicated. Especially when just
learning.
However, that is half the fun, and what better way to learn, right?
I may be over complicating this, but I think you might want to create a user
control that will render everything. To accomodate the zooming and location
functions, your best bet would be to treat these cells as vector objects.
Meaning real Hexagons, instead of simple brush tiles.

One thing that will require special consideration is how you want to define
rows.
Since of course a Hex Grid zig-zags instead of being a classic grid.
Take a look at the attached 2 pictures.
In HexMap1, you have a defined set of rows. However, this is going to be a
mild pain to deal with the offsets. This is probably how the game works.
In HexMap 2, you have a mathematically easier approach, however your row
definition gets a little weird. If you are on an Odd Column, then your Rows
would be Odd. If on Even Column, then your Rows would be Even.

How does your game deal with this?

Gerald

"Niels Jensen" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Niels Jensen
Gerald Hernandez wrote:

[Original message clipped]

This does sound more complicated - but I'm a firm believer that if you
dive in at the deep end you'll always end up with what you want - minus
a few handfuls of hair :)

So, I take it using vector objects is quite a bit more complicated than
Terry Burns solution?...

[Original message clipped]

The game has the following description in it's rules - The game's called
"Atlantis":

----
Since Atlantis is made up of hexagonal regions, the coordinate system is
not always exactly intuitive. Here is the layout of Atlantis regions:

____ ____
/ \ / \
/(0,0) \____/(2,0) \____/
\ / \ / \ N
\____/(1,1) \____/(3,1) \_ |
/ \ / \ / |
/(0,2) \____/(2,2) \____/ |
\ / \ / \ W-O-E
\____/(1,3) \____/(3,3) \_ |
/ \ / \ / S
/(0,4) \____/(2,4) \____/
\ / \ / \
\____/ \____/
/ \ / \

Note that the are "holes" in the coordinate system; there is no region
(1,2), for instance. This is due to the hexagonal system of regions.
---
So it would seem that any hexes with an even column will only have even
rows and likewise any odd column hexes only have odd numbered rows. It
helps knowing that a map will never use negative numbers so a simple
mathematical equation should be able to work out how to place the hexes.

I can also provide an example on how the report processes it's region
information. As it stands, my basic program at the moment is able to
process the reports and categorize them into relevant groups. I'm
thinking of using ADO to store the turn information, this will allow me
to use SQL to filter out specific region information for each hex.

Niels

[Original message clipped]

Reply to this message...
 
    
Gerald Hernandez
Ah, it looks like it resembles the second example I sent.
This is slightly surprising. Good news is that the math is a little easier,
just slightly less intuitive to the user.

Actually, the vector method will essentially be the same as OHM's
suggestion.
But instead of drawing just 1, you would just write formulas to build the
whole grid.
There are many ways to derive the numbers for the points, but in the end you
will just pass an array of points to draw the Hex cell.

I'm giving the overall grid some thought and how that will work with
scaling.
Drawing 1 is easy, but making it interactive is more fun.

My suggestion is to deal with a "grid" where you know the center of the Hex
cells.
Then derive the polygon points from the center point.
This way you would also know where to draw other cool things in the middle
of the cell. ;-)

Gotta run at the moment, but I'll throw up a couple of formulas when I get a
chance.

Gerald

"Niels Jensen" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Gerald Hernandez
Ok, I took the time to put together an intro to Hexagons and Drawing
project, attached.
Take a look at it. Hopefully, it is fairly self explanatory. You should
notice the basic hexagon code is pretty simple. Essentially variations on
OHM's (Terry Burns) suggestion. I included 2 slightly different ways to get
the points for the hexagon, but many more methods could be derived as well.

Overall, the project is very simple.
Draws a single hexagon in the center of a "graphics" area. I arbitrarily
picked a Panel Control.
Also shows a couple ways to deal with size, and automatically refreshing the
drawing.
Disclaimer: This doesn't represent "best practice" coding, just a simple
sample. In the end, I recommend you wrap up the whole HexGrid into a class
and eventually a user control. But you have a long way to go before then.

Of course, this does not address the "grid" issue along with a ton of over
things. But take a look at what there is so far and digest that. It might
get you jump started on the rest of the project. Or at the very least, it
might help you develop a list of questions to get you to the next step.

Gerald

"Gerald Hernandez" <Cablewizard@Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Niels Jensen (VIP)
Hi Gerald,

Thanks for all your help so far, you're an absolute star.

I can't seem to find the attachement anywhere - I've checked using buth my
mail client and Microsoft's newsgroups site and cant find a link to get hold
of it. It was the same with the previous attachements you posted.

Any way I can get hold of them?

Niels

"Gerald Hernandez" wrote:

[Original message clipped]

Reply to this message...
 
    
Gerald Hernandez
It is probably your news reader stripping the attachement for safety
reasons.
Kinda cool (NOT) that Microsoft's "fix" for security holes in their software
is to prevent you from getting to things you might want, instead of actually
fixing the flaw.
If you are using Outlook Express, try going to:
Tools->Options->Security tab,
Virus Protection,
and uncheck the "Do not allow attachments to be saved or opened that could
potentially be a virus."

Then try checking the message again.
Otherwise, email me your email address at Cablewizard@Click here to reveal e-mail address
by removing the @Spam_Remove part, and I will try mailing to you directly.

Gerald

"Niels Jensen" <Niels Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 
System.Drawing.Color




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification