Ejemplo n.º 1
0
        /// <summary>
        /// Add a new cars the given crossing
        /// </summary>
        private void addCars(Crossing c)
        {
            ////////////add new cars to street E
            if (c.FlowE > c.EnteredE &&                                                 //if there are still cars to enter a crossing and
                c.StreetE.LaneEnter1[0] == null && c.StreetE.LaneEnter2[0] == null)   //there is an available slot at the entrance of the street
            {
                Car car = new Car();

                car.Street = c.StreetE;
                car.Crossing = c;
                car.Direction = Direction.West;
                car.StreetIndex[0] = -1;
                car.StreetIndex[1] = -1;
                car.HasEnteredGrid = false;
                car.HasExitedGrid = false;

                c.EnteredE++;
                _listOfCars.Add(car);
                //car.move();
            }

            ////////////add new cars to street W
            if (c.FlowW > c.EnteredW &&                                                 //if there are still cars to enter a crossing and
                c.StreetW.LaneEnter1[0] == null && c.StreetW.LaneEnter2[0] == null)   //there is an available slot at the entrance of the street
            {

                Car car = new Car();

                car.Street = c.StreetW;
                car.Crossing = c;
                car.Direction = Direction.East;
                car.StreetIndex[0] = -1;
                car.StreetIndex[1] = -1;
                car.HasEnteredGrid = false;
                car.HasExitedGrid = false;

                c.EnteredW++;
                _listOfCars.Add(car);
                //car.move();
            }

            ////////add new cars to street S
            if (c.FlowS > c.EnteredS &&                                                   //if there are still cars to enter a crossing and
                c.StreetS.LaneEnter1[0] == null                                           //there is an available slot at the entrance of lane enter 1
                && (c.GetType() == typeof(Crossing_2) || c.StreetS.LaneEnter2[0] == null))//and, in case its a crossing 1, there is an available slot at the entrance of lane 2
            {

                Car car = new Car();

                car.Street = c.StreetS;
                car.Crossing = c;
                car.Direction = Direction.North;
                car.StreetIndex[0] = -1;
                car.StreetIndex[1] = -1;
                car.HasEnteredGrid = false;
                car.HasExitedGrid = false;

                c.EnteredS++;
                _listOfCars.Add(car);
                //car.move();
            }

            ////////add new cars to street N
            if (c.FlowN > c.EnteredN &&                                                   //if there are still cars to enter a crossing
                c.StreetN.LaneEnter1[0] == null                                           //and if there is an available slot at the entrance of lane enter 1
                && (c.GetType() == typeof(Crossing_2) || c.StreetN.LaneEnter2[0] == null))//and, unless it's a crossing_2, if there is an available slot at the entrance of lane 2
            {
                Car car = new Car();

                car.Street = c.StreetN;
                car.Crossing = c;
                car.Direction = Direction.South;
                car.StreetIndex[0] = -1;
                car.StreetIndex[1] = -1;
                car.HasEnteredGrid = false;
                car.HasExitedGrid = false;

                c.EnteredN++;
                _listOfCars.Add(car);
                //car.move();
            }
        }
Ejemplo n.º 2
0
        private void drawCar(Car c)
        {
            int x=pictureBox1.Location.X, y=pictureBox1.Location.Y;
            if(c.Crossing.GetType() == typeof(Crossing_2))
                x += 3*66;

            switch(c.Street.Position)
                {
                    case Direction.North:
                            x += 6 + 66 + 22 * c.StreetIndex[0];
                            y += 6 + 22 * c.StreetIndex[1];
                            break;
                    case Direction.West:
                            x += 6 + 22 * c.StreetIndex[1];
                            y += 66 * 2 - 6 - 22 * c.StreetIndex[0] - 9;
                            break;
                    case Direction.South:
                            x += 66 * 2 - 6 - 22 * c.StreetIndex[0] - 9;
                            y += 66 * 3 - 6 - 22 * c.StreetIndex[1] - 9;
                            break;
                    case Direction.East:
                            x += 66 * 3 - 6 - 22 * c.StreetIndex[1];
                            y += 66 + 6 + 22 * c.StreetIndex[0];
                            break;
                    case Direction.Center:
                            x += 66 + 6 + 22 * c.StreetIndex[0];
                            y += 66 + 6 + 22 * c.StreetIndex[1];
                            break;
            }
            addElement(x, y, "Bitmap1");
                //MessageBox.Show("Street Location: " + c.Street.Position.ToString() + "\nIndex: " + c.StreetIndex[0] + " " + c.StreetIndex[0]);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add a new cars the given crossing
        /// </summary>
        private void addCars(Crossing c)
        {
            ////////////add new cars to street E
            if (c.FlowE > c.EnteredE)//if there are still cars to enter a crossing and
            {
                Car car = new Car(c);

                car.Street = c.StreetE;
                car.Direction = Direction.West;
                car.StreetIndex[0] = -1;
                car.StreetIndex[1] = -1;
                car.HasEnteredGrid = false;
                car.HasExitedGrid = false;

                c.EnteredE++;
                _listOfCars.Add(car);
            }

            ////////////add new cars to street W
            if (c.FlowW > c.EnteredW)
            {

                Car car = new Car(c);

                car.Street = c.StreetW;
                car.Direction = Direction.East;
                car.StreetIndex[0] = -1;
                car.StreetIndex[1] = -1;
                car.HasEnteredGrid = false;
                car.HasExitedGrid = false;

                c.EnteredW++;
                _listOfCars.Add(car);
            }

            ////////add new cars to street S
            if (c.FlowS > c.EnteredS)
            {

                Car car = new Car(c);

                car.Street = c.StreetS;
                car.Direction = Direction.North;
                car.StreetIndex[0] = -1;
                car.StreetIndex[1] = -1;
                car.HasEnteredGrid = false;
                car.HasExitedGrid = false;

                c.EnteredS++;
                _listOfCars.Add(car);
            }

            ////////add new cars to street N
            if (c.FlowN > c.EnteredN)
            {
                Car car = new Car(c);

                car.Street = c.StreetN;
                car.Direction = Direction.South;
                car.StreetIndex[0] = -1;
                car.StreetIndex[1] = -1;
                car.HasEnteredGrid = false;
                car.HasExitedGrid = false;

                c.EnteredN++;
                _listOfCars.Add(car);
            }
        }
Ejemplo n.º 4
0
        private void button4_Click(object sender, EventArgs e)
        {
            Crossing c = new Crossing_2();
            c.ID = "A0";

            Car c2 = new Car();
            c2.Crossing = c;
               // MessageBox.Show("Direction:" + c2.Street.Position.ToString());
                    c2.StreetIndex[0] = 1;
                //c2.Direction = Direction.West;
                c2.Street = c.StreetW;
                c2.StreetIndex[1] = 0;
                c2.HasEnteredGrid = true;
                c2.Crossing = c;
                c2.HasExitedGrid = false;
                drawCar(c2);
        }
Ejemplo n.º 5
0
        private void drawCar(Car c)
        {
            if (c != null && c.HasEnteredGrid && !c.HasExitedGrid) //initial check
            {
                int x = pictureBoxSlotA0.Location.X + (int)(c.Crossing.ID[0] - 'A') * 3 * 66;
                int y = pictureBoxSlotA0.Location.Y + (int)(c.Crossing.ID[1] - '0') * 3 * 66;

                switch (c.Street.Position)
                {
                    case Direction.North:
                        x += 6 + 66 + 22 * c.StreetIndex[0];
                        y += 6 + 22 * c.StreetIndex[1];
                        break;
                    case Direction.West:
                        x += 6 + 22 * c.StreetIndex[1];
                        y += 66 * 2 - 6 - 22 * c.StreetIndex[0] - 10;
                        break;
                    case Direction.South:
                        x += 66 * 2 - 6 - 22 * c.StreetIndex[0] - 10;
                        y += 66 * 3 - 6 - 22 * c.StreetIndex[1] - 10;
                        break;
                    case Direction.East:
                        x += 66 * 3 - 6 - 22 * c.StreetIndex[1] - 10;
                        y += 66 + 6 + 22 * c.StreetIndex[0];
                        break;
                    case Direction.Center:
                        x += 66 + 6 + 22 * c.StreetIndex[0];
                        y += 66 + 6 + 22 * c.StreetIndex[1];
                        break;
                }
                addElement(x, y, "car " + c.Direction.ToString());
            }
        }