算法比较难一点就是当鼠标点击时有点复杂
procedure TMainForm.Image1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
var k, ll,l:integer;
i,mx,my,j,cc:byte;
lr:integer;
begin
image2.Picture:=image3.Picture;
If TStart = True then
Timer1.Enabled:= True;
mx:= x div 16;
my:= y div 16;
k:= mx + my * n;
i:= MineNumAroundBlock[k];
if (button=mbleft) and (FlagAsMine[k]=1) then
exit;
If (i > 0) And (i < 9) And (FlagNoMine[k] = True) then
begin
lr:=0;
For ll:= -1 To 1do
begin
For l:= -1 To 1 do
begin
if ((mx+ll)>=0) and ((mx+ll)<=n-1) and ((my+l)>=0) and ((my+l)<=m-1) then
lr:= lr + FlagAsMine[k + ll + l * n];
end;
end;
If lr = i then
begin
For ll:= -1 To 1do
begin
For l:= -1 To 1 do
begin
if ((mx+ll)>=0) and ((mx+ll)<=n-1) and ((my+l)>=0) and ((my+l)<=m-1) then
begin
cc:= MineNumAroundBlock[k + ll + l * n];
If (cc = 0) And (FlagAsMine[k + ll + l * n] <> 1) then
OpenBlocks(mx+ll,my+l);
If (cc > 0) And (cc < 9) And (FlagAsMine[k + ll + l * n] <> 1) then
PressDangerBlock(cc,mx+ll,my+l);
If (cc = 9) And (FlagAsMine[k + ll + l * n] <> 1) then
begin
TStart:=false;
DrawAllMine(sender);
image2.Picture:= image6.Picture;
Timer1.Enabled:= False;
image1.Enabled:=false;
end;
end;
end;
end;
end;
end;