📄 unit1.pas
字号:
end;
end;
end;
imgfield.Enabled:=true;
//初始化雷区
end;
procedure TForm1.OnCreat(Sender: TObject);
begin
Nummines:=10;
Ncols:=8;
Nrows:=8;
imgfield.Canvas.Brush.Style:=bsclear;
imgfield.Canvas.Font.Style:=[fsBold];
imgfield.Canvas.Font.Size:=10;
panel1.DoubleBuffered:=true;
panel2.DoubleBuffered:=true;
formsize;
initminefield;
end;
procedure TForm1.NewGmOnMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
imgNewGm.Canvas.Draw(0,0,imgNewGmpressed.Picture.Graphic);
end;
procedure TForm1.NewGmOnMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
imgNewGm.Canvas.Draw(0,0,imgNewGmY.Picture.Graphic);
end;
procedure TForm1.NewGmOnClick(Sender: TObject);
begin
initminefield;
end;
procedure TForm1.imgfieldOnMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
intX,intY,wintX,wintY:integer;
i,j,k:integer;
righthit,wronghit:integer;
ndx,ndy:boolean;
begin
Leftbutton:=false;
hitbegin:=false;
intX:=x div buttonwidth;
intY:=y div buttonwidth;
cols:=intX*buttonwidth;
rows:=intY*buttonwidth;
wintX:=0;
wintY:=0;
righthit:=0;
wronghit:=0;
imgNewGm.Canvas.Draw(0,0,imgNewGmY.Picture.Graphic);
if (button=mbleft) and (not leftandrightdown) then //鼠标左键结束点击
begin
if Mark[intY,intX]=2 then exit;
case mine[intY,intX] of
10..18:
begin
imgpressed.Left:=5000;
imgquestdown.Left:=5000;
exit;
end;
1..8: //打开雷周围的数字格子
begin
imgNewGm.Canvas.Draw(0,0,imgNewGmY.Picture.Graphic);
imgpressed.Left:=5000;
imgquestdown.Left:=5000;
imgfield.Canvas.CopyRect(rect(intX*16,intY*16,(intX+1)*16,(intY+1)*16),imgNums.Canvas,rect(0,240-mine[intY,intX]*16,16,240-(mine[intY,intX]-1)*16));
mine[intY,intX]:=10+mine[intY,intX];
end;
9: //打开雷所在的格子
die(intY,intX);
0: //打开空的格子
begin
imgpressed.Left:=5000;
imgquestdown.Left:=5000;
imgNewGm.Canvas.Draw(0,0,imgNewGmY.Picture.Graphic);
mine[intY,intX]:=10;
openblank(intY,intX);
end;
end;
end;
if leftandrightdown then
begin
for j:=-1 to 1 do
for k:=-1 to 1 do
begin
ndx:=(intX+k>=0) and (intX+k<Ncols);
ndy:=(intY+j>=0) and (intY+j<Nrows);
if ndx and ndy then
begin
if Mark[intY+j,intX+k]=2 then
begin
case Mine[intY+j,intX+k] of
0..8:
begin
wronghit:=wronghit+1;
wintY:=intY+j;
wintX:=intX+k;
end;
9: righthit:=righthit+1;
end;
end;
end;
end;
if ((Mine[intY,intX] mod 10)=(righthit+wronghit)) and (wronghit>0) then
begin
die(wintY,wintX);
end;
if (Mine[intY,intX] mod 10)=righthit then
begin
for i:=1 to psed do
begin
case mineopened[i,3] of
0:
begin
mine[mineopened[i,1],mineopened[i,2]]:=10;
openblank(mineopened[i,1],mineopened[i,2]);
end;
1..8:
begin
imgfield.Canvas.CopyRect(rect(mineopened[i,2]*16,mineopened[i,1]*16,(mineopened[i,2]+1)*16,(mineopened[i,1]+1)*16),imgNums.Canvas,rect(0,240-(mine[mineopened[i,1],mineopened[i,2]] mod 10)*16,16,240-(mine[mineopened[i,1],mineopened[i,2]] mod 10-1)*16));
mine[mineopened[i,1],mineopened[i,2]]:=10+mine[mineopened[i,1],mineopened[i,2]];
end;
end;
end;
end;
if (Mine[intY,intX] mod 10)>(righthit+wronghit) then
begin
for i:=1 to psed do
begin
imgfield.Canvas.CopyRect(rect(mineopened[i,2]*16,mineopened[i,1]*16,(mineopened[i,2]+1)*16,(mineopened[i,1]+1)*16),imgNums.Canvas,rect(0,0,16,16));
end;
end;
leftandrightdown:=false;
end;
end;
procedure TForm1.imgfieldOnMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
intX,intY:integer;
j,k:integer;
ndx,ndy:boolean;
keystate:TKeyboardState;
begin
hitbegin:=true;
intX:=x div buttonwidth;
intY:=y div buttonwidth;
cols:=intX*buttonwidth;
rows:=intY*buttonwidth;
GetKeyboardState (keystate );
setlength(mineopened,0,0);
setlength(mineopened,Nrows*Ncols,5);
psed:=0;
if keystate[vk_lbutton] and keystate[vk_rbutton] and $80 <> 0 then //双键点击
begin
leftandrightdown:=true;
if (Mark[intY,intX]=0) and (Mine[intY,intX]>10) then
begin
for j:=-1 to 1 do
for k:=-1 to 1 do
begin
ndx:=(intX+k>=0) and (intX+k<Ncols);
ndy:=(intY+j>=0) and (intY+j<Nrows);
if ndx and ndy then
begin
if (Mark[intY+j,intX+k]=0) and (Mine[intY+j,intX+k]<10) then
begin
imgfield.Canvas.Draw((intX+k)*16,(intY+j)*16,imgpressed.Picture.Graphic);
psed:=psed+1;
mineopened[psed,1]:=intY+j;
mineopened[psed,2]:=intX+k;
mineopened[psed,3]:=Mine[intY+j,intX+k];
end;
end;
end;
end
else
exit;
end;
if mine[intY,intX]>=10 then exit;
if (button=mbleft) and (Mark[intY,intX]=0) and (not leftandrightdown) then //鼠标左键开始点击
begin
Leftbutton:=true;
if timer1.Enabled=false then timer1.Enabled:=true;
imgNewGm.Canvas.Draw(0,0,imgfieldpress.Picture.Graphic);
case Mark[intY,intX] of
0:
begin
imgpressed.Left:=imgfield.Left+cols;
imgpressed.Top:=imgfield.Top+rows;
end;
1:
begin
imgquestdown.Left:=imgfield.Left+cols;
imgquestdown.Top:=imgfield.Top+rows;
end;
2:exit;
end;
end;
if (button=mbright) and (not leftandrightdown) then //鼠标右键点击
begin
Leftbutton:=false;
if Mine[intY,intX]<10 then
begin
case Mark[intY,intX] of
0: //空白,没有做标记
begin
if mineleft>-99 then
begin
Mark[intY,intX]:=2;
imgfield.Canvas.CopyRect(rect(cols,rows,cols+16,rows+16),imgNUms.Canvas,rect(0,16,16,32));
mineleft:=mineleft-1;
led(mineleft,imgmineleft);
if mine[intY,intX]=9 then Hits:=Hits-1;
if (Hits=0) and (mineleft=0) then win; //胜利
if mine[intY,intX]<>9 then
begin
wrHits:=wrHits+1;
wronglocation[wrHits,1]:=intY;
wronglocation[wrHits,2]:=intX;
end;
end
else
MessageDlg('There are too many wronghits.', mtInformation, [mbOk], 0);
end;
1: //问号标记
begin
Mark[intY,intX]:=0;
imgfield.Canvas.copyRect(rect(cols,rows,cols+16,rows+16),imgNums.canvas,rect(0,0,16,16));
end;
2: // flag标记
begin
if Menbj.Checked=true then
begin
Mark[intY,intX]:=1;
imgfield.Canvas.CopyRect(rect(cols,rows,cols+16,rows+16),imgNums.Canvas,rect(0,32,16,48));
end;
if Menbj.Checked=false then
begin
Mark[intY,intX]:=0;
imgfield.Canvas.CopyRect(rect(cols,rows,cols+16,rows+16),imgNums.Canvas,rect(0,0,16,16));
end;
mineleft:=mineleft+1;
led(mineleft,imgmineleft);
end;
end;
end;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
timeused:=timeused+1;
if timeused=999 then
begin
MessageDlg('Times up,You lose.', mtInformation, [mbOk], 0);
imgfield.Enabled:=false;
imgNewGm.Canvas.Draw(0,0,imgCry.Picture.Graphic);
end;
led(timeused,imgtimeused);
end;
procedure TForm1.MenchujiClick(Sender: TObject);
begin
Nummines:=10;
Ncols:=8;
Nrows:=8;
formsize;
initminefield;
Mencheck(Menchuji.GroupIndex);
Menchuji.Checked:=true;
end;
procedure TForm1.MenzhongjiClick(Sender: TObject);
begin
Nummines:=40;
Ncols:=16;
Nrows:=16;
formsize;
initminefield;
Mencheck(Menzhongji.GroupIndex);
Menzhongji.Checked:=true;
end;
procedure TForm1.MenNewGmClick(Sender: TObject);
begin
initminefield;
Mencheck(MenNewGm.GroupIndex);
MenNewGm.Checked:=true;
end;
procedure TForm1.MengaojiClick(Sender: TObject);
begin
Nummines:=10;
Ncols:=30;
Nrows:=16;
formsize;
initminefield;
Mencheck(Mengaoji.GroupIndex);
Mengaoji.Checked:=true;
end;
procedure TForm1.MenzdyClick(Sender: TObject);
begin
Mencheck(Menzdy.GroupIndex);
Menzdy.Checked:=true;
form2.Show;
end;
procedure TForm1.MenexitClick(Sender: TObject);
begin
form1.Close;
end;
procedure TForm1.imgfieldOnMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var
intX,intY:integer;
begin
intX:=x div 16;
intY:=y div 16;
cols:=intX*buttonwidth;
rows:=intY*buttonwidth;
if (intX>=0) and (intX<Ncols) and (intY>=0) and (intY<Nrows) then
begin
if hitbegin and Leftbutton and (Mine[intY,intX]<10) then
begin
imgpressed.Visible:=true;
imgpressed.Left:=imgfield.Left+cols;
imgpressed.Top:=imgfield.Top+rows;
end;
end;
end;
procedure TForm1.MenyxbClick(Sender: TObject);
begin
form3.show;
readfromreg;
end;
procedure TForm1.N13Click(Sender: TObject);
begin
frm_About.show
end;
procedure TForm1.N10Click(Sender: TObject);
begin
ShellExecute (Application.Handle,pchar('open'),pchar(comdir+g_ResourceName+g_ChmFileName),nil,nil,SW_show);
end;
procedure TForm1.N11Click(Sender: TObject);
begin
ShellExecute (Application.Handle,pchar('open'),pchar(comdir+g_ResourceName+g_ChmFileName),pchar(''),pchar(''),SW_show);
end;
procedure TForm1.N12Click(Sender: TObject);
begin
ShellExecute(Application.Handle,pchar('open'),pchar(comdir+g_ResourceName+g_SysHelpFileName),pchar(''),pchar(''),SW_show);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -