version 5.00 0 Form1 1 1 0 0 0 1 0 0 2 0 0 0 0 0 0 0 0 0 0 0 238 268 0 0 0 Sub designer addform(Form1,"Klotski puzzle by Jorge H","",255,255,255)@ addlabel(form1,Label1,10,5,215,20,"Move Big Blue Block to Lower Center",255,255,255,0,0,0,True,True,9)@ addbutton(form1,Button1,155,247,75,23,"Reset",212,208,200,0,0,0,True,True,9)@ End Sub @EndOfDesignText@Sub Globals TX = 1:TY = 1:de = "r":f1 = 0:f2 = 1:P = 1 M = 5:N = 4 dim c(20) , a(20,20) , color(20,20) c(0)=cBeige:c(1)=cBlack:c(2)=cBlue:c(3)=cBrown:c(4)=cCyan:c(5)=cGold c(6)=cGreen:c(7)=cGray:c(8)=cOrange:c(9)=cPink:c(10)=cPurple c(11)=cRed:c(12)=cSilver:c(13)=cYellow:c(15)=cWhite End Sub Sub App_Start Form1.Show Definition Form1.Line (38,38,201,241,cBlack,B) Form1.Line (78,243,161,243,cRed) Draw End Sub Sub Button1_Click ' RESET App_Start End Sub Sub Form1_MouseDown (CX,CY) f1 = 0:f2 = 1 if CX>200 and CY>240 then return TX = CX:TY = CY J=int(CX/40):I=int(CY/40) if I<1 then return P = a(I,J):if P =15 then return End Sub Sub Form1_MouseUp (CX,CY) DX = abs(CX-TX):DY = abs(CY-TY) if DX > DY then if CX>TX then de="r" else de="l" end if end if if DY > DX then if CY>TY then de="d" else de="u" end if end if Direccion End Sub Sub Direccion if de="r" then ER if (f1*f2) = 1 then MR End If if de="l" then EL if (f1*f2) = 1 then ML End If if de="d" then ED if (f1*f2) = 1 then MD End If if de="u" then EU if (f1*f2) = 1 then MU End If End Sub Sub ER ' Empty to the right ? O = N-1 for I = 1 to M for J = 1 to O if a(I,J) = p and a(I,J+1) = 15 then f1 = 1 if a(I,J) = P and a(I,J+1) <> 15 then f3=1 else f3=0 if f3=1 and a(I,J+1) <> P then f2 = 0 if a(I,N) = P then f2 = 0 next next End Sub Sub MR ' Movement to the right O = N-1 for I = 1 to M:for J = O to 1 step -1 if a(I,J)=P then a(I,J+1) = P if a(I,J-1) = P then a(I,J) = P else a(I,J) = 15 End If next next Draw End Sub Sub EL ' Empty to the left ? for I =1 to M:for J = 2 to N if a(I,J) = P and a(I,J-1) =15 then f1 = 1 if a(I,J) = P and a(I,J-1)<>15 and a(I,J-1) <> P then f2 = 0 if a(I,1)=P then f2 = 0 next next End Sub Sub ML ' Movement to left for I = 1 to M:for J =1 to N if a(I,J) = P and J>1 then a(I,J-1)=P if a(I,J+1) = P then a(I,J) = P else a(I,J) = 15 End If next next Draw End Sub Sub ED ' Empy down ? O = M-1 for I =1 to O:for J =1 to N if a(I,J) = P and a(I+1,J) =15 then f1 = 1 if a(I,J) = P and a(I+1,J) <> 15 and a(I+1,J) <> P then f2 = 0 if a(M,J) = P then f2 = 0 next J next I End Sub Sub MD ' Movement down O = M-1 for I = O to 1 step -1:for J =1 to N if a(I,J) = P then a(I+1,J) = P if a(I-1,J) = P then a(I,J) = P else a(I,J) =15 End If next next Draw End Sub Sub EU ' Empty up ? for I = 2 to M:for J=1 to N if a(I,J) = P and a(I-1,J) =15 then f1 = 1 if a(I,J) = P and a(I-1,J) <>15 and a(I-1,J) <> P then f2 = 0 if a(1,J) = P then f2 = 0 next next End Sub Sub MU ' Movement up for I = 2 to M:for J =1 to N if a(I,J) = P then a(I-1,J) = P if a(I+1,J) = P then a(I,J) = P else a(I,J) =15 End If next next Draw End Sub Sub Draw for I=1 to M:for J=1 to N Y = I*40:X = J*40 color(I,J)=c(a(I,J)) Form1.Line (X,Y,X+40,Y+40,color(I,J),BF) next:next 'if a(5,2)=2 and a(5,3)=2 then 'AddLabel (Form1," Label2", 120, 220, 40, 20, "WIN !") 'End If End Sub Sub Definition M=5:N=4 a(1,1)=1:a(1,2)=2:a(1,3)=2:a(1,4)=3 a(2,1)=1:a(2,2)=2:a(2,3)=2:a(2,4)=3 a(3,1)=4:a(3,2)=5:a(3,3)=5:a(3,4)=6 a(4,1)=4:a(4,2)=7:a(4,3)=8:a(4,4)=6 a(5,1)=9:a(5,2)=15:a(5,3)=15:a(5,4)=10 End Sub