Beispiel #1
0
 public bool placeItemInSpace(Equipment item)
 {
     if (Storage.addItem(item))
     {
         item.changeOwner(null, Storage);
         return(true);
     }
     return(false);
 }
Beispiel #2
0
        public List <Equipment> takeItem(String name, int amount, Unit unit = null, SuppliesStorage newStorage = null)
        {
            List <Equipment> returnList = new List <Equipment>();

            int amountCount = 0;

            foreach (Equipment i in storage)
            {
                if ((i.Name == name) && (amountCount < amount))
                {
                    returnList.Add(i);
                    if (unit != null)
                    {
                        unit.Storage.addItem(i);
                    }
                    else if (newStorage != null)
                    {
                        newStorage.addItem(i);
                    }
                    else
                    {
                        throw new ArgumentException("Both unit and newStorage cannot be null");
                    }
                    weight = weight - i.Weight;
                    amountCount++;
                    if (amountCount == amount)
                    {
                        break;
                    }
                }
            }

            if (returnList.Count() > 0)
            {
                return(returnList);
            }

            return(null);
        }