delphi 怎么做一个转盘抽奖的程序?
delphi 如何做一个转盘抽奖的程序??
求高手搞个思路 或者直接上码
------解决方案--------------------
转盘应能够生成一个号码,生成的号码的每一位都是一个从0—9之间的数字,可使用随机的方法生成,Random函数可以返回一个指定范围的数值,再设计一个数据库存储已经生成的号码,避免产生重复。
------解决方案--------------------
转盘是假的,最后人POST发包才是最主要的
------解决方案--------------------
新建一个工程,复制下列代码,覆盖你的 unit1 的所有内容、然后在属性管理器分别关联窗体的 OnCreate、OnCloseQuery 事件。
求高手搞个思路 或者直接上码
------解决方案--------------------
转盘应能够生成一个号码,生成的号码的每一位都是一个从0—9之间的数字,可使用随机的方法生成,Random函数可以返回一个指定范围的数值,再设计一个数据库存储已经生成的号码,避免产生重复。
------解决方案--------------------
转盘是假的,最后人POST发包才是最主要的
------解决方案--------------------
新建一个工程,复制下列代码,覆盖你的 unit1 的所有内容、然后在属性管理器分别关联窗体的 OnCreate、OnCloseQuery 事件。
- Delphi(Pascal) code
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Pies, StdCtrls, ExtCtrls, ComCtrls, Spin; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); private { Private declarations } procedure ButtonClick(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure Timer2Timer(Sender: TObject); public { Public declarations } end; var Form1: TForm1; {本工程需要使用 Tpie 组件,如没安装,须先在 delphi 主菜单 Tools、Environment Options 添加路径: C:\Program Files\Borland\Delphi7\Demos\PropEdit,并在该位置打开 pielib.dpk、编译和安装, Tpie 控件是安装在 控件 Samples 组。(delphi6、7 自带 demo 中,均有此控件)} implementation var pie:array[0..10] of TPie; ColorBox:TColorBox; xCount,rCount,aCount,Flicker,frequency:integer; lab:array[0..9]of TLabel; labl:TLabel; Button:TButton; Memo:TMemo; StatusBar:TStatusBar; CheckBox:TCheckBox; SpinEdit:TSpinEdit; Timer1,Timer2:TTimer; {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); const lab_T:array[0..9]of integer=(24,50,109,185,249,274,251,185,109,50); lab_L:array[0..9]of integer=(166,240,288,288,240,166,88,43,43,88); var i:integer; begin Color:=clWindow; Width:=506; Height:=400; Position:=poScreenCenter; Caption:='轮盘抽奖'; ColorBox:=TColorBox.Create(self); ColorBox.Parent:=Form1; for i:=0 to 10 do begin pie[i]:=Tpie.Create(self); pie[i].Parent:=form1; pie[i].Brush.Color:=ColorBox.Colors[i]; pie[i].Left:=28; pie[i].Top:=28; pie[i].Height:=300; pie[i].Width:=300; pie[i].Angles.EndAngle:=i*36+36; pie[i].Angles.StartAngle:=i*36; pie[i].Pen.Style:=psClear; end; pie[10].Angles.EndAngle:=2*36+36; pie[10].Angles.StartAngle:=2*36; ColorBox.Free; Form1.DoubleBuffered:=true; for i:=0 to 9 do begin lab[i]:=TLabel.Create(self); lab[i].Parent:=Form1; lab[i].Caption:=inttostr(i); lab[i].Left:=lab_L[i]; lab[i].Top:=lab_T[i]; lab[i].Font.Color:=clWindow; lab[i].Font.Size:=36; lab[i].Transparent:=true; lab[i].BringToFront; end; xCount:=2; rCount:=0; frequency:=1; Button:=TButton.Create(self); Button.Parent:=Form1; Button.Left:=260; Button.Top:=315; Button.OnClick:=ButtonClick; Button.Caption:='第 1 次'; Memo:=TMemo.Create(self); Memo.Parent:=Form1; Memo.ReadOnly:=true; Memo.Width:=146; Memo.Align:=alRight; Memo.Lines.Append('抽奖结果:'); Memo.Ctl3D:=false; StatusBar:=TStatusBar.Create(self); StatusBar.Parent:=Form1; StatusBar.Panels.Add; StatusBar.Panels[0].Width:=60; StatusBar.Panels[0].Text:='中奖号码:'; for i:=1 to 14 do begin StatusBar.Panels.Add; StatusBar.Panels[i].Width:=12; end; StatusBar.Panels.Add; StatusBar.Panels[15].Width:=32; StatusBar.Panels.Add; StatusBar.Panels[16].Text:='中国软件研发联盟QQ群122058606 广州佬'; CheckBox:=TCheckBox.Create(self); CheckBox.Parent:=Form1; CheckBox.Width:=65; CheckBox.Caption:='逐次抽'; CheckBox.Checked:=true; CheckBox.Top:=300; CheckBox.Left:=10; labl:=TLabel.Create(self); labl.Parent:=Form1; labl.Caption:='号码个数:'; labl.Left:=10; labl.Top:=326; SpinEdit:=TSpinEdit.Create(self); SpinEdit.Parent:=Form1; SpinEdit.Top:=320; SpinEdit.Left:=76; SpinEdit.Width:=42; SpinEdit.Value:=6; SpinEdit.MaxValue:=13; SpinEdit.MinValue:=1; Timer1:=TTimer.Create(self); Timer1.Enabled:=false; Timer1.OnTimer:=Timer1Timer; Timer2:=TTimer.Create(self); Timer2.Enabled:=false; Timer2.OnTimer:=Timer2Timer; Timer2.Interval:=90; end; procedure TForm1.ButtonClick(Sender: TObject); begin Button.Enabled:=false; Timer1.Interval:=100; Flicker:=0; rCount:=0; Randomize; aCount:=Random(10); Timer1.Enabled:=true; end; procedure TForm1.Timer1Timer(Sender: TObject); var i:integer; begin xCount:=(10+xCount-1)mod 10; pie[10].Angles.EndAngle:=xCount*36+36; pie[10].Angles.StartAngle:=xCount*36; for i:=0 to 9 do lab[i].Font.Color:=clWindow; lab[(12-xCount)mod 10].Font.Color:=clYellow; if rCount<20+aCount then inc(rCount) else begin Randomize; if Random(10)<2 then begin if Timer1.Interval<1000 then Timer1.Interval:=Timer1.Interval+200 else begin Timer1.Enabled:=false; Timer2.Enabled:=true; end; end; end; end; procedure TForm1.Timer2Timer(Sender: TObject); var i:integer; s:string; begin if Flicker<10 then begin pie[10].Visible:=not pie[10].Visible; inc(Flicker); end else begin Timer2.Enabled:=false; StatusBar.Panels[frequency].Text:=Lab[(12-xCount)mod 10].Caption; Button.Enabled:=true; xCount:=2; pie[10].Angles.EndAngle:=xCount*36+36; pie[10].Angles.StartAngle:=xCount*36; if frequency>SpinEdit.Value-1 then begin for i:=1 to SpinEdit.Value do s:=s+StatusBar.Panels[i].Text; showmessage('本轮抽奖结果是:“'+s+'”'); memo.Lines.Append('第 '+inttostr(memo.Lines.Count)+' 轮:'+s); for i:=0 to 9 do lab[i].Font.Color:=clWindow; Button.Caption:='第 1 次'; for i:=1 to SpinEdit.Value do StatusBar.Panels[i].Text:='';; frequency:=1; end else begin inc(frequency); Button.Caption:='第 '+inttostr(frequency)+' 次'; if not CheckBox.Checked then Button.Click; end; end; end; procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); var i:integer; begin for i:=0 to 9 do begin lab[i].Free; pie[i].Free; end; pie[10].Free; labl.Free; Button.Free; Memo.Free; StatusBar.Free; CheckBox.Free; SpinEdit.Free; Timer1.Free; Timer2.Free; end; end.