Esempio n. 1
0
        private void DeleteButton_Click(object sender, EventArgs e)
        {
            ItemsList.RemoveAt(ItemsListBox.SelectedIndex);
            ListBind.DataSource = null;
            ListBind.DataSource = ItemsList;

            NameBox.Clear();
            TypeBox.Clear();
            DescriptionBox.Clear();
            MightBox.Clear();
            DefenceBox.Clear();
            WeightBox.Clear();
            ItemWeightBox.Clear();
            PropertiesBox.Clear();

            foreach (int i in RequirementsCheckedListBox.CheckedIndices)
            {
                RequirementsCheckedListBox.SetItemChecked(i, false);
            }
        }
Esempio n. 2
0
        private void SaveHero_Button(object sender, RoutedEventArgs e)
        {
            var currentHero = (Hero)DataContext;

            stsBarTextBlock.Foreground = new SolidColorBrush(Colors.MediumVioletRed);
            if (HeroNameBox.Text == null || HeroNameBox.Text.Length < 3 || HeroNameBox.Text.Length > 60)
            {
                stsBarTextBlock.Text = "Hero name length allowed: 3-60!";
                HeroNameBox.Focus();
                HeroNameBox.SelectAll();
                return;
            }
            if (GoldBox.Text == null || GoldBox.Text == "" || decimal.Parse(GoldBox.Text) < 0)
            {
                stsBarTextBlock.Text = "Gold cannot be negative or null!";
                GoldBox.Focus();
                GoldBox.SelectAll();
                return;
            }
            if (HpBox.Text == null || HpBox.Text == "" || double.Parse(HpBox.Text) < 0)
            {
                stsBarTextBlock.Text = "Hp cannot be negative or null!";
                HpBox.Focus();
                HpBox.SelectAll();
                return;
            }
            if (ManaBox.Text == null || ManaBox.Text == "" || double.Parse(ManaBox.Text) < 0)
            {
                stsBarTextBlock.Text = "Mana cannot be negative or null!";
                ManaBox.Focus();
                ManaBox.SelectAll();
                return;
            }
            if (DefenceBox.Text == null || DefenceBox.Text == "" || double.Parse(DefenceBox.Text) < 0)
            {
                stsBarTextBlock.Text = "Defence cannot be negative or null!";
                DefenceBox.Focus();
                DefenceBox.SelectAll();
                return;
            }
            if (AttackPowerBox.Text == null || AttackPowerBox.Text == "" || double.Parse(AttackPowerBox.Text) < 0)
            {
                stsBarTextBlock.Text = "AttackPower cannot be negative or null!";
                AttackPowerBox.Focus();
                AttackPowerBox.SelectAll();
                return;
            }

            var hero = context.Heroes.FirstOrDefault(h => h.Id == currentHero.Id);

            hero.Name                  = HeroNameBox.Text;
            hero.Gold                  = decimal.Parse(GoldBox.Text);
            hero.HeroStats.Hp          = double.Parse(HpBox.Text);
            hero.HeroStats.Mana        = double.Parse(ManaBox.Text);
            hero.HeroStats.Defence     = double.Parse(DefenceBox.Text);
            hero.HeroStats.AttackPower = double.Parse(AttackPowerBox.Text);


            context.SaveChanges();
            stsBarTextBlock.Foreground = new SolidColorBrush(Colors.Green);
            stsBarTextBlock.Text       = "Success!";
        }
Esempio n. 3
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            string        name, type, description;
            int           weight, might, defence, carryweight;
            List <string> requirements = new List <string>();
            List <string> properties;
            List <Tuple <string, int> > bonus = new List <Tuple <string, int> >();

            if (NameBox.Text == "")
            {
                MessageBox.Show("Puste pole na imię!");
                return;
            }
            else
            {
                name = NameBox.Text;
            }

            if (TypeBox.Text == "")
            {
                MessageBox.Show("Puste pole określające typ przedmiotu!");
                return;
            }
            else
            {
                type = TypeBox.Text;
            }

            if (DescriptionBox.Text == "")
            {
                MessageBox.Show("Puste pole opisu!");
                return;
            }
            else
            {
                description = DescriptionBox.Text;
            }

            int.TryParse(ItemWeightBox.Text, out weight);
            if (weight == 0)
            {
                MessageBox.Show("Błąd w polu określającym wagę przedmiotu!");
                return;
            }

            bool might_result       = int.TryParse(MightBox.Text, out might);
            bool defence_result     = int.TryParse(DefenceBox.Text, out defence);
            bool carryweight_result = int.TryParse(WeightBox.Text, out carryweight);

            if (!might_result || !defence_result || !carryweight_result)
            {
                MessageBox.Show("Błąd w polach określających bonusy!");
                return;
            }
            else
            {
                Tuple <string, int> MightTuple       = new Tuple <string, int>("Might", might);
                Tuple <string, int> DefenceTuple     = new Tuple <string, int>("Defence", defence);
                Tuple <string, int> CarryWeightTuple = new Tuple <string, int>("CarryWeight", carryweight);
                bonus.Add(MightTuple);
                bonus.Add(DefenceTuple);
                bonus.Add(CarryWeightTuple);
            }

            if (RequirementsCheckedListBox.CheckedItems.Count == 0)
            {
                requirements.Add("Any");
            }
            else
            {
                foreach (object item in RequirementsCheckedListBox.CheckedItems)
                {
                    requirements.Add(item.ToString());
                }
            }

            properties = new List <string>(PropertiesBox.Lines);

            Item New_Item = new Item(name, type, description, requirements, bonus, properties, weight);

            ItemsList.Add(New_Item);
            ListBind.DataSource = null;
            ListBind.DataSource = ItemsList;

            NameBox.Clear();
            TypeBox.Clear();
            DescriptionBox.Clear();
            MightBox.Clear();
            DefenceBox.Clear();
            WeightBox.Clear();
            ItemWeightBox.Clear();
            PropertiesBox.Clear();

            foreach (int i in RequirementsCheckedListBox.CheckedIndices)
            {
                RequirementsCheckedListBox.SetItemChecked(i, false);
            }
        }
Esempio n. 4
0
        private void SaveHero_Button(object sender, RoutedEventArgs e)
        {
            stsBarTextBlock.Foreground = new SolidColorBrush(Colors.MediumVioletRed);
            if (HeroNameBox.Text == null || HeroNameBox.Text.Length < 3 || HeroNameBox.Text.Length > 60)
            {
                stsBarTextBlock.Text = "Hero name length allowed: 3-60!";
                HeroNameBox.Focus();
                HeroNameBox.SelectAll();
                return;
            }
            if (GoldBox.Text == null || GoldBox.Text == "" || decimal.Parse(GoldBox.Text) < 0)
            {
                stsBarTextBlock.Text = "Gold cannot be negative or null!";
                GoldBox.Focus();
                GoldBox.SelectAll();
                return;
            }
            if (HpBox.Text == null || HpBox.Text == "" || double.Parse(HpBox.Text) < 0)
            {
                stsBarTextBlock.Text = "Hp cannot be negative or null!";
                HpBox.Focus();
                HpBox.SelectAll();
                return;
            }
            if (ManaBox.Text == null || ManaBox.Text == "" || double.Parse(ManaBox.Text) < 0)
            {
                stsBarTextBlock.Text = "Mana cannot be negative or null!";
                ManaBox.Focus();
                ManaBox.SelectAll();
                return;
            }
            if (DefenceBox.Text == null || DefenceBox.Text == "" || double.Parse(DefenceBox.Text) < 0)
            {
                stsBarTextBlock.Text = "Defence cannot be negative or null!";
                DefenceBox.Focus();
                DefenceBox.SelectAll();
                return;
            }
            if (AttackPowerBox.Text == null || AttackPowerBox.Text == "" || double.Parse(AttackPowerBox.Text) < 0)
            {
                stsBarTextBlock.Text = "AttackPower cannot be negative or null!";
                AttackPowerBox.Focus();
                AttackPowerBox.SelectAll();
                return;
            }

            var user = AuthenticationService.GetCurrentUser();

            var newHero = new Hero()
            {
                Name   = HeroNameBox.Text,
                Gold   = decimal.Parse(GoldBox.Text),
                UserId = user.Id
            };

            var newHeroStats = new HeroStats()
            {
                Hero        = newHero,
                Hp          = double.Parse(HpBox.Text),
                Mana        = double.Parse(ManaBox.Text),
                Defence     = double.Parse(DefenceBox.Text),
                AttackPower = double.Parse(AttackPowerBox.Text)
            };

            newHero.HeroStats = newHeroStats;

            context.Heroes.Add(newHero);
            context.HeroStatistics.Add(newHeroStats);
            context.SaveChanges();
            stsBarTextBlock.Foreground = new SolidColorBrush(Colors.Green);
            stsBarTextBlock.Text       = "Success!";
        }