コード例 #1
0
        public void ConnectLanes(Crossing cr)
        {
            int indexOfThisCrossingInNeighbourList = cr.GetNeighbourIndex(this);

            foreach (Lane l in this.LisftOfLanes)
            {
                if (Convert.ToInt16(l.Id.Substring(0, 1)) == this.GetNeighbourIndex(cr))
                {
                    foreach (Lane laneToAdd in cr.LisftOfLanes)
                    {
                        if (Convert.ToInt16(laneToAdd.Id.Substring(1, 1)) == indexOfThisCrossingInNeighbourList)
                        {
                            laneToAdd.NextLanes.Add(l);
                            l.PreviousLanes.Add(laneToAdd);
                        }
                    }
                }
                else if (Convert.ToInt16(l.Id.Substring(1, 1)) == this.GetNeighbourIndex(cr))
                {
                    foreach (Lane laneToAdd in cr.LisftOfLanes)
                    {
                        if (Convert.ToInt16(laneToAdd.Id.Substring(0, 1)) == indexOfThisCrossingInNeighbourList)
                        {
                            l.NextLanes.Add(laneToAdd);
                            laneToAdd.PreviousLanes.Add(l);
                        }
                    }
                }
            }
        }
コード例 #2
0
 public bool RemoveCrossing(Crossing cross)
 {
     if (cross != null)
     {
         this.ListOfCrossings.Remove(cross);
         return(true);
     }
     return(false);
 }
コード例 #3
0
 public int GetNeighbourIndex(Crossing c)
 {
     for (int i = 0; i < this.listOfNeighbours.Length; i++)
     {
         if (this.listOfNeighbours[i] == c)
         {
             return(i);
         }
     }
     return(-1);
 }
コード例 #4
0
 public bool IsVisitedCrossing(Crossing cr, List <Crossing> visitedCrossings)
 {
     foreach (Crossing visitedCrossing in visitedCrossings)
     {
         if (visitedCrossing.Position == cr.Position)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #5
0
 public bool AddToVisitedCrossings(Crossing newCrossing)
 {
     foreach (Crossing cro in this.ListOfVisitedCrossings)
     {
         if (cro == newCrossing)
         {
             return(false);
         }
     }
     this.ListOfVisitedCrossings.Add(newCrossing);
     return(true);
 }
コード例 #6
0
        public bool AddNeighbour(Crossing cross, int neighbourPosition)
        {
            if (cross != null)
            {
                if (this.listOfNeighbours[neighbourPosition] == null)
                {
                    this.listOfNeighbours[neighbourPosition] = cross;

                    return(true);
                }
            }
            return(false);
        }
コード例 #7
0
 public bool AddCrossing(Crossing cr, int crplace)
 {
     if (cr is SimpleCrossing)
     {
         this.ListOfCrossings.Add(cr);
         return(true);
     }
     else if (cr is ComplexCrossing)
     {
         this.ListOfCrossings.Add(cr);
         return(true);
     }
     return(false);
 }
コード例 #8
0
 public bool RemoveNeighbour(Crossing cross)
 {
     if (cross != null)
     {
         for (int i = 0; i < this.listOfNeighbours.Length; i++)
         {
             if (this.listOfNeighbours[i] == cross)
             {
                 this.listOfNeighbours[i] = null;
                 return(true);
             }
         }
     }
     return(false);
 }
コード例 #9
0
        public void MakeNeighbours(Crossing crossOne)
        {
            int[] neighbourSlotsOffset = new int[4] {
                -1, 1, -4, 4
            };

            for (int i = 0; i < neighbourSlotsOffset.Length; i++)
            {
                Crossing cr = this.GetCrossingBySlot(crossOne.Slot + neighbourSlotsOffset[i]);
                if (cr != null)
                {
                    switch (neighbourSlotsOffset[i])
                    {
                    case -1:
                        if (!((crossOne.Slot == 4) && (cr.Slot == 3)) &&
                            (!((crossOne.Slot == 8) && (cr.Slot == 7))))
                        {
                            crossOne.AddNeighbour(cr, 0);
                        }
                        break;

                    case -4:
                        crossOne.AddNeighbour(cr, 1);
                        break;

                    case 1:
                        if (!((crossOne.Slot == 3) && (cr.Slot == 4)) &&
                            (!((crossOne.Slot == 7) && (cr.Slot == 8))))
                        {
                            crossOne.AddNeighbour(cr, 2);
                        }
                        break;

                    case 4:
                        crossOne.AddNeighbour(cr, 3);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
コード例 #10
0
        private void button1_Click(object sender, EventArgs e)
        {
            foreach (Crossing crozz in this.cl.ActiveGrid.ListOfCrossings)
            {
                this.cl.ActiveGrid.MakeNeighbours(crozz);
            }
            this.cl.ActiveGrid.SetAllStartPoints();
            MessageBox.Show(this.cl.ActiveGrid.ListOfAllStartPoints.Count.ToString());

            Lane l = this.cl.ActiveGrid.ListOfCrossings.ElementAt(0).LisftOfLanes.ElementAt(0);

            Crossing c = this.cl.ActiveGrid.ListOfCrossings[0];

            c.UserChosenStartPoint = c.LisftOfLanes[0].Road[0];
            this.cl.ActiveGrid.CreateRoads(c, new List <Point>(), new List <Crossing>());
            CarStream cs = new CarStream(0, 10, this.cl.ActiveGrid.AllRoads.First());

            this.cl.ActiveGrid.AddCarStream(cs);
            this.cl.ActiveGrid.SetCurrentCrossingsToCars();

            MessageBox.Show(this.cl.ActiveGrid.AllRoads.Count.ToString());
            this.Invalidate();
        }
コード例 #11
0
        private void GridMouseDown_Down(object sender, MouseEventArgs e)
        {
            Point p            = e.Location;
            Point pointClicked = new Point(0, 0);//To be used differently by the different cases

            if (e.Button == MouseButtons.Right)
            {
                mouseMode             = WhatToDo.None;
                RemoveCarStreamToggle = false;
                EditCarStreamToggle   = false;
            }
            if (((p.X >= 240) && (p.X <= 1140)) && ((p.Y >= 30) && (p.Y <= 710)))
            {
                int spotInput = this.cl.ActiveGrid.GetCrossingSlot(p);
                switch (mouseMode)
                {
                case WhatToDo.SimpleCrossing:
                    if (this.cl.ActiveGrid.IsSpotFree(p))
                    {
                        SimpleCrossing cr = new SimpleCrossing(this.cl.ActiveGrid.CrossingSlots[spotInput], spotInput);
                        this.cl.ActiveGrid.AddCrossing(cr, spotInput);
                        this.cl.ActiveGrid.MakeNeighbours(cr);
                        //Reset Mouse mode
                        this.cl.ActiveGrid.IsChanged = true;
                        this.UpdateToolStrip();
                    }
                    else
                    {
                        MessageBox.Show("This slot is already taken, place the crossing on an EMPTY one!");
                    }
                    this.Refresh();
                    break;

                case WhatToDo.ComplexCrossing:
                    if (this.cl.ActiveGrid.IsSpotFree(p))
                    {
                        ComplexCrossing crCom = new ComplexCrossing(this.cl.ActiveGrid.CrossingSlots[spotInput], spotInput);
                        this.cl.ActiveGrid.MakeNeighbours(crCom);
                        this.cl.ActiveGrid.AddCrossing(crCom, spotInput);
                        this.cl.ActiveGrid.IsChanged = true;
                        this.UpdateToolStrip();
                    }
                    else
                    {
                        MessageBox.Show("This slot is already taken, place the crossing on an EMPTY one!");
                    }
                    this.Refresh();
                    break;

                case WhatToDo.RemoveCrossing:
                    Crossing s = this.cl.ActiveGrid.GetCrossing(p);

                    if (this.cl.ActiveGrid.RemoveCrossing(s))
                    {
                        this.Invalidate();
                        this.cl.ActiveGrid.IsChanged = true;
                        this.UpdateToolStrip();
                    }
                    this.Refresh();
                    break;

                case WhatToDo.AddEditCarStream:
                    SelectedStartPoint = this.cl.ActiveGrid.GetStartingPoint(p);
                    if (SelectedStartPoint != new Point(0, 0))
                    {
                        this.cl.ActiveGrid.GetCrossing(SelectedStartPoint).UserChosenStartPoint = SelectedStartPoint;
                        this.cl.ActiveGrid.CreateRoads(this.cl.ActiveGrid.GetCrossing(SelectedStartPoint), new List <Point>(), new List <Crossing>());
                        this.formNewStream = new FormCarStream(ref this.cl, this);
                        this.formNewStream.Show();
                        this.cl.ActiveGrid.ListOfAllStartPoints.Clear();
                    }
                    else
                    {
                        SelectedStartPoint = this.cl.ActiveGrid.FindPointInList(p, this.cl.ActiveGrid.GetAllCarStreamStartPoints(), 10);
                        if (SelectedStartPoint != new Point(0, 0))
                        {
                            CarStream selectedCarStream = this.cl.ActiveGrid.GetCarStreamByStartPoint(SelectedStartPoint);
                            PossibleEndPoints  = this.cl.ActiveGrid.GetAllEndPointsWithStart(SelectedStartPoint);
                            this.formNewStream = new FormCarStream(ref this.cl, this, ref selectedCarStream);
                            this.formNewStream.Show();
                        }
                    }
                    this.Invalidate();
                    this.UpdateToolStrip();

                    break;

                case WhatToDo.AddEditCarStreamEnd:
                    pointClicked = this.cl.ActiveGrid.FindPointInList(p, this.cl.ActiveGrid.GetAllEndPointsWithStart(SelectedStartPoint), 10);
                    if (pointClicked != new Point(0, 0))
                    {
                        SelectedEndPoint = pointClicked;
                        this.formNewStream.Show();
                        PossibleEndPoints.Clear();
                        this.Refresh();
                        this.UpdateToolStrip();
                    }
                    break;

                case WhatToDo.RemoveCarStream:
                    pointClicked = this.cl.ActiveGrid.FindPointInList(p, this.cl.ActiveGrid.GetAllCarStreamStartPoints(), 10);
                    if (pointClicked != new Point(0, 0))
                    {
                        this.cl.ActiveGrid.RemoveCarStream(pointClicked);
                    }
                    RemoveCarStreamToggle = false;
                    this.Refresh();
                    break;

                case WhatToDo.AddEditPedestrianStreamStart:
                    foreach (List <Point> points in this.cl.ActiveGrid.ListOfPossiblePedestrianStreams)
                    {
                        pointClicked = this.cl.ActiveGrid.FindPointInList(p, points, 2);
                    }
                    if (pointClicked != new Point(0, 0))
                    {
                        this.selectedPedestrianStartPoint = pointClicked;
                        mouseMode = WhatToDo.AddEditPedestrianStreamEnd;
                    }
                    this.Refresh();
                    break;

                case WhatToDo.AddEditPedestrianStreamEnd:
                    foreach (List <Point> possiblePedestrianStream in this.cl.ActiveGrid.ListOfPossiblePedestrianStreams)
                    {
                        pointClicked = this.cl.ActiveGrid.FindPointInList(p, possiblePedestrianStream, 2);
                    }
                    if (pointClicked != new Point(0, 0))
                    {
                        this.cl.ActiveGrid.ListOfPedestrianStreams.Add(new PedestrianStream(this.selectedPedestrianStartPoint, this.selectedPedestrianEndPoint, 5));
                    }
                    mouseMode = WhatToDo.None;
                    this.Refresh();
                    break;

                case WhatToDo.None:

                    break;
                }
            }
            else
            {
                MessageBox.Show("Click inside!");
            }
        }
コード例 #12
0
        public void CreateRoads(Crossing cr, List <Point> tempRoad, List <Crossing> visitedCrossings)
        {
            for (int i = 0; i < cr.GetNeighborList().Length; i++)
            {
                #region If there is a neighbour on the searched position

                if (cr.GetNeighborList()[i] != null)
                {
                    if (!this.IsVisitedCrossing(cr.GetNeighborList()[i], visitedCrossings))
                    {
                        foreach (Lane l in cr.LisftOfLanes)
                        {
                            // NOT USED
                            string endIndex   = Convert.ToInt16(l.Id.Substring(1, 1)).ToString();
                            string startIndex = "";
                            if (endIndex == i.ToString())
                            {
                                if (tempRoad.Count != 0)
                                {
                                    startIndex = cr.GetNeighbourIndex(visitedCrossings[visitedCrossings.Count - 1]).ToString();
                                }
                                else
                                {
                                    foreach (Lane lanes in cr.LisftOfLanes)
                                    {
                                        if (lanes.EntryPoint == cr.UserChosenStartPoint)
                                        {
                                            startIndex = lanes.Id.Substring(0, 1);
                                            break;
                                        }
                                    }
                                }
                                if (startIndex != endIndex)
                                {
                                    List <Point> laneToAdd = cr.GetLaneById(startIndex + endIndex).Road;

                                    tempRoad.AddRange(laneToAdd);
                                    visitedCrossings.Add(cr);
                                    this.CreateRoads(cr.GetNeighborList()[i], new List <Point>(tempRoad), new List <Crossing>(visitedCrossings));
                                    visitedCrossings.Remove(cr);
                                    tempRoad.RemoveRange(((tempRoad.Count - (laneToAdd.Count))), laneToAdd.Count);
                                }
                            }
                        }
                    }
                    else
                    {
                    }
                }

                #endregion

                #region If there is no neighbour on the checked position

                else
                {
                    string startIndex = "";
                    string endIndex   = "";
                    if (tempRoad.Count > 0)
                    {
                        startIndex = cr.GetNeighbourIndex(visitedCrossings.Last()).ToString();
                        endIndex   = i.ToString();
                        List <Point> roadToCreate = tempRoad;
                        List <Point> laneToAdd    = cr.GetLaneById(startIndex + endIndex).Road;
                        roadToCreate.AddRange(laneToAdd);
                        this.AllRoads.Add(new List <Point>(roadToCreate));
                        tempRoad.RemoveRange(((tempRoad.Count - (laneToAdd.Count))), laneToAdd.Count);
                    }
                    else
                    {
                        //Find on which side is the UserChosenStartPoint and set it as startIndex of the crossing
                        //Which will be chosen
                        foreach (Lane lanes in cr.LisftOfLanes)
                        {
                            if (lanes.EntryPoint == cr.UserChosenStartPoint)
                            {
                                startIndex = lanes.Id.Substring(0, 1);
                                break;
                            }
                        }
                        if (startIndex != i.ToString())
                        {
                            endIndex = i.ToString();
                            List <Point> roadToAdd = tempRoad;
                            roadToAdd.AddRange(cr.GetLaneById(startIndex + endIndex).Road);
                            if (cr.GetLaneById(startIndex + endIndex).Road.First() == cr.UserChosenStartPoint)
                            {
                                this.AllRoads.Add(new List <Point>(roadToAdd));
                            }
                            tempRoad.Clear();
                            //listOfVisitedCrossings.Clear();
                        }
                    }
                }

                #endregion
            }
        }