本站使用了 Pjax 等基于 JavaScript 的开发技术,但您的浏览器已禁用 JavaScript,请开启 JavaScript 以保证网站正常显示!

毕业设计思路篇(二)之交通灯的初始化

道路类型的设置

it->m_CTrafficLight_Light.setType(it->JunctionRoad.size());

根据路口道路条数, 设置路灯类型(是T字路口还是+字路口)

/**
 * 交通灯类
 */
class TrafficLight {
public:
    TrafficLight() {
        for (int i = 0; i < 8; i++) {
            roadID[i] = -1;
        }

    };
    void changeStatus();

    void clock(int time);

    void setAllRed();

    void setAllGreen();

    bool getStatus(int from, int to);
    /**
     * 设置灯的类型, 是T字路口还是+字路口
     * @param type 
     */
    void setType(int type) { this->type = type; };
    //路口标号
    // nLeftIn,nLeftOut,nDownIn,nDownOut,nRightIn,nRightOut,nUpIn,nUpOut;
    int roadID[8];
    //路口是否能走通
    bool status[4][4] = {false};
    int type;
    //表示可通过的方向(目标方向)
    //AllRED = 0,LeftGreen = 1,DownGreen = 2,RightGreen = 3,UpGreen = 4,UpDownGreen = 5,LeftRightGreen = 6,cross1 = 7,cross2 = 8
    int emStatus = 0;
    long long int time = 0;
};

对接各路口

it->m_CTrafficLight_Light.roadID[4] = it->JunctionRoad[0].inID;
it->m_CTrafficLight_Light.roadID[5] = it->JunctionRoad[0].outID;

it->m_CTrafficLight_Light.roadID[0] = it->JunctionRoad[1].inID;
it->m_CTrafficLight_Light.roadID[1] = it->JunctionRoad[1].outID;
switch (it->JunctionRoad.size()) {
    case 4:
       it->m_CTrafficLight_Light.roadID[6] = it->JunctionRoad[3].inID;
       it->m_CTrafficLight_Light.roadID[7] = it->JunctionRoad[3].outID;
       //你是不是想说没有break?这里不需要break;
    case 3:
       it->m_CTrafficLight_Light.roadID[2] = it->JunctionRoad[2].inID;
       it->m_CTrafficLight_Light.roadID[3] = it->JunctionRoad[2].outID;
    }

交通灯初始化完毕.

———— 本文结束 感谢阅读 ————

推广

 继续浏览关于 Traffic-Network-Model 的文章

 本文最后更新于:2019/01/26 17:36:41,可能因经年累月而与现状有所差异

 引用转载请注明:指尖魔法屋 > 学习笔记 > 毕业设计思路篇(二)之交通灯的初始化