Esempio n. 1
0
        //view inventory
        private void button1_Click(object sender, EventArgs e)
        {
            InventoryForm view = new InventoryForm(inventory);

            ViewInevtory       += view.ViewInvetory;
            ViewInevtoryWeapon += view.ViewInventoryWeapon;
            ViewInevtoryPotion += view.ViewInventoryPotion;
            view.Equip         += inventory.Equip;

            foreach (Items item in inventory.playerItems)
            {
                if (item is Weapon)
                {
                    ViewInventoryWeapon vie = new ViewInventoryWeapon();
                    vie.Cost       = item.Cost;
                    vie.Desription = item.Desription;
                    vie.Health     = item.Health;
                    vie.Mp         = item.Mp;
                    vie.Name       = item.Name;
                    vie.SellPrice  = item.SellPrice;
                    vie.Str        = item.Str;
                    ViewInevtoryWeapon?.Invoke(this, vie);
                }
                else if (item is Potions)
                {
                    ViewInventoryPotion vie = new ViewInventoryPotion();
                    vie.Cost       = item.Cost;
                    vie.Desription = item.Desription;
                    vie.Health     = item.Health;
                    vie.Mp         = item.Mp;
                    vie.Name       = item.Name;
                    vie.SellPrice  = item.SellPrice;
                    vie.Str        = item.Str;
                    vie.Rounds     = item.Rounds;
                    ViewInevtoryPotion?.Invoke(this, vie);
                }
            }

            foreach (Spells item in inventory.spells)
            {
                ViewInvetoryEvent vie = new ViewInvetoryEvent();
                vie.Cost       = item.Cost;
                vie.Desription = item.Desription;
                vie.Health     = item.Health;
                vie.Mp         = item.Mp;
                vie.Name       = item.Name;
                vie.Rounds     = item.Rounds;
                vie.SellPrice  = item.SellPrice;
                vie.Str        = item.Str;
                vie.SpellType  = ((Spells)item).SpellType;
                ViewInevtory?.Invoke(this, vie);
            }

            view.ShowDialog();
        }
Esempio n. 2
0
        //view inventory event method
        public void ViewInvetory(object sender, ViewInvetoryEvent e)
        {
            TreeNode node = new TreeNode();

            node.Text = $"Spell:{e.Name}";
            node.Tag  = e;
            if (e.Health > 0)
            {
                TreeNode health = new TreeNode();
                health.Text = e.Health.ToString();
                node.Nodes.Add("Health:" + health.Text);
            }
            if (e.Str > 0)
            {
                TreeNode str = new TreeNode();
                str.Text = e.Str.ToString();
                node.Nodes.Add("Str:" + str.Text);
            }
            if (e.Mp > 0)
            {
                TreeNode mp = new TreeNode();
                mp.Text = e.Mp.ToString();
                node.Nodes.Add("MP:" + mp.Text);
            }
            if (e.Rounds > 0)
            {
                TreeNode rounds = new TreeNode();
                rounds.Text = e.Rounds.ToString();
                node.Nodes.Add("Rounds:" + rounds.Text);
            }
            TreeNode sellPrice = new TreeNode();

            sellPrice.Text = e.SellPrice.ToString();
            node.Nodes.Add("Sell Price:" + sellPrice.Text);
            TreeNode description = new TreeNode();

            description.Text = e.Desription;
            node.Nodes.Add(description);

            treeView1.Nodes.Add(node);
        }
Esempio n. 3
0
        //sell item
        private void btnSell_Click(object sender, EventArgs e)
        {
            if (treeView1.SelectedNode.Tag is ViewInventoryWeapon)
            {
                ViewInventoryWeapon weapon = new ViewInventoryWeapon();
                weapon = (ViewInventoryWeapon)treeView1.SelectedNode.Tag;
                inventory.playerGold += weapon.SellPrice;
                treeView1.SelectedNode.Remove();
                inventory.playerItems.RemoveAt(treeView1.SelectedNode.Index);
                MessageBox.Show($"You sold {weapon.Name} for {weapon.SellPrice} gold!");
                lblGold.Text = inventory.playerGold.ToString();
            }
            else if (treeView1.SelectedNode.Tag is ViewInventoryPotion)
            {
                ViewInventoryPotion potion = new ViewInventoryPotion();
                potion = (ViewInventoryPotion)treeView1.SelectedNode.Tag;
                inventory.playerGold += potion.SellPrice;
                treeView1.SelectedNode.Remove();
                inventory.playerItems.RemoveAt(treeView1.SelectedNode.Index);
                MessageBox.Show($"You sold {potion.Name} for {potion.SellPrice} gold!");
                lblGold.Text = inventory.playerGold.ToString();
            }
            else if (treeView1.SelectedNode.Tag is ViewInvetoryEvent)
            {
                ViewInvetoryEvent spell = new ViewInvetoryEvent();
                spell = (ViewInvetoryEvent)treeView1.SelectedNode.Tag;
                inventory.playerGold += spell.SellPrice;
                treeView1.SelectedNode.Remove();
                for (int i = 0; i < inventory.spells.Count; i++)
                {
                    if (inventory.spells[i].Name == spell.Name)
                    {
                        inventory.spells.RemoveAt(i);
                    }
                }
                MessageBox.Show($"You sold {spell.Name} for {spell.SellPrice} gold!");
                lblGold.Text = inventory.playerGold.ToString();
            }

            this.Close();
        }