DHTML Jigsaw Puzzle: NN4; After the Solve | WebReference

DHTML Jigsaw Puzzle: NN4; After the Solve


The DHTML Lab Jigsaw Puzzle, Part III: NN4
cleaning up after the solve

Final Positioning

When a piece is finished flashing after correct manual positioning, or during an automatic solve, the origPos() function is called.

    function origPos() { tempEl.left = puzzLeft; tempEl.top = puzzTop; tempEl.draggable = false; solvedCount++; if (solvedCount > puzzPieces) { allDone(true); } }

The puzzle piece is positioned in the correct position, and its draggable property becomes false to disable further dragging of the piece. The number of pieces solved, stored in solvedCount, is incremented and allDone() is called, with an argument of true, if we are finished solving.


The single Boolean argument of allDone(), internally named solved, tells the function whether to clean up after a complete solve, or during play. A value of false is passed to allDone() by initPuzz() and breakUp(), if you recall, when a new image is loaded, or a new piece count is asked for, and we still have unsolved dispersed pieces.

    function allDone(solved) { for (i=1; i tempEl.visibility = "hide"; } if (isGrid) { elGrid.visibility = "hide" }; elBlank.visibility="hide"; if (isPuzzDraggable) { elPuzzle.draggable = true } solvedCount = 1; if (solved) { isBroken = false; pieceToSolve = 1; tempEl = elImage; flashTimer = setInterval("visToggle(false)",100); } }

When allDone() is called, it hides all the puzzle pieces, dispersed or not. If the grid is on, it gets hidden, as does the elBlank element. This results in the original puzzle image becoming visible.

The full puzzle is made draggable, if the user has chosen it to be, and solvedCount is re-initialized. If the puzzle has been completely solved, then the relevant variables are re-initialized and the full image is flashed.

To complete the Navigator puzzle code discussion, let's look at the remaining functions, which are all connected with the control panel buttons.

Produced by Peter Belesis and

All Rights Reserved. Legal Notices.
Created: Nov. 27, 1997
Revised: Jan. 18, 1998

URL: http://www.webreference.com/dhtml/column10/puzzNSdone.html