Example #1
0
        /**
         * Picks up an item to be placed in backpack if it will fit in the bag and notifies subscribers.
         * @params: (String) name of the item to be picked up.
         **/
        public void pickUpItem(string itemName)
        {
            I_Item item = currentRoom.takeItem(itemName);

            if (item != null)
            {
                NotificationCenter.Instance.postNotification(new Notification("PickedUpItem", this));
                if ((Backpack.weightInBag() + item.Weight) >= Backpack.Capacity)
                {
                    Console.WriteLine("Backpack is full.");
                    currentRoom.giveItem(item);
                }
                else if (item.ItemTypes.Contains(ItemType.Weapon) && Weapon == null)
                {
                    setWeapon((IWeapon)item);
                    Console.WriteLine("\nYour weapon has been set to the " + itemName + "!\n");
                }

                else
                {
                    Backpack.giveItem(item);
                    Console.WriteLine("\nYou picked up a " + itemName + "!\n");
                }
            }
        }