重新说一遍要求,特等奖2名,一等8,二等16,三到六等20,除特等奖外,其他都是按一次,出所有名额,貌似很容易,我怎么改不对呢~~~~
代码献上,麻烦各位大侠,指点了,最好调试过的,拜谢了
var
Form1: TForm1;
number:Integer; //记录已经抽出多少个数
str:string;//取到的数
MyArr: array[0..13] of string;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
number:=0;
Memo1.Clear ;
Memo2.Clear ;
Memo3.Clear ;
ShockwaveFlash1.Movie:=getcurrentdir+'\gundong.swf';//是个数字滚动的flash
ShockwaveFlash1.Play;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if button1.Caption ='开始' then
begin
Timer2.Enabled :=true;
button1.Caption:='停止';
end
else
begin
Timer2.Enabled :=false;
number:=number+1;
Label6.Caption :=inttostr(number);
MyArr[number-1]:=str;//取出来的放在MyArr字符串中
memo3.Text := memo3.Text+ str+' ';
button1.Caption :='开始';
end;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
var j,i:integer;
begin
Timer2.Interval:=50;
Randomize;
i:=Random(13)+1;
if number>0 then
for j:=0 to number-1 do
if i=strtoint(MyArr[j]) then
exit;
Label2.Caption :=Format('%.3d', [i]);//001,002,003,004,005....
str:=Label2.Caption ;
shockwaveflash1.SetVariable('test',str);
end;
9 个解决方案
#1
楼主的代码没贴全,是不是要一次出20个不相同的随机数放到memo3中?
可以用20个label让他们一直滚动,然后按按钮停下来,判断是否重复,再贴到memo3中.
要么按一下出一个, 6+1都这样
可以用20个label让他们一直滚动,然后按按钮停下来,判断是否重复,再贴到memo3中.
要么按一下出一个, 6+1都这样
#2
现在这个是按一下出一个抽奖号码的代码,按照楼上的说法,要是一次出100个,我得放100个滚动数字???这种方法不可取,我只想按下结束按钮后,把后面的20个数字输出,可以吗?
#3
{特等奖2名,一等8,二等16,三到六等20,除特等奖外,其他都是按一次,出所有名额}
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Timer1: TTimer;
Timer2: TTimer;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
mnumber: Integer; //记录已经抽出多少个数
MyArr: array[0..106 - 1] of string;
//记录已被抽取的号码
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
mnumber := 0;
Memo1.Clear;
// ShockwaveFlash1.Movie:=getcurrentdir+'\gundong.swf';//是个数字滚动的flash
// ShockwaveFlash1.Play;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
str: string; //取到的数
begin
if button1.Caption = '特等奖' then
begin
Inc(mnumber);
Memo1.Lines.Add(button1.Caption);
Timer1.Enabled := true;
button1.Caption := '停止';
end else if (button1.Caption <> '停止') and (button1.Caption <> '完成' )then
begin
if mnumber >26-1 then mnumber:=mnumber+20
else if mnumber >10-1 then mnumber:=mnumber+16
else mnumber:=mnumber+8;
Memo1.Lines.Add(button1.Caption);
Timer2.Enabled := true;
button1.Caption := '停止';
end
else
if button1.Caption = '停止' then
begin
Timer1.Enabled := false;
Timer2.Enabled := false;
if mnumber < 2 then begin
button1.Caption := '特等奖';
str := MyArr[mnumber - 1];
end else if mnumber < 10 then begin
button1.Caption := '一等奖';
str := MyArr[mnumber - 1];
end else if mnumber < 26 then begin
button1.Caption := '二等奖';
for i := 3 to 10 do
str := str + MyArr[i - 1]+' ';
end else if mnumber < 46 then begin
button1.Caption := '三等奖';
for i := 11 to 26 do
str := str + MyArr[i - 1]+' ';
end else if mnumber < 66 then begin
button1.Caption := '四等奖';
for i := 27 to 46 do
str := str + MyArr[i - 1]+' ';
end else if mnumber < 86 then begin
button1.Caption := '五等奖';
for i := 47 to 66 do
str := str + MyArr[i - 1]+' ';
end else if mnumber < 106 then begin
button1.Caption := '六等奖';
for i := 67 to 86 do
str := str + MyArr[i - 1]+' ';
end else begin
for i := 87 to 106 do
str := str + MyArr[i - 1]+' ';
button1.Caption := '完成';
end;
memo1.Lines.Add(str);
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var j, i: integer;
existflag: Boolean;
begin
Randomize;
existflag := False;
i := Random(1000);
if i > 0 then
for j := 0 to mnumber - 2 do
begin
if MyArr[j] = Format('%.3d', [i]) then existflag := true;
end;
if not existflag then begin
Label1.Caption := Format('%.3d', [i]); //001,002,003,004,005....
MyArr[mnumber - 1] := Format('%.3d', [i]);
end;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
var j, i, k, m: integer;
existflag: Boolean;
begin
if mnumber > 26 then
k := 20
else
if mnumber > 10 then
k := 16
else
k := 8;
for m := 0 to k - 1 do begin
Randomize;
existflag := False;
i := Random(1000);
if i > 0 then
for j := 0 to mnumber - 1 - k+m do
begin
if MyArr[j] = Format('%.3d', [i]) then existflag := true;
end;
if not existflag then begin
Label1.Caption := Format('%.3d', [i]); //001,002,003,004,005....
MyArr[mnumber-1-k+m] := Format('%.3d', [i]);
end;
end;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Timer1: TTimer;
Timer2: TTimer;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
mnumber: Integer; //记录已经抽出多少个数
MyArr: array[0..106 - 1] of string;
//记录已被抽取的号码
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
mnumber := 0;
Memo1.Clear;
// ShockwaveFlash1.Movie:=getcurrentdir+'\gundong.swf';//是个数字滚动的flash
// ShockwaveFlash1.Play;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
str: string; //取到的数
begin
if button1.Caption = '特等奖' then
begin
Inc(mnumber);
Memo1.Lines.Add(button1.Caption);
Timer1.Enabled := true;
button1.Caption := '停止';
end else if (button1.Caption <> '停止') and (button1.Caption <> '完成' )then
begin
if mnumber >26-1 then mnumber:=mnumber+20
else if mnumber >10-1 then mnumber:=mnumber+16
else mnumber:=mnumber+8;
Memo1.Lines.Add(button1.Caption);
Timer2.Enabled := true;
button1.Caption := '停止';
end
else
if button1.Caption = '停止' then
begin
Timer1.Enabled := false;
Timer2.Enabled := false;
if mnumber < 2 then begin
button1.Caption := '特等奖';
str := MyArr[mnumber - 1];
end else if mnumber < 10 then begin
button1.Caption := '一等奖';
str := MyArr[mnumber - 1];
end else if mnumber < 26 then begin
button1.Caption := '二等奖';
for i := 3 to 10 do
str := str + MyArr[i - 1]+' ';
end else if mnumber < 46 then begin
button1.Caption := '三等奖';
for i := 11 to 26 do
str := str + MyArr[i - 1]+' ';
end else if mnumber < 66 then begin
button1.Caption := '四等奖';
for i := 27 to 46 do
str := str + MyArr[i - 1]+' ';
end else if mnumber < 86 then begin
button1.Caption := '五等奖';
for i := 47 to 66 do
str := str + MyArr[i - 1]+' ';
end else if mnumber < 106 then begin
button1.Caption := '六等奖';
for i := 67 to 86 do
str := str + MyArr[i - 1]+' ';
end else begin
for i := 87 to 106 do
str := str + MyArr[i - 1]+' ';
button1.Caption := '完成';
end;
memo1.Lines.Add(str);
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var j, i: integer;
existflag: Boolean;
begin
Randomize;
existflag := False;
i := Random(1000);
if i > 0 then
for j := 0 to mnumber - 2 do
begin
if MyArr[j] = Format('%.3d', [i]) then existflag := true;
end;
if not existflag then begin
Label1.Caption := Format('%.3d', [i]); //001,002,003,004,005....
MyArr[mnumber - 1] := Format('%.3d', [i]);
end;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
var j, i, k, m: integer;
existflag: Boolean;
begin
if mnumber > 26 then
k := 20
else
if mnumber > 10 then
k := 16
else
k := 8;
for m := 0 to k - 1 do begin
Randomize;
existflag := False;
i := Random(1000);
if i > 0 then
for j := 0 to mnumber - 1 - k+m do
begin
if MyArr[j] = Format('%.3d', [i]) then existflag := true;
end;
if not existflag then begin
Label1.Caption := Format('%.3d', [i]); //001,002,003,004,005....
MyArr[mnumber-1-k+m] := Format('%.3d', [i]);
end;
end;
end;
end.
#4
利害
#5
调试完3楼的发现有错误,因为我一直在调试,调的乱了,忘了是有重复还是遇到重复就取了个空白,没有达到指定中奖名额,反正反反复复就这两种情况。我还在继续调,麻烦3楼的大侠,也能帮忙调试
还有,中将当然先出末等奖,哪有先出特等奖的道理,呵呵,这点怪我,忘说了,调通后,我会把100献上
还有,中将当然先出末等奖,哪有先出特等奖的道理,呵呵,这点怪我,忘说了,调通后,我会把100献上
#6
{特等奖2名,一等8,二等16,三到六等20,除特等奖外,其他都是按一次,出所有名额}
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Label1: TLabel;
Timer1: TTimer;
Timer2: TTimer;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
mnumber: Integer; //记录已经抽出多少个数
MyArr: array[0..106 - 1] of string;
//记录已被抽取的号码
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
mnumber := 0;
Memo1.Clear;
// ShockwaveFlash1.Movie:=getcurrentdir+'\gundong.swf';//是个数字滚动的flash
// ShockwaveFlash1.Play;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
str: string; //取到的数
begin
if button1.Caption = '特等奖' then
begin
Inc(mnumber);
Memo1.Lines.Add(button1.Caption);
Timer1.Enabled := true;
button1.Caption := '停止';
end else if (button1.Caption <> '停止') and (button1.Caption <> '完成') then
begin
if mnumber > 96 - 1 then mnumber := mnumber + 8
else if mnumber > 80 - 1 then mnumber := mnumber + 16
else mnumber := mnumber + 20;
Memo1.Lines.Add(button1.Caption);
Timer2.Enabled := true;
button1.Caption := '停止';
end
else
if button1.Caption = '停止' then
begin
Timer1.Enabled := false;
Timer2.Enabled := false;
if mnumber < 40 then begin
button1.Caption := '五等奖';
for i := 1 to 20 do
str := str + MyArr[i - 1] + ' ';
end else if mnumber < 60 then begin
button1.Caption := '四等奖';
for i := 21 to 40 do
str := str + MyArr[i - 1] + ' ';
end else if mnumber < 80 then begin
button1.Caption := '三等奖';
for i := 41 to 60 do
str := str + MyArr[i - 1] + ' ';
end else if mnumber < 96 then begin
button1.Caption := '二等奖';
for i := 61 to 80 do
str := str + MyArr[i - 1] + ' ';
end else if mnumber < 104 then begin
button1.Caption := '一等奖';
for i := 81 to 96 do
str := str + MyArr[i - 1] + ' ';
end else if mnumber < 105 then begin
button1.Caption := '特等奖';
for i := 97 to 104 do
str := str + MyArr[i - 1] + ' ';
end else if mnumber < 106 then begin
button1.Caption := '特等奖';
str := MyArr[mnumber - 1];
end else begin
str := MyArr[mnumber - 1];
button1.Caption := '完成';
end;
memo1.Lines.Add(str);
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var j, i: integer;
existflag: Boolean;
begin
Randomize;
existflag := False;
i := Random(1000); //基数需要大于中奖的总人数(106)
if i > 0 then
for j := 0 to mnumber - 2 do
begin
if MyArr[j] = Format('%.3d', [i]) then existflag := true;
end;
if not existflag then begin
Label1.Caption := Format('%.3d', [i]); //001,002,003,004,005....
MyArr[mnumber - 1] := Format('%.3d', [i]);
end;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
var j, i, k, m: integer;
makeflag, existflag: Boolean;
begin
if mnumber > 96 then
k := 8
else
if mnumber > 80 then
k := 16
else
k := 20;
for m := 1 to k do begin
makeflag := True;
while makeflag do begin
Randomize;
existflag := False;
i := Random(1000); //基数需要大于中奖的总人数(106)
if i > 0 then
for j := 0 to mnumber - 1 - k + m do
begin
if MyArr[j] = Format('%.3d', [i]) then existflag := true;
end;
if not existflag then begin
Label1.Caption := Format('%.3d', [i]); //001,002,003,004,005....
MyArr[mnumber - 1 - k + m] := Format('%.3d', [i]);
makeflag := False;
end;
end;
end;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Label1: TLabel;
Timer1: TTimer;
Timer2: TTimer;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
mnumber: Integer; //记录已经抽出多少个数
MyArr: array[0..106 - 1] of string;
//记录已被抽取的号码
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
mnumber := 0;
Memo1.Clear;
// ShockwaveFlash1.Movie:=getcurrentdir+'\gundong.swf';//是个数字滚动的flash
// ShockwaveFlash1.Play;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
str: string; //取到的数
begin
if button1.Caption = '特等奖' then
begin
Inc(mnumber);
Memo1.Lines.Add(button1.Caption);
Timer1.Enabled := true;
button1.Caption := '停止';
end else if (button1.Caption <> '停止') and (button1.Caption <> '完成') then
begin
if mnumber > 96 - 1 then mnumber := mnumber + 8
else if mnumber > 80 - 1 then mnumber := mnumber + 16
else mnumber := mnumber + 20;
Memo1.Lines.Add(button1.Caption);
Timer2.Enabled := true;
button1.Caption := '停止';
end
else
if button1.Caption = '停止' then
begin
Timer1.Enabled := false;
Timer2.Enabled := false;
if mnumber < 40 then begin
button1.Caption := '五等奖';
for i := 1 to 20 do
str := str + MyArr[i - 1] + ' ';
end else if mnumber < 60 then begin
button1.Caption := '四等奖';
for i := 21 to 40 do
str := str + MyArr[i - 1] + ' ';
end else if mnumber < 80 then begin
button1.Caption := '三等奖';
for i := 41 to 60 do
str := str + MyArr[i - 1] + ' ';
end else if mnumber < 96 then begin
button1.Caption := '二等奖';
for i := 61 to 80 do
str := str + MyArr[i - 1] + ' ';
end else if mnumber < 104 then begin
button1.Caption := '一等奖';
for i := 81 to 96 do
str := str + MyArr[i - 1] + ' ';
end else if mnumber < 105 then begin
button1.Caption := '特等奖';
for i := 97 to 104 do
str := str + MyArr[i - 1] + ' ';
end else if mnumber < 106 then begin
button1.Caption := '特等奖';
str := MyArr[mnumber - 1];
end else begin
str := MyArr[mnumber - 1];
button1.Caption := '完成';
end;
memo1.Lines.Add(str);
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var j, i: integer;
existflag: Boolean;
begin
Randomize;
existflag := False;
i := Random(1000); //基数需要大于中奖的总人数(106)
if i > 0 then
for j := 0 to mnumber - 2 do
begin
if MyArr[j] = Format('%.3d', [i]) then existflag := true;
end;
if not existflag then begin
Label1.Caption := Format('%.3d', [i]); //001,002,003,004,005....
MyArr[mnumber - 1] := Format('%.3d', [i]);
end;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
var j, i, k, m: integer;
makeflag, existflag: Boolean;
begin
if mnumber > 96 then
k := 8
else
if mnumber > 80 then
k := 16
else
k := 20;
for m := 1 to k do begin
makeflag := True;
while makeflag do begin
Randomize;
existflag := False;
i := Random(1000); //基数需要大于中奖的总人数(106)
if i > 0 then
for j := 0 to mnumber - 1 - k + m do
begin
if MyArr[j] = Format('%.3d', [i]) then existflag := true;
end;
if not existflag then begin
Label1.Caption := Format('%.3d', [i]); //001,002,003,004,005....
MyArr[mnumber - 1 - k + m] := Format('%.3d', [i]);
makeflag := False;
end;
end;
end;
end;
end.
#7
Button的Caption 设为 "六等奖"
#8
中奖咯
#9
还是错误,我还没调了,麻烦调完完整的程序,给我发一份,我的邮箱是12943900@qq.com,谢了
#1
楼主的代码没贴全,是不是要一次出20个不相同的随机数放到memo3中?
可以用20个label让他们一直滚动,然后按按钮停下来,判断是否重复,再贴到memo3中.
要么按一下出一个, 6+1都这样
可以用20个label让他们一直滚动,然后按按钮停下来,判断是否重复,再贴到memo3中.
要么按一下出一个, 6+1都这样
#2
现在这个是按一下出一个抽奖号码的代码,按照楼上的说法,要是一次出100个,我得放100个滚动数字???这种方法不可取,我只想按下结束按钮后,把后面的20个数字输出,可以吗?
#3
{特等奖2名,一等8,二等16,三到六等20,除特等奖外,其他都是按一次,出所有名额}
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Timer1: TTimer;
Timer2: TTimer;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
mnumber: Integer; //记录已经抽出多少个数
MyArr: array[0..106 - 1] of string;
//记录已被抽取的号码
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
mnumber := 0;
Memo1.Clear;
// ShockwaveFlash1.Movie:=getcurrentdir+'\gundong.swf';//是个数字滚动的flash
// ShockwaveFlash1.Play;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
str: string; //取到的数
begin
if button1.Caption = '特等奖' then
begin
Inc(mnumber);
Memo1.Lines.Add(button1.Caption);
Timer1.Enabled := true;
button1.Caption := '停止';
end else if (button1.Caption <> '停止') and (button1.Caption <> '完成' )then
begin
if mnumber >26-1 then mnumber:=mnumber+20
else if mnumber >10-1 then mnumber:=mnumber+16
else mnumber:=mnumber+8;
Memo1.Lines.Add(button1.Caption);
Timer2.Enabled := true;
button1.Caption := '停止';
end
else
if button1.Caption = '停止' then
begin
Timer1.Enabled := false;
Timer2.Enabled := false;
if mnumber < 2 then begin
button1.Caption := '特等奖';
str := MyArr[mnumber - 1];
end else if mnumber < 10 then begin
button1.Caption := '一等奖';
str := MyArr[mnumber - 1];
end else if mnumber < 26 then begin
button1.Caption := '二等奖';
for i := 3 to 10 do
str := str + MyArr[i - 1]+' ';
end else if mnumber < 46 then begin
button1.Caption := '三等奖';
for i := 11 to 26 do
str := str + MyArr[i - 1]+' ';
end else if mnumber < 66 then begin
button1.Caption := '四等奖';
for i := 27 to 46 do
str := str + MyArr[i - 1]+' ';
end else if mnumber < 86 then begin
button1.Caption := '五等奖';
for i := 47 to 66 do
str := str + MyArr[i - 1]+' ';
end else if mnumber < 106 then begin
button1.Caption := '六等奖';
for i := 67 to 86 do
str := str + MyArr[i - 1]+' ';
end else begin
for i := 87 to 106 do
str := str + MyArr[i - 1]+' ';
button1.Caption := '完成';
end;
memo1.Lines.Add(str);
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var j, i: integer;
existflag: Boolean;
begin
Randomize;
existflag := False;
i := Random(1000);
if i > 0 then
for j := 0 to mnumber - 2 do
begin
if MyArr[j] = Format('%.3d', [i]) then existflag := true;
end;
if not existflag then begin
Label1.Caption := Format('%.3d', [i]); //001,002,003,004,005....
MyArr[mnumber - 1] := Format('%.3d', [i]);
end;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
var j, i, k, m: integer;
existflag: Boolean;
begin
if mnumber > 26 then
k := 20
else
if mnumber > 10 then
k := 16
else
k := 8;
for m := 0 to k - 1 do begin
Randomize;
existflag := False;
i := Random(1000);
if i > 0 then
for j := 0 to mnumber - 1 - k+m do
begin
if MyArr[j] = Format('%.3d', [i]) then existflag := true;
end;
if not existflag then begin
Label1.Caption := Format('%.3d', [i]); //001,002,003,004,005....
MyArr[mnumber-1-k+m] := Format('%.3d', [i]);
end;
end;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Timer1: TTimer;
Timer2: TTimer;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
mnumber: Integer; //记录已经抽出多少个数
MyArr: array[0..106 - 1] of string;
//记录已被抽取的号码
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
mnumber := 0;
Memo1.Clear;
// ShockwaveFlash1.Movie:=getcurrentdir+'\gundong.swf';//是个数字滚动的flash
// ShockwaveFlash1.Play;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
str: string; //取到的数
begin
if button1.Caption = '特等奖' then
begin
Inc(mnumber);
Memo1.Lines.Add(button1.Caption);
Timer1.Enabled := true;
button1.Caption := '停止';
end else if (button1.Caption <> '停止') and (button1.Caption <> '完成' )then
begin
if mnumber >26-1 then mnumber:=mnumber+20
else if mnumber >10-1 then mnumber:=mnumber+16
else mnumber:=mnumber+8;
Memo1.Lines.Add(button1.Caption);
Timer2.Enabled := true;
button1.Caption := '停止';
end
else
if button1.Caption = '停止' then
begin
Timer1.Enabled := false;
Timer2.Enabled := false;
if mnumber < 2 then begin
button1.Caption := '特等奖';
str := MyArr[mnumber - 1];
end else if mnumber < 10 then begin
button1.Caption := '一等奖';
str := MyArr[mnumber - 1];
end else if mnumber < 26 then begin
button1.Caption := '二等奖';
for i := 3 to 10 do
str := str + MyArr[i - 1]+' ';
end else if mnumber < 46 then begin
button1.Caption := '三等奖';
for i := 11 to 26 do
str := str + MyArr[i - 1]+' ';
end else if mnumber < 66 then begin
button1.Caption := '四等奖';
for i := 27 to 46 do
str := str + MyArr[i - 1]+' ';
end else if mnumber < 86 then begin
button1.Caption := '五等奖';
for i := 47 to 66 do
str := str + MyArr[i - 1]+' ';
end else if mnumber < 106 then begin
button1.Caption := '六等奖';
for i := 67 to 86 do
str := str + MyArr[i - 1]+' ';
end else begin
for i := 87 to 106 do
str := str + MyArr[i - 1]+' ';
button1.Caption := '完成';
end;
memo1.Lines.Add(str);
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var j, i: integer;
existflag: Boolean;
begin
Randomize;
existflag := False;
i := Random(1000);
if i > 0 then
for j := 0 to mnumber - 2 do
begin
if MyArr[j] = Format('%.3d', [i]) then existflag := true;
end;
if not existflag then begin
Label1.Caption := Format('%.3d', [i]); //001,002,003,004,005....
MyArr[mnumber - 1] := Format('%.3d', [i]);
end;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
var j, i, k, m: integer;
existflag: Boolean;
begin
if mnumber > 26 then
k := 20
else
if mnumber > 10 then
k := 16
else
k := 8;
for m := 0 to k - 1 do begin
Randomize;
existflag := False;
i := Random(1000);
if i > 0 then
for j := 0 to mnumber - 1 - k+m do
begin
if MyArr[j] = Format('%.3d', [i]) then existflag := true;
end;
if not existflag then begin
Label1.Caption := Format('%.3d', [i]); //001,002,003,004,005....
MyArr[mnumber-1-k+m] := Format('%.3d', [i]);
end;
end;
end;
end.
#4
利害
#5
调试完3楼的发现有错误,因为我一直在调试,调的乱了,忘了是有重复还是遇到重复就取了个空白,没有达到指定中奖名额,反正反反复复就这两种情况。我还在继续调,麻烦3楼的大侠,也能帮忙调试
还有,中将当然先出末等奖,哪有先出特等奖的道理,呵呵,这点怪我,忘说了,调通后,我会把100献上
还有,中将当然先出末等奖,哪有先出特等奖的道理,呵呵,这点怪我,忘说了,调通后,我会把100献上
#6
{特等奖2名,一等8,二等16,三到六等20,除特等奖外,其他都是按一次,出所有名额}
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Label1: TLabel;
Timer1: TTimer;
Timer2: TTimer;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
mnumber: Integer; //记录已经抽出多少个数
MyArr: array[0..106 - 1] of string;
//记录已被抽取的号码
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
mnumber := 0;
Memo1.Clear;
// ShockwaveFlash1.Movie:=getcurrentdir+'\gundong.swf';//是个数字滚动的flash
// ShockwaveFlash1.Play;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
str: string; //取到的数
begin
if button1.Caption = '特等奖' then
begin
Inc(mnumber);
Memo1.Lines.Add(button1.Caption);
Timer1.Enabled := true;
button1.Caption := '停止';
end else if (button1.Caption <> '停止') and (button1.Caption <> '完成') then
begin
if mnumber > 96 - 1 then mnumber := mnumber + 8
else if mnumber > 80 - 1 then mnumber := mnumber + 16
else mnumber := mnumber + 20;
Memo1.Lines.Add(button1.Caption);
Timer2.Enabled := true;
button1.Caption := '停止';
end
else
if button1.Caption = '停止' then
begin
Timer1.Enabled := false;
Timer2.Enabled := false;
if mnumber < 40 then begin
button1.Caption := '五等奖';
for i := 1 to 20 do
str := str + MyArr[i - 1] + ' ';
end else if mnumber < 60 then begin
button1.Caption := '四等奖';
for i := 21 to 40 do
str := str + MyArr[i - 1] + ' ';
end else if mnumber < 80 then begin
button1.Caption := '三等奖';
for i := 41 to 60 do
str := str + MyArr[i - 1] + ' ';
end else if mnumber < 96 then begin
button1.Caption := '二等奖';
for i := 61 to 80 do
str := str + MyArr[i - 1] + ' ';
end else if mnumber < 104 then begin
button1.Caption := '一等奖';
for i := 81 to 96 do
str := str + MyArr[i - 1] + ' ';
end else if mnumber < 105 then begin
button1.Caption := '特等奖';
for i := 97 to 104 do
str := str + MyArr[i - 1] + ' ';
end else if mnumber < 106 then begin
button1.Caption := '特等奖';
str := MyArr[mnumber - 1];
end else begin
str := MyArr[mnumber - 1];
button1.Caption := '完成';
end;
memo1.Lines.Add(str);
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var j, i: integer;
existflag: Boolean;
begin
Randomize;
existflag := False;
i := Random(1000); //基数需要大于中奖的总人数(106)
if i > 0 then
for j := 0 to mnumber - 2 do
begin
if MyArr[j] = Format('%.3d', [i]) then existflag := true;
end;
if not existflag then begin
Label1.Caption := Format('%.3d', [i]); //001,002,003,004,005....
MyArr[mnumber - 1] := Format('%.3d', [i]);
end;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
var j, i, k, m: integer;
makeflag, existflag: Boolean;
begin
if mnumber > 96 then
k := 8
else
if mnumber > 80 then
k := 16
else
k := 20;
for m := 1 to k do begin
makeflag := True;
while makeflag do begin
Randomize;
existflag := False;
i := Random(1000); //基数需要大于中奖的总人数(106)
if i > 0 then
for j := 0 to mnumber - 1 - k + m do
begin
if MyArr[j] = Format('%.3d', [i]) then existflag := true;
end;
if not existflag then begin
Label1.Caption := Format('%.3d', [i]); //001,002,003,004,005....
MyArr[mnumber - 1 - k + m] := Format('%.3d', [i]);
makeflag := False;
end;
end;
end;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Label1: TLabel;
Timer1: TTimer;
Timer2: TTimer;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
mnumber: Integer; //记录已经抽出多少个数
MyArr: array[0..106 - 1] of string;
//记录已被抽取的号码
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
mnumber := 0;
Memo1.Clear;
// ShockwaveFlash1.Movie:=getcurrentdir+'\gundong.swf';//是个数字滚动的flash
// ShockwaveFlash1.Play;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
str: string; //取到的数
begin
if button1.Caption = '特等奖' then
begin
Inc(mnumber);
Memo1.Lines.Add(button1.Caption);
Timer1.Enabled := true;
button1.Caption := '停止';
end else if (button1.Caption <> '停止') and (button1.Caption <> '完成') then
begin
if mnumber > 96 - 1 then mnumber := mnumber + 8
else if mnumber > 80 - 1 then mnumber := mnumber + 16
else mnumber := mnumber + 20;
Memo1.Lines.Add(button1.Caption);
Timer2.Enabled := true;
button1.Caption := '停止';
end
else
if button1.Caption = '停止' then
begin
Timer1.Enabled := false;
Timer2.Enabled := false;
if mnumber < 40 then begin
button1.Caption := '五等奖';
for i := 1 to 20 do
str := str + MyArr[i - 1] + ' ';
end else if mnumber < 60 then begin
button1.Caption := '四等奖';
for i := 21 to 40 do
str := str + MyArr[i - 1] + ' ';
end else if mnumber < 80 then begin
button1.Caption := '三等奖';
for i := 41 to 60 do
str := str + MyArr[i - 1] + ' ';
end else if mnumber < 96 then begin
button1.Caption := '二等奖';
for i := 61 to 80 do
str := str + MyArr[i - 1] + ' ';
end else if mnumber < 104 then begin
button1.Caption := '一等奖';
for i := 81 to 96 do
str := str + MyArr[i - 1] + ' ';
end else if mnumber < 105 then begin
button1.Caption := '特等奖';
for i := 97 to 104 do
str := str + MyArr[i - 1] + ' ';
end else if mnumber < 106 then begin
button1.Caption := '特等奖';
str := MyArr[mnumber - 1];
end else begin
str := MyArr[mnumber - 1];
button1.Caption := '完成';
end;
memo1.Lines.Add(str);
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var j, i: integer;
existflag: Boolean;
begin
Randomize;
existflag := False;
i := Random(1000); //基数需要大于中奖的总人数(106)
if i > 0 then
for j := 0 to mnumber - 2 do
begin
if MyArr[j] = Format('%.3d', [i]) then existflag := true;
end;
if not existflag then begin
Label1.Caption := Format('%.3d', [i]); //001,002,003,004,005....
MyArr[mnumber - 1] := Format('%.3d', [i]);
end;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
var j, i, k, m: integer;
makeflag, existflag: Boolean;
begin
if mnumber > 96 then
k := 8
else
if mnumber > 80 then
k := 16
else
k := 20;
for m := 1 to k do begin
makeflag := True;
while makeflag do begin
Randomize;
existflag := False;
i := Random(1000); //基数需要大于中奖的总人数(106)
if i > 0 then
for j := 0 to mnumber - 1 - k + m do
begin
if MyArr[j] = Format('%.3d', [i]) then existflag := true;
end;
if not existflag then begin
Label1.Caption := Format('%.3d', [i]); //001,002,003,004,005....
MyArr[mnumber - 1 - k + m] := Format('%.3d', [i]);
makeflag := False;
end;
end;
end;
end;
end.
#7
Button的Caption 设为 "六等奖"
#8
中奖咯
#9
还是错误,我还没调了,麻烦调完完整的程序,给我发一份,我的邮箱是12943900@qq.com,谢了