void StarChangedHandler(object sender, StarChangedEventArgs e)
 {
     if (e.Removed)
     {
         StarControl starControl = _stars[e.StarThatChanged];
         _stars.Remove(e.StarThatChanged);
         _fadedStars.Add(starControl);
         starControl.FadeOut();
     }
     else
     {
         StarControl newStar;
         if (_stars.ContainsKey(e.StarThatChanged))
         {
             newStar = _stars[e.StarThatChanged];
         }
         else
         {
             newStar = new StarControl();
             _stars[e.StarThatChanged] = newStar;
             newStar.FadeIn();
             BeeStarHelper.SendToBack(newStar);
             _sprites.Add(newStar);
         }
         BeeStarHelper.SetCanvasLocation(
             newStar, e.StarThatChanged.Location.X, e.StarThatChanged.Location.Y);
     }
 }
Пример #2
0
        void StarChangedHandler(object sender, StarChangedEventArgs e)
        {
            StarControl starControl = null;

            if (_stars.ContainsKey(e.StarThatChanged))
            {
                starControl = _stars[e.StarThatChanged];
            }

            if (e.Removed && starControl != null)
            {
                _fadedStars.Add(starControl);
                _stars.Remove(e.StarThatChanged);
                starControl.FadeOut();
                return;
            }
            else if (starControl == null)
            {
                starControl = new StarControl();
                if (_stars.ContainsKey(e.StarThatChanged))
                {
                    _stars[e.StarThatChanged] = starControl;
                }
                else
                {
                    _stars.Add(e.StarThatChanged, starControl);
                }
                _sprites.Add(starControl);

                starControl.FadeIn();
                BeeStarHelper.SendToBack(starControl);
            }

            BeeStarHelper.SetCanvasLocation(starControl, e.StarThatChanged.Location.X, e.StarThatChanged.Location.Y);
        }
Пример #3
0
        private void _model_StarChanged(object sender, StarChangedEventArgs e)
        {
            if (e.Removed && _stars.ContainsKey(e.StarThatChanged))
            {
                StarControl starRemoved = _stars[e.StarThatChanged];
                _fadedStars.Add(starRemoved);
                _stars.Remove(e.StarThatChanged);
                starRemoved.FadeOut();
            }
            else
            {
                StarControl starToBeShown;
                if (_stars.ContainsKey(e.StarThatChanged))
                {
                    starToBeShown = _stars[e.StarThatChanged];
                }
                else
                {
                    starToBeShown = new StarControl();
                    starToBeShown.FadeIn();
                    _sprites.Add(starToBeShown);
                    BeeStarHelper.SentToBack(starToBeShown);
                }

                BeeStarHelper.SetCanvasLocation(starToBeShown, e.StarThatChanged.Location.X, e.StarThatChanged.Location.Y);
            }
        }
Пример #4
0
        private void StarChangedHandler(object sender, StarChangedEventArgs e)
        {
            if (_stars.ContainsKey(e.StarThatChanged))
            {
                if (e.Removed)
                {
                    _fadedStars.Add(_stars[e.StarThatChanged]);
                    _stars[e.StarThatChanged].FadeOut();
                    _stars.Remove(e.StarThatChanged);
                }

                else
                {
                    BeeStarHelper.SetCanvasLocation(_stars[e.StarThatChanged], e.StarThatChanged.Location.X, e.StarThatChanged.Location.Y);
                }
            }
            else
            {
                StarControl newStarControl = new StarControl();
                newStarControl.FadeIn();
                _stars.Add(e.StarThatChanged, newStarControl);
                _sprites.Add(newStarControl);
                BeeStarHelper.SendToBack(newStarControl);
                BeeStarHelper.SetCanvasLocation(newStarControl, e.StarThatChanged.Location.X, e.StarThatChanged.Location.Y);
            }
        }
Пример #5
0
 private void BeeMovedHandler(object sender, BeeMovedEventArgs e)
 {
     if (_bees.ContainsKey(e.BeeThatMoved))
     {
         BeeStarHelper.MoveElementOnCanvas(_bees[e.BeeThatMoved], e.X, e.Y);
     }
     else
     {
         AnimatedImage newAnimatedImage = BeeStarHelper.BeeFactory(e.BeeThatMoved.Width, e.BeeThatMoved.Height, TimeSpan.FromMilliseconds(20));
         BeeStarHelper.SetCanvasLocation(newAnimatedImage, e.X, e.Y);
         _bees[e.BeeThatMoved] = newAnimatedImage;
         _sprites.Add(newAnimatedImage);
     }
 }
 void BeeMovedHandler(object sender, BeeMovedEventArgs e)
 {
     if (!_bees.ContainsKey(e.BeeThatMoved))
     {
         AnimatedImage beeControl = BeeStarHelper.BeeFactory(e.BeeThatMoved.Width, e.BeeThatMoved.Height, TimeSpan.FromMilliseconds(20));
         BeeStarHelper.SetCanvasLocation(beeControl, e.X, e.Y);
         _bees[e.BeeThatMoved] = beeControl;
         _sprites.Add(beeControl);
     }
     else
     {
         AnimatedImage beeImageMoved = _bees[e.BeeThatMoved];
         BeeStarHelper.MoveElementOnCanvas(beeImageMoved, e.X, e.Y);
     }
 }
Пример #7
0
 private void BeeMovedHandler(object sender, BeeMovedEventArgs e)
 {
     if (_bees.ContainsKey(e.BeeThatMoved))
     {
         BeeStarHelper.MoveElememtOnCanvas(_bees[e.BeeThatMoved], e.X, e.Y);
     }
     else
     {
         int           newBeeSize  = _random.Next(50, 100);
         AnimatedImage newBeeImage = BeeStarHelper.BeeFactory(newBeeSize, newBeeSize, TimeSpan.FromMilliseconds(50));
         BeeStarHelper.SetCanvasLocation(newBeeImage, e.X, e.Y);
         _bees.Add(e.BeeThatMoved, newBeeImage);
         _sprites.Add(newBeeImage);
     }
 }
Пример #8
0
 private void _model_BeeMoved(object sender, BeeMovedEventArgs e)
 {
     if (!_bees.ContainsKey(e.BeeThatMoved) || (_bees.ContainsKey(e.BeeThatMoved) && _bees[e.BeeThatMoved] == null))
     {
         AnimatedImage image =
             BeeStarHelper.BeeFactory(e.BeeThatMoved.Width, e.BeeThatMoved.Height,
                                      TimeSpan.FromMilliseconds(50));
         BeeStarHelper.SetCanvasLocation(image, e.X, e.Y);
         _bees.Add(e.BeeThatMoved, image);
         _sprites.Add(image);
     }
     else
     {
         AnimatedImage imageToMove = _bees[e.BeeThatMoved];
         BeeStarHelper.MoveElementOnCanvas(imageToMove, e.X, e.Y);
     }
 }
Пример #9
0
        void StarChangedHandler(object sender, StarChangedEventArgs e)
        {
            // The _stars dictionary works just like the _bees one, except that it maps Star objects
            // to their corresponding StarControl controls. The EventArgs contains references to
            // the Star object (which has a Location property) and a Boolean to tell you if the star
            // was removed. If it is then we want it to fade out, so remove it from _stars, add it
            // to _fadedStars, and call its FadeOut() method (it'll be removed from _sprites the next
            // time the Update() method is called, which is why we set the timer’s tick interval to
            // be greater than the StarControl's fade out animation).

            if (e.Removed)
            {
                StarControl starControl = _stars[e.StarThatChanged];
                _stars.Remove(e.StarThatChanged);
                _fadedStars.Add(starControl);

                starControl.FadeOut();
            }

            //
            // If the star is not being removed, then check to see if _stars contains it - if so, get
            // the StarControl reference; if not, you'll need to create a new StarControl, fade it in,
            // add it to _sprites, and send it to back so the bees can fly in front of it. Then set
            // the canvas location for the StarControl.
            else
            {
                StarControl starControl;
                if (!_stars.ContainsKey(e.StarThatChanged))
                {
                    starControl = new StarControl();
                    _stars.Add(e.StarThatChanged, starControl);
                    starControl.FadeIn();
                    starControl.Rotate(e.StarThatChanged.Rotating);
                    _sprites.Add(starControl);
                    BeeStarHelper.SendToBack(starControl);
                }
                else
                {
                    starControl = _stars[e.StarThatChanged];
                }
                BeeStarHelper.SetCanvasLocation(starControl, e.StarThatChanged.Location.X, e.StarThatChanged.Location.Y);
            }
        }
Пример #10
0
        void BeeMovedHandler(object sender, BeeMovedEventArgs e)
        {
            // The _bees dictionary maps Bee objects in the Model to AnimatedImage controls
            // in the view. When a bee is moved, the BeeViewModel fires its BeeMoved event to
            // tell anyone listening which bee moved and its new location. If the _bees
            // dictionary doesn't already contain an AnimatedImage control for the bee, it needs
            // to create a new one, set its canvas location, and update both _bees and _sprites.
            // If the _bees dictionary already has it, then we just need to look up the corresponding
            // AnimatedImage control and move it on the canvas to its new location with an animation.

            if (!_bees.ContainsKey(e.BeeThatMoved))
            {
                AnimatedImage beeControl = BeeStarHelper.BeeFactory(e.BeeThatMoved.Width, e.BeeThatMoved.Height, TimeSpan.FromMilliseconds(20));
                BeeStarHelper.SetCanvasLocation(beeControl, e.X, e.Y);
                _bees[e.BeeThatMoved] = beeControl;
                _sprites.Add(beeControl);
            }
            else
            {
                BeeStarHelper.MoveElementOnCanvas(_bees[e.BeeThatMoved], e.X, e.Y);
            }
        }