コード例 #1
0
        public Vehicle(int ID, int weight, Road startRoad)
        {
            //picturebox setting
            this.BackColor = System.Drawing.Color.Transparent;
            this.Image = global::SmartTrafficSimulator.Properties.Resources.vehicle0;
            this.Size = new System.Drawing.Size(vehicle_GraphicLength, vehicle_GraphicWidth);
            this.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;

            createdTime = Simulator.getCurrentTime();
            vehicle_ID = ID;
            vehicle_weight = weight;
            locatedRoad = startRoad;

            this.vehicle_length = System.Convert.ToInt16(Simulator.VehicleManager.vehicleLength);
            this.safeDistance = this.vehicle_length*3;
            this.vehicle_GraphicLength = Simulator.VehicleManager.vehicleGraphicSize * 2;
            this.vehicle_GraphicWidth = Simulator.VehicleManager.vehicleGraphicSize;

            this.SetDrivingPath(Simulator.VehicleManager.GetRoadomDrivingPath(startRoad.roadID));

            this.roadPoints = startRoad.GetRoadPointList();

            this.setLocation(roadPoints[0]);
            this.locatedRoad.VehicleEnterRoad(this);
        }
コード例 #2
0
        public void ToNextRoad(int remainRunPixel)
        {
            UploadVehicleWaittingTime();
            travelDistace_pixel += locatedRoad.GetRoadLength();
            locatedRoad.VehicleExitRoad(this);
            if (locatedRoad.roadType == 0 || locatedRoad.roadType == 1) //目前的為一般道路
            {
                passingRoadIndex++;
                if (passingRoadIndex >= passingRoads.Count)
                {
                    travelTime_total = Simulator.getCurrentTime() - createdTime;
                    Simulator.VehicleManager.DestoryVehicle(vehicle_ID);
                }
                else
                {
                    for (int x = 0; x < locatedRoad.intermediateRoadList.Count; x++) //尋找連接到下一條路的連接路段
                    {
                        if (locatedRoad.intermediateRoadList[x].connectRoad.roadID == passingRoads[passingRoadIndex].roadID)
                        {
                            locatedRoad = locatedRoad.intermediateRoadList[x];
                            location = 0;
                            roadPoints = locatedRoad.GetRoadPointList();
                            locatedRoad.VehicleEnterRoad(this);
                            VehicleMove(remainRunPixel);
                        }
                    }
                }
            }

            else if (locatedRoad.roadType == 2)//目前的為連接道路
            {
                locatedRoad = passingRoads[passingRoadIndex];
                location = 0;
                roadPoints = locatedRoad.GetRoadPointList();
                locatedRoad.VehicleEnterRoad(this);
                VehicleMove(remainRunPixel);
            }
        }