我有一些关于 Dephi 的作业(以前从未使用过,只有 c++/java,但在我的大学里,我们有 delphi 语言科目)。好吧,我需要用移动的数字制作形式,展示它们如何碰撞之类的东西。我开始像一些抽象类一样制作一个 uint
unit MyFigure;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, Buttons, StdCtrls;
type
tPoint = record
x,y: Double;
end;
oFigure = class
c: TCanvas;
pos: tPoint;
vel: tPoint;
r: Double;
constructor create(coord, vect: tPoint; radius: Double);
protected
procedure move();
procedure draw(); virtual;
public
function isIntersected(x:oFigure):boolean;
end;
implementation
constructor oFigure.create(coord, vect: tPoint; radius: Double);
begin
pos.x:= coord.x;
pos.y:= coord.y;
vel.x:= vect.x;
vel.y:= vect.y;
r:=radius;
end;
procedure oShape.draw(); virtual;
begin
end;
procedure oShape.move();
begin
pos.x:= pos.x + vel.x;
pos.y:= pos.y + vel.y;
oShape.draw();
end;
function isIntersected(o:oFigure):boolean;
begin
if ((oShape.pos.x - o.pos.x)*(oShape.pos.x - o.pos.x) + (oShape.pos.y - o.pos.y)*(oShape.pos.y - o.pos.y)
< (oShape.r + o.r)*(oShape.r + o.r)) then Result:=True;
end;
end.
然后我创造了它的孩子。好吧,在这里我需要从画布调用 arc 方法来绘制球,但它看不到它,并且 eve 说unable to invoke code completion
。怎么了?
unit Ball;
interface
uses
MyFigure;
type
oBall = class(oFigure);
c: TCanvas;
procedure draw(); override;
end;
implementation
procedure oBall.draw();
begin
c.Arc()//PROBLEM!
end;
end.