Beispiel #1
0
        public bool HasItem(ItemTypes _item, int number = 1)
        {
            int count = 0;

            if (number == 0)
            {
                return(true);
            }
            if (number > inventory.Count)
            {
                return(false);
            }
            Item exampleItem = ItemOperators.extractControlFromType(_item);

            foreach (Item item in inventory)
            {
                if (item.GetType().ToString() == exampleItem.GetType().ToString())
                {
                    count++;
                }
            }
            if (count >= number)
            {
                return(true);
            }
            return(false);
        }
Beispiel #2
0
        public void CollectItem(ItemTypes _item)
        {
            Console.WriteLine("Player Recieved: " + _item.ToString());
            Item item = ItemOperators.extractControlFromType(_item);

            inventory.Add(item);
        }
Beispiel #3
0
 //Load up tools at top
 private void CraftingWindow_Load(object sender, EventArgs e)
 {
     Utils.nonAntialiasingPictureBox naPicSwordSelect = new Utils.nonAntialiasingPictureBox();
     setItemSelectInfo(naPicSwordSelect, new Point(40, 60), "SwordSelect", ItemOperators.extractControlFromType(ItemTypes.Sword));
     Utils.nonAntialiasingPictureBox naPicSpadeSelect = new Utils.nonAntialiasingPictureBox();
     setItemSelectInfo(naPicSpadeSelect, new Point(40 + (itemSelectSize + 32), 60), "SpadeSelect", ItemOperators.extractControlFromType(ItemTypes.Spade));
     Utils.nonAntialiasingPictureBox naPicAxeSelect = new Utils.nonAntialiasingPictureBox();
     setItemSelectInfo(naPicAxeSelect, new Point(40 + (itemSelectSize + 32) * 2, 60), "AxeSelect", ItemOperators.extractControlFromType(ItemTypes.Axe));
     this.Controls.Add(naPicSwordSelect);
     this.Controls.Add(naPicSpadeSelect);
     this.Controls.Add(naPicAxeSelect);
 }
Beispiel #4
0
        public void RemoveItem(ItemTypes _item)
        {
            Item exampleItem = ItemOperators.extractControlFromType(_item);

            foreach (Item item in inventory)
            {
                if (item.GetType().ToString() == exampleItem.GetType().ToString())
                {
                    inventory.Remove(item);
                    return;
                }
            }
        }
Beispiel #5
0
        //Displays inventory
        private void InventoryWindow_Load(object sender, EventArgs e)
        {
            //Maximum number of items in inventory is 100

            /*if (levelHandler.player.inventory.Count == 0)
             * {
             *  this.lblEmpty.Show();
             *  return;
             * }
             * int number = 0;
             * int numberX = 10;
             * int size = 34;
             * foreach (Item item in levelHandler.player.inventory)
             * {
             *  int x = 16 + (size + 16) * (number % numberX);
             *  int y = 16 + (size + 16) * (number / numberX);
             *  Utils.nonAntialiasingPictureBox naPicRef = new Utils.nonAntialiasingPictureBox();
             *  this.Controls.Add(naPicRef);
             *  naPicRef.Location = new Point(x, y);
             *  naPicRef.Size = new Size(size, size);
             *  naPicRef.Image = item.sprite;
             *  naPicRef.SizeMode = PictureBoxSizeMode.Zoom;
             *  naPicRef.BackColor = Color.Transparent;
             *  naPicRef.Show();
             *  number++;
             * }*/
            int size    = 120;
            int numberX = 4;
            int index   = 0;

            //Loop through each item and get how many of that item the player has
            foreach (ItemTypes item in Enum.GetValues(typeof(ItemTypes)))
            {
                if (item == ItemTypes.Relic && levelHandler.relic == null)
                {
                    continue;
                }
                int number = 0;
                //Calculate how many of that item the player has
                while (levelHandler.player.HasItem(item, number + 1))
                {
                    number++;
                }
                //Get coordinates at which to set it
                int x = 10 + (size + 4) * (index % numberX);
                int y = 10 + (size + 4) * (index / numberX);
                Utils.nonAntialiasingPictureBox naPicRef = new Utils.nonAntialiasingPictureBox();
                this.Controls.Add(naPicRef);
                naPicRef.Location  = new Point(x, y);
                naPicRef.Size      = new Size(size, size);
                naPicRef.Image     = ItemOperators.extractControlFromType(item).sprite;
                naPicRef.SizeMode  = PictureBoxSizeMode.Zoom;
                naPicRef.BackColor = Color.Transparent;
                naPicRef.Show();

                System.Windows.Forms.Label lblCount = new System.Windows.Forms.Label();
                this.Controls.Add(lblCount);
                lblCount.Parent    = naPicRef;
                lblCount.Location  = new Point(naPicRef.Width - (size / 2), naPicRef.Height - (size / 6));
                lblCount.Size      = new Size(size / 2, size / 6);
                lblCount.Text      = number.ToString();
                lblCount.Font      = new Font("Times New Roman", 12, lblCount.Font.Style);
                lblCount.TextAlign = ContentAlignment.MiddleRight;
                lblCount.ForeColor = Color.White;
                lblCount.BackColor = Color.Transparent;
                lblCount.Show();

                index++;
            }
        }
Beispiel #6
0
        //Checks
        private void itemSelectClickedOn(object sender, EventArgs e)
        {
            //Console.WriteLine("Item Selected");
            //Get reference to item or tool being selected
            Utils.nonAntialiasingPictureBox itemSelected = (Utils.nonAntialiasingPictureBox)sender;
            //Add new 'items required' if tool is clicked on
            if (itemSelected.Name.Contains("Select"))
            {
                toolToCraft = itemSelected;
                List <ItemTypes> required = extractRequiredItems(itemSelected.Name);
                int multiplier            = 0;

                itemInSlots = 0;
                //Remove previous 'items required'
                for (int i = this.Controls.Count - 1; i >= 0; i--)
                {
                    Control control = this.Controls[i];
                    if (control.Name.Contains("Collect") || control.Name.Contains("Craft"))
                    {
                        this.Controls.Remove(control);
                    }
                }

                //Add new items required
                foreach (ItemTypes itemType in required)
                {
                    Item item = ItemOperators.extractControlFromType(itemType);
                    Utils.nonAntialiasingPictureBox itemReq = new Utils.nonAntialiasingPictureBox();
                    setItemSelectInfo(itemReq, new Point(40 + (itemSelectSize + 32) * multiplier /*algebra - YEAH!*/, lblRequiredItemsTitle.Bottom + 10), itemType.ToString() + "ToCollect", item);
                    multiplier++;
                    this.Controls.Add(itemReq);
                }
            }
            //Moves item to crafting 'equation' if player has it
            else if (itemSelected.Name.Contains("ToCollect"))
            {
                ItemTypes itemType = extractRequiredItemType(itemSelected.Name);
                int       spot     = (itemSelected.Location.X - 40) / (itemSelectSize + 32);
                if (levelHandler.player.HasItem(itemType))
                {
                    itemSelected.Hide();
                    itemSelected.Location = new Point(60 + (140 * spot), 220);
                    itemSelected.Size     = new Size(75, 75);
                    itemSelected.Show();
                    itemInSlots++;
                    itemSelected.Name = itemType.ToString() + "Collected";
                    //Show output tool if 'equation' is complete
                    if (itemInSlots >= 2)
                    {
                        lblClickHere.Show();
                        ItemTypes selectedToolType = extractItemToCraft(toolToCraft.Name);
                        Item      tool             = ItemOperators.extractControlFromType(selectedToolType);
                        Utils.nonAntialiasingPictureBox itemCrafted = new Utils.nonAntialiasingPictureBox();
                        setItemSelectInfo(itemCrafted, new Point(375, 220), selectedToolType.ToString() + "ToCraft", tool);
                        itemCrafted.Size   = new Size(75, 75);
                        itemCrafted.Click += collectItem;
                        this.Controls.Add(itemCrafted);
                    }
                }
            }
            //Move tool out of equation
            else if (itemSelected.Name.Contains("Collected"))
            {
                lblClickHere.Hide();
                ItemTypes itemType = extractRequiredItemType(itemSelected.Name);
                int       spot     = (itemSelected.Location.X - 60) / 140;
                itemSelected.Hide();
                itemSelected.Location = new Point(40 + (itemSelectSize + 32) * spot, lblRequiredItemsTitle.Bottom + 10);
                itemSelected.Size     = new Size(itemSelectSize, itemSelectSize);
                itemSelected.Show();
                itemInSlots--;
                itemSelected.Name = itemType.ToString() + "ToCollect";

                //Remove equation output if there
                for (int i = this.Controls.Count - 1; i >= 0; i--)
                {
                    Control control = this.Controls[i];
                    if (control.Name.Contains("Craft"))
                    {
                        control.Click -= collectItem;
                        this.Controls.Remove(control);
                    }
                }
            }
        }