Polygon Class

J

John

I am a college student and somewhat new to VB.Net

I have programmed for years in VB6 and Java. I am converting a Java program
to VB.Net in Visual Studio 2008. It is a Windows Forms Application. A
board game with a grid of 93 hexagons as the board.

In Java, I used a polygon class to create the individual hexes on the board.
The Polygon class in Java has a boolean property, ".contains(x,y)", that
allows me to check if a mouse click occurs in the polygon.

My VB program currently uses a class to create the hexes and I have written
the "contains" property that works only for the hexagon shape I use (all 93
are the same shape).

What I am looking for is a "built in class" in VB.Net where I can define a
polygon area in my graphics drawing area and also have a "contains(x,y)"
property or equivalent to test if the mouse click(x,y) is in the polygon.

(I have looked at the vb.net Polygon class. It doesn't seem to work in a
Windows Forms Application. If I'm wrong and it does work, then I am failing
to set it up and need help.)

Any help would be appreciated. Thanks.
 
A

Armin Zingler

John said:
I am a college student and somewhat new to VB.Net

I have programmed for years in VB6 and Java. I am converting a Java program
to VB.Net in Visual Studio 2008. It is a Windows Forms Application. A
board game with a grid of 93 hexagons as the board.

In Java, I used a polygon class to create the individual hexes on the board.
The Polygon class in Java has a boolean property, ".contains(x,y)", that
allows me to check if a mouse click occurs in the polygon.

My VB program currently uses a class to create the hexes and I have written
the "contains" property that works only for the hexagon shape I use (all 93
are the same shape).

What I am looking for is a "built in class" in VB.Net where I can define a
polygon area in my graphics drawing area and also have a "contains(x,y)"
property or equivalent to test if the mouse click(x,y) is in the polygon.

(I have looked at the vb.net Polygon class. It doesn't seem to work in a
Windows Forms Application. If I'm wrong and it does work, then I am failing
to set it up and need help.)

Any help would be appreciated. Thanks.

Haven't tried it but I think it does the job:
http://msdn.microsoft.com/en-us/library/dz11htdf.aspx
 
H

Herfried K. Wagner [MVP]

John said:
I have programmed for years in VB6 and Java. I am converting a Java
program to VB.Net in Visual Studio 2008. It is a Windows Forms
Application. A board game with a grid of 93 hexagons as the board.

If you want to do it yourself, take a look at Armin's reply.

You may want to use this library which provides this functionality:

Hexkit
<URL:http://www.kynosarges.de/Hexkit.html>
 
J

John

Herfried K. Wagner said:
If you want to do it yourself, take a look at Armin's reply.

You may want to use this library which provides this functionality:

Hexkit
<URL:http://www.kynosarges.de/Hexkit.html>

Thank you for posting this link. I had fun looking at it and plan to spend
more time with it. I choose to use hexagons because I remember seeing games
that used them and thought they looked better than squares.

My game is won by controlling the most hexes on the board. When I used
squares, there was an even number of squares on a square playing board so it
was possible for ties. With the hexes, my playing board appears relatively
square on the screen but contains an odd number of hexes so no ties.

Using Armin's reply, I found Regions to be exactly what I was looking for.
I have already changed my code to use them. It only required minor changes
but it greatly simplifed the code to detect mouse clicks. That was my goal.

Thanks again

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top