-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scissors, Mai Truong #49
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from swap_meet.item import Item | ||
|
||
|
||
class Clothing(Item): | ||
def __init__(self, category = "Clothing", condition = 0): | ||
self.category = category | ||
self.condition = condition | ||
|
||
|
||
def __str__(self): | ||
return "The finest clothing you could wear." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from swap_meet.item import Item | ||
|
||
|
||
class Decor(Item): | ||
def __init__(self, category = "Decor", condition = 0): | ||
self.category = category | ||
self.condition = condition | ||
|
||
|
||
def __str__(self): | ||
return "Something to decorate your space." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from swap_meet.item import Item | ||
|
||
|
||
class Electronics(Item): | ||
def __init__(self, category = "Electronics", condition = 0): | ||
self.category = category | ||
self.condition = condition | ||
|
||
|
||
def __str__(self): | ||
return "A gadget full of buttons and secrets." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
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 == 0.0: | ||
return "Are you sure you want that?" | ||
elif self.condition <= 1.0: | ||
return "Came from home with 8 kids & 3 mastiffs." | ||
elif self.condition <= 2.0: | ||
return "Could be worse?" | ||
elif self.condition <= 3.0: | ||
return "Meh..." | ||
elif self.condition <= 4.0: | ||
return "One heck of a deal!" | ||
else: | ||
return "If you don't take, it's coming home to mama." | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
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): | ||
|
||
matching_items = [] | ||
for item in self.inventory: | ||
if item.category == category: | ||
matching_items.append(item) | ||
return matching_items | ||
|
||
|
||
def swap_items(self, vendor_friend, my_item, their_item): | ||
|
||
if my_item not in self.inventory or their_item not in vendor_friend.inventory: | ||
return False | ||
else: | ||
self.remove(my_item) | ||
vendor_friend.add(my_item) | ||
vendor_friend.remove(their_item) | ||
self.add(their_item) | ||
return True | ||
|
||
|
||
def swap_first_item(self, vendor_friend): | ||
|
||
if self.inventory and vendor_friend.inventory: | ||
my_item = self.inventory[0] | ||
their_item = vendor_friend.inventory[0] | ||
self.swap_items(vendor_friend, my_item, their_item) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great use of existing method! |
||
return True | ||
else: | ||
return False | ||
|
||
def get_best_by_category(self, category): | ||
|
||
list_of_items = self.get_by_category(category) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great use of existing method! |
||
|
||
for item in list_of_items: | ||
if list_of_items == []: | ||
return None | ||
|
||
best_condition = 0.0 | ||
for item in list_of_items: | ||
if item.condition > best_condition: | ||
best_condition = item.condition | ||
for item in list_of_items: | ||
if best_condition == item.condition: | ||
return item | ||
|
||
def swap_best_by_category(self, other, my_priority, their_priority): | ||
|
||
my_best_item = self.get_best_by_category(their_priority) | ||
their_best_item = other.get_best_by_category(my_priority) | ||
|
||
if their_best_item == None or my_best_item == None: | ||
return False | ||
else: | ||
return self.swap_items(other, my_best_item, their_best_item) | ||
Comment on lines
+70
to
+78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So clean! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love these 😆