Exemplo n.º 1
0
        public AbilityWindow(MainWindowManager manager, bool edit, Ability ability)
        {
            InitializeComponent();

            this.manager = manager;
            openFileManager = new OpenFileManager();
            this.edit = edit;
            this.ability = ability;

            if (edit)
            {
                SetValues();
            }

            InitializeValues();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Saves the information of the ability.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AcceptAbility_Click(object sender, RoutedEventArgs e)
        {
            string errorMessage = null;

            try
            {
                if (String.IsNullOrEmpty(name))
                {
                    errorMessage = "You have to input a name.";
                    throw new NullReferenceException();
                }

                if (String.IsNullOrEmpty(imageAbility))
                {
                    errorMessage = "You have to select an image for the ability.";
                    throw new NullReferenceException();
                }

                if (effect == 0)
                {
                    errorMessage = "The effect/damage for the ability must be higher than 0.";
                    throw new NullReferenceException();
                }

                if (String.IsNullOrEmpty(type))
                {
                    errorMessage = "You have to select the ability type.";
                    throw new NullReferenceException();
                }

                if (String.IsNullOrEmpty(affect) && type == "augmentation")
                {
                    errorMessage = "You have to select the characteristic the ability is going to affect.";
                    throw new NullReferenceException();
                }

                if (duration == 0 && type == "augmentation")
                {
                    errorMessage = "You have to input the duration for the ability.";
                    throw new NullReferenceException();
                }

                if (type == "attack")
                {
                    if (imageAttackUp == null || imageAttackDown == null || imageAttackLeft == null || imageAttackRight == null)
                    {
                        errorMessage = "You have to select all the attack images.";
                        throw new NullReferenceException();
                    }

                    if (speed == null)
                    {
                        errorMessage = "You have to select the speed of the ability.";
                        throw new NullReferenceException();
                    }
                }
                else
                {
                    imageAttackUp = null;
                    imageAttackDown = null;
                    imageAttackLeft = null;
                    imageAttackRight = null;
                    speed = null;
                }

                name = name.Replace(" ", "_");

                if (edit)
                {
                    manager.Abilities.Remove(ability);
                }
                if (manager.NameRepeated(name))
                {
                    errorMessage = "This name already exists";
                    throw new NullReferenceException();
                }

                Ability auxAbility = new Ability(name, type, effect, mana, imageAbility,
                                                    imageAttackUp, imageAttackDown,
                                                    imageAttackLeft, imageAttackRight, affect, duration, speed);

                manager.Abilities.Add(auxAbility);
                manager.Abilities.OrderBy(x => x.Name);

                this.Close();
            }
            catch (NullReferenceException)
            {
                MessageBox.Show(errorMessage, "Attention", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }