Example #1
0
        public Lane(int laneID, Point enter , Point intersect,Direction D, int c1, int c2)
        {
            this.LaneID = laneID;
            this.Entrance = enter;
            this.Intersection = intersect;
            this.DirectionIsTo = D;
            Light = new Light();
            CountCars = 0;
            //Cars = new Car[5];
            Cars = new List<Car>();
            //Group = new List<int>();

            this.NextCrossingLaneNeighbor = null;
            Connections = new List<int>();
            Connections.Add(c1);
            Connections.Add(c2);

            Light.Color = LightColor.red; //change this later
        }
Example #2
0
 public bool CheckCarExist(Lane L,Point c1, Point newc2)
 {
     if (L.DirectionIsTo == Direction.north)
     {
         if ((c1.Y <= newc2.Y - 5) && (c1.Y >= newc2.Y + 5) && c1.X == newc2.X)
             return true;
     }
     else if (L.DirectionIsTo == Direction.south)
     {
         if ((c1.Y <= newc2.Y - 5) && (c1.Y >= newc2.Y + 5) && c1.X == newc2.X)
             return true;
     }
     else if (L.DirectionIsTo == Direction.east)
     {
         if ((c1.X <= newc2.X - 5) && (c1.X >= newc2.X + 5) && c1.Y == newc2.Y)
             return true;
     }
     else if (L.DirectionIsTo == Direction.west)
     {
         if ((c1.X <= newc2.X - 5) && (c1.X >= newc2.X + 5) && c1.Y == newc2.Y)
             return true;
     }
     return false;
 }
Example #3
0
 public bool CheckMove(Lane L,Point p)
 {
     if (L.Cars.Find(x => (x.ID != this.ID) && CheckCarExist(L,x.Position,p)) == null)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Example #4
0
 public void MoveTheCar(Direction D, Lane L)
 {
     if (Direction == Direction.north)
     {
         Point p = new Point(Position.X, Position.Y - 1);
         if (CheckMove(L,p))
             this.Position = p;
     }
     else if (Direction == Direction.south)
     {
         Point p = new Point(Position.X, Position.Y + 1);
         if (CheckMove(L,p))
             this.Position = p;
     }
     else if (Direction == Direction.east)
     {
         Point p = new Point(Position.X + 1, Position.Y);
         if (CheckMove(L,p))
             this.Position = p;
     }
     else if (Direction == Direction.west)
     {
         Point p = new Point(Position.X - 1, Position.Y);
         if (CheckMove(L,p))
             this.Position = p;
     }
 }