home *** CD-ROM | disk | FTP | other *** search
- on startMovie
- global started
- set started to 0
- startTimer()
- updateStage()
- end
-
- on startUp
- global started
- if not started then
- puppet16(1)
- set started to 1
- end if
- end
-
- on keyDown
- if the key = "s" then
- scramble()
- end if
- if the key = "r" then
- cheat()
- end if
- end
-
- on puppet16 value
- repeat with x = 1 to 16
- set the puppet of sprite x to value
- recast(x, x)
- end repeat
- end
-
- on goback
- go(1)
- end
-
- on regap x
- global gap, rgap, cgap
- set gap to x
- row(gap)
- set rgap to the result
- column(gap)
- set cgap to the result
- end
-
- on recast x, y
- set the castNum of sprite x to y
- if y = 1 then
- regap(x)
- end if
- end
-
- on cheat
- go("start")
- repeat with x = 1 to 16
- recast(x, x)
- end repeat
- updateStage()
- end
-
- on scramble
- go("start")
- set done to 0
- set x to 1
- repeat while not done or (x < 100)
- move(random(16))
- set x to x + the result
- contig()
- set done to not (the result)
- if not (x mod 10) then
- updateStage()
- end if
- end repeat
- updateStage()
- end
-
- on row x
- return ((x - 1) / 4) + 1
- end
-
- on column x
- return ((x - 1) mod 4) + 1
- end
-
- on horiz x
- global rgap, cgap
- row(x)
- set rx to the result
- column(x)
- set cx to the result
- set loc to 0
- if rgap = rx then
- if cx < cgap then
- set loc to 1
- end if
- if cx > cgap then
- set loc to -1
- end if
- end if
- return loc
- end
-
- on vert x
- global rgap, cgap
- row(x)
- set rx to the result
- column(x)
- set cx to the result
- set loc to 0
- if cgap = cx then
- if rx < rgap then
- set loc to 1
- end if
- if rx > rgap then
- set loc to -1
- end if
- end if
- return loc
- end
-
- on move x
- global gap, rgap
- horiz(x)
- set h to the result
- vert(x)
- set v to the result
- row(x)
- move1(x, v, the result, rgap, 4)
- move1(x, h, x, gap, 1)
- return h or v
- end
-
- on move1 x, v, xrow, rgap, mult
- global gap
- set range to rgap - xrow - 1
- if v < 0 then
- set range to xrow - rgap - 1
- end if
- repeat with z = 0 to range
- recast(gap + (-1 * v * z * mult), the castNum of sprite (gap + (-1 * v * z * mult) + (-1 * v * mult)))
- end repeat
- if v then
- recast(x, 1)
- end if
- end
-
- on contig
- set adj to 0
- repeat with x = 1 to 4
- repeat with y = 0 to 3
- set loc to x + (4 * y)
- set a to the castNum of sprite loc
- if x < 4 then
- set b to the castNum of sprite (loc + 1)
- if (a + 1) = b then
- set adj to 1
- end if
- end if
- if y < 3 then
- set c to the castNum of sprite (loc + 4)
- if (a + 4) = c then
- set adj to 1
- end if
- end if
- if adj then
- exit repeat
- end if
- end repeat
- if adj then
- exit repeat
- end if
- end repeat
- return adj
- end
-
- on done
- set same to 1
- repeat with x = 1 to 16
- if the castNum of sprite x <> x then
- set same to 0
- exit repeat
- end if
- end repeat
- if same then
- repeat with a = 1 to 5
- ink(4)
- updateStage()
- ink(0)
- updateStage()
- end repeat
- end if
- end
-
- on ink x
- repeat with y = 2 to 16
- set the ink of sprite y to x
- end repeat
- end
-