コード例 #1
0
ファイル: TextBox.cs プロジェクト: thewildvegetable/Portfolio
 public TextBox(Rectangle rectangle, Texture2D texture, InventoryItem item) : base(rectangle, texture)
 {
     this.texture = texture;
     text = "";
     this.rectangle = rectangle;
     this.item = item;
 }
コード例 #2
0
 //adds a number of an item to the inventory
 //if the item isn't in the inventory it adds it and the stack size
 //if add exceeds stackMax returns the differencew
 //if no issues returns -1;
 //dont try to add a negative
 public int AddItem(InventoryItem item, int num)
 {
     int difference;
     if (inventory.ContainsKey(item.Name))
     {
         InventoryItem temp;
         inventory.TryGetValue(item.Name, out temp);
         temp.StackNum += num;
         if (temp.StackNum > temp.StackMax)
         {
             difference = temp.StackNum - temp.StackMax;
             temp.StackNum = temp.StackMax;
             return difference;
         }
         else return -1;
     }
     else
     {
         //add item change was done to make it so we have static items we can add and refer to and can create new items on the fly if we desire
         inventory.Add(item.Name, new InventoryItem(item.Name, item.Description, item.StackNum, item.StackMax, item.BuyPrice, item.SellPrice));
         InventoryItem temp;
         inventory.TryGetValue(item.Name, out temp);
         temp.StackNum = num;
         if (temp.StackNum > temp.StackMax)
         {
             difference = temp.StackNum - temp.StackMax;
             temp.StackNum = temp.StackMax;
             return difference;
         }
         else return -1;
     }
 }
コード例 #3
0
ファイル: Button.cs プロジェクト: thewildvegetable/Portfolio
 public Button(String label, Player play, Rectangle rectangle, Texture2D texture, ChangeValue changeValue, InventoryItem inventoryItem)
     : base(rectangle, texture)
 {
     this.label = label;
     this.rectangle = rectangle;
     returnValue = false;
     this.texture = texture;
     lastKeyPress = 0;
     this.changeValue = changeValue;
     this.inventoryItem = inventoryItem;
     this.play = play;
 }
コード例 #4
0
        //----------------------------------------------------------------------->>METHODS<<

        public void ResolveFishing(Player play, Random rand, InventoryItem item, MouseState mouse)
        {
            //get random number
            int percent = rand.Next(0, 10);

            if(item == Inventory.net)
            {
                if (play.Inventory.GetItemOfType(item.Name) != null && play.Inventory.GetItemOfType(item.Name).StackNum > 0)
                {
                    if (percent < 6)
                       play.Inventory.AddItem(Inventory.herring, 2);
                    else
                       play.Inventory.AddItem(Inventory.tuna, 1);

                    play.Inventory.DecrementItem(Inventory.net, 1);   
                }
            }

            if (item == Inventory.cage)
            {
                if (play.Inventory.GetItemOfType(item.Name) != null && play.Inventory.GetItemOfType(item.Name).StackNum > 0)
                {
                    if (percent < 1)
                    {
                        play.Inventory.AddItem(Inventory.lobster, 3);
                    }
                    else if (percent < 5)
                    {
                        play.Inventory.AddItem(Inventory.lobster, 2);
                    }
                    else if (percent < 9)
                    {
                        play.Inventory.AddItem(Inventory.lobster, 1);
                    }
                    play.Inventory.DecrementItem(Inventory.cage, 1);
                }
            }

            if (item == Inventory.harpoon)
            {
                if (play.Inventory.GetItemOfType(item.Name) != null && play.Inventory.GetItemOfType(item.Name).StackNum > 0)
                {
                    if (percent < 9)
                        play.Inventory.AddItem(Inventory.swordfish, 1);
                    else
                        play.Inventory.AddItem(Inventory.whale, 1);

                    play.Inventory.DecrementItem(Inventory.harpoon, 1);
                }
            }

        }
コード例 #5
0
ファイル: Island.cs プロジェクト: thewildvegetable/Portfolio
        //island inherits object. object has the rectangle property already, DONT REIMPLEMENT IT!

        //----------------------------------------------------------------------->>METHODS<<

        //Adds the specified item to the island's inventory
        public void AddItem(InventoryItem item)
        {
            Items.AddItem(item, int.MaxValue);
        }
コード例 #6
0
        //removes a number of a type of item from the inventory
        //if tries to remove more than available returns the difference
        //returns -1 if no problems
        public int DecrementItem(InventoryItem item, int num)
        {
            InventoryItem temp;
            inventory.TryGetValue(item.Name, out temp);

            if (temp != null)
            {
                if (temp.StackNum - num < 0)
                {
                    int diff = num - temp.StackNum;
                    temp.StackNum = 0;
                    return diff;
                }
                else
                {
                    temp.StackNum -= num;
                    return -1;
                }
            }
            return -1;
        }