-
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
Paper - Dani Sanchez #52
base: master
Are you sure you want to change the base?
Changes from all commits
899c02c
f31c20e
443b06e
d4dc02a
fe5e3e6
a41c1ee
aee0e0e
0ce3094
85a356c
c04eb8d
0d54db5
abd481b
27b1b9f
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,9 @@ | ||
from swap_meet.item import Item | ||
|
||
class Clothing(Item): | ||
|
||
def __init__(self, condition = None ): | ||
super().__init__("Clothing", 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, condition = None): | ||
super().__init__("Decor", 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, condition = None): | ||
super().__init__("Electronics", 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,32 @@ | ||
|
||
|
||
class 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. 👍 |
||
|
||
def __init__(self, category = None, condition = None): | ||
if category: | ||
self.category = category | ||
else: | ||
self.category = "" | ||
|
||
if condition: | ||
self.condition = float(condition) | ||
else: | ||
self.condition = 0 | ||
|
||
|
||
def __str__(self): | ||
return "Hello World!" | ||
|
||
|
||
|
||
def condition_description(self): | ||
if self.condition > 4.0 : | ||
return "super duper best condition" | ||
elif self.condition > 3.0 : | ||
return "pretty alright!" | ||
elif self.condition > 2.0 : | ||
return "Has seen better days" | ||
elif self.condition > 1.0 : | ||
return "maybe wash it once you get home" | ||
elif self.condition >= 0.0 : | ||
return "pretty terrible!!!" |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,65 @@ | ||||||
|
||||||
|
||||||
class Vendor: | ||||||
|
||||||
def __init__(self, inventory = None): | ||||||
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. 👍 |
||||||
if inventory: | ||||||
self.inventory = inventory | ||||||
else: | ||||||
self.inventory = [] | ||||||
|
||||||
def add(self, new_item): | ||||||
self.inventory.append(new_item) | ||||||
return new_item | ||||||
|
||||||
#removes item_to_remove from self's inventory | ||||||
def remove(self, item_to_remove): | ||||||
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. 👍 |
||||||
for item in self.inventory: | ||||||
if item == item_to_remove: | ||||||
self.inventory.remove(item_to_remove) | ||||||
return item_to_remove | ||||||
return False | ||||||
|
||||||
def get_by_category(self, 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. 👍 |
||||||
items_list = [] | ||||||
for item in self.inventory: | ||||||
if item.category == category: | ||||||
items_list.append(item) | ||||||
return items_list | ||||||
|
||||||
def swap_items(self, 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. 👍 |
||||||
if self.remove(my_item): | ||||||
if vendor_friend.remove(their_item): | ||||||
vendor_friend.add(my_item) | ||||||
self.add(their_item) | ||||||
return True | ||||||
else: | ||||||
self.add(my_item) | ||||||
return False | ||||||
|
||||||
|
||||||
def swap_first_item(self, vendor_friend): | ||||||
if len(self.inventory) != 0 and len(vendor_friend.inventory) != 0: | ||||||
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. This type of thing can be simplified a bit because
Suggested change
|
||||||
self.swap_items(vendor_friend, self.inventory[0], vendor_friend.inventory[0]) | ||||||
return True | ||||||
return False | ||||||
|
||||||
def get_best_by_category(self, 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. 👍 |
||||||
category_list = self.get_by_category(category) | ||||||
if len(category_list) >= 1: | ||||||
best_condition_item = category_list[0] | ||||||
for item in category_list: | ||||||
if item.condition > best_condition_item.condition: | ||||||
best_condition_item = item | ||||||
return best_condition_item | ||||||
return None | ||||||
|
||||||
def swap_best_by_category(self, other, my_priority, their_priority): | ||||||
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. 👍 |
||||||
my_best_item = self.get_best_by_category(their_priority) | ||||||
their_best_item = other.get_best_by_category(my_priority) | ||||||
if my_best_item and their_best_item: | ||||||
self.swap_items(other, my_best_item, their_best_item) | ||||||
return True | ||||||
return False | ||||||
|
||||||
|
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.
👍 Very clean child class