blackout

blackout()
Prgm
Local a,b,c,d,e,i,j,k,l,m,n,q,r,s,t,u,w
1àxmin
159àxmax
0àxscl
1àymin
77àymax
0àyscl
newMat(5,5)àw
Lbl n
Request "Niveau",n
Lbl v
newMat(2,expr(n))àl
For a,1,expr(n)
      Lbl t
      rand(5)ài
      rand(5)àj
      If a>1 Then
            For b,1,a-1
                  If l[1,b]=i and l[2,b]=j:Goto t
            EndFor
      EndIf
      iàl[1,a]
      jàl[2,a]
      chg(m,i,j)àm
EndFor
màe
Lbl a
0àq
ClrDraw
For i,1,5
      For j,1,5
            If m[i,j]=0 Then
                  Rclpic p0,yi(i),xi(j)
            Else
                  RclPic p1,yi(i),xi(j)
            EndIf
      EndFor
EndFor
PxlText "0/"&n,0,95
3às
3àt
Lbl g
PxlText "4",yj(s),0
PxlText "5",71,xj(t)
0àc
While c=0
      getkey()àc
EndWhile
PxlText " ",yj(s),0
PxlText " ",71,xj(t)
If c=337 and t>1:t-1àt
If c=240 and t<5:t+1àt
if c=338 and s>1:s-1às
if c=344 and s<5:s+1às
If c=268:Goto k
if c=264:Goto p
if c¹13:Goto g
q+1àq
chg(m,s,t)àm
If s>1:RplcPic #("p"&string(m[s-1,t])),yi(s-1),xi(t)
If s<5:RplcPic #("p"&string(m[s+1,t])),yi(s+1),xi(t)
If t>1:RplcPic #("p"&string(m[s,t-1])),yi(s),xi(t-1)
If t<5:RplcPic #("p"&string(m[s,t+1])),yi(s),xi(t+1)
RplcPic #("p"&string(m[s,t])),yi(s),xi(t)
PxlText string(q)&"/"&n,0,95
If m=w:Goto h
Goto g
Lbl k
PxlText "solution:",0,95
newMat(5,5)àk
For a,1,colDim(l)
      1àk[l[1,a],l[2,a]]
EndFor
For i,1,5
      For j,1,5
            If k[i,j]=0 Then
                  RclPic p0,yi(i)+8,xi(j)+78
            Else
                  RclPic p2,yi(i)+8,xi(j)+78
            Endif
      EndFor
EndFor
Goto g
Lbl h
""àr
If expr(n)=q:" (meilleure solution)"àr
Text "Gagné en "&string(q)&r
Lbl p
If c¹264:PopUp {"Recommencer","Niveau","Nouveau","Quitter"},d
If c=264:PopUp {"Recommencer","Niveau","Nouveau","Quitter","Continuer"},d
If d=1 Then
      eàm
      Goto a
EndIf
If d=2:Goto n
If d=3:Goto v
If d¹4 and c¹264:Goto p
If d=5:Goto g
DispHome
EndPrgm