Exemplo n.º 1
0
Arquivo: Train.cs Projeto: M0N3/Subway
        internal void calcTime(Subway subway, int i, int j)
        {
            Point ps = subway.GetRailways.ElementAt(i).GetStations.ElementAt(id).Coordinate;
            Point p  = new Point();

            if (Back)
            {
                p = subway.GetRailways.ElementAt(i).GetStations.ElementAt(id - 1).Coordinate;
            }
            else
            {
                if (id + 1 < subway.GetRailways.ElementAt(i).GetStations.Count)
                {
                    p = subway.GetRailways.ElementAt(i).GetStations.ElementAt(id + 1).Coordinate;
                }
            }
            int    time = (int)(Math.Sqrt((p.X - ps.X) * (p.X - ps.X) + (p.Y - ps.Y) * (p.Y - ps.Y))) / 50;
            Random r    = new Random(DateTime.Now.Millisecond);

            if (r.Next(1, 30) % 20 == 0)
            {
                int temp = time / 10;
                if (temp == 0)
                {
                    temp = 1;
                }
                time += temp;
                String str = "Train number: " + subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Number + " was late by " + temp + " seconds at the station: " + id;
                subway.GetRailways.ElementAt(i).GetStations.ElementAt(id).AddViolations(str);
            }
            travelTime = time;
        }
Exemplo n.º 2
0
Arquivo: Train.cs Projeto: M0N3/Subway
        internal void Stop(Canvas field, Subway subway)
        {
            pathAnimationStoryboard.Children.Clear();
            field.Children.Remove(trainPath);
            RectangleGeometry rc = trainPath.Data as RectangleGeometry;

            trainPath.RenderTransform = null;
            travelTime     = 0;
            timeOnStation  = 3;
            Start          = false;
            onStation      = false;
            leftStation    = false;
            numOfPassage   = passage;
            currStationInd = 0;
            id             = 0;
            Back           = false;
            away           = false;
            if (subway.GetRailways.ElementAt(lineNumber).GetStations.Count > 1)
            {
                if (subway.GetRailways.ElementAt(lineNumber).GetStations.ElementAt(0) != null)
                {
                    Station st = subway.GetRailways.ElementAt(lineNumber).GetStations.ElementAt(0);
                    rc.Rect = new Rect(st.Coordinate.X - 15, st.Coordinate.Y - 15, 30, 30);
                }
                else
                {
                    trainPath = null;
                }
            }
        }
Exemplo n.º 3
0
Arquivo: Train.cs Projeto: M0N3/Subway
 internal void calcTime(Subway subway, int i, int j)
 {
     Point ps = subway.GetRailways.ElementAt(i).GetStations.ElementAt(id).Coordinate;
     Point p = new Point();
     if (Back)
     {
         p = subway.GetRailways.ElementAt(i).GetStations.ElementAt(id - 1).Coordinate;
     }
     else
     {
         if (id + 1 < subway.GetRailways.ElementAt(i).GetStations.Count)
         {
             p = subway.GetRailways.ElementAt(i).GetStations.ElementAt(id + 1).Coordinate;
         }
     }
     int time = (int)(Math.Sqrt((p.X - ps.X) * (p.X - ps.X) + (p.Y - ps.Y) * (p.Y - ps.Y))) / 50;
     Random r = new Random(DateTime.Now.Millisecond);
     if (r.Next(1, 30) % 20 == 0)
     {
         int temp = time / 10;
         if (temp == 0)
         {
             temp = 1;
         }
         time += temp;
         String str = "Train number: " + subway.GetRailways.ElementAt(i).Trains.ElementAt(j).Number + " was late by " + temp + " seconds at the station: " + id;
         subway.GetRailways.ElementAt(i).GetStations.ElementAt(id).AddViolations(str);
     }
     travelTime = time;
 }
Exemplo n.º 4
0
Arquivo: Train.cs Projeto: M0N3/Subway
 internal void Stop(Canvas field, Subway subway)
 {
     pathAnimationStoryboard.Children.Clear();
     field.Children.Remove(trainPath);
     RectangleGeometry rc = trainPath.Data as RectangleGeometry;
     trainPath.RenderTransform = null;
     travelTime = 0;
     timeOnStation = 3;
     Start = false;
     onStation = false;
     leftStation = false;
     numOfPassage = passage;
     currStationInd = 0;
     id = 0;
     Back = false;
     away = false;
     if (subway.GetRailways.ElementAt(lineNumber).GetStations.Count > 1)
     {
         if (subway.GetRailways.ElementAt(lineNumber).GetStations.ElementAt(0) != null)
         {
             Station st = subway.GetRailways.ElementAt(lineNumber).GetStations.ElementAt(0);
             rc.Rect = new Rect(st.Coordinate.X - 15, st.Coordinate.Y - 15, 30, 30);
         }
         else
         {
             trainPath = null;
         }
     }
 }
Exemplo n.º 5
0
Arquivo: Train.cs Projeto: M0N3/Subway
 internal void SetCurrId(Subway subway)
 {
     if (Back)
     {
         id = subway.GetRailways.ElementAt(lineNumber).GetStations.Count - currStationInd - 1;
     }
     else
     {
         id = currStationInd;
     }
 }
Exemplo n.º 6
0
Arquivo: Train.cs Projeto: M0N3/Subway
 internal void SetCurrId(Subway subway)
 {
     if (Back)
     {
         id = subway.GetRailways.ElementAt(lineNumber).GetStations.Count - currStationInd - 1;
     }
     else
     {
         id = currStationInd;
     }
 }
Exemplo n.º 7
0
Arquivo: Train.cs Projeto: M0N3/Subway
        internal void Animate(Subway subway)
        {
            pathAnimationStoryboard = new Storyboard();
            Start = true;
            MatrixTransform buttonMatrixTransform = new MatrixTransform();

            this.TrainPath.RenderTransform = buttonMatrixTransform;
            NameScope.SetNameScope(this, new NameScope());
            RectangleGeometry rc = TrainPath.Data as RectangleGeometry;
            EllipseGeometry   e  = subway.GetRailways.ElementAt(lineNumber).GetStations.ElementAt(id).ellipsePath.Data as EllipseGeometry;
            Point             c  = e.Center;

            rc.Rect = new Rect(c.X, c.Y, 30, 30);
            this.RegisterName("ButtonMatrixTransform", buttonMatrixTransform);
            PathGeometry animationPath = new PathGeometry();

            if (Back)
            {
                animationPath = subway.GetRailways.ElementAt(lineNumber).GetStations.ElementAt(id).endLinePath.Data as PathGeometry;
            }
            else
            {
                if (subway.GetRailways.ElementAt(lineNumber).GetStations.ElementAt(id).startLinePath != null)
                {
                    animationPath = subway.GetRailways.ElementAt(lineNumber).GetStations.ElementAt(id).startLinePath.Data as PathGeometry;
                }
            }
            Point p = subway.GetRailways.ElementAt(lineNumber).GetStations.ElementAt(id).Coordinate;

            rc.Rect = new Rect(rc.Rect.X - p.X - 15, rc.Rect.Y - p.Y - 15, 30, 30);
            MatrixAnimationUsingPath matrixAnimation =
                new MatrixAnimationUsingPath();

            matrixAnimation.PathGeometry          = animationPath;
            matrixAnimation.Duration              = TimeSpan.FromSeconds(travelTime);
            matrixAnimation.DoesRotateWithTangent = true;
            Storyboard.SetTargetName(matrixAnimation, "ButtonMatrixTransform");
            Storyboard.SetTargetProperty(matrixAnimation,
                                         new PropertyPath(MatrixTransform.MatrixProperty));
            pathAnimationStoryboard.Children.Add(matrixAnimation);
            pathAnimationStoryboard.Begin(this);
        }
Exemplo n.º 8
0
Arquivo: Train.cs Projeto: M0N3/Subway
 internal void Animate(Subway subway)
 {
     pathAnimationStoryboard = new Storyboard();
     Start = true;
     MatrixTransform buttonMatrixTransform = new MatrixTransform();
     this.TrainPath.RenderTransform = buttonMatrixTransform;
     NameScope.SetNameScope(this, new NameScope());
     RectangleGeometry rc = TrainPath.Data as RectangleGeometry;
     EllipseGeometry e = subway.GetRailways.ElementAt(lineNumber).GetStations.ElementAt(id).ellipsePath.Data as EllipseGeometry;
     Point c = e.Center;
     rc.Rect = new Rect(c.X, c.Y, 30, 30);
     this.RegisterName("ButtonMatrixTransform", buttonMatrixTransform);
     PathGeometry animationPath = new PathGeometry();
     if (Back)
     {
         animationPath = subway.GetRailways.ElementAt(lineNumber).GetStations.ElementAt(id).endLinePath.Data as PathGeometry;
     }
     else
     {
         if (subway.GetRailways.ElementAt(lineNumber).GetStations.ElementAt(id).startLinePath != null)
         {
             animationPath = subway.GetRailways.ElementAt(lineNumber).GetStations.ElementAt(id).startLinePath.Data as PathGeometry;
         }
     }
     Point p = subway.GetRailways.ElementAt(lineNumber).GetStations.ElementAt(id).Coordinate;
     rc.Rect = new Rect(rc.Rect.X - p.X - 15, rc.Rect.Y - p.Y - 15, 30, 30);
     MatrixAnimationUsingPath matrixAnimation =
         new MatrixAnimationUsingPath();
     matrixAnimation.PathGeometry = animationPath;
     matrixAnimation.Duration = TimeSpan.FromSeconds(travelTime);
     matrixAnimation.DoesRotateWithTangent = true;
     Storyboard.SetTargetName(matrixAnimation, "ButtonMatrixTransform");
     Storyboard.SetTargetProperty(matrixAnimation,
         new PropertyPath(MatrixTransform.MatrixProperty));
     pathAnimationStoryboard.Children.Add(matrixAnimation);
     pathAnimationStoryboard.Begin(this);
 }