def removeAllItem(self, item: Item) -> bool:
     itemClass: str = item.getItemClass()
     if itemClass in self.__items:
         itemType: str = item.getItemType()
         if itemType in self.__items[itemClass]:
             if item.getName() in self.__items[itemClass][itemType]:
                 del (self.__items[itemClass][itemType][item.getName()])
                 return True
     return False
示例#2
0
 def take(self, item:Item, amount:int, containerIndex:int):
     container:Container = self.containers[containerIndex]
     if amount < 0:
         removed:bool = container.removeAllItem(item)
         if removed:
             print("All", item.getName(), "was removed from the", self.getName() + "'s", container.getName())
         else:
             print(item.getName(), "was not found in the", self.getName() + "'s", container.getName())
     else:
         removed:bool = container.removeItem(item, amount)
         if removed:
             print(amount, item.getName(), "was removed from the", self.getName() + "'s", container.getName() + ",", "with", container.getItemRemaining(item), "remaining")
         else:
             print(item.getName(), "was not found in the", self.getName() + "'s", container.getName())
示例#3
0
 def __put(self, item:Item, amount:int, container:Container):
     if (container.getSpaceLeft() > amount):
         container.store(item, amount)
         print(amount, item.getName(), "stored.")
     else:
         print("Storage is full!")
         #TO-DO add operation for when storage is full
示例#4
0
 def put(self, item:Item, amount:int, containerIndex:int):
     container:Container = self.containers[containerIndex]
     if container.getPrefferedItem() != Container.ANY:
         if item.getItemType() == container.getPrefferedItem():
             self.__put(item, amount, container)
         else:
             prefItem:str = container.getPrefferedItem
             while(True):
                 response:str = input("What you are putting there isn't a ", prefItem + ",", "are you sure? (Y/N):")
                 response.casefold()
                 if response == "y".casefold():
                     self.__put(item, amount, container)
                 elif response == "n".casefold():
                     print(amount, item.getName(), "was not stored.")
                     #TO-DO option to change storage
                     break
                 else:
                     print("Invalid input, please try again.")
     else:
         self.__put(item, amount, container)
 def store(self, item: Item, amount: int = 1):
     itemClass: str = item.getItemClass()
     itemType: str = item.getItemType()
     if itemClass in self.__items:
         if itemType in self.__items[itemClass]:
             if item.getName() in self.__items[itemClass][itemType]:
                 self.__items[itemClass][itemType][item.getName()] += amount
             else:
                 self.__items[itemClass][itemType][item.getName()] = amount
         else:
             self.__items[itemClass][itemType] = {item.getName(): amount}
     else:
         self.__items[itemClass] = {itemType: {item.getName(): amount}}
 def removeItem(self, item: Item, amount: int) -> bool:
     itemClass: str = item.getItemClass()
     if itemClass in self.__items:
         itemType: str = item.getItemType()
         if itemType in self.__items[itemClass]:
             if item.getName() in self.__items[itemClass][itemType]:
                 self.__items[itemClass][itemType][item.getName()] -= amount
                 if self.__items[itemClass][itemType][item.getName()] <= 0:
                     del (self.__items[itemClass][itemType][item.getName()])
                 return True
     return False
 def getItemRemaining(self, item: Item) -> int:
     try:
         return self.__items[item.getItemClass()][item.getItemType()][
             item.getName()]
     except:
         return 0
示例#8
0
def storeItem(container:Container, item:Item):
    if container.getSpaceLeft() > item.getSize():
        container.store(item, item.getSize())
        print(item.getName(), "was stored.")
    else:
        print(item.getName(), "was not stored due to not enough space in the", container.getName(), "container")