示例#1
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     for (int i = 0; i < grid.Cells.Count; i++)
     {
         int nrOfCars = 0;
         if (grid.Cells[i].Taken)
         {
             Crossing cr = grid.Cells[i].Crossing;
             foreach (Lane lane in cr.LaneInList)
             {
                 nrOfCars += lane.CarList.Count;
             }
             foreach (Lane lane in cr.LaneOutList)
             {
                 nrOfCars += lane.CarList.Count;
             }
             labels[i].Text = "Cars: " + nrOfCars;
             StartChecking(labels[i]);
             nrOfCars = 0;
         }
         else
         {
             labels[i].Text = "";
         }
     }
 }
示例#2
0
        public CrossingOptionsForm(Crossing cr)
        {
            InitializeComponent();
            label25.Hide();
            TBGroup1          = new List <TextBox>();
            TBGroup2          = new List <TextBox>();
            TBGroup3          = new List <TextBox>();
            TBGroup4          = new List <TextBox>();
            this.cr           = cr;
            pictureBox1.Image = cr.Pb_Background.Image;

            this.LoadCarsPerMinute();
            this.LoadPercentages();
            this.DisableTextBox();
            this.GetTrafficLightGroupsDuration();
            this.InitializeTBGroups();

            TBgroup1.Leave += TBgroup_Leave;
            TBgroup2.Leave += TBgroup_Leave;
            TBgroup3.Leave += TBgroup_Leave;
            TBgroup4.Leave += TBgroup_Leave;

            if (cr is CrossingT1)
            {
                HideCT1();
            }
        }
示例#3
0
        /// <summary>
        /// Removes crossing, visual representation + object
        /// </summary>
        /// <param name="selectedCell">cell with position of the crossing</param>
        public void RemoveCrossing(int selectedCell)
        {
            Crossing selectedCrossing = this.cells[selectedCell - 1].Crossing;

            selectedCrossing.Pb_Background.Dispose();
            selectedCrossing.Pb_Transparent.Dispose();
            crossings.Remove(selectedCrossing);
            cells[selectedCell - 1].Taken    = false;
            cells[selectedCell - 1].Crossing = null;
        }
示例#4
0
 /// <summary>
 /// Resets the stop point of a neighbour's lane out.
 /// </summary>
 /// <param name="cr">The crossing that will have its neighbour's laneout reset.</param>
 /// <param name="laneOutIndex">The index of the lane out in the neighbour's laneOutList.</param>
 public void ResetNeighbourLaneOut(Crossing cr, int laneOutIndex)
 {
     if (cr != null)
     {
         cr.laneOutList[laneOutIndex].StopPoint = -1;
         foreach (Car car in cr.laneOutList[laneOutIndex].CarList)
         {
             car.Moving = true;
         }
     }
 }
示例#5
0
        /// <summary>
        ///  checks the south neighbour of the crossing on a given cell
        /// </summary>
        /// <param name="cellNr">the cell Nr of the crossing whose neighbour its checked</param>
        public void CheckSouth(int cellNr)
        {
            Crossing cr = Cells[cellNr].Crossing;

            //If there is south neighbour - laneIns from the south of the current crossing are NOT endLane
            if (cells[cellNr + 4].Taken)
            {
                foreach (LaneIn laneIn in cr.LaneInList)
                {
                    if (laneIn.Direction == "north")
                    {
                        laneIn.EndLane = false;
                    }
                }

                //car should NOT be spawned from south direction
                //LaneOut of current crossing with direction to the north is NOT endLane
                cr.IncomingStreams[0]     = "";
                cr.LaneOutList[2].EndLane = false;


                //LaneIn 'south' of the south neighbour is NOT endLane
                foreach (LaneIn laneIn in cells[cellNr + 4].Crossing.LaneInList)
                {
                    if (laneIn.Direction == "south")
                    {
                        laneIn.EndLane = false;
                    }
                }
                //no spawned car in the neighbour from the south laneIns and LaneOut 'north' is not endlane
                cells[cellNr + 4].Crossing.IncomingStreams[2]     = "";
                cells[cellNr + 4].Crossing.LaneOutList[3].EndLane = false;
                cr.Neighbours[2] = cells[cellNr + 4].Crossing;
                cells[cellNr + 4].Crossing.Neighbours[0] = cr;
            }
            //if there is NO neighbour on south side, laneIns of the current crossing are endlane(spawning point)
            //laneout is endlane, cars are erased after leaving it
            else
            {
                cr.Neighbours[2]          = null;
                cr.IncomingStreams[0]     = "north";
                cr.LaneOutList[2].EndLane = true;
                foreach (LaneIn laneIn in cr.LaneInList)
                {
                    if (laneIn.Direction == "north")
                    {
                        laneIn.EndLane = true;
                    }
                }
            }
        }
示例#6
0
        /// <summary>
        /// checks the west neighbour of the crossing on a given cell
        /// </summary>
        /// <param name="cellNr">the cell Nr of the crossing whose neighbour its checked</param>
        public void CheckWest(int cellNr)
        {
            //crossing whose neighbour we check
            Crossing cr = Cells[cellNr].Crossing;

            //check whether there is a west neighbour
            //If there is - cr.LaneIn with direction east is NOT endLane
            if (cells[cellNr - 1].Taken)
            {
                foreach (LaneIn laneIn in cr.LaneInList)
                {
                    if (laneIn.Direction == "east")
                    {
                        laneIn.EndLane = false;
                    }
                }
                //car should NOT be spawned && LaneOut with directin West is NOT endLane
                cr.IncomingStreams[1]     = "";
                cr.LaneOutList[1].EndLane = false;

                //LaneIn 'west' of the west neighbour is NOT endLane
                foreach (LaneIn laneIn in cells[cellNr - 1].Crossing.LaneInList)
                {
                    if (laneIn.Direction == "west")
                    {
                        laneIn.EndLane = false;
                    }
                }
                //no spawned car in the neighbour from the east laneIns and LaneOut 'east' is not endlane
                cells[cellNr - 1].Crossing.IncomingStreams[3]     = "";
                cells[cellNr - 1].Crossing.LaneOutList[0].EndLane = false;

                cr.Neighbours[3] = cells[cellNr - 1].Crossing;
                cells[cellNr - 1].Crossing.Neighbours[1] = cr;
            }
            //if there is NO neighbour on west side, laneIns is endlane(spawning point)
            //laneout is endlane, cars are erased after leaving it
            else
            {
                cr.Neighbours[3]          = null;
                cr.IncomingStreams[1]     = "east";
                cr.LaneOutList[1].EndLane = true;
                foreach (LaneIn laneIn in cr.LaneInList)
                {
                    if (laneIn.Direction == "east")
                    {
                        laneIn.EndLane = true;
                    }
                }
            }
        }
示例#7
0
        /// <summary>
        /// enables the stream of cars from a particular side of the crossing
        /// </summary>
        /// <param name="direction">side of the crossing where the streams of cars should be enabled to</param>
        /// <param name="cellNr">cell number of the crossing being checked</param>
        public void EnableStream(string direction, int cellNr)
        {
            Crossing cr = cells[cellNr].Crossing;

            //if direction = 'north', laneIn to north are ednLane and laneOut to south is endlane, No south neighbour
            if (direction == "north")
            {
                cr.IncomingStreams[0] = "north";
                foreach (LaneIn laneIn in cr.LaneInList)
                {
                    if (laneIn.Direction == "north")
                    {
                        laneIn.EndLane = true;
                    }
                }
                cr.LaneOutList[2].EndLane = true;
                cr.Neighbours[2]          = null;
            }

            //if direction = 'east', laneIn to east are ednLane and laneOut to west is endlane, No west neighbour
            else if (direction == "east")
            {
                cr.IncomingStreams[1] = "east";
                foreach (LaneIn laneIn in cr.LaneInList)
                {
                    if (laneIn.Direction == "east")
                    {
                        laneIn.EndLane = true;
                    }
                }
                cr.LaneOutList[1].EndLane = true;
                cr.Neighbours[3]          = null;
            }

            //laneIn to sout are ednLane and laneOut to north is endlane, No north neighbour
            else if (direction == "south")
            {
                cr.IncomingStreams[2] = "south";
                foreach (LaneIn laneIn in cr.LaneInList)
                {
                    if (laneIn.Direction == "south")
                    {
                        laneIn.EndLane = true;
                    }
                }
                cr.LaneOutList[3].EndLane = true;
                cr.Neighbours[0]          = null;
            }

            //laneIn to west are ednLane and laneOut to east is endlane, No east neighbour
            else if (direction == "west")
            {
                cr.IncomingStreams[3] = "west";
                foreach (LaneIn laneIn in cr.LaneInList)
                {
                    if (laneIn.Direction == "west")
                    {
                        laneIn.EndLane = true;
                    }
                }
                cr.LaneOutList[0].EndLane = true;
                cr.Neighbours[1]          = null;
            }
        }
示例#8
0
 public void AddCrossing(Crossing cr)
 {
     crossings.Add(cr);
 }
示例#9
0
        /// <summary>
        /// Adds a car to a crossing from a direction.
        /// </summary>
        /// <param name="cr">The crossing that the car will be added to.</param>
        /// <param name="direction">The direction.</param>
        public void AddCarToLane(Crossing cr, string direction)
        {
            Car car = new Car(new Point(0, 0), "");

            if (direction == "north")
            {
                nrOfCars++;
                if (cr is CrossingT1)
                {
                    if (!cr.laneInList[5].CheckFullLane())
                    {
                        car.Destination = "straight";
                        car.Location    = new Point(cr.laneInList[5].Location.X + 7, 299);
                        cr.laneInList[5].CarList.Add(car);
                    }
                }
                else
                {
                    car.Destination = SetCarDestination(2);
                    if (car.Destination == "straight" || car.Destination == "right")
                    {
                        if (!cr.laneInList[3].CheckFullLane())
                        {
                            car.Location = new Point(cr.laneInList[3].Location.X + 7, 299);
                            cr.laneInList[3].CarList.Add(car);
                        }
                    }
                    else
                    {
                        if (!cr.laneInList[2].CheckFullLane())
                        {
                            car.Location = new Point(cr.laneInList[2].Location.X + 7, 299);
                            cr.laneInList[2].CarList.Add(car);
                        }
                    }
                }
            }
            else if (direction == "east")
            {
                nrOfCars++;
                car.Destination = SetCarDestination(3);
                if (cr is CrossingT1)
                {
                    if (car.Destination == "straight" || car.Destination == "right")
                    {
                        if (!cr.laneInList[1].CheckFullLane())
                        {
                            car.Location = new Point(1, cr.laneInList[1].Location.Y + 4);
                            cr.laneInList[1].CarList.Add(car);
                        }
                    }
                    else
                    {
                        if (!cr.laneInList[0].CheckFullLane())
                        {
                            car.Location = new Point(1, cr.laneInList[0].Location.Y + 4);
                            cr.laneInList[0].CarList.Add(car);
                        }
                    }
                }
                else
                {
                    if (car.Destination == "straight" || car.Destination == "right")
                    {
                        if (!cr.laneInList[5].CheckFullLane())
                        {
                            car.Location = new Point(1, cr.laneInList[5].Location.Y + 4);
                            cr.laneInList[5].CarList.Add(car);
                        }
                    }
                    else
                    {
                        if (!cr.laneInList[4].CheckFullLane())
                        {
                            car.Location = new Point(1, cr.laneInList[4].Location.Y + 4);
                            cr.laneInList[4].CarList.Add(car);
                        }
                    }
                }
            }
            else if (direction == "south")
            {
                nrOfCars++;
                if (cr is CrossingT1)
                {
                    if (!cr.laneInList[4].CheckFullLane())
                    {
                        car.Destination = "straight";
                        car.Location    = new Point(cr.laneInList[4].Location.X + 7, 1);
                        cr.laneInList[4].CarList.Add(car);
                    }
                }
                else
                {
                    car.Destination = SetCarDestination(0);
                    if (car.Destination == "straight" || car.Destination == "right")
                    {
                        if (!cr.laneInList[0].CheckFullLane())
                        {
                            car.Location = new Point(cr.laneInList[0].Location.X + 7, 1);
                            cr.laneInList[0].CarList.Add(car);
                        }
                    }
                    else
                    {
                        if (!cr.laneInList[1].CheckFullLane())
                        {
                            car.Location = new Point(cr.laneInList[1].Location.X + 7, 1);
                            cr.laneInList[1].CarList.Add(car);
                        }
                    }
                }
            }
            else if (direction == "west")
            {
                nrOfCars++;
                car.Destination = SetCarDestination(1);
                if (cr is CrossingT1)
                {
                    if (car.Destination == "straight" || car.Destination == "right")
                    {
                        if (!cr.laneInList[2].CheckFullLane())
                        {
                            car.Location = new Point(300, cr.laneInList[2].Location.Y + 4);
                            cr.laneInList[2].CarList.Add(car);
                        }
                    }
                    else
                    {
                        if (!cr.laneInList[3].CheckFullLane())
                        {
                            car.Location = new Point(300, cr.laneInList[3].Location.Y + 4);
                            cr.laneInList[3].CarList.Add(car);
                        }
                    }
                }
                else
                {
                    if (car.Destination == "straight" || car.Destination == "right")
                    {
                        if (!cr.laneInList[6].CheckFullLane())
                        {
                            car.Location = new Point(298, cr.laneInList[6].Location.Y + 4);
                            cr.laneInList[6].CarList.Add(car);
                        }
                    }
                    else
                    {
                        if (!cr.laneInList[7].CheckFullLane())
                        {
                            car.Location = new Point(298, cr.laneInList[7].Location.Y + 4);
                            cr.laneInList[7].CarList.Add(car);
                        }
                    }
                }
            }
        }