Graphics 800,600,32,2
SetBuffer BackBuffer()
SeedRnd MilliSecs()
Dim Map_Grid(8,8)
For I=0 To 8
For J=0 To 8
Map_Grid(I,J)=Rand(1,5)
Next
Next
While KeyDown(1)=0
Cls
For j=0 To 7
For i=0 To 7
If Map_Grid(i,j)=1 Then Color 0,200,200
If Map_Grid(i,j)=2 Then Color 200,200,0
If Map_Grid(i,j)=3 Then Color 200,0,0
If Map_Grid(i,j)=4 Then Color 0,200,0
If Map_Grid(i,j)=5 Then Color 0,0,200
Rect 317+i*48,113+j*48,46,46
Next
Next
For j=0 To 7
For i=0 To 7
Color 0,0,0
If Map_Grid(i,j)>0
If i=sx1 And j=sy1 And selectst=1
Rect 317+i*48,113+j*48,46,46
EndIf
EndIf
Next
Next
sx=(MouseX()-318)/48
sy=(MouseY()-113)/48
If sx>7 Then sx=7
If sx<0 Then sx=0
If sy>7 Then sy=0
If sy<0 Then sy=7
If MouseHit(1)
FlushMouse()
If selectst=1
byside = 1
If Abs(sx-sx1)<2 And Abs(sy-sy1)<2
If (byside) And (Abs(sx-sx1)<>Abs(sy-sy1)) ;by side
c=Map_Grid(sx,sy)
Map_Grid(sx,sy)=Map_Grid(sx1,sy1)
Map_Grid(sx1,sy1) = c
EndIf
EndIf
selectst=2
EndIf
If selectst=0
sx1=sx
sy1=sy
selectst=1
EndIf
If selectst=2 Then selectst=0
EndIf
Flip 1
Wend
End