5,6年没做程序了,朋友让帮个小忙,时间紧没时间复习语法啥的了!

aloelan 2011-09-20 11:13:35
要求 和电视上抽奖那样,一点按钮 一串数字开始滚动,再一点这个按钮就停止!
求段程序,能具体点最好!分数大大的有!
源程序发给我也行:aloelan@126.com
...全文
388 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
Lonwii 2011-10-03
  • 打赏
  • 举报
回复
random()
jingtuzhong 2011-10-01
  • 打赏
  • 举报
回复
var
temp.i,j,k:integer;
num:array[0..99] of integer;
begin
for i:=1 to 100 do
num[i-1]:=i;
j:=99;
i:=0;
while i <=99 do
begin
randomize;
k:=random(j);
while (k=j) or (k <0) do
begin
randomize;
k:=random(j);
end;
temp:=num[k];
num[k]:=num[j];
num[j]:=temp;
j:=j-1;
i:=i+1;
end;
广州佬 2011-09-29
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 yanguoliumao 的回复:]
大师,你的代码总是异军突起,超凡脱俗。
[/Quote]
见笑了,我新手噢,这称谓离我太远,不敢当!

我都知道,许多人更多的是使用我后一种的手法来写,那样简单,不过,要抽组随机数本身就不用搞那么多事,像12楼那样即可,既然要拿它来玩,我仅想把它玩彻底些而已,可是,效果不那么像往上滚动。
cntigercat 2011-09-29
  • 打赏
  • 举报
回复
好多代码。。。
雁过留毛 2011-09-29
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 gzzai 的回复:]
漏了一段:
...
[/Quote]

大师,你的代码总是异军突起,超凡脱俗。
z109876543210 2011-09-29
  • 打赏
  • 举报
回复
蛋疼............
一剑飘雪 2011-09-29
  • 打赏
  • 举报
回复

var
i: Integer;
str: string;
begin
Randomize;
str := '';
for i := 1 to 8 do
Str := str+IntToStr(Random(9));
Label1.Caption := str;
end;
广州佬 2011-09-28
  • 打赏
  • 举报
回复
再给你另外的算法:
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.
haitao 2011-09-28
  • 打赏
  • 举报
回复
好像以前发布过这样的工具
不过只是exe
广州佬 2011-09-28
  • 打赏
  • 举报
回复
漏了一段:
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;
广州佬 2011-09-28
  • 打赏
  • 举报
回复
新建工程、双击工程的窗体、用下列代码覆盖unit1的所有内容:
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.
Gogo520520 2011-09-27
  • 打赏
  • 举报
回复
学习学习。。。。
iqyely 2011-09-21
  • 打赏
  • 举报
回复
代码都已经给了,O(∩_∩)O哈哈~
李_军 2011-09-21
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Timer1: TTimer;
Button2: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
Timer1.Enabled := True;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Timer1.Enabled := False;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
i: Integer;
str: string;
begin
Randomize;
str := '';
for i := 1 to 8 do
Str := str+IntToStr(Random(9));
Label1.Caption := str;
end;

end.
babydog01 2011-09-21
  • 打赏
  • 举报
回复
这里下载,研究一下吧
http://download.csdn.net/detail/butterflyja/2469460
薛定谔之死猫 2011-09-21
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
NumArr: Array of integer;
i: integer;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
if Timer1.Enabled = true then
begin
Timer1.Enabled := false;
setlength(NumArr, 0);
end
else
begin
setlength(NumArr, 5);
NumArr[0] := 1;
NumArr[1] := 2;
NumArr[2] := 3;
NumArr[3] := 4;
NumArr[4] := 5;
i := 0;
Timer1.Enabled := true;
end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
if i >= 5 then
begin
i := 0
end;
Edit1.Text := inttostr(NumArr[i]);
i := i + 1;
end;

end.

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧