Table of Contents

Puzzle game conceptions

The goal: the interface for the user to allow him to join many pieces into one picture.

The piece – is a shape with non-rectangle complex boundary.

The shape – is the closed polygon. It can be filled by the TGraphic's procedure Polygon.

The polygon – is a line with straight segments. First point is closed with last point.

The edge – is the straight segment of the polygon.

In this program internal edges made by jigsaw are used. There are complex simmetrical contours. And external edges – not complex but simple line between two points.

Edge definition

We have special drawing procedure. It draw the line between two points using edge-pattern (see picture). puzzle_game_the_edge_in_autocad.jpg

seg{jigsaw}:array[1..Nseg] of TPoint = [X:0; Y:0], [ X:3; Y:-2], [ X:12; Y:-3], [ X:19; Y:-3], [ X:31; Y:0), (X:27; Y:2], [ X:23; Y:6], [ X:21; Y:10], [ X:21; Y:12], [ X:23; Y:16], [ X:27; Y:20], [ X:33; Y:22], [ X:41; Y:22], [ X:46; Y:20], [ X:50; Y:16], [ X:52; Y:12], [ X:52; Y:10], [ X:50; Y:6], [ X:45; Y:2], [ X:43; Y:0], [ X:55; Y:-3], [ X:62; Y:-3], [ X:71; Y:-2], [ X:74; Y:0];
where Nseg = 18+6.

The procedure use vectoral geometric calculations. Therefore the edge as a whole could be drawn by any angle.

And any edge could be processes. See simpler edge here — simple_edge.

As an additional ability – when the edge is drawn – it insert new points into the global array, and when all 4 edges of the rectangle will be drawn by edge-draw procedure — we'll receive the complex jigsaw polygon. This ability is used in this game.

Initial dividing of the picture into pieces

Ok. We have the picture 520 x 520 pixels and we want to divide it into 6 * 6 parts. Of course for rectangle pieces it's a simple task. But how to do the same with jigsaw edges?

Ok. The definition: the neighbours are two polygons between one jigsaw edge. One of them should have sign = '+' and second – sign '-'. Sign Plus ('+') – means this polygon is greater because his jigsaw edge goes into the '-' polygon. Each polygon will have 4 signs – one per each its edge.

Now we will set '+' signs into every even polygon. And minus – all others. Then we will check where all edges have signs '-'/'+' in our compilation. If everything correct – we'll received the puzzle game before of dividing and the piece random displacement.

How to draw the piece of picture? Very simple – a piece is the set of pixels are inside the polygon.

So we have the function returns true if the point [X, Y] is inside the polygon.

May be this article to be continued…