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

📄 fangmain.cpp

📁 俄罗斯方块的源程序.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
            }
        return true;
}
//----下面运动函数,控制方块的各种运动---------------------------------------------
void TForm1::NewMove(emMove Xiang,int step)
{
    int TempYang[2][5];
    TPoint pntPos[5];
    for (int i=0;i<=intKuaiCount;i++)
        {
            TempYang[0][i]=intYang[0][i];
            TempYang[1][i]=intYang[1][i];
            pntPos[i].x=FangKuai[i]->Left;
            pntPos[i].y=FangKuai[i]->Top;
        }

    if(Xiang== mvFastDown)//快速向下
    {
        while(NewMove1(mvDown,pntPos,TempYang,1)==100)
        ;
        for (int i=0;i<=intKuaiCount;i++)
              {
                    FangKuai[i]->SetBounds(pntPos[i].x,pntPos[i].y-GetDaXiao,GetDaXiao,GetDaXiao);
              }
        Guan=true;
        return;
    }
    int pk= NewMove1(Xiang,pntPos,TempYang,step);
    if( Xiang<=3  &&  pk==100)
        {
StartMove:    for (int i=0;i<=intKuaiCount;i++)//真正开始运动
              {
                    FangKuai[i]->SetBounds(pntPos[i].x,pntPos[i].y,GetDaXiao,GetDaXiao);
                    intYang[0][i]=TempYang[0][i];
                    intYang[1][i]=TempYang[1][i];
              }
              return;
        }
    if (Xiang==mvRound)
        {
              if (pntPos[2].x<pntPos[pk].x)
              {
                if(NewMove1(mvLeft,pntPos,TempYang,2)==100)goto StartMove;
                return;
              }
              if (pntPos[2].x>pntPos[pk].x)
              {
                if(NewMove1(mvRight,pntPos,TempYang,2)==100)goto StartMove;
                return;
              }
              return;
        }
    if (Xiang==mvDown)Guan=true;
}
//----------------------------------------------------------------------------
void TForm1::KaiShi()
{
    JuShu++;
    timXia->Enabled =false;
    while(Panel1->ControlCount >4)delete Panel1->Controls[4];
    Panel3->Caption ="第 " + AnsiString(JuShu) + " 局";
    YangShi(intYangShi1,intXuan1);
    ChuFangKuai();
}
//----------------------------------------------------------------------------
void TForm1::ReadModel(int intModel)
{
        for(int i=0;i<=intKuaiCount;i++)//读样式数组
        {
            intYang[0][i]= intKuai[intModel][0][i];
            intYang[1][i]= intKuai[intModel][1][i];
        }
}
//----------------------------------------------------------------------------
void __fastcall TForm1::SpeedButton7Click(TObject *Sender)
{
    timXia->Enabled =false;
    while (Panel1->ControlCount >4)delete Panel1->Controls[4];
    blMsgOk=false;
    spbtnLeft->Enabled =false;
    spbtnRound->Enabled =false;
    spbtnRight->Enabled =false;
    spbtnDown->Enabled =false;
    Form2=new TForm2(this);
    Form2->Left=Form1->Left;
    Form2->Top=Form1->Top+100;
    Form2->ShowModal();
    delete Form2;
}
//---------控制运动的四个按钮的公用句柄-------------------------------
void __fastcall TForm1::MoveKeyDown(TObject *Sender, TMouseButton Button,
      TShiftState Shift, int X, int Y)
{
    switch (((TSpeedButton *)Sender)->Tag)
    {
      case 0:NewMove(mvLeft) ;
      break;
      case 1:NewMove(mvRight) ;
      break;
      case 2:
      {
            if (Button==mbRight)NewMove(mvFastDown);
            else  NewMove(mvDown) ;
      }
      break;
      case 3:NewMove(mvRound) ;
      break;
    }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SpeedButton8Click(TObject *Sender)
{
    Close();    
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SpeedButton6Click(TObject *Sender)
{
        static bool blPause;
        timXia->Enabled =blPause;
        if (blPause)SpeedButton6->Caption ="暂 停(&P)";
        else SpeedButton6->Caption ="继 续(&P)";
        blPause=!blPause;
}
//-------------下面函数检查方块是否达到规定的上限--------------------------------------------------------------
bool TForm1::JianCha1()
{
    TPoint pntStop;
    pntStop.x=StartPosX +0.5*GetDaXiao;
    pntStop.y=95;
    for (int i=0;i<(KUAN/GetDaXiao);i++)
    {
        if (Panel1->ControlAtPos (pntStop,1,0)!=NULL)return true;
        pntStop.x=pntStop.x+GetDaXiao;
    }
    return false;
}
//----------下面函数判断是否能进行某种运动,由运动函数调用-----------------
int TForm1::NewMove1(emMove Xiang1, TPoint pntPos[5],int TempYang[2][5],int step)
{
    TPoint pntPan[5];
    switch (Xiang1)
    {
      case mvLeft:
      {
         for (int i=0;i<=intKuaiCount;i++)
            pntPos[i].x=pntPos[i].x-step*GetDaXiao;
      }
      break;
      case mvRight:
      {
         for (int i=0;i<=intKuaiCount;i++)
            pntPos[i].x=pntPos[i].x+step*GetDaXiao;
      }
      break;
      case mvDown:
      {
         for (int i=0;i<=intKuaiCount;i++)
            pntPos[i].y=pntPos[i].y+GetDaXiao;
      }
      break;
      case mvRound:
      {
         Xuan(TempYang);
         for (int i=0;i<=intKuaiCount;i++)
         {
            pntPos[i].x=pntPos[2].x+TempYang[0][i]*GetDaXiao;
            pntPos[i].y=pntPos[2].y+TempYang[1][i]*GetDaXiao;
         }
      }
      break;
    }
    for (int i=0;i<=intKuaiCount;i++)
        {
              pntPan[i].x=pntPos[i].x+0.5*GetDaXiao;
              pntPan[i].y=pntPos[i].y+0.5*GetDaXiao;
              if ( Panel1->ControlAtPos(pntPan[i],1,0)!=NULL && Panel1->ControlAtPos(pntPan[i],1,0)->Tag==9)
              return i;
        }
    return 100;
}
//---------------下面把选项从注册表中读出------------------------------
void __fastcall TForm1::FormShow(TObject *Sender)
{
    int i1,i2,i3,i4,i5,i6,i7,i8,i9;
    GetBackColor=clBackground;
    MyReg=new TRegistry;
    MyReg->RootKey =HKEY_LOCAL_MACHINE;
    MyReg->OpenKey("SOFTWARE\\FangKuai\\Option",true);
    try//这段代码在调试环境中会显示错误,但在实际运行中会很正常运行
    {
        i1=MyReg->ReadInteger ("intKuaiCount");
        i2=MyReg->ReadInteger ("GetKuaiCount");
        i3=MyReg->ReadInteger ("clBrushKuai");
        i4=MyReg->ReadInteger ("clBrushKuai1");
        i5=MyReg->ReadInteger ("clPenKuai");
        i6=MyReg->ReadInteger ("LetJiBie");
        i7=MyReg->ReadInteger ("GetDaXiao");
        i8=MyReg->ReadBool    ("GetKuaiColor");
        i9=MyReg->ReadInteger ("GetBackColor");
        intKuaiCount=i1;
        GetKuaiCount=i2;
        clBrushKuai=i3;
        clBrushKuai1=i4;
        clPenKuai= i5;
        LetJiBie=i6;
        GetDaXiao=i7;
        GetKuaiColor=i8;
        GetBackColor=i9;
    }
    catch(...){}
    Form1->timXia->Interval =440-LetJiBie*40;
    Panel1->Color =GetBackColor;
}
//--------------------下面把选项写入注册表-------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
    MyReg->WriteInteger("intKuaiCount" ,intKuaiCount);
    MyReg->WriteBool ("GetKuaiColor" ,GetKuaiColor);
    MyReg->WriteInteger("GetKuaiCount",GetKuaiCount );
    MyReg->WriteInteger("clBrushKuai",clBrushKuai );
    MyReg->WriteInteger("clBrushKuai1" ,clBrushKuai1);
    MyReg->WriteInteger("clPenKuai",clPenKuai );
    MyReg->WriteInteger("LetJiBie",LetJiBie );
    MyReg->WriteInteger("GetDaXiao",GetDaXiao );
    MyReg->WriteInteger("GetBackColor",GetBackColor );
    MyReg->Free ();
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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