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; } }
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); } } }