private void Submit_ButtonClick(object sender, RoutedEventArgs e) { bool isNumeric = int.TryParse(tbHealthField.Text, out int health); if (String.IsNullOrWhiteSpace(tbNameField.Text) || String.IsNullOrWhiteSpace(tbHealthField.Text) || !isNumeric) { tb_SubmitErrorMessage.Text = "Please make sure that all entered values are valid"; } else { string name = tbNameField.Text; DamageType type = (DamageType)cbTypeList_window.SelectedItem; int targetId; CharacterAccount target; if (cbTargetType.SelectedIndex == 0) { targetId = GameContainer.AddEnvironmentTarget(name, health, type); target = GameContainer.ActiveGame.AllTargets[targetId]; MainWindow.EnvironmentTargets.Add(target); } else { targetId = GameContainer.AddVillainTarget(name, health, type); target = GameContainer.ActiveGame.AllTargets[targetId]; MainWindow.VillainTargets.Add(target); } MainWindow.AllTargets.Add(target); MainWindow.NonHeroTargets.Add(target); if (MainWindow.NonHeroTargets.Count == 1) { MainWindow.lbNonHeroTargets.SelectedIndex = 0; } this.Close(); } }