From 91cd6ca3bd28a2ee1ef43fc9531bcf438d7bb91d Mon Sep 17 00:00:00 2001 From: Andrea Palacios Date: Tue, 6 Apr 2021 20:19:40 -0700 Subject: [PATCH] Final draft --- swap_meet/clothing.py | 10 ++++++ swap_meet/decor.py | 10 ++++++ swap_meet/electronics.py | 9 +++++ swap_meet/item.py | 22 ++++++++++++ swap_meet/vendor.py | 77 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 128 insertions(+) create mode 100644 swap_meet/clothing.py create mode 100644 swap_meet/decor.py create mode 100644 swap_meet/electronics.py create mode 100644 swap_meet/item.py create mode 100644 swap_meet/vendor.py diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py new file mode 100644 index 000000000..774b71b20 --- /dev/null +++ b/swap_meet/clothing.py @@ -0,0 +1,10 @@ +from swap_meet.item import Item + +class Clothing(Item): + + def __init__(self, condition = 0): + super().__init__(condition, category = 'Clothing') + + + 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..31fdc414e --- /dev/null +++ b/swap_meet/decor.py @@ -0,0 +1,10 @@ +from swap_meet.item import Item + +class Decor(Item): + + def __init__(self, condition = 0): + super().__init__(condition, category = 'Decor') + + 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..a216e1c4a --- /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__(condition, category='Electronics') + + 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..9cb5e0967 --- /dev/null +++ b/swap_meet/item.py @@ -0,0 +1,22 @@ + +class Item: + + def __init__(self, condition= 0, category= ""): + self.category = category + self.condition = condition + + def __str__(self): + return "Hello World!" + + def condition_description(self): + if self.condition > 4: + return "Excellent Condition!" + elif 3 < self.condition > 4: + return "Barely used!" + elif 1 < self.condition > 3: + return "Needs a little TLC" + else: + return "This item could use A LOT of LOVE." + + + diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py new file mode 100644 index 000000000..8bb06df5b --- /dev/null +++ b/swap_meet/vendor.py @@ -0,0 +1,77 @@ + +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): + cat_list = [] + for item in self.inventory: + if item.category is category: + cat_list.append(item) + return cat_list + #return [item for item in self.inventory if item.category == category] + + + def swap_items(self, other, my_item, their_item): + if my_item in self.inventory and their_item in other.inventory: + self.remove(my_item) + other.add(my_item) + self.add(their_item) + other.remove(their_item) + return True + else: + return False + + + def swap_first_item(self, other): + if len(self.inventory) == 0 or len(other.inventory) == 0: + return False + else: + my_first_item = self.inventory[0] + their_first_item = other.inventory[0] + self.swap_items(other, my_first_item, their_first_item) + return True + + + def get_best_by_category(self, category): + items_list = self.get_by_category(category) + if len(items_list) == 0: + return None + + best_condition_item = items_list[0] + for item in items_list: + if item.condition > best_condition_item.condition: + best_condition_item = item + return best_condition_item +#[for item in items_list if item.condition > best_condition_item.condition] + + + def swap_best_by_category(self, other, my_priority, their_priority): + my_item = self.get_best_by_category(their_priority) + their_item = other.get_best_by_category(my_priority) + + if my_item and their_item: + self.swap_items(other, my_item, their_item) + return True + else: + return False + +