Esempio n. 1
0
        private void openToolStripMenuOpen_Click(object sender, EventArgs e)
        {
            debug    = this.cBDebugPoint.Checked;
            cardebug = this.cBDebugCars.Checked;

            if (selectedPicBox != null)
            {
                unselectCurrentCrossing();
            }

            if (Simulation.Saved == true)
            {
                Clear();
            }
            else
            {
                DialogResult dResult = MessageBox.Show("Would you like to save your changes? Unsaved changes will be lost.", "New simulation", MessageBoxButtons.YesNoCancel);
                if (dResult == DialogResult.Yes)
                {
                    Simulation.SaveAs(Simulation.Name);
                    SaveToFile();

                    Clear();
                }
                else if (dResult == DialogResult.No)
                {
                    Clear();
                }
            }


            if (!GetFromFile())
            {
                MessageBox.Show("Error whilst loading file");
            }
            else
            {
                foreach (Crossing item in Simulation.Crossings)
                {
                    tempCrossing.Add(item);
                }
                Simulation.Crossings.Clear();

                foreach (Crossing cr in tempCrossing)
                {
                    if (cr.GetType() == typeof(Crossing_A))
                    {
                        Crossing_A cra = new Crossing_A(cr.CrossingId);
                        Simulation.AddCrossing(cra);
                        CrossingType(cra);
                    }
                    else
                    {
                        Crossing_B crb = new Crossing_B(cr.CrossingId);
                        Simulation.AddCrossing(crb);
                        CrossingType(crb);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// A constructor for Pedestrian lane
        /// </summary>
        /// <param name="iD">the id of the lane</param>
        /// <param name="points">a list of points on the lane</param>
        /// <param name="pLight">the light object on the lane</param>
        /// <param name="crossing">the crossing this lane belongs to</param>
        public PedestrianLane(int iD, List<Point> points, PedestrianLight pLight, Crossing_B crossing)
            : base(iD, points)
        {
            this.PLight = pLight;
            this.parent = crossing;

        }
Esempio n. 3
0
        /// <summary>
        /// Constructor for type pedestrian
        /// </summary>
        /// <param name="pedId">which pedestrian</param>
        /// <param name="Crossing">on which crossing should it be created</param>

        public Pedestrian(int pedId, Crossing_B Crossing)
        {
            this.pedId         = pedId;
            this.crossing      = Crossing;
            this.StartPosition = WhereToStart();
            this.position      = StartPosition;
            PressSensor();
        }
Esempio n. 4
0
        /// <summary>
        /// Constructor for type pedestrian
        /// </summary>
        /// <param name="pedId">which pedestrian</param>
        /// <param name="Crossing">on which crossing should it be created</param>

        public Pedestrian(int pedId, Crossing_B Crossing)
        {
            this.pedId = pedId;
            this.crossing = Crossing;
            this.StartPosition = WhereToStart();
            this.position = StartPosition;
            PressSensor();
        }
Esempio n. 5
0
        private void TimerSimulation_Tick(object sender, EventArgs e)
        {
            if (count > 0)
            {
                if (play)
                {
                    this.labelTime.Text            = Simulation.Watch.Elapsed.Minutes + " Minutes " + Simulation.Watch.Elapsed.Seconds + " Seconds";
                    this.labelCarsAdded.Text       = Simulation.TotalNumberCars.ToString();
                    this.labelCarsRemaining.Text   = count.ToString();
                    this.labelLightSwitches.Text   = Simulation.TotalNumberofSwitches.ToString();
                    this.labelCrossingNumbers.Text = Simulation.Crossings.Count.ToString();
                    foreach (Crossing c in Simulation.Crossings)
                    {
                        foreach (TrafficLane l in c.Lanes)
                        {
                            for (int i = 0; i < l.Cars.Count; i++)
                            {
                                GetAllPictureboxes(panel1);

                                Car car = l.Cars.ElementAt(i);

                                foreach (PictureBox p in ControlList)
                                {
                                    p.Invalidate();
                                }

                                car.DriveLane();

                                foreach (PictureBox p in ControlList)
                                {
                                    p.Invalidate();
                                }
                            }
                        }

                        //will need to be changed
                        if (c.GetType() == typeof(Crossing_B))
                        {
                            Crossing_B b = (Crossing_B)c;
                            for (int p = 0; p < b.GetNumberOfPedesToMove(); p++)
                            {
                                b.pedestrians[p].Walk();
                            }
                        }

                        //ped walk stuff
                    }
                }
            }
            else
            {
                this.labelCarsRemaining.Text = "0";
                this.Stop();
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Gets the properties of the individual crossing
        /// </summary>
        /// <param name="id"></param>
        /// <param name="nCars"></param>
        /// <param name="time"></param>
        /// <param name="style"></param>
        public void getProperties(int id, ref int nCars, ref int time, ref string style)
        {
            Crossing cr = Crossings.Find(x => x.CrossingId == (id));

            nCars = cr.NumCars;
            time  = cr.Time.Seconds;

            if (cr.GetType() == typeof(Crossing_B))
            {
                Crossing_B cr1 = (Crossing_B)cr;
                //nPed = cr1.NumPeds;
                style = cr1.style;
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Edits the properties of the crossing
        /// eg. number of cars for that crossing, time the light is green, etc.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="numCars"></param>
        /// <param name="time"></param>
        /// <param name="style"></param>
        public void EditCrossing(int id, int numCars, int time, string style)
        {
            Crossing cr = Crossings.Find(x => x.CrossingId == (id));

            if (cr.GetType() == typeof(Crossing_A))
            {
                cr.NumCars = numCars;
                cr.Time    = new TimeSpan(0, 0, time);
            }
            else
            {
                Crossing_B cr1 = (Crossing_B)cr;
                cr1.NumCars = numCars;
                cr1.Time    = new TimeSpan(0, 0, time);
                cr1.style   = style;
                cr1.CreatePedestrians();
            }
        }
Esempio n. 8
0
        /// <summary>
        /// changes the lights to the next iteration
        /// </summary>
        /// <param name="c"></param>
        public void SwitchAll(Crossing c)
        {
            TotalNumberofSwitches++;

            if (c.GetType() == typeof(Crossing_A))
            {
                /*
                 #region A Crossing
                 *
                 * foreach (TrafficLane l in c.Lanes)
                 * {
                 *  if (l.TrafficLight != null)
                 *  {
                 *      if (l.Direction == (Direction)(c.Turn - 1))
                 *      {
                 *          l.TrafficLight.State = true;
                 *      }
                 *      else
                 *      {
                 *          l.TrafficLight.State = false;
                 *      }
                 *  }
                 *  c.Turn = ((c.Turn + 1) % 4);
                 *
                 *  if (c.Turn == 0)
                 *      c.Turn = 1;
                 * }
                 *
                 #endregion
                 */

                #region A Crossing
                switch (c.Turn)
                {
                case 1:
                    foreach (TrafficLane l in c.Lanes)
                    {
                        if (l.TrafficLight != null)
                        {
                            if (l.Direction == Direction.NORTH)
                            {
                                l.TrafficLight.State = true;
                            }
                            else
                            {
                                l.TrafficLight.State = false;
                            }
                        }
                    }
                    c.Turn++;
                    break;

                case 2:
                    foreach (TrafficLane l in c.Lanes)
                    {
                        if (l.TrafficLight != null)
                        {
                            if (l.Direction == Direction.EAST)
                            {
                                l.TrafficLight.State = true;
                            }
                            else
                            {
                                l.TrafficLight.State = false;
                            }
                        }
                    }
                    c.Turn++;
                    break;

                case 3:
                    foreach (TrafficLane l in c.Lanes)
                    {
                        if (l.TrafficLight != null)
                        {
                            if (l.Direction == Direction.SOUTH)
                            {
                                l.TrafficLight.State = true;
                            }
                            else
                            {
                                l.TrafficLight.State = false;
                            }
                        }
                    }
                    c.Turn++;
                    break;

                case 4:
                    foreach (TrafficLane l in c.Lanes)
                    {
                        if (l.TrafficLight != null)
                        {
                            if (l.Direction == Direction.WEST)
                            {
                                l.TrafficLight.State = true;
                            }
                            else
                            {
                                l.TrafficLight.State = false;
                            }
                        }
                    }
                    c.Turn = 1;
                    break;
                }
                #endregion
            }
            else
            {
                #region B Crossing


                Crossing_B cb = (Crossing_B)c;
                switch (c.Turn)
                {
                case 1:
                    cb.ATimer.Interval = 1000 * cb.Time.Seconds;
                    foreach (TrafficLane l in c.Lanes)
                    {
                        if (l.TrafficLight != null)
                        {
                            if (l.Direction == Direction.NORTH || l.Direction == Direction.SOUTH)
                            {
                                l.TrafficLight.State = true;
                            }
                            else
                            {
                                l.TrafficLight.State = false;
                            }
                        }
                    }
                    foreach (PedestrianLane pl in cb.pLanes)
                    {
                        if (pl.PLight != null)
                        {
                            pl.PLight.State = false;
                        }
                    }
                    c.Turn++;
                    break;

                case 2:
                    foreach (TrafficLane l in c.Lanes)
                    {
                        if (l.TrafficLight != null)
                        {
                            if (l.Direction == Direction.EAST)
                            {
                                l.TrafficLight.State = true;
                            }
                            else
                            {
                                l.TrafficLight.State = false;
                            }
                        }
                    }
                    c.Turn++;
                    break;

                case 3:
                    foreach (TrafficLane l in c.Lanes)
                    {
                        if (l.TrafficLight != null)
                        {
                            if (l.Direction == Direction.WEST)
                            {
                                l.TrafficLight.State = true;
                            }
                            else
                            {
                                l.TrafficLight.State = false;
                            }
                        }
                    }
                    bool sensor = false;
                    cb.CreatePedestrians();
                    foreach (PedestrianLane pl in cb.pLanes)
                    {
                        if (pl.PLight.Sensor)
                        {
                            sensor = true;
                        }
                    }
                    if (sensor)
                    {
                        c.Turn++;
                    }
                    else
                    {
                        c.Turn = 1;
                    }
                    break;

                case 4:
                    if (cb.style == "Quiet")
                    {
                        cb.ATimer.Interval = (int)(1000 * (double)cb.Time.Seconds * 0.25);
                    }
                    else
                    {
                        cb.ATimer.Interval = (int)(1000 * (double)cb.Time.Seconds * 0.75);
                    }
                    foreach (PedestrianLane pl in cb.pLanes)
                    {
                        if (pl.PLight != null)
                        {
                            pl.PLight.State = true;
                        }
                    }
                    foreach (TrafficLane l in c.Lanes)
                    {
                        if (l.TrafficLight != null)
                        {
                            l.TrafficLight.State = false;
                        }
                    }
                    c.Turn = 1;
                    break;
                }
                #endregion
            }
        }
Esempio n. 9
0
 /// <summary>
 /// A constructor for Pedestrian lane
 /// </summary>
 /// <param name="iD">the id of the lane</param>
 /// <param name="points">a list of points on the lane</param>
 /// <param name="pLight">the light object on the lane</param>
 /// <param name="crossing">the crossing this lane belongs to</param>
 public PedestrianLane(int iD, List <Point> points, PedestrianLight pLight, Crossing_B crossing)
     : base(iD, points)
 {
     this.PLight = pLight;
     this.parent = crossing;
 }
        private void openToolStripMenuOpen_Click(object sender, EventArgs e)
        {
            debug = this.cBDebugPoint.Checked;
            cardebug = this.cBDebugCars.Checked;

            if (selectedPicBox != null)
            {
                unselectCurrentCrossing();
            }

            if (Simulation.Saved == true)
            {
                Clear();
            }
            else
            {
                DialogResult dResult = MessageBox.Show("Would you like to save your changes? Unsaved changes will be lost.", "New simulation", MessageBoxButtons.YesNoCancel);
                if (dResult == DialogResult.Yes)
                {
                    Simulation.SaveAs(Simulation.Name);
                    SaveToFile();

                    Clear();
                }
                else if (dResult == DialogResult.No)
                {
                    Clear();
                }
            }


            if (!GetFromFile())
            {
                MessageBox.Show("Error whilst loading file");
            }
            else
            {
                foreach (Crossing item in Simulation.Crossings)
                {
                    tempCrossing.Add(item);
                }
                Simulation.Crossings.Clear();

                foreach (Crossing cr in tempCrossing)
                {
                    if (cr.GetType() == typeof(Crossing_A))
                    {
                        Crossing_A cra = new Crossing_A(cr.CrossingId);
                        Simulation.AddCrossing(cra);
                        CrossingType(cra);
                    }
                    else
                    {
                        Crossing_B crb = new Crossing_B(cr.CrossingId);
                        Simulation.AddCrossing(crb);
                        CrossingType(crb);
                    }

                }

            }
        }