Exemplo n.º 1
0
        public DoorKeyWindow(MainWindowManager manager, bool edit, Door door, KeyItem key)
        {
            InitializeComponent();

            this.manager = manager;
            openFileManager = new OpenFileManager();
            this.edit = edit;
            this.door = door;
            this.key = key;

            if (edit)
            {
                SetValues();
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Saves the door's information.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AcceptDoor_Click(object sender, RoutedEventArgs e)
        {
            string errorMessage = null;

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

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

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

                nameDoor = nameDoor.Replace(" ", "_");
                nameKey = nameKey.Replace(" ", "_");

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

                if (edit)
                {
                    manager.Doors.Remove(door);
                    manager.Keys.Remove(key);
                }
                if (manager.NameRepeated(nameDoor))
                {
                    errorMessage = "This name already exists";
                    throw new NullReferenceException();
                }

                Door auxDoor = new Door(nameDoor, imageDoor, manager.DoorID);

                manager.Doors.Add(auxDoor);
                manager.Doors.OrderBy(x => x.Name);

                KeyItem auxKey = new KeyItem(nameKey, imageKey, manager.DoorID);

                manager.Keys.Add(auxKey);
                manager.Keys.OrderBy(x => x.Name);

                manager.DoorID++;

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