/// <summary> /// Initializes a new instance of the RollDiceViewModel class. /// </summary> public CombatViewModel() { CombatRound round = new CombatRound(); if (IsInDesignMode) { // Code runs in Blend --> create design time data. for (int i = 0; i < 2; i++) { CombatForce combatForce = round.AddCombatForce("Combat Force " + i); for (int x = 0; x < 2; x++) { Unit unit = new Unit(); unit.CombatForce = combatForce; unit.Name = "Unit " + x; unit.TypeOfUnit = UnitType.Both; unit.Health = 6.0; unit.AttackPower = 6.0; combatForce.AddUnit(unit); } } } else { // Code runs "for real" ReloadUnitStats(); } RoundsOfCombat.Add(round); }
private void unitStatisticsChildWindow_unitListbox_AddAbove_Click(object sender, RoutedEventArgs e) { Unit newUnit = new Unit(); newUnit.Name = unitNameTextBox.Text; if (string.IsNullOrWhiteSpace(unitHealthTextBox.Text)) newUnit.Health = 0.0; else newUnit.Health = Convert.ToInt32(unitHealthTextBox.Text); if (string.IsNullOrWhiteSpace(unitHealthTextBox.Text)) newUnit.AttackPower = 0.0; else newUnit.AttackPower = Convert.ToInt32(unitAttackTextBox.Text); if (unitDetectedCheckBox.IsChecked.HasValue) newUnit.Detected = unitDetectedCheckBox.IsChecked.Value; else newUnit.Detected = false; if (unitIsCommandAndControlCheckBox.IsChecked.HasValue) newUnit.IsCommandAndControl = unitIsCommandAndControlCheckBox.IsChecked.Value; else newUnit.IsCommandAndControl = false; Button originalSource = (Button)e.OriginalSource; ViewModel.AddAbove((Unit)originalSource.DataContext, newUnit); }
public void RemoveUnit(Unit unit) { UnitStatistics.Units.Remove(unit); }
public void AddAbove(Unit unit, Unit unitToAdd) { int index = UnitStatistics.Units.IndexOf(unit); UnitStatistics.Units.Insert(index, unitToAdd); }
public Unit(Unit otherUnit) { TypeOfUnit = otherUnit.TypeOfUnit; Name = otherUnit.Name; Health = otherUnit.Health; AttackPower = otherUnit.AttackPower; IsCommandAndControl = otherUnit.IsCommandAndControl; Cost = otherUnit.Cost; BuildRate = otherUnit.BuildRate; NumberBuildAtATime = otherUnit.NumberBuildAtATime; SkipAttack = otherUnit.SkipAttack; Detected = otherUnit.Detected; Invulnerable = otherUnit.Invulnerable; CombatForce = otherUnit.CombatForce; }
private void SubmitUnitButton_Clicked(object sender, RoutedEventArgs e) { Debug.WriteLine("Submit Unit Button Clicked"); if (string.IsNullOrWhiteSpace(nameTextBox_addUnit_childWindow.Text) || string.IsNullOrWhiteSpace(healthTextBox_addUnit_childWindow.Text) || string.IsNullOrWhiteSpace(attackValueTextBox_addUnit_childWindow.Text)) { return; } // Parse the Data out of the UI Elements string name = nameTextBox_addUnit_childWindow.Text; double health = 0.0; if (!double.TryParse(healthTextBox_addUnit_childWindow.Text, out health)) return; double attackPower = 0.0; if (!double.TryParse(attackValueTextBox_addUnit_childWindow.Text, out attackPower)) return; int quantityOfUnits = 1; if (!int.TryParse(quantityOfUnits_addUnit_childWindow.Text, out quantityOfUnits)) quantityOfUnits = 1; quantityOfUnits_addUnit_childWindow.Text = "1"; // Populate the CombatForce Unit comboBoxSelectedUnit = presetComboBox_addUnit_childWindow.SelectedItem as Unit; for (int i = 0; i < quantityOfUnits; i++) { Unit unit = new Unit(); unit.Name = name; unit.Health = health; unit.AttackPower = attackPower; if (commandAndControlCheckBox_addUnit_childWindow.IsChecked.HasValue) unit.IsCommandAndControl = commandAndControlCheckBox_addUnit_childWindow.IsChecked.Value; else unit.IsCommandAndControl = false; if (detectedCheckBox_addUnit_childWindow.IsChecked.HasValue) unit.Detected = detectedCheckBox_addUnit_childWindow.IsChecked.Value; else unit.Detected = false; try { if (typeOfUnitComboBox_addUnit_childWindow.SelectedIndex < 0 || typeOfUnitComboBox_addUnit_childWindow.SelectedIndex > 2) unit.TypeOfUnit = UnitType.Both; else unit.TypeOfUnit = (UnitType)typeOfUnitComboBox_addUnit_childWindow.SelectedIndex; } catch (Exception) { unit.TypeOfUnit = UnitType.Both; } addUnitCombatForce.AddUnit(unit); } // Reset and Close presetComboBox_addUnit_childWindow.SelectedIndex = 0; addUnitCombatForce = null; addUnitChildWindow.Close(); }