Graphics 640,480
SetBuffer BackBuffer()
SeedRnd MilliSecs()
Dim piece_imgs(12)
pointer_img=LoadImage("pointer.bmp")
img=LoadImage("hill_castle.jpg")
DrawBlock img,0,0
init()
shuffle()
last_n=0
Repeat
display()
DrawImage pointer_img,MouseX(),MouseY()
Flip
If MouseHit(1)
n=which_one()
If last_n=0 Then
last_n=n
Else
t=piece_imgs(n):piece_imgs(n)=piece_imgs(last_n):piece_imgs(last_n)=t
last_n=0
End If
End If
Until KeyHit(1)
End
Function init()
n=1
y=0
For row=1 To 3
x=0
For col=1 To 4
piece_imgs(n)=CreateImage(160,160)
GrabImage piece_imgs(n),x,y
n=n+1
x=x+160
Next
y=y+160
Next
End Function
Function display()
n=1
y=0
For row=1 To 3
x=0
For col=1 To 4
DrawBlock piece_imgs(n),x,y
n=n+1
x=x+160
Next
y=y+160
Next
End Function
Function shuffle()
For i=1 To 200
r1=Rand(12)
r2=Rand(12)
t=piece_imgs(r1):piece_imgs(r1)=piece_imgs(r2):piece_imgs(r2)=t
Next
End Function
Function which_one()
n=1
y=0
For row=1 To 3
x=0
For col=1 To 4
If mouse_in(x,y,x+160,y+160) Then piece=n
n=n+1
x=x+160
Next
y=y+160
Next
Return piece
End Function
Function mouse_in(x1,y1,x2,y2)
x=MouseX(): y=MouseY()
m=True
If x<x1 Then m=False
If x>x2 Then m=False
If y<y1 Then m=False
If y>y2 Then m=False
Return m
End Function