private void addShipToPlayer(Ship s, Player p) { int countOfClass = p.Ships.Where(f => f.ClassName == s.ClassName).Count(); Ship shipToAdd = s.Clone(); shipToAdd.Name = string.Format("{0} - {1}", s.ClassName, (countOfClass + 1).ToString("000")); shipToAdd.Owner = p; p.Ships.Add(shipToAdd); }
public static List<ShipPart> GetShipPartList(XDocument sourceDoc, Ship parent) { List<ShipPart> ShipPartList = new List<ShipPart>(); XElement weaponParts = sourceDoc.Element("shipParts").Element("weaponParts"); foreach (XElement weaponPart in weaponParts.Elements()) ShipPartList.Add(new WeaponPart(weaponPart, parent)); XElement defenseParts = sourceDoc.Element("shipParts").Element("defenseParts"); foreach (XElement defensePart in defenseParts.Elements()) ShipPartList.Add(new DefensePart(defensePart, parent)); XElement actionParts = sourceDoc.Element("shipParts").Element("actionParts"); foreach (XElement actionPart in actionParts.Elements()) ShipPartList.Add(new ActionPart(actionPart, parent)); XElement engineParts = sourceDoc.Element("shipParts").Element("engineParts"); foreach (XElement enginePart in engineParts.Elements()) ShipPartList.Add(new EnginePart(enginePart, parent)); return ShipPartList; }
public StrategicWindow(Game gameState, Player currentPlayer = null, StarSystem currentSystem = null, System.Drawing.Point currentSystemLoc = new System.Drawing.Point(), Ship currentShip = null) { InitializeComponent(); #region Bindings lbxTargetShips.ItemsSource = SelectedShipList; #endregion initImages(); this.GameState = gameState; this.currentPlayer = currentPlayer; this.currentSystem = currentSystem; this.currentShip = currentShip; initGalaxyMap(); ShowSystemMap(currentSystem); scrollGalaxyGridToSystem(currentSystem); highlightSelectedSystem(currentSystem); selectSystemCoordinates(currentSystemLoc); }
private void InitShip() { ship = new Ship(); ship.Name = "Test Ship"; ship.HP.Max = 50; ship.HP.Current = 50; ship.Equipment.Add(new WeaponPart("Laser Beam", 1, 5, 2, 0, new List<ShipAction>())); ship.Equipment.Add(new WeaponPart("Laser Beam", 1, 5, 2, 0, new List<ShipAction>())); ship.Equipment.Add(new WeaponPart("Laser Beam", 1, 5, 2, 0, new List<ShipAction>())); ship.Equipment.Add(new WeaponPart("Laser Beam", 1, 5, 2, 0, new List<ShipAction>())); List<ShipAction> ShieldGenAction = new List<ShipAction>(); ShieldGenAction.Add(new RepairThisPart(2)); ship.Equipment.Add(new DefensePart("Shield Generator", 15, 1, "Down", "Penetrating", ShieldGenAction)); ship.Equipment.Add(new DefensePart("Shield Generator", 15, 1, "Down", "Penetrating", ShieldGenAction)); ship.Equipment.Add(new DefensePart("Armor Plate", 15, 3, "Destroyed", "Shattering", new List<ShipAction>())); List<ShipAction> DmgControlAction = new List<ShipAction>(); DmgControlAction.Add(new RepairTargetShip(5)); ship.Equipment.Add(new ActionPart("Damage Control", 1, "Regen: 5 HPs", DmgControlAction)); lblShip.Text = ship.Name; ShowShipDetails(ship, tlpShip); }
private void btnClear_Click(object sender, EventArgs e) { ship = new Ship(); ShowShip(); }
void ShowShipStatus(Ship ship, StackPanel panel) { try { panel.Children.Clear(); // Name & Icon StackPanel titlebar = new StackPanel(); titlebar.Orientation = Orientation.Horizontal; titlebar.VerticalAlignment = VerticalAlignment.Center; Image img = new Image(); img.Source = ship.Image.Source; img.Height = 32; img.Width = 32; img.Stretch = Stretch.None; titlebar.Children.Add(img); panel.Children.Add(titlebar); addStatusLabel(string.Format("{0} ({1} {2})", ship.Name, ship.ClassName, ship.TacticalPosition), Brushes.White, titlebar); // HP addStatusLabel(string.Format("Hit Points: {0}", ship.HP.ToString()), Brushes.White, panel); // MP addStatusLabel(string.Format("Move Points: {0}", ship.MP.ToString()), Brushes.White, panel); // Orders Header if (currentPlayer.Ships.Any(f => f == ship)) //owned by current player { try { addStatusLabel("Current Orders:", Brushes.White, panel); foreach (var order in ship.Orders) addStatusLabel(order.ToString(), Brushes.Wheat, panel); } catch (Exception ex) { if (LogEverything) Logger(ex); } } // Parts addStatusLabel("Equipment:", Brushes.White, panel); foreach (var part in ship.Parts) addStatusLabel(part.ToString(), (part.IsDestroyed ? Brushes.DarkRed : Brushes.LightSlateGray), panel); } catch (Exception ex) { if (LogEverything) Logger(ex); } }
void ShowShipStatus(Ship ship, StackPanel panel) { panel.Children.Clear(); // Name addStatusLabel(string.Format("{0} - Class {1}", ship.ClassName, ship.HullType.Name), Brushes.White, panel); StackPanel spPoints = new StackPanel(); spPoints.Orientation = Orientation.Horizontal; spPoints.Width = 300; // HP addStatusLabel(string.Format("Hit Points: {0} ", ship.HP.ToString()), Brushes.White, spPoints); // MP addStatusLabel(string.Format("Move Points: {0}", ship.MP.ToString()), Brushes.White, spPoints); panel.Children.Add(spPoints); // Parts addStatusLabel("Equipment:", Brushes.White, panel); foreach (var part in ship.Parts) addStatusLabel(part.ToString(), (part.IsDestroyed ? Brushes.DarkRed : Brushes.LightSlateGray), panel); }
private void AddExplosionImage(Ship shipToExplode) { try { if (explosionImg.Parent != null) ((Grid)explosionImg.Parent).Children.Remove(explosionImg); Grid.SetRow(explosionImg, shipToExplode.TacticalPosition.X); Grid.SetColumn(explosionImg, shipToExplode.TacticalPosition.Y); g.Children.Add(explosionImg); Action<Image, Ship> removeExpImage = new Action<Image, Ship>(removeExplosionImage); RemoveExplosion(removeExpImage, explosionImg, shipToExplode); } catch (Exception ex) { if (LogEverything) Logger(ex); } }
private void ofdOpen_FileOk(object sender, CancelEventArgs e) { currentShipDocFileName = ofdOpen.FileName; shipDoc = XDocument.Load(ofdOpen.FileName); LoadShipList(shipDoc); ShowShipList(); ship = new Ship(); bsShipParts.DataSource = ship.Parts; ShowShip(); }
void cbxShipList1_SelectedIndexChanged(object sender, EventArgs e) { Ship1 = (Ship)cbxShipList1.SelectedItem; gbxShip1.Text = Ship1.ClassName; ShowShipDetails(Ship1, tlpShip1); if (Ship1 != null && Ship2 != null) { victory = false; btnFight.Enabled = true; btnToTheDeath.Enabled = true; btnResetShips.Enabled = true; } }
public abstract List<string> ExecuteOrder(Ship ship);
void ClearSelectedCurrentShip() { imgCurrentShipPlayerIcon.Source = null; imgCurrentShipShipIcon.Source = null; txtCurrentShipName.Text = string.Empty; txtCurrentShipLocation.Text = string.Empty; txtCurrentShipHP.Text = string.Empty; txtCurrentShipMP.Text = string.Empty; currentShip = null; }
/// <summary> /// Used to clone a Ship, for grabbing a copy of a pre-built ship from a list of available definitions (Factory). /// </summary> /// <returns>The new Ship object</returns> public Ship Clone() { Ship result = new Ship(); result.ClassName = this.ClassName; foreach (ShipPart part in this.Parts) result.Parts.Add(part.Clone()); result.HullType = this.HullType.Clone(); result.MP.Max = this.MP.Max; result.initImage(this.Image.Source,40); return result; }
public List<string> FireWeapons(Ship Target) { List<string> result = new List<string>(); foreach (WeaponPart weapon in Parts.Where(f => f is WeaponPart)) { // check if destroyed if (weapon.IsDestroyed) result.Add(string.Format("{0} is destroyed!", weapon.Name)); else { // check if needs to be reloaded if (!weapon.IsLoaded) result.Add(string.Format("{0} will be reloaded in {1} turns", weapon.Name, weapon.Reload())); else { // check if has a target if (weapon.Target == null) weapon.Target = Target; result.Add(string.Format("{0} fires, {1}", weapon.Name,weapon.Fire())); } } } return result; }
private void EndTurn() { try { // process end-of-turn actions if (GameState.Players[GameState.Players.Count - 1] == currentPlayer) ProcessTurnResults(); // set current to next player and first ship currentPlayer = GameState.Players.Next(); currentPlayer.Ships.ResetIndex(); currentShip = currentPlayer.Ships.GetNextShip(); txbCurrentPlayer.Text = currentPlayer.Name; imgCurrentPlayerIcon.Source = currentPlayer.Icon.Source; // perform Start Of Turn for current player's ships foreach (Ship s in currentPlayer.Ships) s.StartOfTurn(); // highlight next player's ship AddHighlightImage(currentShip.TacticalPosition.X, currentShip.TacticalPosition.Y); // clear movement target image RemoveMoveTargetImage(); // refresh menu options for ships RefreshContextMenuImages(); // show current ship status ShowShipStatus(currentShip, spCurrentShip); // clear target window spTargetShip.Children.Clear(); if (currentPlayer.IsAI) { try { currentPlayer.ExecuteAI(GameState); initHandlers(currentPlayer); EndTurn(); } catch (Exception ex) { if (LogEverything) Logger(ex); } } } catch (Exception ex) { if (LogEverything) Logger(ex); } }
void BuildMap() { try { g.Children.Clear(); currentPlayer = GameState.Players[0]; txbCurrentPlayer.Text = currentPlayer.Name; imgCurrentPlayerIcon.Source = currentPlayer.Icon.Source; currentShip = currentPlayer.Ships[0]; using (RNG rng = new RNG()) { for (int x = 0; x < GridDimensionX; x++) { for (int y = 0; y < GridDimensionY; y++) { AddBackgroundImage(x, y, rng.d(4)); AddContextMenuImage(x, y); AddShipImages(x, y); //AddLabel(x, y); if (GameState.CombatLocations[x, y].IsBlocked) { try { AddBlockedImage(x, y); } catch { MessageBox.Show("error in blocked images"); } } } } } // highlight next player's ship AddHighlightImage(currentShip.TacticalPosition.X, currentShip.TacticalPosition.Y); ShowShipStatus(currentShip, spCurrentShip); lbxTargetShips.ItemsSource = SelectedLocShips; lbxTargetShips.UpdateLayout(); } catch (Exception ex) { if (LogEverything) Logger(ex); } }
private void btnNextShip_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { try { Border b = (Border)sender; b.Background = buttondown; currentShip = currentPlayer.Ships.GetNextShip(); ShowShipStatus(); RefreshContextMenuImages(); AddHighlightImage(currentShip.TacticalPosition.X, currentShip.TacticalPosition.Y); } catch (Exception ex) { if (LogEverything) Logger(ex); } }
private void btnLoadShip_Click(object sender, EventArgs e) { ship = (Ship)cbxShipList.SelectedItem; ShowShip(); }
private void endTurn() { // process end-of-turn actions if (GameState.Players[GameState.Players.Count - 1] == currentPlayer) ProcessTurnResults(); // set current to next player and first ship currentPlayer = GameState.Players.Next(); currentPlayer.Ships.ResetIndex(); currentShip = null; //txbCurrentPlayer.Text = currentPlayer.Name; //imgCurrentPlayerIcon.Source = currentPlayer.Icon.Source; // perform Start Of Turn for current player's ships foreach (Ship s in currentPlayer.Ships) s.StartOfTurn(); // refresh menu options for ships RefreshSystemContextMenuImages(); ClearSelectedCurrentShip(); // "focus" on home system for current player ShowSystemMap(currentPlayer.HomeSystem); scrollGalaxyGridToSystem(currentPlayer.HomeSystem); //if (currentPlayer.IsAI) //{ // try // { // currentPlayer.ExecuteAI(GameState); // initHandlers(currentPlayer); // EndTurn(); // } // catch (Exception ex) // { // if (LogEverything) // Logger(ex); // } //} }
private void newToolStripMenuItem_Click(object sender, EventArgs e) { ExistingShips = new List<Ship>(); ship = new Ship(); ShowShip(); }
private void removeExplosionImage(Image explosionImage, Ship shipToExplode) { try { ((Grid)explosionImg.Parent).Children.Remove(explosionImg); ((Grid)shipToExplode.Image.Parent).Children.Remove(shipToExplode.Image); } catch (Exception ex) { if (LogEverything) Logger(ex); } }
private void ShowShipDetails(Ship ship, TableLayoutPanel tlp) { int rowcount; rowcount = 0; tlp.Controls.Clear(); addLabel(string.Format("Current HP: {0}", ship.HP.ToString()), Color.Black, rowcount, tlp); rowcount++; foreach (ShipPart part in ship.Parts) { addLabel(part.ToString(), (part.IsDestroyed ? Color.Red : Color.Black), rowcount, tlp); rowcount++; } addLabel(string.Empty, Color.Black, rowcount, tlp); }
void ShowSelectedCurrentShip(Ship ship) { imgCurrentShipPlayerIcon.Source = ship.Owner.Icon.Source; imgCurrentShipShipIcon.Source = ship.Image.Source; txtCurrentShipName.Text = string.Format("Name: {0} ({1}-Class {2})", ship.Name, ship.ClassName, ship.HullType.Name); txtCurrentShipLocation.Text = string.Format("Location: {0} ({1},{2})", ship.StrategicSystem.Name, ship.StrategicPosition.X, ship.StrategicPosition.Y); txtCurrentShipHP.Text = string.Format("HP: {0}/{1}", ship.HP.Current, ship.HP.Max); txtCurrentShipMP.Text = string.Format("MP: {0}/{1}", ship.MP.Current, ship.MP.Max); currentShip = ship; RefreshSystemContextMenuImages(); }
void initShips(Player p) { this.ExistingShips.Clear(); // load source document, hulls and parts XDocument xdoc = XDocument.Load(string.Format("Empires\\{0}\\Ships.xml",p.IconSet)); foreach (XElement shipElement in xdoc.Descendants("ship")) { Ship ship = new Ship(shipElement, GameState.ExistingParts, GameState.ExistingHulls, p); ship.Origin = new System.Drawing.Point(); Image img = new Image(); if (File.Exists(string.Format("Empires\\{0}\\Images\\{1}", p.IconSet, ship.HullType.ImageURL))) { BitmapImage src = new BitmapImage(); src.BeginInit(); src.UriSource = new Uri(string.Format("Empires\\{0}\\Images\\{1}", p.IconSet, ship.HullType.ImageURL), UriKind.Relative); ; src.CacheOption = BitmapCacheOption.OnLoad; src.EndInit(); img.Source = src; } img.Height = 32; img.Width = 32; img.Stretch = Stretch.None; img.SetValue(Panel.ZIndexProperty, 10); ship.Image = img; ExistingShips.Add(ship); } }
void ShowShipStatus(Ship ship) { try { spSelectedEidos.Children.Clear(); Grid nameGrid = new Grid(); nameGrid.Width = spSelectedEidos.ActualWidth; nameGrid.VerticalAlignment = VerticalAlignment.Center; nameGrid.HorizontalAlignment = HorizontalAlignment.Center; // row RowDefinition rowName = new RowDefinition(); rowName.Height = new GridLength(32); nameGrid.RowDefinitions.Add(rowName); // column: owner icon ColumnDefinition columnIcon = new ColumnDefinition(); columnIcon.Width = new GridLength(32); nameGrid.ColumnDefinitions.Add(columnIcon); // column: ship icon ColumnDefinition columnShip = new ColumnDefinition(); columnShip.Width = new GridLength(32); nameGrid.ColumnDefinitions.Add(columnShip); // column: name ColumnDefinition columnName = new ColumnDefinition(); columnName.Width = new GridLength(1, GridUnitType.Star); nameGrid.ColumnDefinitions.Add(columnName); // column: position ColumnDefinition columnPosition = new ColumnDefinition(); columnPosition.Width = new GridLength(1, GridUnitType.Auto); nameGrid.ColumnDefinitions.Add(columnPosition); //owner icon Image icon = new Image(); icon.Source = ship.Owner.Icon.Source; icon.Height = 32; icon.Width = 32; icon.Stretch = Stretch.None; Grid.SetColumn(icon, 0); Grid.SetRow(icon, 0); nameGrid.Children.Add(icon); //ship icon Image img = new Image(); img.Source = ship.Image.Source; img.Height = 32; img.Width = 32; img.Stretch = Stretch.None; Grid.SetColumn(img, 1); Grid.SetRow(img, 0); nameGrid.Children.Add(img); //ship name TextBlock txtName = new TextBlock(); txtName.Text = ship.Name; txtName.Padding = new Thickness(5, 0, 5, 0); txtName.Foreground = Brushes.White; Grid.SetColumn(txtName, 2); Grid.SetRow(txtName, 0); nameGrid.Children.Add(txtName); //ship position TextBlock txtPosition = new TextBlock(); txtPosition.Text = string.Format("{0} ({1},{2})", ship.StrategicSystem.Name, ship.StrategicPosition.X, ship.StrategicPosition.Y); txtPosition.Padding = new Thickness(5, 0, 5, 0); txtPosition.Foreground = Brushes.White; Grid.SetColumn(txtPosition, 3); Grid.SetRow(txtPosition, 0); nameGrid.Children.Add(txtPosition); spSelectedEidos.Children.Add(nameGrid); Grid classGrid = new Grid(); classGrid.Width = spSelectedEidos.ActualWidth; classGrid.VerticalAlignment = VerticalAlignment.Center; classGrid.HorizontalAlignment = HorizontalAlignment.Center; // row: owner RowDefinition rowOwner = new RowDefinition(); rowOwner.Height = new GridLength(1, GridUnitType.Auto); classGrid.RowDefinitions.Add(rowOwner); // row: class/hull RowDefinition rowClass = new RowDefinition(); rowClass.Height = new GridLength(1, GridUnitType.Auto); classGrid.RowDefinitions.Add(rowClass); // row: hp/mp RowDefinition rowHP = new RowDefinition(); rowHP.Height = new GridLength(1, GridUnitType.Auto); classGrid.RowDefinitions.Add(rowHP); // column: HP ColumnDefinition columnHP = new ColumnDefinition(); columnHP.Width = new GridLength(1, GridUnitType.Star); classGrid.ColumnDefinitions.Add(columnHP); // column: MP ColumnDefinition columnMP = new ColumnDefinition(); columnMP.Width = new GridLength(1, GridUnitType.Star); classGrid.ColumnDefinitions.Add(columnMP); //owner TextBlock txtOwner = new TextBlock(); txtOwner.Text = string.Format("{0} Empire ({1})", ship.Owner.EmpireName, ship.Owner.Name); txtOwner.Foreground = Brushes.White; Grid.SetColumn(txtOwner, 0); Grid.SetRow(txtOwner, 0); Grid.SetColumnSpan(txtOwner, 2); classGrid.Children.Add(txtOwner); //class/hull TextBlock txtClass = new TextBlock(); txtClass.Text = string.Format("{0}-Class {1}", ship.ClassName, ship.HullType.Name); txtClass.Foreground = Brushes.White; Grid.SetColumn(txtClass, 0); Grid.SetRow(txtClass, 1); Grid.SetColumnSpan(txtClass, 2); classGrid.Children.Add(txtClass); //hp TextBlock txtHP = new TextBlock(); txtHP.Text = string.Format("HP: {0}/{1}", ship.HP.Current,ship.HP.Max); txtHP.Foreground = Brushes.White; Grid.SetColumn(txtHP, 0); Grid.SetRow(txtHP, 2); classGrid.Children.Add(txtHP); //mp TextBlock txtMP = new TextBlock(); txtMP.Text = string.Format("Move: {0}/{1}", ship.MP.Current,ship.MP.Max); txtMP.Foreground = Brushes.White; Grid.SetColumn(txtMP, 1); Grid.SetRow(txtMP, 2); classGrid.Children.Add(txtMP); spSelectedEidos.Children.Add(classGrid); if(currentPlayer.Ships.Any(f=>f == ship)) { // Ship Orders Grid orderGrid = new Grid(); orderGrid.Width = spSelectedEidos.ActualWidth; orderGrid.VerticalAlignment = VerticalAlignment.Center; spSelectedEidos.Children.Add(orderGrid); ColumnDefinition columnOrder = new ColumnDefinition(); columnOrder.Width = new GridLength(1, GridUnitType.Star); orderGrid.ColumnDefinitions.Add(columnOrder); RowDefinition rowHeader = new RowDefinition(); rowHeader.Height = new GridLength(1, GridUnitType.Auto); orderGrid.RowDefinitions.Add(rowHeader); TextBlock txtOrders = new TextBlock(); txtOrders.Text = "Orders:"; txtOrders.FontSize = 16; txtOrders.Foreground = Brushes.CornflowerBlue; Grid.SetRow(txtOrders, 0); Grid.SetColumn(txtOrders, 0); orderGrid.Children.Add(txtOrders); if(ship.Orders.Count==0) { RowDefinition rowNoOrder = new RowDefinition(); rowNoOrder.Height = new GridLength(1, GridUnitType.Auto); orderGrid.RowDefinitions.Add(rowNoOrder); TextBlock txtNoOrders = new TextBlock(); txtNoOrders.Text = "No Orders"; txtNoOrders.Foreground = Brushes.CornflowerBlue; Grid.SetRow(txtNoOrders, 1); Grid.SetColumn(txtNoOrders, 0); orderGrid.Children.Add(txtNoOrders); } else for (int i = 0; i < ship.Orders.Count; i++) { ShipOrder order = ship.Orders[i]; RowDefinition rowOrder = new RowDefinition(); rowOrder.Height = new GridLength(1, GridUnitType.Auto); orderGrid.RowDefinitions.Add(rowOrder); Border borderOrder = new Border(); ContextMenu menu = new ContextMenu(); MenuItem menuRemoveOrder = new MenuItem(); menuRemoveOrder.Header = string.Format("Remove Order: {0}", order.ToString()); menuRemoveOrder.CommandParameter = new Tuple<Ship,ShipOrder>(ship,order); menuRemoveOrder.Click += menuRemoveOrder_Click; menu.Items.Add(menuRemoveOrder); borderOrder.ContextMenu = menu; TextBlock txtOrder = new TextBlock(); txtOrder.Text = order.ToString(); txtOrder.Foreground = Brushes.CornflowerBlue; borderOrder.Child = txtOrder; Grid.SetColumn(borderOrder, 0); Grid.SetRow(borderOrder, i + 1); orderGrid.Children.Add(borderOrder); } // Equipment Grid partGrid = new Grid(); partGrid.Width = spSelectedEidos.ActualWidth; partGrid.VerticalAlignment = VerticalAlignment.Center; spSelectedEidos.Children.Add(partGrid); ColumnDefinition columnParts = new ColumnDefinition(); columnParts.Width = new GridLength(1, GridUnitType.Star); partGrid.ColumnDefinitions.Add(columnParts); RowDefinition rowPartsHeader = new RowDefinition(); rowPartsHeader.Height = new GridLength(1, GridUnitType.Auto); partGrid.RowDefinitions.Add(rowPartsHeader); TextBlock txtParts = new TextBlock(); txtParts.Text = "Equipment:"; txtParts.FontSize = 16; txtParts.Foreground = Brushes.LightSlateGray; Grid.SetRow(txtParts, 0); Grid.SetColumn(txtParts, 0); partGrid.Children.Add(txtParts); for (int i = 0; i < ship.Parts.Count; i++) { ShipPart part = ship.Parts[i]; RowDefinition rowPart = new RowDefinition(); rowPart.Height = new GridLength(1, GridUnitType.Auto); partGrid.RowDefinitions.Add(rowPart); TextBlock txtPart = new TextBlock(); txtPart.Text = part.ToString(); txtPart.Foreground = (part.IsDestroyed ? Brushes.DarkRed : Brushes.LightSlateGray); Grid.SetColumn(txtPart, 0); Grid.SetRow(txtPart, i + 1); partGrid.Children.Add(txtPart); } } } catch (Exception ex) { if (LogEverything) Logger(ex); } }
public void onShipDestroyedHandler(object sender, EventArgs e, Ship shipDestroyed) { try { statusWindow.Items.Insert(0, string.Format("{0} is Destroyed!", shipDestroyed.Name)); AnimationQueue.Enqueue(() => { try { AddExplosionImage(shipDestroyed); } catch (Exception ex) { if (LogEverything) Logger(ex); } }); } catch (Exception ex) { if (LogEverything) Logger(ex); } }
public void RemoveExplosion(Action<Image, Ship> RemoveExplosionAction, Image explosionImage, Ship shipToExplode, int delay = 300) { try { var dispatcherTimer = new System.Windows.Threading.DispatcherTimer(System.Windows.Threading.DispatcherPriority.Render); EventHandler handler = null; handler = (sender, e) => { // Stop the timer so it won't keep executing every X seconds // and also avoid keeping the handler in memory. dispatcherTimer.Tick -= handler; dispatcherTimer.Stop(); // Perform the action. RemoveExplosionAction(explosionImage, shipToExplode); NextAnimation(); }; dispatcherTimer.Tick += handler; dispatcherTimer.Interval = TimeSpan.FromMilliseconds(delay); dispatcherTimer.Start(); } catch (Exception ex) { if (LogEverything) Logger(ex); } }