回 帖 发 新 帖 刷新版面

主题:代码较长,找好心人帮我挑错误.

不知道哪里弄错了 
在南北方向红灯的情况下 不能实现南北方向 流量只增加不减少 
      在东西方向红灯的情况下 也不能实现东西方向 流量只增加不减少 
而且记时 有时候会出现 "卡"的情况 
请大家帮帮我,挺着急的
有空的话帮我看一下 挺着急的 
可以 有报酬的 改.. 
联系方式: 
信箱 :lovar_008@yahoo.com.cn 
   QQ:88934591 

欲实现的功能是 

一、功能 
      实现十字路口的红绿灯简单演示。具体显示细节: 
         在FORM 上用PANEL 做了个十字路口 
         4个灯根据随机比较的结果改变颜色(红绿),每个方向用两个灯来表示通行信号。 
         6个EDIT 显示 横向纵向随即产生的车流量的动态变化,每个方向各3个EDIT表述单位时间内 
            流量信息:现流量、增加流量、减少流量(减少只有在绿灯的情况下发生) 
         BUTTON 按纽 控制整个程序的开始结束 

          
       
二、判断条件 
      X>=Y东西绿灯亮 南北红       X<Y南北绿灯亮 东西灯红 
      X<1或T=60s或X<10且Y>40东西灯红南北绿  Y<1或T=60s或Y<10且X>40南北灯红东西绿 
      Y<1或T=60s或Y<10且X>40南北灯红东西绿  X<1或T=60s或X<10且Y>40东西灯红南北绿 

      判断优先顺序: XY的现流量优先,时间和流量差次之。 
      XY分别代表东西、南北的车流现量。 
       
三、流量的产生 
XY分别代表东西、南北的车流现量。XY的变化,在绿灯的情况下,同时受到增加和减少的音响; 
 在红灯的情况下就只受到增加的影响。增加和减少是一个随机数,单位时间内各自不同。 
nb表示南北 
dx表示东西 

回复列表 (共5个回复)

沙发

代码太长 只能分成两部分发了
#include "Main.h" 
//---------------------------------------------------------- ----------------- 
#pragma resource "*.dfm" 
TMainForm *MainForm; 
int dwsj, llzjfw,lljsfw; 
int  sj; 
//---------------------------------------------------------- ----------------- 
__fastcall TMainForm::TMainForm(TComponent* Owner) 
   : TForm(Owner) 


//---------------------------------------------------------- ------------------ 

void __fastcall TMainForm::FormCreate(TObject *Sender) 

    MainForm->B_tz->Enabled = false; 
    dwsj = MainForm->E_dwsj->Text.ToInt(); 
    llzjfw = MainForm->E_llzjfw->Text.ToInt(); 
    lljsfw = MainForm->E_lljsfw->Text.ToInt(); 
    Timer1->Interval = dwsj; 

//---------------------------------------------------------- ----------------- 

void __fastcall TMainForm::B_gxClick(TObject *Sender) 

    dwsj = MainForm->E_dwsj->Text.ToInt(); 
    llzjfw = MainForm->E_llzjfw->Text.ToInt(); 
    lljsfw = MainForm->E_lljsfw->Text.ToInt(); 
    Timer1->Interval = dwsj; 

//---------------------------------------------------------- ----------------- 

板凳


void __fastcall TMainForm::B_ksClick(TObject *Sender) 


    int  nbmqll,nbzjll,nbjsll; 
    int  dxmqll,dxzjll,dxjsll; 
    int  x,y; //X(东西)与Y(南北) 

    MainForm->Timer1->Enabled = true; 
    MainForm->B_ks->Enabled = false; 
    MainForm->B_tz->Enabled = true; 
    //x = random(14); 
    //y = random(14); 

    while (1) 
    { 
     //X>=Y东西绿灯亮 南北红 
     if  (x>=y) 
     { 
       //x<1 归零 
       if  (x<1) 
       { 
           x = abs(x); 
       } 
       //y<1 归零 
        if  (y<1) 
       { 
           y = abs(y); 
       } 

       S_East->Brush->Color = clLime; 
       S_West->Brush->Color = clLime; 
       S_South->Brush->Color = clRed; 
       S_North->Brush->Color = clRed; 

       nbzjll = random(llzjfw + 1); 
       nbjsll = random(lljsfw + 1); 
       E_nbzjll->Text = nbzjll; 
       E_nbjsll->Text = 0; 
       y = y + nbzjll; 
       E_nbmqll->Text = y; 

       dxzjll = random(llzjfw + 1); 
       dxjsll = random(lljsfw + 1); 
       E_dxzjll->Text = dxzjll; 
       E_dxjsll->Text = dxjsll; 
       x = x + dxzjll - dxjsll; 
       E_dxmqll->Text = x; 

       sj++; 
       //sj>60 归零 
       if  (sj>60) 
       { 
           sj = 0; 
       } 
       MainForm->E_sj->Text = sj; 
     } 
     else 
       { 
       break; 
       } 

     //X<1或T=60s或X<10且Y>40东西灯红南北绿 
     while  (x<1 || sj==60 || (x<10&&y>40)) 
     { 
       //x<1 归零 
       if  (x<1) 
       { 
           x = abs(x); 
       } 
       //y<1 归零 
        if  (y<1) 
       { 
           y = abs(y); 
       } 

       S_East->Brush->Color = clRed; 
       S_West->Brush->Color = clRed; 
       S_South->Brush->Color = clLime; 
       S_North->Brush->Color = clLime; 

       sj = 0; 
       nbzjll = random(llzjfw + 1); 
       nbjsll = random(lljsfw + 1); 
       E_nbzjll->Text = nbzjll; 
       E_nbjsll->Text = nbjsll; 
       y = y + nbzjll - nbjsll; 
       E_nbmqll->Text = y; 

       dxzjll = random(llzjfw + 1); 
       dxjsll = random(lljsfw + 1); 
       E_dxzjll->Text = dxzjll; 
       E_dxjsll->Text = 0; 
       x = x + dxzjll; 
       E_dxmqll->Text = x; 

       sj++; 
        //sj>60 归零 
       if  (sj>60) 
       { 
           sj = 0; 
       } 
       MainForm->E_sj->Text = sj; 
       break; 
     } 
     //else 
       //{ 
       //break; 
       //} 

3 楼

//Y<1或T=60s或Y<10且X>40南北灯红东西绿 
     while  (y<1 || sj==60 || (y<10&&x>40)) 
     { 
       //x<1 归零 
       if  (x<1) 
       { 
           x = abs(x); 
       } 
       //y<1 归零 
        if  (y<1) 
       { 
           y = abs(y); 
       } 
       S_South->Brush->Color = clRed; 
       S_North->Brush->Color = clRed; 
       S_East->Brush->Color = clLime; 
       S_West->Brush->Color = clLime; 

       sj = 0; 
       nbzjll = random(llzjfw + 1); 
       nbjsll = random(lljsfw + 1); 
       E_nbzjll->Text = nbzjll; 
       E_nbjsll->Text = 0; 
       y = y + nbzjll; 
       E_nbmqll->Text = y; 

       dxzjll = random(llzjfw + 1); 
       dxjsll = random(lljsfw + 1); 
       E_dxzjll->Text = dxzjll; 
       E_dxjsll->Text = dxjsll; 
       x = x + dxzjll - dxjsll; 
       E_dxmqll->Text = x; 

       sj++; 
       //sj>60 归零 
       if  (sj>60) 
       { 
           sj = abs(x); 
       } 
       MainForm->E_sj->Text = sj; 
       break; 
     } 
     //else 
       // { 
       //break; 
       //} 

      //X<Y南北绿灯亮 东西灯红 
    if  (x<y) 
    { 
        //x<1 归零 
       if  (x<1) 
       { 
           x = abs(x); 
       } 
       //y<1 归零 
        if  (y<1) 
       { 
           y = abs(y); 
       } 
       S_South->Brush->Color = clLime; 
       S_North->Brush->Color = clLime; 
       S_East->Brush->Color = clRed; 
       S_West->Brush->Color = clRed; 

       sj = 0; 
       nbzjll = random(llzjfw + 1); 
       nbjsll = random(lljsfw + 1); 
       E_nbzjll->Text = nbzjll; 
       E_nbjsll->Text = nbjsll; 
       y = y + nbzjll - nbjsll; 
       E_nbmqll->Text = y; 

       dxzjll = random(llzjfw + 1); 
       dxjsll = random(lljsfw + 1); 
       E_dxzjll->Text = dxzjll; 
       E_dxjsll->Text = 0; 
       x = x + dxzjll; 
       E_dxmqll->Text = x; 

       sj++; 
       //sj>60 归零 
       if  (sj>60) 
       { 
           sj = 0; 
       } 
       MainForm->E_sj->Text = sj; 
       //break; 
     } 
     else 
       { 
       break; 
       } 

     //Y<1或T=60s或Y<10且X>40南北灯红东西绿 
     while  (y<1 || sj==60 || (y<10&&x>40)) 
     { 
        //x<1 归零 
       if  (x<1) 
       { 
           x = abs(x); 
       } 
       //y<1 归零 
       if  (y<1) 
       { 
           y = abs(y); 
       } 
       S_South->Brush->Color = clRed; 
       S_North->Brush->Color = clRed; 
       S_East->Brush->Color = clLime; 
       S_West->Brush->Color = clLime; 

       sj = 0; 
       nbzjll = random(llzjfw + 1); 
       nbjsll = random(lljsfw + 1); 
       E_nbzjll->Text = nbzjll; 
       E_nbjsll->Text = 0; 
       y = y + nbzjll; 
       E_nbmqll->Text = y; 

       dxzjll = random(llzjfw + 1); 
       dxjsll = random(lljsfw + 1); 
       E_dxzjll->Text = dxzjll; 
       E_dxjsll->Text = dxjsll; 
       x = x + dxzjll - dxjsll; 
       E_dxmqll->Text = x; 

       sj++; 
       //sj>60 归零 
       if  (sj>60) 
       { 
        sj = 0; 
       } 
       MainForm->E_sj->Text = sj; 
       break; 
     } 
     //else 
       //{ 
       //break; 
       //} 

4 楼

//X<1或T=60s或X<10且Y>40东西灯红南北绿 
     while  (x<1 || sj==60 || (x<10&&y>40)) 
     { 
        //x<1 归零 
       if  (x<1) 
       { 
           x = abs(x); 
       } 
       //y<1 归零 
       if  (y<1) 
       { 
           y = abs(y); 
       } 
       S_East->Brush->Color = clRed; 
       S_West->Brush->Color = clRed; 
       S_South->Brush->Color = clLime; 
       S_North->Brush->Color = clLime; 

       sj = 0; 
       nbzjll = random(llzjfw + 1); 
       nbjsll = random(lljsfw + 1); 
       E_nbzjll->Text = nbzjll; 
       E_nbjsll->Text = nbjsll; 
       y = y + nbzjll - nbjsll; 
       E_nbmqll->Text = y; 

       dxzjll = random(llzjfw + 1); 
       dxjsll = random(lljsfw + 1); 
       E_dxzjll->Text = dxzjll; 
       E_dxjsll->Text = 0; 
       x = x + dxzjll; 
       E_dxmqll->Text = x; 

       sj++; 
       //sj>60 归零 
       if  (sj>60) 
       { 
           sj = 0; 
       } 
       MainForm->E_sj->Text = sj; 
       break; 
     } 
     //else 
       //{ 
       //break; 
       //} 
    } 

}

5 楼

代码长 只能发这么多次了
希望 有空 有能力的好心人帮帮我~
先谢谢 各位浏览了
再先 万分感谢 帮助我的人~!

我来回复

您尚未登录,请登录后再回复。点此登录或注册