A class sharing members with others

Jun 14, 2013 at 9:39pm
Hi!

I'm creating the classes for a hexgrid based game.

The problem is that I don't know how to make each "block" contain it's corners and edges since those are shared with others. The only plan I have at the moment is to create one container for each type(edge, corner, block) and then let each "block" contain the pointers to it's corners and edges.

There should be an easier way, could anyone point me in it's general direction?
Jun 15, 2013 at 12:47am
Are these blocks static? Is that why you want to distinguish the ones on an edge and corner from ones that aren't?

You need to be more specific on what a block needs to do.

If you want help please provide a story about your game. How is the game played?
Jun 15, 2013 at 12:57am
I'm making a simple 4X game (civilization type of deal).

and the problem with my hexsquares that are the gamemap is that I store height in each corner, some information on the sides and the most in the tile itself.
But since each corner to each hex is shared with adjacent tiles I can't just create a container like : Corner[6] corners; since some of the corners are identical to others.

So how do I solve this?
Jun 15, 2013 at 3:12am
> The problem is that I don't know how to make each "block" contain it's corners and edges
> since those are shared with others.
> The only plan I have at the moment is to create one container for each type(edge, corner, block)
> and then let each "block" contain the pointers to it's corners and edges.

Blocks as flyweights seems to be a reasonable plan.
http://www.oodesign.com/flyweight-pattern.html

You might want to consider using reference wrappers instead of pointers; the syntax would become cleaner.
http://en.cppreference.com/w/cpp/utility/functional/reference_wrapper
Jun 15, 2013 at 10:43am
Looks good, busy today, will look at it tomorrow. Will set it to solved in the meantime thanks!
Topic archived. No new replies allowed.