diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py new file mode 100644 index 000000000..5475dfc5f --- /dev/null +++ b/swap_meet/clothing.py @@ -0,0 +1,9 @@ +from swap_meet.item import Item + +class Clothing(Item): + + def __init__(self, condition=0): + super().__init__("Clothing", condition) + + def __str__(self): + return "The finest clothing you could wear." diff --git a/swap_meet/decor.py b/swap_meet/decor.py new file mode 100644 index 000000000..5602e26f0 --- /dev/null +++ b/swap_meet/decor.py @@ -0,0 +1,8 @@ +from swap_meet.item import Item + +class Decor(Item): + def __init__(self, condition=0): + super().__init__("Decor", condition) + + def __str__(self): + return "Something to decorate your space." diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py new file mode 100644 index 000000000..0685b3683 --- /dev/null +++ b/swap_meet/electronics.py @@ -0,0 +1,9 @@ +from swap_meet.item import Item + +class Electronics(Item): + def __init__(self, condition=0): + super().__init__("Electronics", condition) + + + def __str__(self): + return "A gadget full of buttons and secrets." diff --git a/swap_meet/item.py b/swap_meet/item.py new file mode 100644 index 000000000..c3fe17cf3 --- /dev/null +++ b/swap_meet/item.py @@ -0,0 +1,21 @@ +class Item: + def __init__(self, category = "", condition=0): + self.category = category + self.condition = condition + + def __str__(self): + return "Hello World!" + + def condition_description(self): + if self.condition < 1: + return "I would be cautious handling this, it's really old." + elif self.condition < 2: + return "Probably has some use still left?" + elif self.condition < 3: + return "Doesn't look like much but it will get the job done." + elif self.condition < 4: + return "This has a lot of use left!" + elif self.condition < 5: + return "Really good condition!" + else: + return "It's perfect, never used, still in orginal packaging." diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py new file mode 100644 index 000000000..b8ea13813 --- /dev/null +++ b/swap_meet/vendor.py @@ -0,0 +1,53 @@ +class Vendor: + def __init__(self, inventory = None): + if inventory == None: + self.inventory = [] + else: + self.inventory = inventory + + def add(self, item): + self.inventory.append(item) + return item + + def remove(self, item): + if item in self.inventory: + self.inventory.remove(item) + return item + else: + return False + + def get_by_category(self, category): + matched = [] + for item in self.inventory: + if item.category == category: + matched.append(item) + return matched + + def swap_items(self, them, my_item, their_item): + if their_item not in them.inventory or my_item not in self.inventory: + return False + else: + self.inventory.remove(my_item) + them.inventory.append(my_item) + them.inventory.remove(their_item) + self.inventory.append(their_item) + return True + + def swap_first_item(self, them): + if len(self.inventory) == 0 or len(them.inventory) == 0: + return False + return self.swap_items(them, self.inventory[0], them.inventory[0]) + + def get_best_by_category(self, category): + items_in_category = self.get_by_category(category) + if len(items_in_category) > 0: + #lambda lets me define a func in a single line + return max(items_in_category, key = lambda item: item.condition) + else: + return None + + def swap_best_by_category(self, other, my_priority, their_priority): + my_category = self.get_best_by_category(their_priority) + their_category = other.get_best_by_category(my_priority) + total = self.swap_items(other, my_category, their_category) + return total