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 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); } }
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) { 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; } } }