Exemplo n.º 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);
                }
            }
        }
 private void ModelShotMovedEventHandler(object sender, ShotMovedEventArgs e)
 {
     if (!e.IsDisappeared)
     {
         if (!_shots.ContainsKey(e.Shot))
         {
             FrameworkElement shotControl = InvadersHelper.ShotControlFactory(e.Shot, Scale);
             _shots[e.Shot] = shotControl;
             _sprites.Add(shotControl);
         }
         else
         {
             FrameworkElement shotControl = _shots[e.Shot];
             InvadersHelper.MoveElementOnCanvas(shotControl, e.Shot.Location.X * Scale, e.Shot.Location.Y * Scale);
         }
     }
     else
     {
         if (_shots.ContainsKey(e.Shot))
         {
             FrameworkElement shotControl = _shots[e.Shot];
             _sprites.Remove(shotControl);
             _shots.Remove(e.Shot);
         }
     }
 }
Exemplo n.º 3
0
 private void ModelShipChangedEventHandler(object sender, ShipChangedEventArgs e)
 {
     if (!e.Killed)
     {
         if (e.ShipUpdated is Invader)
         {
             Invader invader = e.ShipUpdated as Invader;
             if (!_invaders.ContainsKey(invader))
             {
                 FrameworkElement invaderControl = InvadersHelper.InvaderControlFactory(invader, Scale);
                 _invaders[invader] = invaderControl;
                 _sprites.Add(invaderControl);
             }
             else
             {
                 FrameworkElement invaderControl = _invaders[invader];
                 InvadersHelper.MoveElement(invaderControl, invader.Location.X, Scale, invader.Location.Y * Scale);
                 InvadersHelper.ResizeElement(invaderControl, invader.Size.Width * Scale, invader.Size.Height * Scale);
             }
         }
         else if (e.ShipUpdated is Player)
         {
             if (_playerFlashing)
             {
                 AnimatedImage playerImage = _playControl as AnimatedImage;
                 _playerFlashing = false;
             }
             if (_playControl == null)
             {
                 FrameworkElement playerControl = InvadersHelper.PlayerControlFactory(player, Scale);
                 _sprites.Add(playerControl);
             }
         }
     }
 }
 private void CreatePlayer(Player player)
 {
     if (_playerControl == null)
     {
         _playerControl = InvadersHelper.PlayerControlFactory(player, Scale);
         _sprites.Add(_playerControl);
     }
     else
     {
         InvadersHelper.MoveElementOnCanvas(_playerControl, player.Location.X * Scale, player.Location.Y * Scale);
         InvadersHelper.ResizeElement(_playerControl, player.Size.Width * Scale, player.Size.Height * Scale);
     }
 }
 private void CreateOrMoveInvader(Invader invader)
 {
     if (!_invaders.ContainsKey(invader))
     {
         FrameworkElement invaderControl = InvadersHelper.InvaderControlFactory(invader, Scale);
         _invaders[invader] = invaderControl;
         _sprites.Add(invaderControl);
     }
     else
     {
         FrameworkElement invaderControl = _invaders[invader];
         InvadersHelper.MoveElementOnCanvas(invaderControl, invader.Location.X * Scale, invader.Location.Y * Scale);
         InvadersHelper.ResizeElement(invaderControl, invader.Size.Width * Scale, invader.Size.Height * Scale);
     }
 }
 //only for testing public
 public void RecreateScanLines()
 {
     foreach (FrameworkElement scanLine in _scanLines)
     {
         if (_sprites.Contains(scanLine))
         {
             _sprites.Remove(scanLine);
         }
     }
     _scanLines.Clear();
     for (int y = 0; y < 300; y += 2)
     {
         FrameworkElement scanLine = InvadersHelper.ScanLineFactory(y, 400, Scale);
         _scanLines.Add(scanLine);
         _sprites.Add(scanLine);
     }
 }
Exemplo n.º 7
0
 private void RecreateScanLines()
 {
     foreach (var scanLine in _scanLines)
     {
         if (_sprites.Contains(scanLine))
         {
             _sprites.Remove(scanLine);
         }
     }
     _scanLines.Clear();
     for (var y = 0; y < 300; y += 2)
     {
         var scanLine = InvadersHelper.ScanLineFactory(y, 400, Scale);
         _scanLines.Add(scanLine);
         _sprites.Add(scanLine);
     }
 }
Exemplo n.º 8
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);
                }
            }
        }
Exemplo n.º 9
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);
     }
 }
 private void ModelStarChangedEventHandler(object sender, StarChangedEventArgs e)
 {
     if (e.isDisappeared && _stars.ContainsKey(e.Point))
     {
         FrameworkElement starControl = _stars[e.Point];
         _sprites.Remove(starControl);
     }
     else
     {
         if (!_stars.ContainsKey(e.Point))
         {
             FrameworkElement starControl = InvadersHelper.StarControlFactory(e.Point, Scale);
             _stars[e.Point] = starControl;
             _sprites.Add(starControl);
         }
         else
         {
             FrameworkElement starControl = _stars[e.Point];
             InvadersHelper.SetCanvasLocation(starControl, e.Point.X * Scale, e.Point.Y * Scale);
         }
     }
 }
Exemplo n.º 11
0
 private void ModelStarChangedEventHandler(object sender, StarChangedEventArgs e)
 {
     if (e.Disappeared && _stars.ContainsKey(e.Point))
     {
         _sprites.Remove(_stars[e.Point]);
         _stars.Remove(e.Point);
     }
     else
     {
         if (!_stars.ContainsKey(e.Point))
         {
             var starControl = InvadersHelper.StarControlFactory(e.Point, Scale);
             _stars.Add(e.Point, starControl);
             _sprites.Add(starControl);
         }
         else
         {
             var starControl = _stars[e.Point];
             InvadersHelper.MoveElementOnCanvas(starControl,
                                                e.Point.X * Scale,
                                                e.Point.Y * Scale);
         }
     }
 }
Exemplo n.º 12
0
        void ModelShipChangedEventHandler(object sender, ShipChangedEventArgs e)
        {
            if (!e.Killed)
            {
                if (e.ShipUpdated is Invader)
                {
                    Invader invader = e.ShipUpdated as Invader;
                    if (!_invaders.ContainsKey(invader))
                    {
                        FrameworkElement invaderControl = InvadersHelper.InvaderControlFactory(invader, Scale);
                        _invaders[invader] = invaderControl;
                        _sprites.Add(invaderControl);
                    }
                    else
                    {
                        FrameworkElement invaderControl = _invaders[invader];
                        InvadersHelper.MoveElementOnCanvas(invaderControl, invader.Location.X * Scale,
                                                           invader.Location.Y * Scale);
                        InvadersHelper.ResizeElement(invaderControl, invader.Size.Width * Scale,
                                                     invader.Size.Height * Scale);
                    }
                }
                else if (e.ShipUpdated is Player)
                {
                    if (_playerFlashing)
                    {
                        _playerFlashing = false;
                        AnimatedImage control = _playerControl as AnimatedImage;
                        if (control != null)
                        {
                            control.StopFlashing();
                        }
                    }

                    Player player = e.ShipUpdated as Player;
                    if (_playerControl == null)
                    {
                        _playerControl = InvadersHelper.PlayerControlFactory(player, Scale);
                        _sprites.Add(_playerControl);
                    }
                    else
                    {
                        InvadersHelper.MoveElementOnCanvas(_playerControl, player.Location.X * Scale,
                                                           player.Location.Y * Scale);
                        InvadersHelper.ResizeElement(_playerControl, player.Size.Width * Scale,
                                                     player.Size.Height * Scale);
                    }
                }
            }
            else
            {
                if (e.ShipUpdated is Invader)
                {
                    Invader invader = e.ShipUpdated as Invader;
                    if (!_invaders.ContainsKey(invader))
                    {
                        return;
                    }
                    AnimatedImage invaderControl = _invaders[invader] as AnimatedImage;
                    if (invaderControl != null)
                    {
                        invaderControl.InvaderShot();
                        _shotInvaders[invaderControl] = DateTime.Now;
                        _invaders.Remove(invader);
                    }
                }
                else if (e.ShipUpdated is Player)
                {
                    AnimatedImage control = _playerControl as AnimatedImage;
                    if (control != null)
                    {
                        control.StartFlashing();
                    }
                    _playerFlashing = true;
                }
            }
        }
Exemplo n.º 13
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;
                }
            }
        }
Exemplo n.º 14
0
        private void ModelShipChangedEventHandler(object sender, ShipChangedEventArgs e)
        {
            if (!e.Killed)
            {
                switch (e.ShipUpdated)
                {
                case Invader _:
                    var invader = e.ShipUpdated as Invader;
                    if (!_invaders.ContainsKey(invader))
                    {
                        var fe = InvadersHelper.InvaderControlFactory(invader, Scale);
                        _invaders.Add(invader, fe);
                        _sprites.Add(fe);
                    }
                    else
                    {
                        var fe = _invaders[invader];
                        InvadersHelper.MoveElementOnCanvas(fe,
                                                           invader.Location.X * Scale,
                                                           invader.Location.Y * Scale);
                        InvadersHelper.ResizeElement(fe,
                                                     invader.Size.Width * Scale,
                                                     invader.Size.Height * Scale);
                    }

                    break;

                case Player _:
                    if (_playerFlashing)
                    {
                        var playerControl = _playerControl as AnimatedImage;
                        playerControl?.StopFlashing();
                        _playerFlashing = false;
                    }

                    var player = e.ShipUpdated as Player;
                    if (_playerControl == null)
                    {
                        _playerControl = InvadersHelper.PlayerControlFactory(player, Scale);
                        _sprites.Add(_playerControl);
                    }
                    else
                    {
                        InvadersHelper.MoveElementOnCanvas(_playerControl,
                                                           player.Location.X * Scale,
                                                           player.Location.Y * Scale);
                        InvadersHelper.ResizeElement(_playerControl,
                                                     player.Size.Width * Scale,
                                                     player.Size.Height * Scale);
                    }

                    break;
                }
            }
            else
            {
                switch (e.ShipUpdated)
                {
                case Invader _:
                    var invader = e.ShipUpdated as Invader;
                    if (!_invaders.ContainsKey(invader))
                    {
                        return;
                    }
                    if (_invaders[invader] is AnimatedImage invaderControl)
                    {
                        invaderControl.InvaderShot();
                        _shotInvaders[invaderControl] = DateTime.Now;
                        _invaders.Remove(invader);
                    }

                    break;

                case Player _:
                    var playerControl = (AnimatedImage)_playerControl;
                    playerControl.StartFlashing();
                    _playerFlashing = true;
                    OnPlayerShot();
                    break;
                }
            }
        }