-
Notifications
You must be signed in to change notification settings - Fork 0
Home
200601
Hexagon Game Board (HGB) is a package of Java classes that create data necessary to support several thousand hexagons. Each cell is bound to adjacent cells. The creation and binding is done very rapidly.
The cells of HGB are tiled in a pattern of 6 hexagons about a central hexagon. I call this pattern a rose. Naturally the 6 surrounding hexagons are petals. One rose is set at the center and 6 additional roses are then tiled about the first. Continuing outward, another ring of 12 roses is tiled about the previous ring. Thus the hive grows by rings, not by individual roses. A hive of 4 rings contains 366 hexagons. Each rose is numbered in units of 10: rose 0 with petals 1-6 then rose 10 (10-16), then rose 20 (20-26) etc. This results in 3 member of the cellAry (see below) left null for each rose. I would love to credit the University web site that was the origin of my tiling scheme; but it is long forgotten.
HGBShared is a common class. HGBShared is not a Singleton; but there should be one and only one instance of HGBShared. This restriction is not enforced. HGBShared is a distribution point for common variables and useful classes. The instance of HGBShared is create high and passes downward as a constructor argument.
HGBVector2D is a set of vector calculating methods which I ported from Classic C to C++ then onto C# and now to Java. Written by (and credited to) denniscr. A Vector does not have a location on a 2D plane. It is not a coordinate. A number of these methods are used extensively in HGB.
HGBLocator rapidly locate any cell selected. Vectors are extensively used in the locator. When the hive is created, vectors from the hive origin to each cell origin are calculated . The Integer value of these are sorted in a SpareArrays via their x or y Vector components. And then used to establish near cells. A Vector magnitude narrows the selection down to the single chosen cell. The locator has problems locating cells when the cell size is set very small.
HGBCellPack stores cell properties. CellAry is a HGB managed array of HGBCellPack. Only the hive origin, cell 0 (the center of rose 0) has a screen origin. Calling cellPack.getOrigin() returns an origin computed as a offset from cell 0. Thus only one origin (and cell size) need be managed.
HGBStatic stores some useful defined static variables. In HGBStatics you will find definitions for Portrait mode. These values are never used. HGB only supports Landscape. The values have been left in, should someone choose to add Portrait.
At one time I thought HGB should be a library. To that end, much of HGB is accessed though HGBUtils or HGBShared. However, I have changed my mind about a library controlled implementation of HGB. I use HGB as a package. I think it best that it be provided as a package. Then you can access methods as you choose and add your own as needed.
Point of Optimization
Cell bindings never change. Even so, for flexibility, HGB computes the cell binding each time a new hive is created. Should your app use a consistent number of rings, it would be easy to simply define the cell bindings in class HGBStatics and save some computation cycles.
The Example
One does not need to draw the hexagons to use them. However it is nice to be able see them. The provided example shows you how to draw the hexagons as a single Graphical Path. Because the hive is a path it translates very smoothly. In the example one may change the number of rings to increase or decrease the number of hexagons in the hive. You can also increase or decrease the size of each cell. This gives the effect of zooming in or out. (Line quality remains constant.) To demonstrate the locator, a cell that is touched will be filled with a red color. And to demonstrate cell navigation, the menu pick "Fill" will cause the last two selected cells to be joined. In addition you can ask for a report of how many cells, roses and rings are in the hive.
With my emulator, when the hive neared 47000 cells, Android sometimes failed to display the path. This is a Android problem. The example is limited to 60 rings. Find the limit in class Shared should you choose to see how many cell your device or emulator will create before it bogs down or crashes.
HGB and the example provided (plus one other very simple example) may be found at https://github.com/gammillweg. HGB contains all the fundamentals necessary for immediate use. If you find it useful, perhaps you will join me on GitHub and help improve the code.