So, let's get it straight, will the game play on the console? That's right, now you will need to configure your data structures, the most obvious is the nodes.
Knots
Each hexagon is a node with six edges.
typedef struct Node { void *object; Node *node_array; int node_count; } Node;
How to initialize and connect node structure
Imagine the following hexagon:
/\ | | \/
It has the following edges: NORTHEAST, EAST, SOUTHEAST, SOUTHWEST, WEST, and NORTHWEST. Then see how they will be arranged (10, 11 and 12 were presented in Hex so that they can fit in one space):
// 0 1 2 3 // 4 5 6 7 8 // 9 ABC
So 0 will refer to 5 through the SOUTHEAST link and 4 through the SOUTHWEST link. Also notice how the lines alternate between even and even numbers of elements. Call {0, 1, 2, 3} row [0] and {4, 5, 6, 7, 8} row [1] . And let me call it a 5x3 hexagram. The easiest way to create this array is malloc(sizeof(Node) * width * height) .
Connection nodes
First of all, let me point out that every even line (0, 2, 4, ...) will have width-1 elements. But there is more, each element (x, y) in this line will refer to the next element in your array:
- (x + 1, y-1) - NORTHEAST
- (x + 1, y) - EAST
- (x + 1, y + 1) - SOUTHEAST
- (x, y + 1) - SOUTHWEST
- (x-1, y) - WEST
- (x, y-1) - NORTHWEST
Elements of other lines, such as { 4, 5, 6, 7, 8 }, will have width elements, where the element (x, y) refers to the following:
- (x, y-1) - NORTHEAST
- (x + 1, y) - EAST
- (x, y + 1) - SOUTHEAST
- (x-1, y + 1) - SOUTHWEST
- (x-1, y) - WEST
- (x-1, y-1) - NORTHWEST
When trying to associate (x1, y1) with (x2, y2), make sure that 0 <= x < width and 0 <= y < height .
Remember ...
Your array contains one unused element at the end of every two lines (line [0], line [2], etc.). You can also provide them to everyone with a label or index so you can reference them. You can mark them as pairs (x, y) or numerically by their index, it all depends on you. The pair (x, y) is very simple for you, as it will map directly to the array in which they are stored.