16,748
社区成员
发帖
与我相关
我的任务
分享
var
i: Integer;
str: string;
begin
Randomize;
str := '';
for i := 1 to 8 do
Str := str+IntToStr(Random(9));
Label1.Caption := str;
end;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure ButtonClick(Sender: TObject);
procedure TimerTimer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
const FontSize=32;
h=48;
w=21;
var Image:TImage;
Button:TButton;
Timer:TTimer;
zj,xh:array[0..3] of Integer;
stop:array[0..3] of Boolean;
Panel:TPanel;
Memo:TMemo;
cvs:TCanvas;
PnlRct,ImageRct:TRect;
logo:Boolean;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var i:Integer;
Pt:TPoint;
begin
Form1.Position:=poScreenCenter;
Form1.Caption:='滚动抽奖';
Form1.Height:=480;
Form1.Width:=190;
Form1.DoubleBuffered:=true;
Form1.OnCloseQuery:=FormCloseQuery;
Panel:=TPanel.Create(self);
Panel.Parent:=Form1;
Panel.Height:=130;
Panel.Align:=alBottom;
Panel.Color:=clSkyBlue;
Memo:=TMemo.Create(self);
Memo.Parent:=Form1;
Memo.ReadOnly:=true;
Memo.Align:=alClient;
Image.Free;
Image:=TImage.Create(self);
Image.Width:=w;
Image.Height:=550;
Image.Canvas.Font.Size:=FontSize;
Image.Canvas.Font.Color:=clLime;
Image.Canvas.Brush.Color:=clNavy;
for i:=0 to 9 do Image.Canvas.TextOut(0,i*h+1+i*2,inttostr(i));
Image.Canvas.TextOut(0,501,'0');
cvs:=TCanvas.Create;
cvs.Handle:=GetDC(Panel.Handle);
Pt.X:=0;
PT.Y:=0;
ImageRct.TopLeft:=Pt;
PnlRct.TopLeft:=Pt;
Pt.X:=21;
PT.Y:=50;
ImageRct.BottomRight:=Pt;
PnlRct.BottomRight:=Pt;
PnlRct.Top:=18;
PnlRct.Bottom:=68;
Button:=TButton.Create(self);
Button.Parent:=Panel;
Button.Top:=90;
Button.Left:=55;
Button.Caption:='开始';
logo:=true;
Button.OnClick:=ButtonClick;
Timer:=TTimer.Create(self);
Timer.Interval:=1;
Timer.OnTimer:=TimerTimer;
Timer.Enabled:=true;
end;
procedure TForm1.TimerTimer(Sender: TObject);
var i:integer;
s:string;
begin
if logo then
begin
Timer.Enabled:=false;
logo:=false;
cvs.Brush.Color:=clNavy;
cvs.Font.Size:=FontSize;
cvs.Font.Color:=clLime;
for i:=0 to 3 do cvs.TextOut(i*42+18,w,'0');//初始化4个数码为0
exit;
end;
for i:=0 to 3 do
begin
//将要显示的图片:
ImageRct.Top:=xh[i]+1;
ImageRct.Bottom:=xh[i]+49;
//显示的位置:
PnlRct.Left:=i*42+18;
PnlRct.Right:=i*42+39;
//取图显示:
cvs.CopyRect(PnlRct,Image.Canvas,ImageRct);
if not Button.Enabled and (xh[i]/50=zj[i]) then stop[i]:=false//按停止后,显示与抽奖数相符,设置标志
else xh[i]:=(xh[i]+10) mod 500; //下次取图片的位置
end;
Timer.Enabled:=stop[0] or stop[1] or stop[2] or stop[3];//所有标志为假就停止计时
if not Timer.Enabled then //抽奖终了
begin
for i:=0 to 3 do s:=s+inttostr(zj[i]);
if pos(s,Memo.Text)>0 then Memo.Lines.Append('第 '+inttostr(Memo.Lines.Count+1)+' 轮抽出重复号:'+s)
else Memo.Lines.Append('第 '+inttostr(Memo.Lines.Count+1)+' 轮抽出中奖号:'+s);
Button.Caption:='开始';
Button.Enabled:=true;
end
else if (not Button.Enabled) then Timer.Interval:=Timer.Interval+5;//如果按了停止键,就让滚动速度逐步变慢
end;
procedure TForm1.ButtonClick(Sender: TObject);
var i:integer;
begin
if Button.Caption='开始' then
begin
Button.Caption:='停止';
Randomize;
for i:=0 to 3 do
begin
zj[i]:=Random(10);
xh[i]:=(xh[i]+60*Random(10)) mod (500);
if zj[i]<0 then showmessage('fsdf');
stop[i]:=true;
end;
Timer.Interval:=30;
Timer.Enabled:=true;
end
else Button.Enabled:=false;
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
Image.Free;
Button.Free;
Timer.Free;;
Panel.Free;
Memo.Free;
cvs.Free;
end;
end.
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var i:integer;
begin
Image.Free;
for i:=0 to 3 do bmp[i].Free;
Button.Free;
Timer.Free;;
Panel.Free;
Memo.Free;
end;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure ButtonClick(Sender: TObject);
procedure TimerTimer(Sender: TObject);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
const FontSize=32;
h=48;
w=21;
var Image:TImage;
bmp:array [0..3]of TImage;
Button:TButton;
Timer:TTimer;
xh:array[0..3] of Integer;
tz:array[0..3] of Boolean;
stop:array[0..3] of Boolean;
Panel:TPanel;
Memo:TMemo;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var i:Integer;
begin
Form1.Position:=poScreenCenter;
Form1.Caption:='滚动抽奖';
Form1.Height:=480;
Form1.Width:=190;
Form1.DoubleBuffered:=true;
Panel:=TPanel.Create(self);
Panel.Parent:=Form1;
Panel.Height:=130;
Panel.Align:=alBottom;
Panel.Color:=clSkyBlue;
Memo:=TMemo.Create(self);
Memo.Parent:=Form1;
Memo.ReadOnly:=true;
Memo.Align:=alClient;
Image.Free;
Image:=TImage.Create(self);
Image.Width:=w;
Image.Height:=550;
Image.Canvas.Font.Size:=FontSize;
Image.Canvas.Font.Color:=clLime;
Image.Canvas.Brush.Color:=clNavy;
for i:=0 to 9 do Image.Canvas.TextOut(0,i*h+1+i*2,inttostr(i));
Image.Canvas.TextOut(0,501,'0');
for i:=0 to 3 do
begin
bmp[i]:=TImage.Create(self);
bmp[i].Parent:=Panel;
bmp[i].Width:=w;
bmp[i].Height:=h;
bmp[i].Top:=w;
bmp[i].Left:=i*42+w;
bmp[i].Canvas.Font.Size:=FontSize;
bmp[i].Canvas.Brush.Color:=clNavy;
bmp[i].Canvas.Font.Color:=clLime;
bmp[i].Canvas.TextOut(0,0,'0');
end;
Button:=TButton.Create(self);
Button.Parent:=Panel;
Button.Top:=90;
Button.Left:=55;
Button.Caption:='开始';
Button.OnClick:=ButtonClick;
Timer:=TTimer.Create(self);
Timer.Enabled:=false;
Timer.OnTimer:=TimerTimer;
end;
procedure TForm1.TimerTimer(Sender: TObject);
var Rct:TRect;
i,rdm:integer;
s:string;
begin
rdm:=2;
if not Button.Enabled then
begin
if Timer.Interval<400 then
begin
rdm:=50;
Timer.Interval:=Timer.Interval+10;
end
else if Timer.Interval<800 then
begin
Timer.Interval:=Timer.Interval+2;
if rdm>3 then rdm:=rdm-2;
end;
end;
for i:=0 to 3 do
begin
Rct:=bmp[i].ClientRect;
if not Button.Enabled then
begin
if not tz[i] then
begin
if Random(rdm)<2 then tz[i]:=true;
xh[i]:=(xh[i]+10) mod 500;
end
else
begin
if (xh[i] mod 50)<>0 then xh[i]:=(xh[i]+10) mod 500
else stop[i]:=false;
end;
Timer.Enabled:=stop[0] or stop[1] or stop[2] or stop[3];
end
else xh[i]:=(xh[i]+60*Random(10)) mod (500);
Rct.Top:=xh[i]+1;
Rct.Bottom:=xh[i]+1+h;
bmp[i].Canvas.CopyRect(bmp[i].ClientRect,Image.Canvas,Rct);
end;
if not Timer.Enabled then
begin
for i:=0 to 3 do s:=s+inttostr(xh[i]div 50);
if pos(s,Memo.Text)>0 then Memo.Lines.Append('第 '+inttostr(Memo.Lines.Count+1)+' 轮抽出重复号:'+s)
else Memo.Lines.Append('第 '+inttostr(Memo.Lines.Count+1)+' 轮抽出中奖号:'+s);
Button.Caption:='开始';
Button.Enabled:=true;
end;
end;
procedure TForm1.ButtonClick(Sender: TObject);
var i:integer;
begin
if Button.Caption='开始' then
begin
Button.Caption:='停止';
for i:=0 to 3 do
begin
tz[i]:=false;
stop[i]:=true;
end;
Randomize;
Timer.Interval:=30;
Timer.Enabled:=true;
end
else Button.Enabled:=false;
end;
end.