Shapes.Move(btn1, GraphicsWindow.Width / 2 - btnWidth / 2, GraphicsWindow.Height / 2 - btnHeight / 2)
Shapes.Move(btn2, GraphicsWindow.Width / 2 - btnWidth / 2, GraphicsWindow.Height / 2 - btnHeight / 2)
Shapes.ShowShape(btn1)
pic = false
'------------------------------------------------------------------------------ UPDATE ON MOUSE MOVE
'Highlight the picture below the cursor and highlight the button.
Sub MouseMove
If button = true then
mx = GraphicsWindow.MouseX
my = GraphicsWindow.MouseY
bb = Math.SquareRoot((gfxwidth2 - mx)*(gfxwidth2 - mx) + (gfxheight2 - my)*(gfxheight2 - my))
if bb < 74 and btnup = true then
Shapes.ShowShape(btn2)
Shapes.HideShape(btn1)
btnup = false
elseif bb > 74 and btnup = false then
Shapes.ShowShape(btn1)
Shapes.HideShape(btn2)
btnup = true
endif
else
x = math.Floor(GraphicsWindow.MouseX / 125) '* 125
y = math.Floor(GraphicsWindow.MouseY / 125) '* 125
For i = 0 To 3
Shapes.Move(shape_frame[i], x*125, y*125)
EndFor
EndIf
EndSub
'------------------------------------------------------------------------------ UPDATE ON MOUSE BUTTON UP
Sub MouseClick
If (x-1 >= 0) And (field[y][x-1] = 0) then
move = move + 1
field[y][x-1] = field[y][x]
field[y][x] = 0
puzzle[y][x-1] = puzzle[y][x]
Shapes.Animate(puzzle[y][x], (x-1)*125, y*125, duration)
ElseIf (x+1 <= 3) And (field[y][x+1] = 0) then
move = move + 1
field[y][x+1] = field[y][x]
field[y][x] = 0
puzzle[y][x+1] = puzzle[y][x]
Shapes.Animate(puzzle[y][x], (x+1)*125, y*125, duration)
ElseIf (y-1 >= 0) And (field[y-1][x] = 0) then
move = move + 1
field[y-1][x] = field[y][x]
field[y][x] = 0
puzzle[y-1][x] = puzzle[y][x]
Shapes.Animate(puzzle[y][x], x*125, (y-1)*125, duration)
ElseIf (y+1 <= 3) And (field[y+1][x] = 0) then
move = move + 1
field[y+1][x] = field[y][x]
field[y][x] = 0
puzzle[y+1][x] = puzzle[y][x]
Shapes.Animate(puzzle[y][x], x*125, (y+1)*125, duration)
EndIf
CheckWin() 'after moving , check if the picture is already complete
If button = true and btnup = false then
button = false
Shapes.HideShape(btn2)
For f = 1 To 500
Shuffle() 'shuffle the picture
EndFor
For i = 0 To 3 'draw frame
Shapes.ShowShape(shape_frame[i])
EndFor
EndIf
EndSub
'------------------------------------------------------------------------------ CHECK IF THE PICTURE IS COMPLETED
Sub CheckWin
if move > 0 then
win = true
For a = 1 to 4
For b = 1 To 4
If (b <> 4 or a <> 4) then
If field[a-1][b-1] <> (a-1)*4 + b then
win = false
EndIf
EndIf
EndFor
EndFor
EndIf
GraphicsWindow.Title = Title + " " + win
EndSub
'------------------------------------------------------------------------------ SHUFFLE THE PICTURE
Sub Shuffle
px = 0
py = 0
GetNull()
if xn = 0 Then
px = (Math.GetRandomNumber(3-1) + 1) - 2
elseif xn = 3 Then
px = (Math.GetRandomNumber(3-1)) - 2
else
px = (Math.GetRandomNumber(3)) - 2
EndIf
If px = 0 then
While py = 0
if yn = 0 Then
py = (Math.GetRandomNumber(3-1) + 1) - 2
elseif yn = 3 Then
py = (Math.GetRandomNumber(3-1)) - 2
else
py = (Math.GetRandomNumber(3)) - 2
EndIf
EndWhile
EndIf
x = xn + px
y = yn + py
For i = 0 To 3
Shapes.Move(shape_frame[i], x*125, y*125)
EndFor
MouseClick() ' simulate a click to move the part
EndSub
'------------------------------------------------------------------------------ Get the empty field
Sub GetNull
For a = 1 to 4
For b = 1 To 4
If field[a-1][b-1] = 0 then
xn = b-1
yn = a-1
EndIf
EndFor
EndFor
EndSub