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

📄 unit1.cpp

📁 一个彩票模拟程序
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include "dos.h"
#include "stdlib.h"
#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TComboBox **Choice;
TForm1 *Form1;
int ItemCounter=0;
int ChoiceCounter=0;
int Counter=0;
int Click_flag=1;
int TimeCounter=0;
int Times_Counter=0;
AnsiString ChoiceNumber="";
AnsiString container="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ComboBox1Change(TObject *Sender)
{
  char a;
  int i,j;
  if (ComboBox1->ItemIndex==0)
  {
    for (j=0;j<7;j++)
    {
      Choice[j]->Items->Clear();
      for (i=0;i<10;i++)
      Choice[j]->Items->Add(IntToStr(i));
    }
    Label7->Caption="0123456789";
  }
  else
  {
    for (j=0;j<7;j++)
    {
    Choice[j]->Items->Clear();
    for (i=0;i<10;i++)
    Choice[j]->Items->Add(IntToStr(i));
    for (a='A';a!=91;a++)
    Choice[j]->Items->Add(a);
    }
    Label7->Caption="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  }
  for (j=0;j<7;j++)
  {
    Choice[j]->ItemIndex=0;
  }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  int i,j;
  Choice=new TComboBox*[7];
  for(i=0;i<7;i++)
  {
    Choice[i]=new TComboBox(this);
    Choice[i]->Left=8+i*56;
    Choice[i]->Top=80;
    Choice[i]->Width=41;
    Choice[i]->Height=21;
    Choice[i]->Parent=this;
    Choice[i]->Style=csDropDownList;
  }
  for (j=0;j<7;j++)
  {
    Choice[j]->Items->Clear();
    for (i=0;i<10;i++)
     Choice[j]->Items->Add(IntToStr(i));
  }
    for (j=0;j<7;j++)
  {
    Choice[j]->ItemIndex=0;
  }
  Label7->Caption="0123456789";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  int i,j,flag=0;
  char cha;
  AnsiString str="";
  if (ComboBox1->ItemIndex==1)
  {
   for (i=0;i<7;i++)
   {
    cha=getchoice(Choice[i]->ItemIndex);
    for (j=1;j<=str.Length();j++)
      if (str[j]==cha)
        flag=1;
    str+=cha;
    str+=" ";
   }
  }
  else
  for (i=0;i<7;i++)
      str+=IntToStr(Choice[i]->ItemIndex)+" ";
  
  if (ItemCounter==3)
  Application->MessageBox("对不起,您最多只能选择3组号码!","注意",MB_OK);
  else
  {
    if(!flag)
    {
      ItemCounter++;
      ListBox1->Items->Add(str);
    }
    else if (ComboBox1->ItemIndex==1)
  Application->MessageBox("对不起,在福彩模式下不容许出现相同的号码!","注意",MB_OK);
  }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
  if (ItemCounter==0)
    ShowMessage("列表框中没有号码可以删除!");
  else
  {
    ListBox1->Items->Delete(ItemCounter-1);
    ItemCounter--;
  }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
  if (Counter<7)
  {
    if (Click_flag==1)
    {
     Click_flag=0;
     Button3->Caption="停止";
     Timer1->Enabled=true;
     ChoiceNumber+=Label3->Caption;
    }
    else if (Click_flag==0)
    {
     Click_flag=1;
     Button3->Caption="请摇第"+IntToStr(Counter+2)+"个号码";
     if (Counter==6)
     Button3->Caption="再来一次";
     Timer1->Enabled=false;
     Counter++;
     ChoiceNumber=Label4->Caption;
     ChoiceNumber+=Label3->Caption;
     Label4->Caption=ChoiceNumber;
     if (ComboBox1->ItemIndex==1)
     {
       container.Delete(ChoiceCounter+1,1);
       Label7->Caption=container;
     }
     else Label7->Caption="0123456789";
    }
  }
  else
  {
     Button3->Caption="请摇第1个号码";
     Counter=0;
     if (ComboBox1->ItemIndex==1)
     {
       container="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
       Label7->Caption=container;
     }
     else Label7->Caption="0123456789";
     ChoiceNumber=Label4->Caption;
     Label4->Caption="";
  }

}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
   AnsiString str;
   ChoiceCounter++;
   if (ComboBox1->ItemIndex==1)
   {
      if (ChoiceCounter==container.Length())
      ChoiceCounter=0;
      str=container[ChoiceCounter+1];
      Label3->Caption=str;
      Times_Counter++;
   }
   else
   {
     if (ChoiceCounter==10)
        ChoiceCounter=0;
     Label3->Caption=IntToStr(ChoiceCounter);
   }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ComboBox2Change(TObject *Sender)
{
  if (ComboBox2->ItemIndex==0)
  {
   Button3->Visible=true;
   Button4->Visible=false;
  }
  else
  {
   Button3->Visible=false;
   Button4->Visible=true;
  }
  Counter=0;
  Label4->Caption="";
  if (ComboBox1->ItemIndex==1)
  {
    container="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    Label7->Caption=container;
  }
  else Label7->Caption="0123456789";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
   struct time seed_time;
   gettime(&seed_time);
   srand(seed_time.ti_hund);
   TimeCounter=random(100)+1;
    if(Counter!=7)
    {
       Timer2->Enabled=true;
       Button4->Visible=false;
       if (Counter==0)
       Label4->Caption="";
    }
    else
    {
      Counter=0;
      Button4->Visible=True;
      Button4->Caption="重新开始";
      if (ComboBox1->ItemIndex==1)
      {
        container="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
      }
      else Label7->Caption="0123456789";
    }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer2Timer(TObject *Sender)
{
    if (TimeCounter<=0)
    {
       Timer1->Enabled=false;
       Timer2->Enabled=false;
       ChoiceNumber=Label4->Caption;
       ChoiceNumber+=Label3->Caption;
       Label4->Caption=ChoiceNumber;
       if (ComboBox1->ItemIndex==1)
       {
        container.Delete(ChoiceCounter+1,1);
        Label7->Caption=container;
       }
       else Label7->Caption="0123456789";
       Counter++;
       Button4Click(Sender);
    }
    else
    {
      TimeCounter--;
      Timer1->Enabled=true;
    }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCloseQuery(TObject *Sender, bool &CanClose)
{
  for(int i=0;i<7;i++)delete Choice[i];
  delete[]Choice;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N3Click(TObject *Sender)
{
  Form2->Show();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::N2Click(TObject *Sender)
{
  WinExec("notepad data.dat",SW_SHOWNORMAL);  
}
//---------------------------------------------------------------------------


⌨️ 快捷键说明

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