예제 #1
0
 public RoadIntersection(SerializationInfo info, StreamingContext ctxt)
 {
     RoadIntersection.RED_LIGHT = (short)info.GetValue("RED_LIGHT", typeof(short));
     RoadIntersection.YELLOW_LIGHT = (short)info.GetValue("YELLOW_LIGHT", typeof(short));
     RoadIntersection.GREEN_LIGHT = (short)info.GetValue("GREEN_LIGHT", typeof(short));
     RoadIntersection.TURNING_YELLOW_LIGHT = (short)info.GetValue("TURNING_YELLOW_LIGHT", typeof(short));
     RoadIntersection.TURNING_GREEN_LIGHT = (short)info.GetValue("TURNING_GREEN_LIGHT", typeof(short));
     RoadIntersection.TURNING_RED_LIGHT = (short)info.GetValue("TURNING_RED_LIGHT", typeof(short));
     this.road = (Road)info.GetValue("road", typeof(Road));
     this.lightState = (short)info.GetValue("lightState", typeof(short));
     this.roadOrientation = (bool)info.GetValue("roadOrientation", typeof(bool));
     this.intersectionCenter = (int)info.GetValue("intersectionCenter", typeof(int));
 }
예제 #2
0
        private bool trafficJam(Road road, Boolean trafficDirection)
        {
            int noBlockedLanes = 0;

            for (int i = 0; i < road.getLanes(trafficDirection).Count(); i++)
            // foreach (Lane l in road.getLanes(trafficDirection))
            {
                Lane l = road.getLanes(trafficDirection)[i];
                //   foreach (Car c in l.getCars())
                for (int j = 0; j < l.getCars().Count(); j++)
                {
                    Car c = l.getCars()[j];
                    if (trafficDirection == Settings.TRAFFIC_EAST_SOUTH)
                    {
                        if (c.getLanePosition() <= (1 - Settings.TRAFFIC_JAM_THRESHOLD) * road.getRoadLength() && c.getStopped() == true)
                        {
                            noBlockedLanes++;
                        }
                    }
                    else
                    {
                        if (c.getLanePosition() >= Settings.TRAFFIC_JAM_THRESHOLD * road.getRoadLength() && c.getStopped() == true)
                        {
                            noBlockedLanes++;
                        }
                    }
                }
            }

            if (noBlockedLanes >= (int)(road.getNoLanes(trafficDirection) * Settings.TRAFFIC_JAM_LANES_JAMMED))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
예제 #3
0
        private void renderCars(Road renderRoad, Graphics g, int roadX, int roadY, Boolean roadOrient, Boolean trafficFlowDirection)
        {
            SolidBrush myBrush2 = new SolidBrush(Color.White);
            myBrush2.Color = Color.White;
            int lNum = 0;
            int rectW, rectH, rectX, rectY, lanesXEastSouth, lanesYEastSouth, lanesXWestNorth, lanesYWestNorth;

            if (roadOrient == Settings.ROAD_EAST_WEST)
            {
                rectW = Settings.CAR_LENGTH; ;
                rectH = Settings.CAR_WIDTH;
            }
            else
            {
                rectW = Settings.CAR_WIDTH;
                rectH = Settings.CAR_LENGTH;
            }

            if (trafficFlowDirection == Settings.TRAFFIC_FLOW_LEFT_HAND_TRAFFIC)
            {
                if (roadOrient == Settings.ROAD_SOUTH_NORTH)
                {
                    lanesXEastSouth = roadX + (renderRoad.getNoLanes(Settings.TRAFFIC_WEST_NORTH) * Settings.LANE_WIDTH);
                    lanesXWestNorth = roadX;
                    lanesYEastSouth = roadY;
                    lanesYWestNorth = roadY;
                }
                else
                {
                    lanesXEastSouth = roadX;
                    lanesXWestNorth = roadX;
                    lanesYEastSouth = roadY;
                    lanesYWestNorth = roadY + (renderRoad.getNoLanes(Settings.TRAFFIC_EAST_SOUTH) * Settings.LANE_WIDTH);
                }
            }
            else
            {
                if (roadOrient == Settings.ROAD_SOUTH_NORTH)
                {
                    lanesXEastSouth = roadX;
                    lanesXWestNorth = roadX + (renderRoad.getNoLanes(Settings.TRAFFIC_EAST_SOUTH) * Settings.LANE_WIDTH);
                    lanesYEastSouth = roadY;
                    lanesYWestNorth = roadY;
                }
                else
                {
                    lanesXEastSouth = roadX;
                    lanesXWestNorth = roadX;
                    lanesYEastSouth = roadY + (renderRoad.getNoLanes(Settings.TRAFFIC_WEST_NORTH) * Settings.LANE_WIDTH);
                    lanesYWestNorth = roadY;
                }
            }

            foreach (Lane l in renderRoad.getLanes(Settings.TRAFFIC_EAST_SOUTH))
            {
                lNum++;
                foreach (Car c in l.getCars())
                {
                    if (roadOrient == Settings.ROAD_EAST_WEST)
                    {
                        rectX = lanesXEastSouth + c.getLanePosition();
                        rectY = lanesYEastSouth + ((lNum - 1) * Settings.LANE_WIDTH) + ((Settings.LANE_WIDTH - Settings.CAR_WIDTH) / 2);
                    }
                    else
                    {
                        rectX = lanesXEastSouth + ((lNum - 1) * Settings.LANE_WIDTH) + ((Settings.LANE_WIDTH - Settings.CAR_WIDTH) / 2);
                        rectY = lanesYEastSouth + c.getLanePosition();
                    }
                    g.FillRectangle(myBrush2, rectX, rectY, rectW, rectH);
                }
            }

            lNum = 0;

            foreach (Lane l in renderRoad.getLanes(Settings.TRAFFIC_WEST_NORTH))
            {
                lNum++;
                foreach (Car c in l.getCars())
                {
                    if (roadOrient == Settings.ROAD_EAST_WEST)
                    {
                        rectX = lanesXWestNorth + c.getLanePosition();
                        rectY = lanesYWestNorth + ((lNum - 1) * Settings.LANE_WIDTH) + ((Settings.LANE_WIDTH - Settings.CAR_WIDTH) / 2);
                    }
                    else
                    {
                        rectX = lanesXWestNorth + ((lNum - 1) * Settings.LANE_WIDTH) + ((Settings.LANE_WIDTH - Settings.CAR_WIDTH) / 2);
                        rectY = lanesYWestNorth + c.getLanePosition();
                    }
                    g.FillRectangle(myBrush2, rectX, rectY, rectW, rectH);
                }
            }
        }
예제 #4
0
 public RoadIntersection(int intersectionCenter, short noWestNorthLanes, short noEastSouthLanes, int roadLength, int roadSpeed, bool roadOrientation)
 {
     this.road = new Road(noEastSouthLanes, noWestNorthLanes, roadLength, roadSpeed);
     this.intersectionCenter = intersectionCenter;
     this.roadOrientation = roadOrientation;
 }
예제 #5
0
 // Sets the road element which this section of the intersection belongs to
 public void setRoad(Road road)
 {
     this.road = road;
 }