local status={}-- 0=pas de bombe pas decouvert, 1=bombe (pas decouvert), 2=pas de bombe et drapeau, 3=bombe et drapeau,4=decouvert(case touchant au moins une bombe) 5=decouvert, case blanche local nbrBombe={}-- 0,1,2,3,4,5,6,7,8 local cell--numero de cellule, de gauche a droite, ligne par ligne ce qui fait 189 cellule : donc 0 en haut a gauche 188 en bas a droite function init() --Initialisation du tableaux a 0 local i=0 while i<=188 do status[i]=0 nbrBombe[i]=0 i=i+1 end --tirage des bombes i=25 local cellTemp=0 while i>0 do cellTemp=misc.random(188) if status[cellTemp]==0 then status[cellTemp]=1 i=i-1 end end --Comptage du nombre de bombe voisines par case i=0 while i<=188 do ligne=int(i/21) colone=i%21 if status[i]==0 then if i-1 >= ligne*21 then if status[i-22]==1 then nbrBombe[i]=nbrBombe[i]+1 end--haut gauche if status[i-1]==1 then nbrBombe[i]=nbrBombe[i]+1 end--gauche if status[i+20]==1 then nbrBombe[i]=nbrBombe[i]+1 end--bas gauche end if status[i-21]==1 then nbrBombe[i]=nbrBombe[i]+1 end--haut if status[i+21]==1 then nbrBombe[i]=nbrBombe[i]+1 end--bas if i+1 < (ligne+1)*21 then if status[i-20]==1 then nbrBombe[i]=nbrBombe[i]+1 end--haut droite if status[i+1]==1 then nbrBombe[i]=nbrBombe[i]+1 end--droite if status[i+22]==1 then nbrBombe[i]=nbrBombe[i]+1 end--bas droite end end i=i+1 end --affichage clear nil graydraw.rect(2,2,126,54,2,2) --horizontales graydraw.line(1,1,127,1,4) graydraw.line(1,7,127,7,4) graydraw.line(1,13,127,13,4) graydraw.line(1,19,127,19,4) graydraw.line(1,25,127,25,4) graydraw.line(1,31,127,31,4) graydraw.line(1,37,127,37,4) graydraw.line(1,43,127,43,4) graydraw.line(1,49,127,49,4) graydraw.line(1,55,127,55,4) --verticales graydraw.line(1,1,1,55,4) graydraw.line(7,1,7,55,4) graydraw.line(13,1,13,55,4) graydraw.line(19,1,19,55,4) graydraw.line(25,1,25,55,4) graydraw.line(31,1,31,55,4) graydraw.line(37,1,37,55,4) graydraw.line(43,1,43,55,4) graydraw.line(49,1,49,55,4) graydraw.line(55,1,55,55,4) graydraw.line(61,1,61,55,4) graydraw.line(67,1,67,55,4) graydraw.line(73,1,73,55,4) graydraw.line(79,1,79,55,4) graydraw.line(85,1,85,55,4) graydraw.line(91,1,91,55,4) graydraw.line(97,1,97,55,4) graydraw.line(103,1,103,55,4) graydraw.line(109,1,109,55,4) graydraw.line(115,1,115,55,4) graydraw.line(121,1,121,55,4) graydraw.line(127,1,127,55,4) --smiley graydraw.rect(60,57,62,59,4,0) graydraw.rect(66,57,68,59,4,0) graydraw.pixel(61,62,4) graydraw.pixel(67,62,4) graydraw.line(62,63,66,63,4) --touche en bas a gauche graydraw.line(3,63,3,57,4) graydraw.line(4,57,19,57,4) graydraw.rect(10,59,14,63,4,0) graydraw.line(22,63,22,57,4) graydraw.line(23,57,38,57,4) graydraw.line(30,59,32,59,4) graydraw.line(30,60,32,60,4) graydraw.line(32,61,32,63,2) state(false) refresh end function curseur(cell) state(true) local ligne=int(cell/21) local colone=cell%21 graydraw.line(colone*6+1,ligne*6+1,colone*6+7,ligne*6+1,0) graydraw.line(colone*6+7,ligne*6+1,colone*6+7,ligne*6+7,0) graydraw.line(colone*6+1,ligne*6+7,colone*6+7,ligne*6+7,0) graydraw.line(colone*6+1,ligne*6+1,colone*6+1,ligne*6+7,0) refresh end function play() local cell=94 local ligne local colone local flag=0 curseur(cell) while 1 --boucle principale do if key(44) then misc.exit() end--menu if key(40)--droite then misc.wait(5) if (cell+1)<189 then cell=cell+1 curseur(cell) else cell=0 curseur(cell) end end if key(37)--gauche then misc.wait(5) if (cell-1)>=0 then cell=cell-1 curseur(cell) else cell=188 curseur(cell) end end if key(39)--haut then misc.wait(5) if (cell-21)>=0 then cell=cell-21 curseur(cell) else cell=8*21+(cell%21) curseur(cell) end end if key(38) --bas then misc.wait(5) if (cell+21)<189 then cell=cell+21 curseur(cell) else cell=(cell%21) curseur(cell) end end if key(46) --F2 (drapeau) then ligne=int(cell/21) colone=cell%21 state(true) if status[cell]==0--si case sans bombe et sans drapeau then misc.wait(5) status[cell]=2 flag=flag+1 graydraw.rect(109,57,119,64,0,0) graydraw.text(110,58,flag) graydraw.line(6*colone+3,6*ligne+3,6*colone+5,6*ligne+3,4) graydraw.line(6*colone+3,6*ligne+4,6*colone+5,6*ligne+4,4) graydraw.line(6*colone+5,6*ligne+5,6*colone+5,6*ligne+6,0) elseif status[cell]==2--si case sans bombe et avec drapeau then misc.wait(5) flag=flag-1 status[cell]=0 graydraw.rect(109,57,119,64,0,0) graydraw.text(110,58,flag) graydraw.rect(6*colone+2,6*ligne+2,6*colone+6,6*ligne+6,2,2) elseif status[cell]==1--si case avec bombe et sans drapeau then misc.wait(5) status[cell]=3 flag=flag+1 graydraw.rect(109,57,119,64,0,0) graydraw.text(110,58,flag) graydraw.line(6*colone+3,6*ligne+3,6*colone+5,6*ligne+3,4) graydraw.line(6*colone+3,6*ligne+4,6*colone+5,6*ligne+4,4) graydraw.line(6*colone+5,6*ligne+5,6*colone+5,6*ligne+6,0) elseif status[cell]==3--si case avec bombe et avec drapeau then misc.wait(5) flag=flag-1 status[cell]=1 graydraw.rect(109,57,119,64,0,0) graydraw.text(110,58,flag) graydraw.rect(6*colone+2,6*ligne+2,6*colone+6,6*ligne+6,2,2) end state(false) curseur(cell) refresh if flag==25 then local countWin=0 i=0 while i<289 do if status[i]==3 then countWin=countWin+1 end i=i+1 end if countWin==25 then graydraw.rect(1,1,128,64,4,1) graydraw.text(50,31,"Gagne !") refresh misc.wait(250) break end end end if key(45) then--F1 clique gauche if status[cell]==0 or status[cell]==1--si la case n'est pas découverte et sans drapeau then if status[cell]==1 then--si bombe : perdu graydraw.rect(1,1,128,64,4,1) graydraw.text(50,31,"Perdu !") refresh misc.wait(250) break else if nbrBombe[cell]==0 then--si case blanche sans bombe autour :recherche de toutes les cases vide autour i=0; --rend blanc state(true) ligne=int(cell/21) colone=cell%21 graydraw.rect(6*colone+2,6*ligne+2,6*colone+6,6*ligne+6,0,0) status[cell]=5 local encore=1 while encore==1 do i=0 encore=0 while i<=188 do if status[i]==0 and nbrBombe[i]==0 then if status[i-21]==5 or status[i-1]==5 or status[i+1]==5 or status[i+21]==5 then encore=1 ligne=int(i/21) colone=i-(ligne*21) graydraw.rect(6*colone+2,6*ligne+2,6*colone+6,6*ligne+6,0,0) status[i]=5 end end if status[i]==0 and nbrBombe[i]>0 then if status[i-22]==5 or status[i-21]==5 or status[i-20]==5 or status[i-1]==5 or status[i+1]==5 or status[i+22]==5 or status[i+21]==5 or status[i+20]==5 then encore=1 ligne=int(i/21) colone=i-(ligne*21) graydraw.rect(6*colone+2,6*ligne+2,6*colone+6,6*ligne+6,0,0) graydraw.text(colone*6+2,ligne*6+2,nbrBombe[i]) status[i]=4 end end i=i+1 refresh end if encore==0 then state(false) curseur(cell) refresh break end end else --affichage du nombre de bombes voisines state(true) ligne=int(cell/21) colone=cell%21 graydraw.rect(6*colone+2,6*ligne+2,6*colone+6,6*ligne+6,0,0) graydraw.text(colone*6+2,ligne*6+2,nbrBombe[cell]) state(false) curseur(cell) refresh end end end end end end graydraw.setcolor(true) misc.contrast(-1) misc.contrast(-1) misc.contrast(-1) misc.contrast(-1) init() play()