⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 classvehicle.pas

📁 这是从不同语言来实现操作系统交通灯的调度问题
💻 PAS
字号:
unit classVehicle;

interface

uses
  unitConst, ExtCtrls, Classes;

type
  TVehicle= class
  public
    constructor Create(var image: TImage; vtype: TVehicleType; direction: TDirection; head: TCoordinateSD; timeinterval: TTime);
                  //head表示车头在自己道路上相距街道外边缘的距离,正值表示在街道内,负职表示在街道外等候
    procedure Move;                                           //移动
    procedure Draw(frontier: TCoordinateDD);                 //BoundaryCoordinate--各个路口外边线线左上角相对于canvas的坐标
  private
    datImage: TImage;                                       //绘图区域
    datHead: TCoordinateSD;                                 //车头的相对坐标
    datType: TVehicleType;                                  //车辆特点描述
    datMoveable: TMoveable;                                 //判断能否移动
    datRealSpeed: TCoordinateSD;                            //每个时间周期的速度

    conTimerInterval: TTime;                                //扫描的时间周期
    conDirection: TDirection;                               //车辆方向
    procedure setMoveable(moveable: TMoveable);             //用于改变Moveable的属性
  published
    property Moveable: TMoveable read datMoveable write setMoveable;      //能否移动
    property Long: TCoordinateSD read datType.long;                      //车长
    property Head: TCoordinateSD read datHead;                          //车辆头坐标
    property Speed: TCoordinateSD read datRealSpeed;                    //每个时间周期的速度
  end;

implementation

{ TVehicle }

constructor TVehicle.Create(var image: TImage; vtype: TVehicleType; direction: TDirection; head: TCoordinateSD; timeinterval: TTime);
begin
    datImage:=image;
    datMoveable:= false;
    datType:= vtype;
    conDirection:= direction;
    datHead:= head;
    conTimerInterval:=timeinterval;
    datRealSpeed:=( datType.speed * conTimerInterval) div const_PerTime ;
end;

procedure TVehicle.Draw(frontier: TCoordinateDD);
begin
  datImage.Canvas.Brush.Color:=datType.color;
  case conDirection of
    1:begin
        datImage.Canvas.FillRect(Rect(frontier.x+datHead,frontier.y,frontier.x+datHead-datType.long,frontier.y+datType.width));
      end;
    2:begin
        datImage.Canvas.FillRect(Rect(frontier.x,frontier.y+datHead,frontier.x+datType.width,frontier.y+datHead-datType.long));
      end;
    3:begin
        datImage.Canvas.FillRect(Rect(frontier.x-datHead,frontier.y,frontier.x-datHead+datType.long,frontier.y+datType.width));
      end;
    4:begin
        datImage.Canvas.FillRect(Rect(frontier.x,frontier.y-datHead,frontier.x+datType.width,frontier.y-datHead+datType.long));
      end;
  end;
end;

procedure TVehicle.Move;
begin
    if  (Moveable)
    then begin
        datHead:=datHead+datRealSpeed;
    end;
end;

procedure TVehicle.setMoveable(moveable: TMoveable);
begin
  if datMoveable <> moveable then
  begin
    datMoveable:= moveable;
  end;    
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -