private void ModelShipChangedEventHandler(object sender, ShipChangedEventArgs e) { if (!e.IsKilled) { if (e.ShipUpdated is Invader) { Invader invader = e.ShipUpdated as Invader; CreateOrMoveInvader(invader); } else if (e.ShipUpdated is Player) { Player player = e.ShipUpdated as Player; StopPlayerFromFlashing(); CreatePlayer(player); } } 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(); } _isPlayerFlashing = true; } } }
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; } } }
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.InvaderFactory((int)invader.InvaderType, invader.Size.Width, invader.Size.Height, Scale, _timer.Interval); _sprites.Add(invaderControl); _invaders.Add(invader, invaderControl); InvadersHelper.SetCanvasLocation(invaderControl, invader.Location.X, invader.Location.Y, Scale); } else { FrameworkElement invaderControl = _invaders[invader]; InvadersHelper.MoveElementOnCanvas(invaderControl, invader.Location.X, invader.Location.Y, Scale); InvadersHelper.ResizeElement((AnimatedImage)invaderControl, invader.Size.Width, invader.Size.Height, Scale); } } else if (e.ShipUpdated is Player) { Player player = e.ShipUpdated as Player; if (_playerFlashing && !_model.PlayerDying) { _playerFlashing = false; AnimatedImage playerControl = (AnimatedImage)_playerControl; playerControl.StopFlashing(); } if (_playerControl == null) { _playerControl = InvadersHelper.PlayerFactory(player.Size.Width, player.Size.Height, Scale, _timer.Interval); _sprites.Add(_playerControl); InvadersHelper.SetCanvasLocation(_playerControl, player.Location.X, player.Location.Y, Scale); } else { InvadersHelper.MoveElementOnCanvas(_playerControl, player.Location.X, player.Location.Y, Scale); InvadersHelper.ResizeElement((AnimatedImage)_playerControl, player.Size.Width, player.Size.Height, Scale); } } } else { // Invader killed if (e.ShipUpdated is Invader) { Invader invader = e.ShipUpdated as Invader; if (_invaders.ContainsKey(invader)) { AnimatedImage invaderControl = (AnimatedImage)_invaders[invader]; invaderControl.InvaderShot(_timeLimitInvadersFadeoutSeconds); _shotInvaders.Add(invaderControl, DateTime.Now); _invaders.Remove(invader); } } // Player killed else if (e.ShipUpdated is Player) { Player player = e.ShipUpdated as Player; AnimatedImage playerControl = (AnimatedImage)_playerControl; playerControl.StartFlashing(); _playerFlashing = true; } } }