Пример #1
0
        public static bool HasRaceColor(this PairsRaceColors colors, PairsRaceColor raceColor)
        {
            switch (colors)
            {
            case PairsRaceColors.WhiteRed:
                return(raceColor == PairsRaceColor.White || raceColor == PairsRaceColor.Red);

            case PairsRaceColors.YellowBlue:
                return(raceColor == PairsRaceColor.Yellow || raceColor == PairsRaceColor.Blue);

            default:
                throw new ArgumentOutOfRangeException(nameof(colors));
            }
        }
Пример #2
0
        public static PairsRaceColors ToPairColor(this PairsRaceColor raceColor)
        {
            switch (raceColor)
            {
            case PairsRaceColor.White:
            case PairsRaceColor.Red:
                return(PairsRaceColors.WhiteRed);

            case PairsRaceColor.Yellow:
            case PairsRaceColor.Blue:
                return(PairsRaceColors.YellowBlue);

            default:
                throw new ArgumentOutOfRangeException(nameof(raceColor));
            }
        }
Пример #3
0
        public static string ToShortString(this PairsRaceColor color)
        {
            switch (color)
            {
            case PairsRaceColor.White:
                return("Wh");

            case PairsRaceColor.Red:
                return("Rd");

            case PairsRaceColor.Yellow:
                return("Yw");

            case PairsRaceColor.Blue:
                return("Bl");

            default:
                throw new ArgumentOutOfRangeException(nameof(color));
            }
        }
Пример #4
0
        private void OnSkaterChanged(PairsRaceColor color, IActiveTrackRaceViewModel oldRace, IActiveTrackRaceViewModel newRace, Style style)
        {
            if (Distance == null || PathProvider == null || canvas == null)
            {
                return;
            }

            TrackCompetitorStoryboard storyboard;

            if (storyboards.TryGetValue(color, out storyboard))
            {
                storyboard.DetachAndStop();
                storyboards.Remove(color);
            }

            Shape shape;

            if (skaters.TryGetValue(color, out shape))
            {
                canvas.Children.Remove(shape);
                skaters.Remove(color);
            }

            if (oldRace != null)
            {
                oldRace.TimeInvalidReasonChanged -= RaceTimeInvalidReasonChanged;
            }

            if (newRace == null)
            {
                return;
            }

            newRace.TimeInvalidReasonChanged += RaceTimeInvalidReasonChanged;
            if (newRace.TimeInvalidReason != null)
            {
                return;
            }

            var path = PathProvider.CreatePath(Distance, newRace.Lane);

            if (path == null)
            {
                return;
            }

            var ellipse = new EllipseGeometry(path.Figures[0].StartPoint, 2, 2);
            var ball    = new Path
            {
                Data  = ellipse,
                Style = style
            };

            Panel.SetZIndex(ball, 4 - newRace.Color);
            NameScope.SetNameScope(ball, new NameScope());
            ball.RegisterName("Ellipse", ellipse);
            canvas.Children.Add(ball);

            var animation = new PointAnimationUsingPath
            {
                Duration     = TimeSpan.FromSeconds(PathProvider.Calculator.Length(Distance)),
                PathGeometry = path
            };

            Storyboard.SetTargetName(animation, "Ellipse");
            Storyboard.SetTargetProperty(animation, new PropertyPath(EllipseGeometry.CenterProperty));
            storyboard = new TrackCompetitorStoryboard(newRace, PathProvider.Calculator);
            storyboard.Children.Add(animation);
            storyboard.AttachAndBegin(ball);

            skaters[color]     = ball;
            storyboards[color] = storyboard;
        }