diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py new file mode 100644 index 000000000..2c47b5f38 --- /dev/null +++ b/swap_meet/clothing.py @@ -0,0 +1,11 @@ + +class Clothing: + def __init__(self, condition=0): + self.category = "Clothing" + self.condition = condition + + def __str__(self): + return "The finest clothing you could wear." + + def __repr__(self): + return f"{self.category} in {self.condition} condition" \ No newline at end of file diff --git a/swap_meet/decor.py b/swap_meet/decor.py new file mode 100644 index 000000000..40acbff2f --- /dev/null +++ b/swap_meet/decor.py @@ -0,0 +1,8 @@ +class Decor: + def __init__(self, condition = 0): + self.category = "Decor" + self.condition = 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..0f8373d64 --- /dev/null +++ b/swap_meet/electronics.py @@ -0,0 +1,7 @@ +class Electronics: + def __init__(self, condition = 0): + self.category = "Electronics" + self.condition = condition + + def __str__(self): + return "A gadget full of buttons and secrets." \ No newline at end of file diff --git a/swap_meet/item.py b/swap_meet/item.py new file mode 100644 index 000000000..babdbcfd7 --- /dev/null +++ b/swap_meet/item.py @@ -0,0 +1,8 @@ + +class Item: + def __init__(self, category=""): + self.category = category + + + def __str__(self): + return "Hello World!" \ No newline at end of file diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py new file mode 100644 index 000000000..c54fefac4 --- /dev/null +++ b/swap_meet/vendor.py @@ -0,0 +1,58 @@ +class Vendor: + + def __init__(self, inventory=[]): + self.inventory = inventory + + def add(self, item): + self.inventory.append(item) + return item + + def remove(self, item): + try: + self.inventory.remove(item) + return item + except ValueError as ve: + return False + + def get_by_category(self, category): + return [item for item in self.inventory if item.category == category] + + def swap_first_item(self, other_vendor): + if len(self.inventory) == 0 or len(other_vendor.inventory) == 0: + return False + + my_first = self.inventory[0] + other_first = other_vendor.inventory[0] + self.remove(my_first) + other_vendor.remove(other_first) + self.add(other_first) + other_vendor.add(my_first) + return True + + def get_best_by_category(self, category): + inv_by_category = [item for item in self.inventory if item.category == category] + + if len(inv_by_category) == 0: + return None + + print(inv_by_category) + + max = inv_by_category[0] + for item in inv_by_category: + if item.condition > max.condition: + max = item + + return max + + def swap_best_by_category(self, other: 'Vendor', my_priority: str, their_priority: str): + my_best = self.get_best_by_category(their_priority) + their_best = other.get_best_by_category(my_priority) + + if my_best is None or their_best is None: + return False + + self.remove(my_best) + other.remove(their_best) + self.add(their_best) + other.add(my_best) + return True diff --git a/test.sh b/test.sh old mode 100644 new mode 100755