示例#1
0
        private bool FindCollision(MouseEventArgs e, Lane lane)
        {
            if (e.X < lane.X || e.Y < lane.Y)
            {
                return(false);
            }
            if (lane.Owner.From == Direction.Up || lane.Owner.From == Direction.Down)
            {
                if (e.X - lane.X <= 20 && e.Y - lane.Y <= 60)
                {
                    return(true);
                }
            }
            else
            {
                if (e.X - lane.X <= 60 && e.Y - lane.Y <= 20)
                {
                    return(true);
                }
            }

            return(false);
        }
示例#2
0
        static System.Drawing.Point[] PathFromLane(Lane lane)
        {
            Lane next = lane.Next;

            int midX   = lane.X;
            int midY   = next.Y;
            int startX = lane.X;
            int startY = lane.Y;

            //single
            if (lane.To.HasFlag(Direction.Left) && lane.To.HasFlag(Direction.Down) && next.To.HasFlag(Direction.Left))
            {
                midX = next.X + 100;
                midY = lane.Y - 15;
            }
            if (lane.To.HasFlag(Direction.Right) && next.To.HasFlag(Direction.Right) && next.From.HasFlag(Direction.Left))
            {
                midX = lane.X;
                midY = next.Y;
            }
            if (lane.To.HasFlag(Direction.Up) && next.To.HasFlag(Direction.Up) && next.From.HasFlag(Direction.Down))
            {
                midX = next.X;
                midY = lane.Y;
            }
            if (lane.To.HasFlag(Direction.Left) && next.To.HasFlag(Direction.Left) && next.From.HasFlag(Direction.Right))
            {
                midX = lane.X;
                midY = next.Y;
            }
            if (lane.To.HasFlag(Direction.Down) && next.To.HasFlag(Direction.Down) && next.From.HasFlag(Direction.Up))
            {
                midX = next.X;
                midY = lane.Y;
            }
            //double
            if (lane.To.HasFlag(Direction.Down) && lane.To.HasFlag(Direction.Right) && next.To.HasFlag(Direction.Down) && next.From.HasFlag(Direction.Up))
            {
                if (lane.Owner.Owner is CrossingA)
                {
                    midX = lane.X - 20;
                    midY = next.Y - 30;
                }
                else
                {
                    midX = next.X;
                    midY = next.Y - 30;
                }
            }
            if (lane.To.HasFlag(Direction.Left) && lane.To.HasFlag(Direction.Up) && next.To.HasFlag(Direction.Up) && next.From.HasFlag(Direction.Right))
            {
                midX = lane.X;
                midY = next.Y;
            }
            if (lane.To.HasFlag(Direction.Right) && lane.To.HasFlag(Direction.Up) && next.To.HasFlag(Direction.Up) && next.From.HasFlag(Direction.Down))
            {
                midX = next.X;
                midY = lane.Y;
            }
            if (lane.To.HasFlag(Direction.Left) && lane.To.HasFlag(Direction.Up) && next.To.HasFlag(Direction.Up) && next.From.HasFlag(Direction.Down))
            {
                if (lane.Owner.Owner is CrossingA)
                {
                    midX = next.X - 5;
                    midY = lane.Y - 80;
                }
                else
                {
                    midX = next.X;
                    midY = lane.Y;
                }
            }
            if (lane.To.HasFlag(Direction.Down) && lane.To.HasFlag(Direction.Left) && next.To.HasFlag(Direction.Down) && next.From.HasFlag(Direction.Up))
            {
                if (lane.Owner.Owner is CrossingA)
                {
                    midX = next.X;
                    midY = lane.Y;
                }
                else
                {
                    midX = lane.X;
                    midY = next.Y;
                }
            }
            if (lane.To.HasFlag(Direction.Down) && lane.To.HasFlag(Direction.Left) && next.To.HasFlag(Direction.Left) && next.From.HasFlag(Direction.Right))
            {
                if (lane.Owner.Owner is CrossingA)
                {
                    midX = next.X + 10;
                    midY = next.Y - 5;
                }
                else
                {
                    midX = lane.X;
                    midY = next.Y;
                }
            }
            if (lane.To.HasFlag(Direction.Up) && lane.To.HasFlag(Direction.Right) && next.To.HasFlag(Direction.Right) && next.From.HasFlag(Direction.Left))
            {
                if (lane.Owner.Owner is CrossingA)
                {
                    midX = lane.X + 160;
                    midY = next.Y;
                }
                else
                {
                    midX = lane.X;
                    midY = next.Y;
                }
            }


            if (lane.To.HasFlag(Direction.Left) && lane.To.HasFlag(Direction.Up))
            {
                startY += 30;
            }
            if (lane.To.HasFlag(Direction.Left) && lane.To.HasFlag(Direction.Down))
            {
                startX += 30;
            }
            if (lane.To.HasFlag(Direction.Down) && lane.To.HasFlag(Direction.Right))
            {
                startY -= 30;
            }
            System.Drawing.Point start = new System.Drawing.Point(startX, startY);
            System.Drawing.Point end   = new System.Drawing.Point(next.X, next.Y);
            System.Drawing.Point mid   = new System.Drawing.Point(midX, midY);

            if (next.To == Direction.Up)
            {
                end.Y -= 60;
            }
            else if (next.To == Direction.Down)
            {
                end.Y += 60;
            }
            else if (next.To == Direction.Left)
            {
                end.X -= 50;
            }
            else if (next.To == Direction.Right)
            {
                end.X += 50;
            }

            return(new System.Drawing.Point[] { start, mid, end });
        }
示例#3
0
 public Car(int startX, int startY, Lane lane) : base(startX, startY, PathFromLane(lane))
 {
     this.CurrentLane = lane;
 }
 /// <summary>
 /// Defines changes to apply
 /// </summary>
 protected override void OnRedo()
 {
     Lane.UpdateFlow(Flow);
     OnString = "Flow change from {0} to {1}";
 }
 /// <summary>
 /// Defines changes to remove
 /// </summary>
 protected override void OnUndo()
 {
     Lane.UpdateFlow(previousFlow);
     OnString = "Flow change from {1} to {0}";
 }
 public UpdateFlowAction(int flow, Lane lane)
 {
     this.Lane         = lane;
     this.Flow         = flow;
     this.previousFlow = lane.Flow;
 }