|
发表于 2019-5-12 16:36:28
|
显示全部楼层
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Button2: TButton;
Button3: TButton;
Timer1: TTimer;
Label4: TLabel;
Memo1: TMemo;
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
var i:string;
var a,b,c,d,e,f:integer;
tCount:integer;
{$R *.dfm}
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9', #3, #13, #8, #22]) then
key := #0;
end;
procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9', #3, #13, #8, #22]) then
key := #0;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
case random(4) of //case语句用来随机产生+-*/
0: i:='+';
1: i:='-';
2: i:='*';
3: i:='/';
end;
label1.Caption :='第'+inttostr(f+1)+'题:' + edit1.Text + i + edit2.Text + '=' + edit3.Text ;
label3.Caption :='';
label1.Caption :='';
label3.Caption :=i;
randomize;//初始随机数;
a:=random(20);
b:=random(20);
edit1.Text :=inttostr(a);
edit2.Text :=inttostr(b);
button1.Enabled :=false;
button2.Enabled :=true;
edit1.Enabled :=true;
edit2.Enabled :=true;
edit3.Enabled :=true;
button1.Caption :='下一题';
end;
procedure TForm1.FormCreate(Sender: TObject);
begin label3.Caption :='';
label1.Caption :='';
label2.Caption :='';
label1.Font.Size :=10;
label3.Font.Size :=10;
label2.Font.Size :=10;
button2.Enabled :=false;
edit1.Enabled :=false;
edit2.Enabled :=false;
edit3.Enabled :=false;
memo1.Text :='';
case random(4) of //case语句用来随机产生+-*/
0: i:='+';
1: i:='-';
2: i:='*';
3: i:='/';
end;
//////////////////////
tCount := 20*60; // 100分钟
Timer1.Interval := 1000; // 1秒钟触发一次
Timer1.Enabled := false;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if edit3.Text =''then
exit;
c:=strtoint(edit1.text)+strtoint(edit2.text);
f:=f+1;
if i= '+' then
begin
if c=strtoint(edit3.Text) then
begin
messagebox(handle,'小朋友真棒!回答正确!请准备开始下一题的练习!','恭喜!',MB_ICONASTERISK);
label1.Caption :='第'+inttostr(f)+'题:' + edit1.Text + i + edit2.Text + '=' + edit3.Text ;
memo1.Text :=memo1.Text+#10+#13+label1.Caption +#10#13;
button2.Enabled :=false;
edit3.Text :='';
edit2.Text :='';
edit1.Text :='';
button1.Enabled :=true;
label2.Visible :=true;
d:=d+1;
label2.Caption := '总数:'+inttostr(f)+#10#13+'正确:'+inttostr(d)+#10#13+'错误:' + inttostr(e);
exit;
end
else
begin
messagebox(handle,'很遗憾!小朋友,你的答案不正确,要加油哦!没关系我们开始下一题的练习!','回答错误!',MB_ICONEXCLAMATION);
button2.Enabled :=false;
label1.Caption :='第'+inttostr(f)+'题:' + edit1.Text + i + edit2.Text + '=' + edit3.Text ;
memo1.Text :=memo1.Text+#10+#13+label1.Caption +#10#13;
edit3.Text :='';
edit2.Text :='';
edit1.Text :='';
edit1.Enabled :=false;
edit2.Enabled :=false;
edit3.Enabled :=false;
button1.Enabled :=true;
e:=e+1;
label2.Caption := '总数:'+inttostr(f)+#10#13+'正确:'+inttostr(d)+#10#13+'错误:' + inttostr(e);
exit;
end;
end;
c:=strtoint(edit1.text)-strtoint(edit2.text);
////////////////////////////////////////////////////
if i= '-' then
begin
if c=strtoint(edit3.Text) then
begin
messagebox(handle,'小朋友真棒!回答正确!请准备开始下一题的练习!','恭喜!',MB_ICONASTERISK);
button2.Enabled :=false;
label1.Caption :='第'+inttostr(f)+'题:' + edit1.Text + i + edit2.Text + '=' + edit3.Text ;
memo1.Text :=memo1.Text+#10+#13+label1.Caption +#10#13;
edit3.Text :='';
edit2.Text :='';
edit1.Text :='';
button1.Enabled :=true;
label2.Visible :=true;
d:=d+1;
label2.Caption := '总数:'+inttostr(f)+#10#13+'正确:'+inttostr(d)+#10#13+'错误:' + inttostr(e);
exit;
end
else
begin
messagebox(handle,'很遗憾!小朋友,你的答案不正确,要加油哦!没关系我们开始下一题的练习!','回答错误!',MB_ICONEXCLAMATION);
button2.Enabled :=false;
label1.Caption :='第'+inttostr(f)+'题:' + edit1.Text + i + edit2.Text + '=' + edit3.Text ;
memo1.Text :=memo1.Text+#10+#13+label1.Caption +#10#13;
edit3.Text :='';
edit2.Text :='';
edit1.Text :='';
edit1.Enabled :=false;
edit2.Enabled :=false;
edit3.Enabled :=false;
button1.Enabled :=true;
e:=e+1;
label2.Caption := '总数:'+inttostr(f)+#10#13+'正确:'+inttostr(d)+#10#13+'错误:' + inttostr(e);
exit;
end;
end;
///////////////////////////////////////////////////////////////////////
c:=strtoint(edit1.text)*strtoint(edit2.text);
if i= '*' then
begin
if c=strtoint(edit3.Text) then
begin
messagebox(handle,'小朋友真棒!回答正确!请准备开始下一题的练习!','恭喜!',MB_ICONASTERISK);
button2.Enabled :=false;
label1.Caption :='第'+inttostr(f)+'题:' + edit1.Text + i + edit2.Text + '=' + edit3.Text ;
memo1.Text :=memo1.Text+#10+#13+label1.Caption +#10#13;
edit3.Text :='';
edit2.Text :='';
edit1.Text :='';
button1.Enabled :=true;
label2.Visible :=true;
d:=d+1;
label2.Caption := '总数:'+inttostr(f)+#10#13+'正确:'+inttostr(d)+#10#13+'错误:' + inttostr(e);
exit;
end
else
begin
messagebox(handle,'很遗憾!小朋友,你的答案不正确,要加油哦!没关系我们开始下一题的练习!','回答错误!',MB_ICONEXCLAMATION);
button2.Enabled :=false;
label1.Caption :='第'+inttostr(f)+'题:' + edit1.Text + i + edit2.Text + '=' + edit3.Text ;
memo1.Text :=memo1.Text+#10+#13+label1.Caption +#10#13;
edit3.Text :='';
edit2.Text :='';
edit1.Text :='';
edit1.Enabled :=false;
edit2.Enabled :=false;
edit3.Enabled :=false;
button1.Enabled :=true;
e:=e+1;
label2.Caption :='总数:'+inttostr(f)+#10#13+'正确:'+inttostr(d)+#10#13+'错误:' + inttostr(e);
exit;
end;
end;
/////////////////////////////////////////////////////////
c:=strtoint(edit1.text) div strtoint(edit2.text);
if i= '/' then
begin
if c=strtoint(edit3.Text) then
begin
messagebox(handle,'小朋友真棒!回答正确!请准备开始下一题的练习!','恭喜!',MB_ICONASTERISK);
button2.Enabled :=false;
label1.Caption :='第'+inttostr(f)+'题:' + edit1.Text + i + edit2.Text + '=' + edit3.Text ;
memo1.Text :=memo1.Text+#10+#13+label1.Caption +#10#13;
edit3.Text :='';
edit2.Text :='';
edit1.Text :='';
button1.Enabled :=true;
label2.Visible :=true;
d:=d+1;
label2.Caption := '总数:'+inttostr(f)+#10#13+'正确:'+inttostr(d)+#10#13+'错误:' + inttostr(e);
exit;
end
else
begin
messagebox(handle,'很遗憾!小朋友,你的答案不正确,要加油哦!没关系我们开始下一题的练习!','回答错误!',MB_ICONEXCLAMATION);
button2.Enabled :=false;
label1.Caption :='第'+inttostr(f)+'题:' + edit1.Text + i + edit2.Text + '=' + edit3.Text ;
memo1.Text :=memo1.Text+#10+#13+label1.Caption +#10#13;
edit3.Text :='';
edit2.Text :='';
edit1.Text :='';
edit1.Enabled :=false;
edit2.Enabled :=false;
edit3.Enabled :=false;
button1.Enabled :=true;
e:=e+1;
label2.Caption := '总数:'+inttostr(f)+#10#13+'正确:'+inttostr(d)+#10#13+'错误:' + inttostr(e);
exit;
end;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
h,n,s:string;
begin
Dec(tCount);
h := IntToStr(tCount div 3600); // 小时
n := IntToStr((tCount div 60) mod 60); // 分钟
s := IntToStr(tCount mod 60); // 秒
if Length(h)=1 then h := '0'+h;
if Length(n)=1 then n := '0'+n;
if Length(s)=1 then s := '0'+s;
Label4.Caption := '离学习时间20分钟还有:'+h+':'+n+':'+s;
if tCount=0 then begin // 倒计时结束
Timer1.Enabled := False;
label4.Font.Size :=12;
label4.caption:='时间到,请结束学习进行打分!'
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
timer1.Enabled :=true;
end;
end.
已测试,通过! |
|