Beispiel #1
0
        /// <summary>
        /// creates the cars for each lane in each crossing
        /// </summary>
        public void CreateCars()
        {
            cars = new List<Car>();
            List<TrafficLane> tmp = new List<TrafficLane>();
            Random rnd = new Random();
            Color c;

            foreach (Crossing item in Crossings)
            {
                tmp.AddRange(item.Lanes.FindAll(x => x.LaneType == true));

                for (int i = 0; i < item.NumCars; i++)
                {
                    c = Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255));

                    // car = new Car(count, c, item); // DEBUG
                    car = new Car(c, tmp.ElementAt(rnd.Next(tmp.Count())));


                    cars.Add(car);
                }
                tmp = new List<TrafficLane>();

            }
        }
Beispiel #2
0
		/// <summary>
		/// Draw cars
		/// </summary>
		/// <param name="c">Car instance</param>
		/// <param name="d">Direction the car is heading to</param>
		public void drawCar(Car c, Direction d)
        {
            Rectangle r;
            SolidBrush brush = new SolidBrush(c.Color);

            if (d == Direction.WEST || d == Direction.EAST)
                r = new Rectangle(c.CurPoint.X, c.CurPoint.Y, CAR_WIDTH, CAR_HEIGHT);
            else
                r = new Rectangle(c.CurPoint.X, c.CurPoint.Y, CAR_HEIGHT, CAR_WIDTH);

            painter.Graphics.FillRectangle(brush, r);
        }