コード例 #1
0
        public LaneManager(Server server, settings Settings)
        {
            _server = server;
            _settings = Settings;

            _settings.orangeTime = Math.Max(_settings.orangeTime, 5);

            //generate all lanes
            foreach (char side in new []{'N', 'S', 'E', 'W' })
            {
                for (int laneNr = 1; laneNr <= 8; laneNr++)
                {
                    string id = String.Format("{0}{1}", side, laneNr);
                    _lanes[id] = LaneFactory.FromLaneNr(id, laneNr, _server, _settings);
                }
            }
        }
コード例 #2
0
        public static Lane FromLaneNr(string id, int laneNr, Server server, settings Settings )
        {
            switch (laneNr)
            {
                case 1:
                case 2:
                    return new Lane(id, server, Vehicle.PEDESTRIAN, Settings);
                case 3:
                case 4:
                case 5:
                    return new Lane(id, server, Vehicle.CAR, Settings);
                case 6:
                    return new Lane(id, server, Vehicle.BUS, Settings);
                case 7:
                case 8:
                    return new Lane(id, server, Vehicle.BICYCLE, Settings);
                default:
                    throw new ArgumentException("laneNr");

            }
        }
コード例 #3
0
        public Lane(string id, Server server, Vehicle type, settings Settings)
        {
            _id = id;
            _laneNr = Convert.ToInt32(id.Substring(1,1));
            _direction = (WindDirection) Enum.Parse(typeof(WindDirection),
                Enum.GetNames(typeof(WindDirection)).First((s) => s.StartsWith(id.Substring(0, 1))), true);

            _server = server;
            _vehicle = type;
            _state = TrafficLightState.Red;
            _orangeTime = Settings.orangeTime;
            BusDirections = new Queue<Direction>();

            int windPriority = _direction == WindDirection.North || _direction == WindDirection.South ? 10 : 0;
            switch (type)
            {
                case Vehicle.PEDESTRIAN:
                    _priority = 73;
                    break;
                case Vehicle.BICYCLE:
                    _priority = 100;
                    break;
                case Vehicle.CAR:
                    _priority = 200 + windPriority;
                    break;
                case Vehicle.BUS:
                    _priority = 300 + windPriority;
                    break;
            }

            _compatibilityList = new bool[][,] { _compatibilitySelf, _compatibilityLeft, _compatibilityStraight, _compatibilityRight };
        }