www.pudn.com > SingleNumber.rar > Unit1.cpp
//--------------------------------------------------------------------------- #include#pragma hdrstop #include "Unit1.h" #include "Unit2.h" #include "Unit3.h" #include "Unit4.h" #include "String.h" TDateTime DateTime; String str,str1=""; AnsiString str2; Boolean tf; int p,q,kz=0,mu=-1,x=0,v=0,z=0; int cc=0; TImage *TIN[9]; //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { int i,j,k; for(i=0;i<9;i++) { for(j=0;j<9;j++) { SN[i][j]=new TPanel(this); SN[i][j]->Parent=this; SN[i][j]->Width=47; SN[i][j]->Height=47; if(i==0) { SN[i][j]->Left=-44; SN[i][j]->Top=2; } else { SN[i][j]->Top=SN[0][0]->Top+i*53; } SN[i][j]->Left=-44; SN[i][j]->Font->Size=24; SN[i][j]->Visible=true; TM[i][j]=new TMemo(this); TM[i][j]->Parent=this; TM[i][j]->Width=47; TM[i][j]->Height=47; if(i==0) { TM[i][j]->Left=4; TM[i][j]->Top=2; } else { TM[i][j]->Top=2+i*53; } TM[i][j]->Left=4+j*53; TM[i][j]->Alignment=taCenter; TM[i][j]->Visible=false; TM[i][j]->MaxLength=9; TM[i][j]->Font->Size=24; TM[i][j]->OnKeyUp=MyKeyUp; int u=0; TI[i][j]=new TImage(SN[i][j]); TI[i][j]->Parent=SN[i][j]; TI[i][j]->Height=47; TI[i][j]->Width=47; str2=".\\"+IntToStr(u) + ".jpg"; TI[i][j]->Picture->LoadFromFile(str2); } } randomize(); q=random(3)+1; long lRt=GetWindowLong(Handle,GWL_EXSTYLE); lRt=lRt|WS_EX_LAYERED; SetWindowLong(Handle,GWL_EXSTYLE,lRt); SetLayeredWindowAttributes(Handle,clBlue,0,LWA_ALPHA); } //--------------------------------------------------------------------------- void __fastcall TForm1::DeleteAllCB(void) { int i,j; for(i=0;i<9;i++) for(j=0;j<9;j++) { SN[i][j]->Visible=true; TM[i][j]->Visible=false; SN[i][j]->Caption=""; } } //--------------------------------------------------------------------------- void __fastcall TForm1::N2Click(TObject *Sender) { tf=true; Create(50); str1=""; str1="新人"; } //--------------------------------------------------------------------------- void __fastcall TForm1::chuti(int n) { int n1; int a[9][9]={9,6,3,1,7,4,2,5,8,1,7,8,3,2,5,6,4,9,2,5,4,6,8,9,7,3,1,8,2,1,4,3,7,5,9,6,4,9,6,8,5,2,3,1,7,7,3,5,9,6,1,8,2,4,5,8,9,7,1,3,4,6,2,3,1,7,2,4,6,9,8,5,6,4,2,5,9,8,1,7,3}; k=0; p=0; randomize(); x=random(9); y=random(9); i=x/3*3; for(j=0;j<9;j++) { temp=a[i][j]; a[i][j]=a[i+x%2+1][j]; a[i+x%2+1][j]=temp; } i=y/3*3; for(j=0;j<9;j++) { temp=a[j][i]; a[j][i]=a[j][i+y%2+1]; a[j][i+y%2+1]=temp; } n1=random(2); if(n1*3==x/3)n1++; n1=n1*3; for(i=x/3*3;i<=x/3*3+2;i++,n1++) { for(j=0;j<9;j++) { temp=a[i][j]; a[i][j]=a[n1][j]; a[n1][j]=temp; } } n1=random(2); if(n1*3==x/3)n1++; n1=n1*3; for(i=y/3*3;i<=y/3*3+2;i++,n1++) { for(j=0;j<9;j++) { temp=a[j][i]; a[j][i]=a[j][n1]; a[j][n1]=temp; } } while(k Visible=false; TM[i][j]->Visible=true; } if(SN[i][j]->Visible==true) { str2=".\\"+IntToStr(a[i][j]) + ".jpg"; TI[i][j]->Picture->LoadFromFile(str2); } SN[i][j]->Caption=a[i][j]; TM[i][j]->Text=""; TM[i][j]->Color=clWindow; } while(SN[x][y]->Visible==false) { x=random(9); y=random(9); } k++; } if(p==0) { DateTime=0; p++; } } //--------------------------------------------------------------------------- void __fastcall TForm1::Create(int m) { int n; DeleteAllCB(); randomize(); x=random(9); y=random(9); n=random(11)+m; chuti(n); } //--------------------------------------------------------------------------- void __fastcall TForm1::N3Click(TObject *Sender) { tf=true; Create(55); str1=""; str1="大侠"; } //--------------------------------------------------------------------------- void __fastcall TForm1::N4Click(TObject *Sender) { tf=true; Create(60); str1=""; str1="大师"; } //--------------------------------------------------------------------------- void __fastcall TForm1::N5Click(TObject *Sender) { for(i=0;i<9;i++) for(j=0;j<9;j++) { if(SN[i][j]->Visible==false) { TM[i][j]->Visible=true; } TM[i][j]->Text=""; TM[i][j]->Color=clWindow; } p=1; DateTime=0; tf=true; } //--------------------------------------------------------------------------- void __fastcall TForm1::N10Click(TObject *Sender) { int a[9][9]; //Form3->Label1->Caption =""; if(p==1||tf==true) { for(i=0;i<9;i++) { for(j=0;j<9;j++) { if(SN[i][j]->Visible==false) { try { TM[i][j]->Color=clWindow; int b=TM[i][j]->GetTextLen(); if(TM[i][j]->Text==""||b>1) { a[i][j]=0; TM[i][j]->Color=clRed; } else a[i][j]=StrToInt(TM[i][j]->Text); } catch(...) { TM[i][j]->Color=clRed; } } else a[i][j]=StrToInt(SN[i][j]->Caption); } } for(i=0;i<9;i++) { for(j=0;j<9;j++) { if(TM[i][j]->Visible==true) { for(x=0;x<9;x++) { if(j!=x&&a[i][j]==a[i][x])TM[i][j]->Color=clRed; if(i!=x&&a[i][j]==a[x][j])TM[i][j]->Color=clRed; } for(x=i/3*3;xColor=clRed; if(x!=i&&a[i][j]==a[x][y])TM[i][j]->Color=clRed; } } } } } try { for(i=0;i<9;i++) { for(j=0;j<9;j++) { if(TM[i][j]->Color==clRed) { //Form3->Label1->Caption =" 答案错误\n你可以继续玩或重新玩"; ShowMessage("答案错误!"); break; } if(i==8&&j==8&&p==1) { try { Form4->Show(); Form4->Height=247; Form4->Width=345; Form4->Visible=false; AnsiString NewStr; InputQuery("Name","请输入你的大名 ",NewStr); if(NewStr=="") NewStr=str1; Form4->ADOQuery1->Insert(); Form4->ADOQuery1->FieldValues["Name"]=NewStr; Form4->ADOQuery1->FieldValues["Time"]=this->Label1->Caption; Form4->ADOQuery1->FieldValues["Rank"]=str1; String date=FormatDateTime("yyyymmdd",Date()); Form4->ADOQuery1->FieldValues["Date"]=date; Form4->ADOQuery1->Post(); Form4->Visible=true; } catch(...) { } } } if(TM[i][j]->Color==clRed)break; } } catch(...) { } if(p==1) { p++; if(this->Label1->Caption=="") { this->Label1->Caption=" 00:00:00 "; str=" 00:00:00 "; } //Form3->Label1->Caption=Form3->Label1->Caption+"\n "+str; //Form3->Show(); } } } //--------------------------------------------------------------------------- void __fastcall TForm1::N11Click(TObject *Sender) { for(i=0;i<9;i++) for(j=0;j<9;j++) { if(SN[i][j]->Visible==false)TM[i][j]->Text=SN[i][j]->Caption; TM[i][j]->Color=clAqua; TM[i][j]->Font->Size=24; } p=3; tf=false; } //--------------------------------------------------------------------------- void __fastcall TForm1::MyKeyUp(TObject *Sender, WORD &Key, TShiftState Shift) { int p,q; for(i=0;i<9;i++) { for(j=0;j<9;j++) { if(TM[i][j]->Focused()) { p=i;q=j; break; } } } int g = TM[p][q]->GetTextLen(); if(g>1) { TM[p][q]->Font->Size=11; } else { TM[p][q]->Font->Size=24; } } //--------------------------------------------------------------------------- void __fastcall TForm1::Timer4Timer(TObject *Sender) { if(v<9) { if(SN[x][v]->Left<4+v*53) { if((this->SN[x][0]->Left+v*53-this->SN[x][v]->Left)>40) { for(int i=0;i<9;i++) { this->SN[i][v]->Left+=40; } } else if((4+v*53-this->SN[x][v]->Left)>30) { for(int i=0;i<9;i++) { this->SN[i][v]->Left+=30; } } else if((4+v*53-this->SN[x][v]->Left)>20) { for(int i=0;i<9;i++) { this->SN[i][v]->Left+=20; } } else if((4+v*53-this->SN[x][v]->Left)>10) { for(int i=0;i<9;i++) { this->SN[i][v]->Left+=10; } } else if((4+v*53-this->SN[x][v]->Left)>0) { for(int i=0;i<9;i++) { this->SN[i][v]->Left+=1; } } } else v++; } else if(v==9&&N1->Enabled!=true) { N1->Enabled=true; N7->Enabled=true; N8->Enabled=true; N13->Enabled=true; } } //--------------------------------------------------------------------------- void __fastcall TForm1::Timer3Timer(TObject *Sender) { this->Timer3->Interval=5; if(cc<=240) { cc+=5; long lRt=GetWindowLong(Handle,GWL_EXSTYLE); lRt=lRt|WS_EX_LAYERED; SetWindowLong(Handle,GWL_EXSTYLE,lRt); SetLayeredWindowAttributes(Handle,clBlue,cc,LWA_ALPHA); } } //--------------------------------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender) { Timer1->Interval = 1000; if(p==1) { DateTime += 0.000011574074074074074074; str =TimeToStr(DateTime); this->Label1->Caption=str; } } //--------------------------------------------------------------------------- void __fastcall TForm1::Xsm1Click(TObject *Sender) { TForm3 *wnd; wnd=new TForm3(Application); wnd->Left=224; wnd->Top=164; wnd->Height=264; wnd->Width=364; wnd->Show(); } //--------------------------------------------------------------------------- void __fastcall TForm1::N12Click(TObject *Sender) { TForm4 *wnd; wnd=new TForm4(Application); wnd->Left=251; wnd->Top=221; wnd->Height=247; wnd->Width=345; wnd->Show(); } //--------------------------------------------------------------------------- void __fastcall TForm1::N6Click(TObject *Sender) { this->Close(); } //--------------------------------------------------------------------------- void __fastcall TForm1::Letsgo1Click(TObject *Sender) { TForm2 *wnd; wnd=new TForm2(Application); wnd->Left=251; wnd->Top=221; wnd->Height=327; wnd->Width=361; wnd->Show(); } //---------------------------------------------------------------------------