GraphicsWindow.BrushColor="Blue"
GraphicsWindow.DrawBoundText(5,5,290,"Press S to shuffle the puzzle")
GraphicsWindow.DrawBoundText(5,20,290,"Press 1 for one single Shuffle move")
GraphicsWindow.DrawBoundText(5,35,290,"Click a piece with the mouse to move it")
While "true"
If shuffleCount>0 Then
ShufflePuzzle()
program.delay(200)
shuffleCount=ShuffleCount-1
endif
endwhile
Sub createPuzzle
x=1
y=1
For i=1 To maxx*maxy-1
img=ImageList.LoadImage("http://www.li-do.nl/userfiles/apple33"+y+x+".jpg")
square[x][y]=shapes.AddImage(img)
Shapes.Move(square[x][y],50+x*50,50+y*50)
x=x+1
If x>maxx Then
y=y+1
x=1
endif
Sub onMouseDown
a=GraphicsWindow.MouseX
b=GraphicsWindow.MouseY
a=a-50
a=a/55
a=math.floor(a)
b=b-50
b=b/55
b=math.floor(b)
If (math.abs(freex-a)=1 And (freey=b)) or ((freex=a) And math.abs(freey-b)=1) Then
t=square[a][b]
square[freex][freey]=t
Shapes.animate(square[freex][freey],50+freex*50,50+freey*50,500)
freex=a
freey=b
endif
EndSub
Sub OnKeyDown
' shuffle pieces
key=GraphicsWindow.LastKey
If key="S" then
ShuffleCount= 64
ElseIf key="D1" then
shuffleCount =1
endif
EndSub