spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / dhtml / column10
Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source
Logo

The DHTML Lab Jigsaw Puzzle, Part III: NN4
solving the puzzle automatically


Automatic Solve

When the user presses the Solve button, the solve() function is called to automatically move all unsolved puzzle pieces to their correct position.

The single argument of solve() is isFullSolve. If the Solve button is pressed, this argument is true, calling for a full solve. The Hint button also calls solve() but with a false value for the argument, telling the function to only solve one piece.

If the puzzle is not broken, there is nothing to solve, so the function returns. The next piece in line to be solved is retrieved using pieceToSolve and its draggable property is checked. If it is false, it means the user manually solved this piece so pieceToSolve is incremented and solve() is called again. When a draggable piece is found, it is moved above the other pieces and visToggle() is called repeatedly.

Flashing

Whenever the user correctly positions a piece, a piece is solved automatically, or the full puzzle is solved, the visToggle() function is called to flash the piece or full image to alert the user to success.

When the flashTotal has been reached, the repeated calls to visToggle() are cancelled, the flash counter is re-initialized and the element is made visible. This possibly redundant statement is useful if an element was left invisible after an odd flashCount.

If the element being flashed is a piece and not the full image, origPos() is called to position it. Once positioned, and a full solve has been called for, solve() is called again.

Two functions remain to complete the puzzle solving discussion, origPos() and allDone().


Produced by Peter Belesis and

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Working with the DOM Stylesheets Collection · Administering RBAC in PHP 5 CMS Framework · xref: Automatic Cross Referencing Script
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Combine BottomCount() with Other MDX Functions to Add Sophistication · Creating a Daemon with Python · The Coming Voice-over-WiMAX Revolution

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

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