public PegScore()
 {
     FirstPegControl         = new PegControl();
     FirstPegControl.Width   = 15.0;
     FirstPegControl.Height  = 15.0;
     SecondPegControl        = new PegControl();
     SecondPegControl.Width  = 15.0;
     SecondPegControl.Height = 15.0;
     Canvas.SetZIndex(SecondPegControl, 75);
     Canvas.SetZIndex(FirstPegControl, 75);
     Score1 = 0;
     Score2 = 0;
 }
        private void UpdatePegTransform(PegControl pegControl, bool outsidePeg)
        {
            pegControl.Width  = _pegDiameter;
            pegControl.Height = _pegDiameter;
            CompositeTransform transform  = pegControl.RenderTransform as CompositeTransform;
            double             translateX = -(Radius - 100 + _pegDiameter / 2.0 + PLAYER_PEG_OFFSET);

            if (outsidePeg)
            {
                translateX = -(Radius - PLAYER_PEG_OFFSET - _pegDiameter / 2.0);
            }

            transform.TranslateX = translateX;
            transform.CenterX    = -translateX;
        }
        public List <Task <object> > AnimateScore(PlayerType type, int scoreDelta)
        {
            List <Task <object> > taskList = new List <Task <object> >();
            PegControl            backPeg  = null;

            List <Ellipse> holeList = null;
            int            newScore = -1;

            if (type == PlayerType.Player)
            {
                holeList = _playerHoles;
                if (_playerPegScore1.Score > _playerPegScore2.Score)
                {
                    backPeg  = _playerPegScore2;
                    newScore = _playerPegScore1.Score + scoreDelta;
                }
                else
                {
                    backPeg  = _playerPegScore1;
                    newScore = _playerPegScore2.Score + scoreDelta;
                }
            }
            else
            {
                holeList = _computerHoles;
                if (_computerPegScore1.Score > _computerPegScore2.Score)
                {
                    backPeg  = _computerPegScore2;
                    newScore = _computerPegScore1.Score + scoreDelta;
                }
                else
                {
                    backPeg  = _computerPegScore1;
                    newScore = _computerPegScore2.Score + scoreDelta;
                }
            }

            int animateScore = newScore;

            if (newScore > 121)
            {
                animateScore = 121;
            }


            double ms = 50;

            if (MainPage.AnimationSpeeds != null)
            {
                ms = MainPage.AnimationSpeeds.Medium / 10;
            }

            Duration rotateDuration = TimeSpan.FromMilliseconds(ms * (animateScore - backPeg.Score));
            Duration durationTo120  = TimeSpan.FromMilliseconds(ms * (120 - backPeg.Score));
            TimeSpan durationZero   = TimeSpan.FromMilliseconds(0);

            backPeg.Score = newScore;

            DoubleAnimation animateRotate     = backPeg.MovePegStoryBoard.Children[0] as DoubleAnimation;
            DoubleAnimation animateTranslateX = backPeg.MovePegStoryBoard.Children[1] as DoubleAnimation;
            DoubleAnimation animateCenterX    = backPeg.MovePegStoryBoard.Children[2] as DoubleAnimation;


            Ellipse            ellipse            = GetEllipseForScore(holeList, animateScore);
            CompositeTransform compositeTransform = ellipse.RenderTransform as CompositeTransform;

            animateRotate.To     = compositeTransform.Rotation;
            animateTranslateX.To = compositeTransform.TranslateX;
            animateCenterX.To    = compositeTransform.CenterX;

            animateCenterX.Duration    = TimeSpan.FromMilliseconds(0);
            animateTranslateX.Duration = TimeSpan.FromMilliseconds(0);
            if (newScore <= 120)
            {
                animateRotate.Duration      = rotateDuration;
                animateCenterX.BeginTime    = durationZero;
                animateTranslateX.BeginTime = durationZero;
                animateCenterX.Duration     = durationZero;
                animateTranslateX.Duration  = durationZero;
            }
            else
            {
                animateCenterX.BeginTime    = durationTo120.TimeSpan;
                animateTranslateX.BeginTime = durationTo120.TimeSpan;
                Duration durationToWin = TimeSpan.FromMilliseconds(ms);
                animateCenterX.Duration    = durationToWin;
                animateTranslateX.Duration = durationToWin;
            }

            taskList.Add(backPeg.MovePegStoryBoard.ToTask());
            return(taskList);
        }