procedure TForm1.Button1Click(Sender: TObject); begin s1:=StrToInt(Edit1.text); //кількість стовпчиків if (s1<4) or (s1>30) then showmessage('Стовпчиків має бути від 4 до 30'); s2:=StrToInt(Edit2.text); //кількість рядків if (s2<4) or (s2>20) then showmessage('Рядків має бути від 4 до 20'); if (s1>=4) and (s1<=30) and (s2>=4) and (s2<=30) then begin k:=s1*s2; //кількість клітинок на полі Edit4.text:=IntToStr(k); Edit4.visible:=true; Label4.visible:=true; m:=k div 10; //кількість мін Edit3.text:=IntToStr(m); Edit3.visible:=true; Label3.visible:=true; r:=0; //кількість розкритих клітинок Edit5.text:=IntToStr(r); Edit5.visible:=true; Label5.visible:=true; Label6.visible:=true; StringGrid1.ColCount:=s1; StringGrid1.RowCount:=s2; StringGrid1.Height:=s2*23; StringGrid1.Width:=s1*23; StringGrid1.visible:=true; for i:=1 to s1 do for j:=1 to s2 do a[i,j]:=''; for i:=0 to s1-1 do for j:=0 to s2-1 do StringGrid1.Cells[i,j]:='?'; randomize; // розташування мін n:=1; while n<=m do begin i:=random(s1); j:=random(s2); if a[i+1,j+1]<>'+' then begin a[i+1,j+1]:='+'; inc(n); end; end; for i:=1 to s1 do for j:=1 to s2 do // обчислення кількості мін у сусідніх клітинах if a[i,j]<>'+' then begin n:=0; if (i<>1) and (j<>1) and (a[i-1,j-1]='+') then inc(n); if (i<>1) and (a[i-1,j]='+') then inc(n);; if (i<>1) and (j<>s2) and (a[i-1,j+1]='+') then inc(n);; if (j<>1) and (a[i,j-1]='+') then inc(n); if (j<>s2) and (a[i,j+1]='+') then inc(n); if (i<>s1) and (j<>1) and (a[i+1,j-1]='+') then inc(n); if (i<>s1) and (a[i+1,j]='+') then inc(n); if (i<>s1) and (j<>s2) and (a[i+1,j+1]='+') then inc(n); if n<>0 then a[i,j]:=IntToStr(n) else a[i,j]:=' '; end; end; end;