Lingo Game: Jigsaw Puzzle

READING: Read pages 280-282 in D8D

File "arkas.dir"

Contains the basic pieces for making a 4x4 puzzle:
arkas11arkas21arkas12arkas22

taken from the Greek cartoonist Arkas.
The four pieces of the puzzle (cut in Photoshop) and the complete image for reference, it is not used in this example):

arkas

The cast members have a simple script that will help us determine their final (correct) destination (to more completely understand testing functions in the Message window):

on mouseUp
   put sprite(the ClickOn).locH
   put sprite(the ClickOn).locV
end


That way, after we assemble them in their final location, we can click on them and find their coordinates.
Note that each sprite is moveable. You can set that either by clicking on the appropriate button on the properties window or by setting the property moveableSprite to TRUE in the script.

File "arkas1.dir"

has the programming of the puzzle complete.
Each puzzle piece checks to see if it is within epsilon = 20 pixels to its final destination, and if so,
it is placed ("magnetized") in its correct destination.

on mouseUp
   finH = 267 -- inserted manually
   finV = 147 -- inserted manually
               
   currH = sprite(the ClickOn).locH
   currV = sprite(the ClickOn).locV
   if (abs(currH - finH) < 20) and (abs(currV - finV) < 20) then 
      sprite(the ClickOn).locH = finH
      sprite(the ClickOn).locV = finV
      beep
   end if
end


Note that a "beep" gives the positive feedback of success.
Also note that the four cast members share a large part of the script.

File "arkas2.dir"

is a little prettier in terms of interface and less cumbersome to replicate using the moveAndCheck() function:

on mouseUp
   finH = 267 -- needs to be inserted manually
   finV = 147 -- needs to be inserted manually
   moveAndCheck(finH, finV)
end


which contains the pieces of the code that do not change.
There is also a field that is used for feedback.
A variable "success" is used to count the correctly placed pieces.
When all 4 pieced have been placed correctly, it declares success:

on startMovie
   global success
   success = 0 -- counts correctly placed pieces
   member("banner").text = "Assemble the puzzle"
end

on checkIfDone
   global success
   if success = 4 then 
      member("banner").text = "Success!"
      -- here you should play a sound and/or go to another frame
      -- to celebrate success!
   end if
end


Also, if you have a bunch of puzzles of the same size, you can program it so that it shows a different group of sprites every time. See Arthur's Music Box on for an example.

File "arkas3.dcr"

Note that there are a couple problems with the game presentation: First, if you accidentally move a piece out of its position, the counter of successes will not decrease. So, you can "cheat" by moving a single piece in and out of position 4 times. It would be better to have a piece "stick" to its final place once it has moved there. You can do that by setting to false the moveableSprite property of a sprite.

Next, when a piece moves on top of another, you cannot see the one below. That makes it difficult to move sprites on top of a congested stage. To avoid that you can move the sprite you are currently clicking on at the top channel available to your application. You can do that by setting the locZ property of a sprite to the highest channel available. locZ works like locH and locV, but it has only a temporary effect. After the end of the event handler it is in, it will go back to its original position. The file at the header of this section implements both of these improvements.

 

 

Maintained By: Takis Metaxas
Last Modified: November 12, 2007