Пример #1
0
        private void ModelShotMovedEventHandler(object sender, Model.Event_Arguments.ShotMovedEventArgs e)
        {
            if (!e.Disappeared)
            {
                if (!_shots.ContainsKey(e.Shot))
                {
                    Rectangle shot = InvadersHelper.ShotFactory(new Rect(e.Shot.Location, e.Shot.ShotSize), e.PlayerShot);
                    _shots.Add(e.Shot, shot);
                    _sprites.Add(shot);
                    InvadersHelper.ResizeElement(shot, shot.Width * Scale, shot.Height * Scale);
                    InvadersHelper.RepositionElement(shot, e.Shot.Location.X * Scale, e.Shot.Location.Y * Scale);
                }
                else
                {
                    InvadersHelper.ResizeElement(_shots[e.Shot], e.Shot.ShotSize.Width * Scale, e.Shot.ShotSize.Height * Scale);
                    InvadersHelper.RepositionElement(_shots[e.Shot], e.Shot.Location.X * Scale, e.Shot.Location.Y * Scale);
                }
            }

            else
            {
                if (_shots.ContainsKey(e.Shot))
                {
                    _sprites.Remove(_shots[e.Shot]);
                    _shots.Remove(e.Shot);
                }
            }
        }
Пример #2
0
        private void ModelStarChangedEventHandler(object sender, Model.Event_Arguments.StarChangedEventArgs e)
        {
            if (e.Disappeared && _stars.ContainsKey(e.Point))
            {
                _sprites.Remove(_stars[e.Point]);
            }

            else
            {
                if (!_stars.ContainsKey(e.Point))
                {
                    FrameworkElement newStar = InvadersHelper.StarControlFactory(Scale) as FrameworkElement;
                    _stars.Add(e.Point, newStar);
                    _sprites.Add(newStar);
                    InvadersHelper.RepositionElement(newStar, e.Point.X * Scale, e.Point.Y * Scale);
                    InvadersHelper.SendToBack(newStar);
                }
            }
        }
Пример #3
0
 private void RecreateScanLines()
 {
     foreach (FrameworkElement scanLine in _scanLines)
     {
         if (_sprites.Contains(scanLine))
         {
             _sprites.Remove(scanLine);
         }
     }
     _scanLines.Clear();
     for (int y = 0; y < 300; y += 4)
     {
         FrameworkElement scanLine = InvadersHelper.ScanLineFactory();
         _scanLines.Add(scanLine);
         _sprites.Add(scanLine);
         InvadersHelper.ResizeElement(scanLine, 400 * Scale, 1 * Scale);
         InvadersHelper.RepositionElement(scanLine, 0, y * Scale);
     }
 }
Пример #4
0
        private void ModelShipChangedEventHandler(object sender, Model.Event_Arguments.ShipChangedEventArgs e)
        {
            if (!e.Killed)
            {
                if (e.ShipUdated is Invader)
                {
                    Invader invader = e.ShipUdated as Invader;

                    if (!_invaders.ContainsKey(invader))
                    {
                        AnimatedImage animatedImage = InvadersHelper.InvadersControlFactory(invader.InvaderType, invaderAnimationInterval);
                        _invaders.Add(invader, animatedImage);
                        _sprites.Add(animatedImage);
                        InvadersHelper.RepositionElement(_invaders[invader], invader.Location.X * Scale, invader.Location.Y * Scale);
                        InvadersHelper.ResizeElement(animatedImage, invader.Size.Width * Scale, invader.Size.Height * Scale);
                    }
                    else
                    {
                        InvadersHelper.RepositionElement(_invaders[invader], invader.Location.X * Scale, invader.Location.Y * Scale);
                        InvadersHelper.ResizeElement(_invaders[invader], invader.Size.Width * Scale, invader.Size.Height * Scale);
                    }
                }

                else if (e.ShipUdated is Player)
                {
                    Player player = e.ShipUdated as Player;
                    if (_playerFlashing == true)
                    {
                        _playerControl.StopFlashing();
                        _playerFlashing = false;
                    }
                    if (_playerControl == null)
                    {
                        _playerControl = InvadersHelper.PlayerControlFactory(invaderAnimationInterval);
                        _sprites.Add(_playerControl);
                        InvadersHelper.RepositionElement(_playerControl, player.Location.X * Scale, player.Location.Y * Scale);
                        InvadersHelper.ResizeElement(_playerControl, player.Size.Width * Scale, player.Size.Height * Scale);
                    }
                    else
                    {
                        InvadersHelper.RepositionElement(_playerControl, player.Location.X * Scale, player.Location.Y * Scale);
                        InvadersHelper.ResizeElement(_playerControl, player.Size.Width * Scale, player.Size.Height * Scale);
                    }
                }
            }

            else
            {
                if (e.ShipUdated is Invader)
                {
                    if (e.ShipUdated != null)
                    {
                        if (_invaders.ContainsKey(e.ShipUdated as Invader))
                        {
                            (_invaders[e.ShipUdated as Invader] as AnimatedImage).InvaderShot();
                            _shotInvaders.Add(_invaders[e.ShipUdated as Invader], DateTime.Now);
                            _invaders.Remove(e.ShipUdated as Invader);
                        }
                    }
                }

                else if (e.ShipUdated is Player)
                {
                    _playerControl.StartFlashing();
                    _playerFlashing = true;
                }
            }
        }