Esempio n. 1
0
        /// <summary>
        /// Saves the enemy's information.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AcceptEnemy_Click(object sender, RoutedEventArgs e)
        {
            string errorMessage = null;
            string previewImage = "";

            PreviewImageWindowEnemy previewWindow = null;

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

                if (String.IsNullOrEmpty(imageMovingUp) || String.IsNullOrEmpty(imageMovingDown) || String.IsNullOrEmpty(imageMovingLeft) || String.IsNullOrEmpty(imageMovingRight))
                {
                    errorMessage = "You have to select all the moving animation images.";
                    throw new NullReferenceException();
                }

                if (frameCount == 0)
                {
                    errorMessage = "You have to input the number of frames for the moving animation.";
                    throw new NullReferenceException();
                }

                if (String.IsNullOrEmpty(initialState))
                {
                    errorMessage = "You have to select the initial direction of the character.";
                    throw new NullReferenceException();
                }

                if (String.IsNullOrEmpty(behavoir))
                {
                    errorMessage = "You have to select the IA behavoir of the enemy.";
                    throw new NullReferenceException();
                }

                if (behavoir == "patrolling" && patrolZone == 0)
                {
                    errorMessage = "You have to input a number for the patrol zone.";
                    throw new NullReferenceException();
                }

                if (String.IsNullOrEmpty(preference))
                {
                    errorMessage = "You have to select the IA preference of the enemy.";
                    throw new NullReferenceException();
                }

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

                if (detectZone == 0)
                {
                    errorMessage = "You have to input a number for the detection zone.";
                    throw new NullReferenceException();
                }

                if ((bool)CanShoot.IsChecked)
                {
                    if (String.IsNullOrEmpty(imageArrowUp) || String.IsNullOrEmpty(imageArrowDown) || String.IsNullOrEmpty(imageArrowLeft) || String.IsNullOrEmpty(imageArrowRight))
                    {
                        errorMessage = "You have to select all the arrow images.";
                        throw new NullReferenceException();
                    }
                }
                else
                {
                    imageArrowUp = null;
                    imageArrowDown = null;
                    imageArrowLeft = null;
                    imageArrowRight = null;
                }

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

                if (manager.CheckIfNumber(name))
                {
                    errorMessage = "The name cannot be only numbers.";
                    throw new Exception();
                }

                if (edit)
                {
                    previewWindow = new PreviewImageWindowEnemy(enemy, edit);
                    previewWindow.ShowDialog();

                    previewImage = enemy.PreviewImage;

                    manager.Enemies.Remove(enemy);
                }
                if (manager.NameRepeated(name))
                {
                    errorMessage = "This name already exits";
                    throw new NullReferenceException();
                }

                Enemy auxEnemy = new Enemy(name, strenght, intelligence, dexterity, hitPoints, imageMovingUp,
                                                imageMovingDown, imageMovingLeft, imageMovingRight, frameCount, imageArrowUp,
                                                imageArrowDown, imageArrowLeft, imageArrowRight, loot, behavoir, preference,
                                                boss, initialState, patrolZone, detectZone, speed);

                if (edit)
                {
                    auxEnemy.PreviewImage = previewImage;
                }
                else
                {
                    previewWindow = new PreviewImageWindowEnemy(auxEnemy, edit);
                    previewWindow.ShowDialog();
                }

                if (auxEnemy.PreviewImage == null)
                {
                    errorMessage = "You have to select a preview image.";
                    throw new NullReferenceException();
                }
                else
                {
                    manager.Enemies.Add(auxEnemy);
                    manager.Enemies.OrderBy(x => x.Name);
                }

                this.Close();
            }
            catch (Exception)
            {
                MessageBox.Show(errorMessage, "Attention", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Saves the enemy's information.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AcceptEnemy_Click(object sender, RoutedEventArgs e)
        {
            string errorMessage = null;
            string previewImage = "";

            PreviewImageWindowEnemy previewWindow = null;

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

                if (String.IsNullOrEmpty(imageMovingUp) || String.IsNullOrEmpty(imageMovingDown) || String.IsNullOrEmpty(imageMovingLeft) || String.IsNullOrEmpty(imageMovingRight))
                {
                    errorMessage = "You have to select all the moving animation images.";
                    throw new NullReferenceException();
                }

                if (frameCount == 0)
                {
                    errorMessage = "You have to input the number of frames for the moving animation.";
                    throw new NullReferenceException();
                }

                if (String.IsNullOrEmpty(initialState))
                {
                    errorMessage = "You have to select the initial direction of the character.";
                    throw new NullReferenceException();
                }

                if (String.IsNullOrEmpty(behavoir))
                {
                    errorMessage = "You have to select the IA behavoir of the enemy.";
                    throw new NullReferenceException();
                }

                if (behavoir == "patrolling" && patrolZone == 0)
                {
                    errorMessage = "You have to input a number for the patrol zone.";
                    throw new NullReferenceException();
                }

                if (String.IsNullOrEmpty(preference))
                {
                    errorMessage = "You have to select the IA preference of the enemy.";
                    throw new NullReferenceException();
                }

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

                if (detectZone == 0)
                {
                    errorMessage = "You have to input a number for the detection zone.";
                    throw new NullReferenceException();
                }

                if ((bool)CanShoot.IsChecked)
                {
                    if (String.IsNullOrEmpty(imageArrowUp) || String.IsNullOrEmpty(imageArrowDown) || String.IsNullOrEmpty(imageArrowLeft) || String.IsNullOrEmpty(imageArrowRight))
                    {
                        errorMessage = "You have to select all the arrow images.";
                        throw new NullReferenceException();
                    }
                }
                else
                {
                    imageArrowUp    = null;
                    imageArrowDown  = null;
                    imageArrowLeft  = null;
                    imageArrowRight = null;
                }

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

                if (manager.CheckIfNumber(name))
                {
                    errorMessage = "The name cannot be only numbers.";
                    throw new Exception();
                }

                if (edit)
                {
                    previewWindow = new PreviewImageWindowEnemy(enemy, edit);
                    previewWindow.ShowDialog();

                    previewImage = enemy.PreviewImage;

                    manager.Enemies.Remove(enemy);
                }
                if (manager.NameRepeated(name))
                {
                    errorMessage = "This name already exits";
                    throw new NullReferenceException();
                }

                Enemy auxEnemy = new Enemy(name, strenght, intelligence, dexterity, hitPoints, imageMovingUp,
                                           imageMovingDown, imageMovingLeft, imageMovingRight, frameCount, imageArrowUp,
                                           imageArrowDown, imageArrowLeft, imageArrowRight, loot, behavoir, preference,
                                           boss, initialState, patrolZone, detectZone, speed);

                if (edit)
                {
                    auxEnemy.PreviewImage = previewImage;
                }
                else
                {
                    previewWindow = new PreviewImageWindowEnemy(auxEnemy, edit);
                    previewWindow.ShowDialog();
                }

                if (auxEnemy.PreviewImage == null)
                {
                    errorMessage = "You have to select a preview image.";
                    throw new NullReferenceException();
                }
                else
                {
                    manager.Enemies.Add(auxEnemy);
                    manager.Enemies.OrderBy(x => x.Name);
                }

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