Example #1
0
 public Character(string name, int strenght, int intelligence, int dexterity, int hitPoints, int mana, string imageMovingUp,
                 string imageMovingDown, string imageMovingLeft, string imageMovingRight, string imageAttackingUp,
                 string imageAttackingDown, string imageAttackingLeft, string imageAttackingRight, Weapon melee, Weapon distance,
                 int frameCount, int frameAttackingCount, string attackSoundEffect, string shootSoundEffect,
                 string castSoundEffect, string initialState, string speed)
 {
     this.Name = name;
     this.Strenght = strenght;
     this.Intelligence = intelligence;
     this.Dexterity = dexterity;
     this.HitPoints = hitPoints;
     this.Mana = mana;
     this.ImageMovingUp = imageMovingUp;
     this.ImageMovingDown = imageMovingDown;
     this.ImageMovingLeft = imageMovingLeft;
     this.ImageMovingRight = imageMovingRight;
     this.ImageAttackingUp = imageAttackingUp;
     this.ImageAttackingDown = imageAttackingDown;
     this.ImageAttackingLeft = imageAttackingLeft;
     this.ImageAttackingRight = imageAttackingRight;
     this.FrameCount = frameCount;
     this.FrameAttackingCount = frameAttackingCount;
     this.AttackSoundEffect = attackSoundEffect;
     this.ShootSoundEffect = shootSoundEffect;
     this.CastSoundEffect = castSoundEffect;
     this.Melee = melee;
     this.Distance = distance;
     this.InitialState = initialState;
     this.Speed = speed;
 }
        public WeaponWindow(MainWindowManager manager, bool edit, Weapon weapon)
        {
            InitializeComponent();

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

            if (edit)
            {
                SetValues();
            }

            InitializeValues();
        }
Example #3
0
        /// <summary>
        /// Inserts the selected element in the stage.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CanvasGame_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            string errorMessage = "An error ocurred when introducing the element.";

            try
            {
                if (currentID < 0)
                {
                    throw new NullReferenceException();
                }

                if (textureSelected != null)
                {
                    if (textureSelected.Uid == "Eraser")
                    {
                        CanvasGame_MouseRightButtonDown(sender, e);
                    }

                    textureCanvas = new Image();

                    textureCanvas.Source = textureSelected.Source;
                    textureCanvas.Width = textureSelected.Width;
                    textureCanvas.Height = textureSelected.Height;
                    textureCanvas.Uid = textureSelected.Uid;
                    textureCanvas.Name = textureSelected.Name;

                    Point pos = Mouse.GetPosition(CanvasGame);

                    pos.X -= textureCanvas.Width;
                    pos.Y -= textureCanvas.Height;

                    if (pos.X  < 0)
                    {
                        pos.X = 0;
                    }

                    if (pos.Y < 0)
                    {
                        pos.Y = 0;
                    }

                    //if ((pos.X + textureCanvas.Width) > 640)
                    //{
                    //    pos.X = 640 - textureCanvas.Width;
                    //}

                    //if ((pos.Y + textureCanvas.Height) > 380)
                    //{
                    //    pos.Y = 380 - textureCanvas.Height;
                    //}

                    pos.X = Math.Round(pos.X, 2);
                    pos.Y = Math.Round(pos.Y, 2);

                    Stage currentStage = manager.GetStage(currentID);

                    if (textureCanvas.Uid == "Character")
                    {
                        if (manager.Player.IsSet == true)
                        {
                            errorMessage = "The main character is already set.";
                            throw new Exception();
                        }

                        CanvasGame.Children.Add(textureCanvas);

                        Canvas.SetLeft(textureCanvas, pos.X);
                        Canvas.SetTop(textureCanvas, pos.Y);

                        currentStage.Player = manager.Player;

                        currentStage.Player.PositionX = (int)pos.X;
                        currentStage.Player.PositionY = (int)pos.Y;
                        currentStage.Player.CurrentImage = textureCanvas;

                        manager.Player.IsSet = true;
                    }
                    else if (textureCanvas.Uid == "Consumable")
                    {
                        CanvasGame.Children.Add(textureCanvas);

                        Canvas.SetLeft(textureCanvas, pos.X);
                        Canvas.SetTop(textureCanvas, pos.Y);

                        Consumable consumableStage = manager.GetConsumable(textureCanvas.Name);
                        Consumable newConsumable = new Consumable(consumableStage.Name, consumableStage.Type, consumableStage.Effect, consumableStage.Image);

                        newConsumable.PositionX = (int)pos.X;
                        newConsumable.PositionY = (int)pos.Y;
                        newConsumable.CurrentImage = textureCanvas;

                        currentStage.Consumables.Add(newConsumable);
                    }
                    else if (textureCanvas.Uid == "Weapon")
                    {
                        CanvasGame.Children.Add(textureCanvas);

                        Canvas.SetLeft(textureCanvas, pos.X);
                        Canvas.SetTop(textureCanvas, pos.Y);

                        Weapon weaponStage = manager.GetWeapon(textureCanvas.Name);
                        Weapon newWeapon = new Weapon(weaponStage.Name, weaponStage.Type, weaponStage.Damage, weaponStage.Speed, weaponStage.ImageWeapon,
                            weaponStage.ImageArrowUp, weaponStage.ImageArrowDown, weaponStage.ImageArrowLeft, weaponStage.ImageArrowRight);

                        newWeapon.PositionX = (int)pos.X;
                        newWeapon.PositionY = (int)pos.Y;
                        newWeapon.CurrentImage = textureCanvas;

                        currentStage.Weapons.Add(newWeapon);
                    }
                    else if (textureCanvas.Uid == "Enemy")
                    {
                        CanvasGame.Children.Add(textureCanvas);

                        Canvas.SetLeft(textureCanvas, pos.X);
                        Canvas.SetTop(textureCanvas, pos.Y);

                        Enemy enemyStage = manager.GetEnemy(textureCanvas.Name);
                        Enemy newEnemy = new Enemy(enemyStage.Name, enemyStage.Strenght, enemyStage.Intelligence, enemyStage.Dexterity, enemyStage.HitPoints,
                            enemyStage.ImageMovingUp, enemyStage.ImageMovingDown, enemyStage.ImageMovingLeft, enemyStage.ImageMovingRight, enemyStage.FrameCount,
                            enemyStage.ImageArrowUp, enemyStage.ImageArrowDown, enemyStage.ImageArrowLeft, enemyStage.ImageArrowRight, enemyStage.Loot,
                            enemyStage.Behavoir, enemyStage.Preference, enemyStage.Boss, enemyStage.InitialState, enemyStage.PatrolZone, enemyStage.DetectZone,
                            enemyStage.Speed);

                        newEnemy.PositionX = (int)pos.X;
                        newEnemy.PositionY = (int)pos.Y;
                        newEnemy.CurrentImage = textureCanvas;

                        currentStage.Enemies.Add(newEnemy);
                    }
                    else if (textureCanvas.Uid == "NPC")
                    {
                        CanvasGame.Children.Add(textureCanvas);

                        Canvas.SetLeft(textureCanvas, pos.X);
                        Canvas.SetTop(textureCanvas, pos.Y);

                        NPC npcStage = manager.GetNPC(textureCanvas.Name);
                        NPC newNPC = new NPC(npcStage.Name, npcStage.Image, npcStage.DialogImage);

                        newNPC.PositionX = (int)pos.X;
                        newNPC.PositionY = (int)pos.Y;
                        newNPC.CurrentImage = textureCanvas;

                        currentStage.NonPlayers.Add(newNPC);
                    }
                    else if (textureCanvas.Uid == "Wall")
                    {
                        CanvasGame.Children.Add(textureCanvas);

                        Canvas.SetLeft(textureCanvas, pos.X);
                        Canvas.SetTop(textureCanvas, pos.Y);

                        BackgroundItem wallStage = manager.GetBgItem(textureCanvas.Name);
                        BackgroundItem newWall = new BackgroundItem(wallStage.Name, wallStage.Solid, wallStage.BulletProof, wallStage.Image);

                        newWall.PositionX = (int)pos.X;
                        newWall.PositionY = (int)pos.Y;
                        newWall.CurrentImage = textureCanvas;

                        currentStage.BgItems.Add(newWall);
                    }
                    else if (textureCanvas.Uid == "Key")
                    {
                        CanvasGame.Children.Add(textureCanvas);

                        Canvas.SetLeft(textureCanvas, pos.X);
                        Canvas.SetTop(textureCanvas, pos.Y);

                        KeyItem keyStage = manager.GetKey(textureCanvas.Name);
                        KeyItem newKey = new KeyItem(keyStage.Name, keyStage.Image, keyStage.ID);

                        newKey.PositionX = (int)pos.X;
                        newKey.PositionY = (int)pos.Y;
                        newKey.CurrentImage = textureCanvas;

                        currentStage.Keys.Add(newKey);
                    }
                    else if (textureCanvas.Uid == "Door")
                    {
                        CanvasGame.Children.Add(textureCanvas);

                        Canvas.SetLeft(textureCanvas, pos.X);
                        Canvas.SetTop(textureCanvas, pos.Y);

                        Door doorStage = manager.GetDoor(textureCanvas.Name);
                        Door newDoor = new Door(doorStage.Name, doorStage.Image, doorStage.ID);

                        newDoor.PositionX = (int)pos.X;
                        newDoor.PositionY = (int)pos.Y;
                        newDoor.CurrentImage = textureCanvas;

                        currentStage.Doors.Add(newDoor);
                    }
                }
            }
            catch(NullReferenceException)
            {
                MessageBox.Show("You have to create a stage first.", "Attention", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            catch (Exception)
            {
                MessageBox.Show(errorMessage, "Attention", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        /// <summary>
        /// Saves the character's information.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AcceptCharacter_Click(object sender, RoutedEventArgs e)
        {
            string errorMessage = null;
            bool isAlreadySet = false;
            string previewImage = "";

            PreviewImageWindowCharacter 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(speed))
                {
                    errorMessage = "You have to select the speed of the character.";
                    throw new NullReferenceException();
                }

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

                if ((bool)CanMelee.IsChecked)
                {
                    if (String.IsNullOrEmpty(imageAttackingUp) || String.IsNullOrEmpty(initialState) || String.IsNullOrEmpty(initialState) || String.IsNullOrEmpty(initialState))
                    {
                        errorMessage = "You have to select all the attacking animation images.";
                        throw new NullReferenceException();
                    }

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

                    if (melee == null)
                    {
                        errorMessage = "You have to select an initial melee weapon.";
                        throw new NullReferenceException();
                    }
                }
                else
                {
                    imageAttackingUp = null;
                    imageAttackingDown = null;
                    imageAttackingLeft = null;
                    imageAttackingRight = null;
                    frameAttackingCount = 0;
                    melee = null;
                    attackSoundEffect = null;
                }

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

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

                if (edit)
                {
                    previewWindow = new PreviewImageWindowCharacter(manager.Player, edit);
                    previewWindow.ShowDialog();

                    previewImage = manager.Player.PreviewImage;

                    isAlreadySet = manager.Player.IsSet;
                    manager.Player = null;
                }
                if (manager.NameRepeated(name))
                {
                    errorMessage = "This name already exits";
                    throw new NullReferenceException();
                }

                manager.Player = new Character(name, strenght, intelligence, dexterity, hitPoints, mana, imageMovingUp,
                                                 imageMovingDown, imageMovingLeft, imageMovingRight, imageAttackingUp,
                                                 imageAttackingDown, imageAttackingLeft, imageAttackingRight, melee, distance,
                                                 frameCount, frameAttackingCount, attackSoundEffect, shootSoundEffect,
                                                 castSoundEffect, initialState, speed);

                manager.Player.IsSet = isAlreadySet;

                if (edit)
                {
                    manager.Player.PreviewImage = previewImage;
                }
                else
                {
                    previewWindow = new PreviewImageWindowCharacter(manager.Player, edit);
                    previewWindow.ShowDialog();
                }

                if (manager.Player.PreviewImage == null)
                {
                    manager.Player = null;
                    errorMessage = "You have to select a preview image.";
                    throw new NullReferenceException();
                }

                this.Close();
            }
            catch (Exception)
            {
                MessageBox.Show(errorMessage, "Attention", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        /// <summary>
        /// Sets the values to their actual state if the character is being edited.
        /// </summary>
        private void SetValues()
        {
            CharacterNameTextBox.Text = manager.Player.Name;
            name = manager.Player.Name;

            StrenghtValue.Value = manager.Player.Strenght;
            IntelligenceValue.Value = manager.Player.Intelligence;
            DexterityValue.Value = manager.Player.Dexterity;
            HPValue.Value = manager.Player.HitPoints;
            ManaValue.Value = manager.Player.Mana;

            FramecountMovement.Value = manager.Player.FrameCount;;
            FramecountAttack.Value = manager.Player.FrameAttackingCount;

            initialState = manager.Player.InitialState;
            switch(manager.Player.InitialState)
            {
                case "up":
                    InitialDirectionComboBox.SelectedIndex = 0;
                    break;
                case "down":
                    InitialDirectionComboBox.SelectedIndex = 1;
                    break;
                case "left":
                    InitialDirectionComboBox.SelectedIndex = 2;
                    break;
                case "right":
                    InitialDirectionComboBox.SelectedIndex = 3;
                    break;
            }

            speed = manager.Player.Speed;
            switch (manager.Player.Speed)
            {
                case "slow":
                    SpeedComboBox.SelectedIndex = 0;
                    break;
                case "normal":
                    SpeedComboBox.SelectedIndex = 1;
                    break;
                case "fast":
                    SpeedComboBox.SelectedIndex = 2;
                    break;
            }

            imageMovingUp = SetImageLabel(manager.Player.ImageMovingUp, CharacterMovingUpLabel);
            imageMovingDown = SetImageLabel(manager.Player.ImageMovingDown, CharacterMovingDownLabel);
            imageMovingLeft = SetImageLabel(manager.Player.ImageMovingLeft, CharacterMovingLeftLabel);
            imageMovingRight = SetImageLabel(manager.Player.ImageMovingRight, CharacterMovingRightLabel);

            if (manager.Player.ImageAttackingUp != null)
            {
                CanMelee.IsChecked = true;

                imageAttackingUp = SetImageLabel(manager.Player.ImageAttackingUp, CharacterAttackingUpLabel);
                imageAttackingDown = SetImageLabel(manager.Player.ImageAttackingDown, CharacterAttackingDownLabel);
                imageAttackingLeft = SetImageLabel(manager.Player.ImageAttackingLeft, CharacterAttackingLeftLabel);
                imageAttackingRight = SetImageLabel(manager.Player.ImageAttackingRight, CharacterAttackingRightLabel);

                if (manager.Player.Melee != null)
                {
                    melee = manager.Player.Melee;
                    CurrentMeleeTextBox.Text = melee.Name;
                }
            }

            if (manager.Player.AttackSoundEffect != null)
            {
                attackSoundEffect = manager.Player.AttackSoundEffect;
                AttackSoundEffectTextBox.Text = manager.Player.AttackSoundEffect;
            }
            if (manager.Player.ShootSoundEffect != null)
            {
                shootSoundEffect = manager.Player.ShootSoundEffect;
                ShootSoundEffectTextBox.Text = manager.Player.ShootSoundEffect;
            }
            if (manager.Player.CastSoundEffect != null)
            {
                castSoundEffect = manager.Player.CastSoundEffect;
                CastSoundEffectTextBox.Text = manager.Player.CastSoundEffect;
            }

            if (manager.Player.Distance != null)
            {
                distance = manager.Player.Distance;
                CurrentDistanceTextBox.Text = distance.Name;
            }
        }
        /// <summary>
        /// Sets the initial melee weapon when you change the selection in the list.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MeleeEquipedList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string selectedItem = (string)MeleeEquipedList.SelectedItem;

            if (selectedItem == "Nothing")
            {
                melee = null;
                CurrentMeleeTextBox.Text = null;
            }
            else
            {
                melee = manager.GetWeapon(selectedItem);
                CurrentMeleeTextBox.Text = melee.Name;
            }
        }
        /// <summary>
        /// Saves the weapon's information and closes the window.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AcceptWeapon_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(imageWeapon))
                {
                    errorMessage = "You have to select an image for the weapon.";
                    throw new NullReferenceException();
                }

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

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

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

                if (type == "distance")
                {
                    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)
                {
                    manager.Weapons.Remove(weapon);
                }
                if (manager.NameRepeated(name))
                {
                    errorMessage = "This name already exits";
                    throw new NullReferenceException();
                }

                Weapon auxWeapon = new Weapon(name, type, damage, speed, imageWeapon, imageArrowUp, imageArrowDown,
                                                imageArrowLeft, imageArrowRight);
                manager.Weapons.Add(auxWeapon);
                manager.Weapons.OrderBy(x => x.Name);

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