Beispiel #1
0
        // CharacterChoice is when selecting a character other lists and texts get filled in with info for selected character
        private void lbxCharacterChoice_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            SelectableCharacters selectedCharacter = lbxCharacterChoice.SelectedItem as SelectableCharacters;

            if (selectedCharacter != null)
            {
                tblkNo_Character_Selected.Text = $"The {selectedCharacter} class is currently selected.";
                // Displays abilities for the selected class
                lbxSkillList.ItemsSource  = selectedCharacter.Abilities;
                lbxSkillList1.ItemsSource = selectedCharacter.Abilities;
                // Displays the background story for selected character
                tblkCharacterInfoBackground.Text = string.Format($"{selectedCharacter.Details}");

                // Character Stats
                tblkHealth.Text = string.Format($"{selectedCharacter.Health}");
                tblkMana.Text   = string.Format($"{selectedCharacter.Mana}");
                tblkStr.Text    = string.Format($"{selectedCharacter.Strength}");
                tblkInt.Text    = string.Format($"{selectedCharacter.Inteligence}");
                tblkDex.Text    = string.Format($"{selectedCharacter.Dexterity}");

                // Tab 3
                tblk_t3_Health.Text      = string.Format($"{selectedCharacter.Health}");
                tblk_t3_Mana.Text        = string.Format($"{selectedCharacter.Mana}");
                tblk_t3_Strength.Text    = string.Format($"{selectedCharacter.Strength}");
                tblk_t3_Inteligence.Text = string.Format($"{selectedCharacter.Inteligence}");
                tblk_t3_Dexterity.Text   = string.Format($"{selectedCharacter.Dexterity}");

                tblk_ClassChosen.Text = string.Format($"{selectedCharacter}");

                // Image
                img_CharacterImage.Source = new BitmapImage(new Uri(selectedCharacter.CharacterImage, UriKind.Relative));
            }
        }
Beispiel #2
0
        private void btn_t3_SaveProfile_Click(object sender, RoutedEventArgs e)
        {
            SelectableCharacters selectedCharacter = lbxCharacterChoice.SelectedItem as SelectableCharacters;

            if (tbxName.Text != "" && selectedCharacter != null)
            {
                Character c = new Character()
                {
                    Name        = string.Format($"{tblk_CharacterName.Text}"),
                    Class       = string.Format($"{selectedCharacter}"),
                    Health      = selectedCharacter.Health,
                    Mana        = selectedCharacter.Mana,
                    Strength    = selectedCharacter.Strength,
                    Inteligence = selectedCharacter.Inteligence,
                    Dexterity   = selectedCharacter.Dexterity
                };

                try
                {
                    string data = JsonConvert.SerializeObject(c, Formatting.Indented);
                    using (StreamWriter sw = new StreamWriter("c:\\tempFolder\\Charactersheet.json"))
                    {
                        sw.Write(data);
                        sw.Close();
                    }
                    string message = "Character Information has been save to Json";
                    MessageBox.Show(message);
                }
                catch
                {
                    string message = "Path Not Found Exception. File Not Saved to Json";
                    MessageBox.Show(message);
                }
                try
                {
                    db.Characters.Add(c);
                    db.SaveChanges();
                    string message = "Character Information has been saved to Database";
                    MessageBox.Show(message);
                }
                catch
                {
                    string message = "Database Not Found Exception. File Not Saved to Database";
                    MessageBox.Show(message);
                }
            }
            else
            {
                string message = "No Character/Name Chosen";
                MessageBox.Show(message);
            }
        }