⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unitmain.pas

📁 经典游戏扫雷,仿XP
💻 PAS
📖 第 1 页 / 共 2 页
字号:

    End;
    IsStart :=false;
//---------------------------show mark if win-------------------------------------
    if(Elementary.Checked) then
        WinnerRange :='First'
    else
        WinnerRange :='Second';
if(not IsShow) then
    if(IsDie ) then
        ShowMessage('you die')
    else
    Begin
        IniFile :=TIniFile.Create(ChangeFileExt(Application.ExeName, '.ini'));
        if ( ( StrToInt( IniFile.ReadString(WinnerRange, 'Mark', '999') ) > Time ) and ( (LeiNum=10) or (LeiNum=40) ) ) then
        Begin
            IniFile.WriteString(WinnerRange, 'Name', InputBox('恭喜恭喜','留下你的大名吧','匿名'));
            IniFile.WriteString(WinnerRange, 'Mark', IntToStr(Time) );
            IniFile.Free;
            if (Form2 =NIL) then
            Begin
                Form2 :=TForm2.Create(Self);

            End;
            Form2.ShowModal;
            FreeAndNIL(Form2);
        End;

    End;
    IsShow :=true;
//-----------------------------------------------------------------------------
// Release---------------------------------------------------------------------
    BitMap.Free();
    Time :=0;
    BackGround.Enabled :=false;
    IsReady :=false;
//------------------------------------------------------------------------------
end;


procedure TForm1.ClearSpace(var x,y :integer);
var
    i, N : Integer;
    BitMap :TBitMap;
    MyRect, OtherRect:TRect;
begin

    MyRect := Rect(x*32,y*32,(x+1)*32,(y+1)*32);
    OtherRect := Rect(0,0,32,32);
    BitMap :=TBitMap.Create;
    BitMap.LoadFromFile('Img/Button2.bmp');
    BackGround.Canvas.CopyRect(MyRect,BitMap.Canvas,OtherRect);
    Leis[x][y].IsShow :=true;
    LeftRect :=LeftRect-1;
    BitMap.Free;
// -----------------------------------------------------------------------------
    for i :=x-1 to x+1 do
    Begin
        for N :=y-1 to y+1 do
        Begin
            if( (i>=0) and (i<=Level-1) and (N>=0) and (N<=Level-1) ) then
            Begin
                if( (not Leis[i][n].IsShow) and not (Leis[i][n].IsMark) and (not Leis[i][n].IsLei) )  then
                    if ( Leis[i][n].Num>0 ) then
                    Begin
                        MyRect := Rect(i*32,n*32,(i+1)*32,(n+1)*32);
                        OtherRect := Rect(0,0,32,32);
                        BitMap :=TBitMap.Create;
                        BitMap.LoadFromFile('Img/Num'+IntToStr(Leis[i][n].Num)+'.bmp');
                        BackGround.Canvas.CopyRect(MyRect,BitMap.Canvas,OtherRect);
                        Leis[i][n].IsShow :=true;
                        LeftRect :=LeftRect-1;
                        BitMap.Free;
                    End
                    else
                    Begin
                        ClearSpace(i,n);
                    End;

            End;
        End;
    End;
// -----------------------------------------------------------------------------
end;

procedure TForm1.InitLeis;
var
    x, y : Integer;
begin
    SetLength(Leis,Level,Level);
    for x :=0 to Level-1 do
        for y :=0 to Level-1 do
        Begin
            Leis[x][y].IsLei :=false;
            Leis[x][y].IsShow :=false;
            Leis[x][y].IsMark :=false;
            Leis[x][y].Num :=0;
        End;

end;

procedure TForm1.InitGround;
var
    Bitmap : TBitMap;
    Row , Column: integer;
    x ,y : integer;

begin
    Bitmap:=TBitMap.Create();
    Bitmap.LoadFromFile('Img/Button1.bmp');
    x :=0;
    y :=0;
    for Row :=1 to Level do
    Begin
        for  Column :=1 to Level do
        Begin
            BackGround.Canvas.Draw(x,y,BitMap);
            y :=y+32;
        End;

       x :=x+32;
       y :=0;


    End;

    Bitmap.Free;
end;

procedure TForm1.MiddleClick(Sender: TObject);
begin


    BackGround.Free;
    BackGround :=TImage.Create(self);
    BackGround.Parent :=Panel3;
    BackGround.Align :=Panel3.Align;
    BackGround.OnMouseDown :=BackGroundMouseDown;
    BackGround.OnMouseUp :=BackGroundMouseUp;
    BackGround.OnDblClick :=BackGroundDblClick;
    Level :=14;
    LeiNum :=40;
    Form1.Width :=32*(Level+1)-20;
    Form1.Height :=32*(Level+2)+Panel2.Height;
    InitGround();
    InitLeis;
    CreateLei;
    SetNum(0,0,0);
    Middle.Checked :=true;
    Elementary.Checked :=false;
    SetLei.Checked :=false;
    LeftRect :=Level*Level;
    SLNum :=LeiNum;
    ShowLeiNum(SLNum);
    IsShow :=false;
    IsStart :=false;
    SetLei.Enabled :=true;
    IsReady :=true;
   // ShowLei;
end;

procedure TForm1.BackGroundMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
StartButton.Glyph.LoadFromFile('Img/SmileyFace.bmp');
end;

procedure TForm1.GameOver;
begin
    ShowLei();
    
end;

procedure TForm1.SetNum( N1,N2,N3:Integer);
begin
    Num1.Picture.LoadFromFile('Img/Num'+IntToStr(N1)+'.bmp');
    Num2.Picture.LoadFromFile('Img/Num'+IntToStr(N2)+'.bmp');
    Num3.Picture.LoadFromFile('Img/Num'+IntToStr(N3)+'.bmp');
end;

procedure TForm1.StartButtonClick(Sender: TObject);
begin
    StartClick(NIL);
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
if(IsFirst) then
    Begin
        ElementaryClick(NIL);
    End ;
    IsFirst :=false;

end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
    FreeAndNil(BackGround);
    Leis :=NIL;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
    N1,N2,N3 : Integer;
begin
    if(IsStart) then
    Begin
        if( Time<999 ) then
            Time :=Time+1
        else
            Time:=0;


        N1 :=Trunc(Time/100);
        N2 :=Trunc( (Time-100*n1)/10);
        N3 :=Trunc(Time-100*N1-10*N2);
        SetNum(N1,N2,N3);
    End;
end;

procedure TForm1.SetLeiClick(Sender: TObject);
begin
    LeiNum :=StrToInt(InputBox('设定雷的数目','雷数:',IntToStr(LeiNum)));
    InitLeis;
    CreateLei;
end;





procedure TForm1.BackGroundDblClick(Sender: TObject);
var
    Pointxy : TPoint;
    x, y : Integer;
    i, N : Integer;
    Shift : TShiftState;
    IsGameOver : bool;
    Counter : Integer;
begin
    IsGameOver :=false;
    Counter :=0;
    GetCursorPos(Pointxy);

    Pointxy :=ScreenToClient(Pointxy);
    x :=Trunc(Pointxy.X/32);
    y :=Trunc((Pointxy.Y-Panel2.Height)/32);

    if ( (Leis[x][y].Num>0) and (Leis[x][y].IsShow) and not Leis[x][y].IsMark and IsStart) then
    Begin
        for i :=x-1 to x+1 do
        Begin
            for N:=y-1 to y+1 do
            Begin
                if( (i>=0) and (i<=Level-1) and (n>=0) and (N<=Level-1) ) then
                Begin
                    if(Leis[i][N].IsMark) then
                        Counter :=Counter+1;
                End;
            End;

        End;
//-----------------------------------------------------------------------------
    if ( Leis[x][y].Num=Counter) then

    for i :=x-1 to x+1 do
    Begin
        for N:=y-1 to y+1 do
        Begin
            if( (i>=0) and (i<=Level-1) and (n>=0) and (N<=Level-1) ) then
            Begin

                if(Leis[i][N].IsLei and not Leis[i][N].IsShow and not Leis[i][n].IsMark) then
                Begin
                    IsGameOver :=true;
                    BackGround.OnMouseDown( NIL, mbLeft, Shift	, i*32, N*32 );
                    break;
                End
                else
                    BackGround.OnMouseDown( NIL, mbLeft, Shift	, i*32, N*32 );
            End;
        End;
        if (IsGameOver) then break;
    End;

    End;

end;

procedure TForm1.StartClick(Sender: TObject);
begin
    if (Elementary.Checked) then
        Elementary.Click()
    else
        Middle.Click();
end;

procedure TForm1.ShowLeiNum(LN : Integer);
var
    L1, L2 : Integer;
begin
    L1 :=Trunc(LN/10);
    L2 :=Trunc(LN-L1*10);

    Lei1.Picture.LoadFromFile('Img/Num' + IntToStr(L1) + '.bmp');
    Lei2.Picture.LoadFromFile('Img/Num' + IntToStr(L2) + '.bmp');

end;

procedure TForm1.MarkClick(Sender: TObject);
begin
    if(Form2=NIL) then
        Form2 :=TForm2.Create(Self);
    Form2.ShowModal;
    FreeAndNIL(Form2);    
end;

procedure TForm1.N7Click(Sender: TObject);
begin
    Form3.ShowModal;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -