大家帮我看下怎样解决??(50分)

  • 主题发起人 ICMGDCHN
  • 开始时间
I

ICMGDCHN

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
ball: TShape;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
a,x,y,l,t,flag:integer;
b:real;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
randomize;
a:=random(180);
b:=a*pi/180;
x:=round(2*cos(b));
y:=round(2*sin(b));
ball.Left:=width div 2-20;
ball.Top:=height-40;
flag:=0;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
l:=ball.left+20;
t:=ball.top+20;
if (t<=20) then
flag:=1;
if(l<=20) then
flag:=2;
if (l>=form1.Width-20) then
flag:=3;
if (t>=form1.Height -20) then
flag:=4;
with ball do
begin
case flag of
0:
begin
Left:=Left+x;
Top:=Top-y;
end;
1:
begin
left:=left-x;
top:=top+y;
end;
2:
begin
left:=left+x;
top:=top+y;
end;
3:
begin
left:=left-x;
top:=top-y;
end;
4:
begin
left:=left-x;
top:=top+y;
end;
end;
end;
end;
end.
问题总是解决不了,原想反弹一个小球,但反弹不了
 
顶部