主题:[讨论]请教delphi中随机函数的使用
lingliner
[专家分:0] 发布于 2010-04-08 21:07:00
老师今天布置了一个作业,需要用到随机函数来做一个加法的小游戏!
在此请教一下随机函数用法!
回复列表 (共5个回复)
沙发
kingkey110 [专家分:0] 发布于 2010-04-14 10:36:00
很早以前做的
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, TFlatButtonUnit;
type
TForm1 = class(TForm)
Image1: TImage;
Image2: TImage;
Txt: TEdit;
Label1: TLabel;
Label2: TLabel;
Label4: TLabel;
Lbl4: TLabel;
Label3: TLabel;
Label7: TLabel;
Lbl6: TLabel;
Label9: TLabel;
Lbl5: TLabel;
Lbl1: TLabel;
Lbl2: TLabel;
Lbl3: TLabel;
LblName: TLabel;
FlatButton1: TFlatButton;
FlatButton2: TFlatButton;
procedure Start;
procedure OnlyNumber;
procedure TxtKeyPress(Sender: TObject; var Key: Char);
procedure FormCreate(Sender: TObject);
procedure FlatButton1Click(Sender: TObject);
procedure FlatButton2Click(Sender: TObject);
procedure TxtKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure TxtKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
var
a: integer;
b: integer;
c: integer;
d: integer;
shu: integer;
{$R *.DFM}
procedure TForm1.OnlyNumber;
var
i : Integer;
s : String;
begin
s := Txt.Text ;
for i := 1 to Length(s) do
if (s[i] < '0') or (s[i] > '9') then
begin
Beep;
Application.MessageBox('只能输入输入数字!','错误',mb_ok);
Txt.Text := '';
end;
end;
procedure TForm1.Start;
begin
Randomize;
a := Random(100);
b := Random(100);
lbl1.Caption := inttostr(a);
lbl2.Caption := inttostr(b);
lbl3.Caption := inttostr(strtoint(lbl3.caption) + 1);
If strtoint(lbl3.Caption) = 11 Then
begin
shu := shu + 1;
label3.Caption := '第 ' + inttostr(shu) + ' 次';
lbl3.Caption := '1';
End;
end;
procedure TForm1.TxtKeyPress(Sender: TObject; var Key: Char);
begin
If key = chr(13) Then
begin
c := a + b;
if Txt.Text = '' then Exit;
If c = StrTOInt(txt.Text) Then
lbl4.Caption := inttostr(strtoint(lbl4.Caption) + 1) ;
if c <> strtoint(txt.text) then
lbl5.Caption := inttostr(strtoint(lbl5.Caption) + 1) ;
If strtoint(lbl3.Caption) = 10 Then
begin
d := (StrToInt(Lbl4.Caption) * 10 );
lbl6.Caption := IntToStr(d) ;
form2.Lst.Items.Add (' ' + LblName.Caption + ' ' + label3.Caption
+ ' ' + Label7.caption + ' ' + lbl6.Caption + ' ' + '分');
lbl4.Caption := '0';
lbl5.Caption := '0';
End;
txt.SetFocus;
txt.text:= '';
start;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
InputName : string;
begin
InputName := InputBox('数学测试', '请输入的大名:', '无名氏');
Form1.LblName.Caption := InputName;
Randomize;
lbl3.Caption := '0';
lbl4.Caption := '0';
lbl5.Caption := '0';
lbl6.Caption := '0';
label3.Caption := '练 习';
start;
shu := 0 ;
end;
procedure TForm1.FlatButton1Click(Sender: TObject);
begin
Beep;
Form1.Hide;
Form2.Show;
end;
procedure TForm1.FlatButton2Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.TxtKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
OnlyNumber;
end;
procedure TForm1.TxtKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
OnlyNumber;
end;
end.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm2 = class(TForm)
Lst: TListBox;
Shape1: TShape;
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses Unit1;
{$R *.DFM}
procedure TForm2.FormKeyPress(Sender: TObject; var Key: Char);
begin
MessageDlg(Key + ' has been pressed', mtInformation, [mbOK], 0);
end;
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Form2.Hide;
Form1.Show;
end;
end.
板凳
冷杉软件 [专家分:0] 发布于 2010-04-16 19:54:00
福州冷杉软件招聘delphi程序员
http://new.hxrc.com/CompanyOneJobDetail.aspx?jobGuid=1f7bdd6c-00a0-41fc-9fae-ee448b6a3e32
职位要求: 基本要求
招聘形式:社会人士
工作时间要求:全职
学历要求:大专以上
性别要求:男
职称要求:不限
年龄要求:25岁 至 60岁
参考月薪:2500元 至 3500元
其他要求:
------------------------------------------------------------
1.大专以上学历。
2.熟悉Delphi,ms-sqlserver。
3.有通讯行业开发经验,或者财务软件,ERP开发经验优先。
4.一年以上工作经验者优先,有IOCP ,异步网络服务器开发经验优先。
工作概述: 1.进销存软件、财务软件、ERP,
2.客户关系管理,会员管理,酒店管理,
3.企业信息系统,开发维护。
联系地址:福建省福州市鼓楼区杨桥西路6晨光江景3#403
邮政号码:350001
联系电话:0591-83717263 QQ:853122287
移动电话:13850178931
传真号码:
联 系 人:林浩
电子邮箱:newpioneer@163.com
机构网址:www.ablersoft.com
3 楼
lingliner [专家分:0] 发布于 2010-04-18 21:37:00
出现了这样的错误
[Fatal Error] Unit1.pas(7): File not found: 'TFlatButtonUnit.dcu'
4 楼
kingkey110 [专家分:0] 发布于 2010-04-19 10:06:00
这是个第三方控件(button),你在Uses里 把它删了
用标准的Button去替换它
5 楼
moke9 [专家分:30] 发布于 2010-09-02 08:40:00
你好.我是全职网赚工作者.
如果你有时间有电脑.
想在网络上创业.请联系我..
项目绝对真实.详情QQ空间资料
加盟请联系 QQ908889846
我来回复