Exemple #1
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;
                }
            }
        }