当前位置:编程学习 > Delphi >>

关于delphi作业!

我的作业 有点小要求 联系我哦
追问:

行么?

要求:

一、基本功能按如下要求必须完成,如有余力可自己开发其它功能。

二、说明:真正的控制需运用各种简单或复杂的控制算法、PLC、单片机等,我们这里只是采用Delphi程序设计方法模拟真正控制的效果,不要求一定用真实的控制方法去实现。

三、报告正文至少包括以下内容:能体现运行效果的若干界面截图,用到的各种控件,设计方法步骤,程序源代码等。

 

内容:

14、载人电梯系统设计

要求:

(1)建筑、人与电梯的界面设计;

(2)当有人按向上按钮时,电梯若位于人的上面,则电梯先下来,然后开门;

(3)人进入电梯后,按相应的数字键,电梯则上升到相应的楼层。

答案:

所用的控件如图:

 

 

源代码如下:

unit DT;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Shape1: TShape;
    Shape3: TShape;
    Shape9: TShape;
    Shape4: TShape;
    Shape5: TShape;
    Shape6: TShape;
    Shape7: TShape;
    Shape10: TShape;
    Shape11: TShape;
    Shape12: TShape;
    Shape13: TShape;
    Shape2: TShape;
    Shape8: TShape;
    Shape14: TShape;
    Shape15: TShape;
    Shape16: TShape;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Edit1: TEdit;
    Button9: TButton;
    Button10: TButton;
    Button11: TButton;
    Button12: TButton;
    Button13: TButton;
    Timer1: TTimer;
    Timer2: TTimer;
    Shape17: TShape;
    Shape18: TShape;
    Shape19: TShape;
    Timer3: TTimer;
    Timer4: TTimer;
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure Button13Click(Sender: TObject);
    procedure Timer3Timer(Sender: TObject);
    procedure Timer4Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  N:integer; //用于计时的临时变量
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin //所有电梯外按钮
edit1.text:=inttostr((Sender As TButton).tag);//记录按钮号
TIMER1.Enabled :=TRUE; //启动空电梯来计时器
shape17.Top:=104+(4-strtoint(edit1.text)DIV 2)*128;//将人物形象移动到此层
shape18.Top:=120+(4-strtoint(edit1.text)DIV 2)*128;
shape19.Top:=144+(4-strtoint(edit1.text)DIV 2)*128;
shape19.left:= 276;
shape18.Left:=shape19.Left-4;
shape17.left:=shape18.Left;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin //电梯空计时器
if  shape3.top<32+(4-strtoint(edit1.text)DIV 2)*128 then
begin
SHAPE3.Top:=SHAPE3.TOP+1;  //向下移动电梯外框及 电梯内按钮
SHAPE4.Top:=SHAPE4.TOP+1;
SHAPE5.Top:=SHAPE5.TOP+1;
SHAPE9.Top:=SHAPE9.TOP+1;
BUTTON9.Top:=BUTTON9.Top+1;
BUTTON10.Top:=BUTTON10.Top+1;
BUTTON11.Top:=BUTTON11.Top+1;
BUTTON12.Top:=BUTTON12.Top+1;
BUTTON13.Top:=BUTTON13.Top+1;
end;

if  shape3.top>32+(4-strtoint(edit1.text)DIV 2)*128 then
begin
SHAPE3.Top:=SHAPE3.TOP-1;  //向上移动电梯外框及电梯内按钮
SHAPE4.Top:=SHAPE4.TOP-1;
SHAPE5.Top:=SHAPE5.TOP-1;
SHAPE9.Top:=SHAPE9.TOP-1;
BUTTON9.Top:=BUTTON9.Top-1;
BUTTON10.Top:=BUTTON10.Top-1;
BUTTON11.Top:=BUTTON11.Top-1;
BUTTON12.Top:=BUTTON12.Top-1;
BUTTON13.Top:=BUTTON13.Top-1;
end;

if  shape3.top=32+(4-strtoint(edit1.text)DIV 2)*128 then
begin
timer1.Enabled :=false; //到达该层后 停止计时器
timer2.Enabled :=true;  //启动开门 进人计时器
N:=0;
end;

end;

procedure TForm1.Timer2Timer(Sender: TObject);
begin //开门进人计时器
N:=N+1;
if N=1 then shape5.Brush.Color:=clBtnFace; //隐藏门
shape19.left:= 276-(276-148)div 6*N;    //人物移动
shape18.Left:=shape19.Left-4;
shape17.left:=shape18.Left;
if N=6 then      //6秒后关门
begin
shape5.Brush.Color:=clTeal;
timer2.Enabled :=false;   //停止计时
end;
end;

procedure TForm1.Button13Click(Sender: TObject);
begin  //电梯内所有按钮程序
edit1.text:=inttostr((Sender As TButton).tag);
TIMER3.Enabled :=TRUE;
end;

procedure TForm1.Timer3Timer(Sender: TObject);
begin //有人电梯移动计时器
if  shape3.top<32+(4-strtoint(edit1.text)DIV 2)*128 then
begin                        //向下移动
SHAPE3.Top:=SHAPE3.TOP+1;
SHAPE4.Top:=SHAPE4.TOP+1;
SHAPE5.Top:=SHAPE5.TOP+1;
SHAPE9.Top:=SHAPE9.TOP+1;
BUTTON9.Top:=BUTTON9.Top+1;
BUTTON10.Top:=BUTTON10.Top+1;
BUTTON11.Top:=BUTTON11.Top+1;
BUTTON12.Top:=BUTTON12.Top+1;
BUTTON13.Top:=BUTTON13.Top+1;
shape17.Top:=shape17.Top+1;  //人物随着电梯移动
shape18.Top:=shape18.Top+1;
shape19.Top:=shape19.Top+1;
end;

if  shape3.top>32+(4-strtoint(edit1.text)DIV 2)*128 then
begin                      //向上移动
SHAPE3.Top:=SHAPE3.TOP-1;
SHAPE4.Top:=SHAPE4.TOP-1;
SHAPE5.Top:=SHAPE5.TOP-1;
SHAPE9.Top:=SHAPE9.TOP-1;
BUTTON9.Top:=BUTTON9.Top-1;
BUTTON10.Top:=BUTTON10.Top-1;
BUTTON11.Top:=BUTTON11.Top-1;
BUTTON12.Top:=BUTTON12.Top-1;
BUTTON13.Top:=BUTTON13.Top-1;
shape17.Top:=shape17.Top-1;
shape18.Top:=shape18.Top-1;
shape19.Top:=shape19.Top-1;
end;

if  shape3.top=32+(4-strtoint(edit1.text)DIV 2)*128 then
begin                    //到达目的层
timer3.Enabled :=false;  //停止计时
timer4.Enabled :=true;   // 启动开门出人计时器
N:=0;
end;
end;

procedure TForm1.Timer4Timer(Sender: TObject);
begin //开门出人计时器
N:=N+1;
if N=1 then shape5.Brush.Color:=clBtnFace;
shape19.left:= 148+(276-148)div 6*N; //人向电梯外移动
shape18.Left:=shape19.Left-4;
shape17.left:=shape18.Left;
if N=6 then
begin
shape5.Brush.Color:=clTeal;  //关门
timer4.Enabled :=false;     //停止计时
end;
end;
end.

 

运行中图片

 

缺点:程序中只有1人乘电梯  程序中并没有对 :例如人在电梯内 若电梯外按钮呼叫的处理机制。但对于题目提出的要求能很好的满足,而且多出到楼层后自动开门 出人的功能。

希望楼主满意!可追问。

太简单的就别说了

上一个:delphi学习问题
下一个:如何应用Delphi编程数据库?

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,