-
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 - Lindsey #69
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,13 @@ | ||
from swap_meet.item import Item | ||
|
||
class Clothing(Item): | ||
def __init__(self, condition = 0): | ||
self.category = "Clothing" | ||
self.condition = condition | ||
|
||
def __str__(self): | ||
return "The finest clothing you could wear." | ||
|
||
def condition_description(self): | ||
return super().condition_description() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from swap_meet.item import Item | ||
|
||
class Decor(Item): | ||
def __init__(self, condition = 0): | ||
self.category = "Decor" | ||
self.condition = condition | ||
|
||
def __str__(self): | ||
return "Something to decorate your space." | ||
|
||
def condition_description(self): | ||
return super().condition_description() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from swap_meet.item import Item | ||
|
||
class Electronics(Item): | ||
def __init__(self, condition = 0): | ||
self.category = "Electronics" | ||
self.condition = condition | ||
|
||
def __str__(self): | ||
return "A gadget full of buttons and secrets." | ||
|
||
def condition_description(self): | ||
return super().condition_description() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class Item: | ||
def __init__(self, category = ""): | ||
# default parameter is what we want in case nothing is passed | ||
self.category = category | ||
|
||
def __str__(self): | ||
return "Hello World!" | ||
|
||
def condition_description(self): | ||
if self.condition == 5: | ||
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 function uses self.condition, but self.condition is not initialized in init. The following code will throw an exception:
|
||
return "This fit is fire" | ||
elif self.condition == 4: | ||
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. The condition of an item can have a decimal place. What will happen if self.condition is 3.5? How could you modify these conditionals to account for that possibility? (PS: I love your descriptions!). |
||
return "Issa mood" | ||
elif self.condition == 3: | ||
return "Yay, we love basics" | ||
elif self.condition == 2: | ||
return "I'm feeling meh" | ||
elif self.condition == 1: | ||
return "I want to burn these clothes" | ||
elif self.condition == 0: | ||
return "I hate it here" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from swap_meet.item import Item | ||
from swap_meet.clothing import Clothing | ||
from swap_meet.decor import Decor | ||
from swap_meet.electronics import Electronics | ||
|
||
class Vendor(): | ||
def __init__(self,inventory = None): | ||
if inventory is 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 | ||
return False | ||
|
||
def get_by_category(self, category): | ||
items = [] | ||
for item in self.inventory: | ||
if item.category == category: | ||
items.append(item) | ||
return items | ||
|
||
def swap_items(self, friend, my_item, their_item): | ||
if my_item in self.inventory and their_item in friend.inventory: | ||
friend.inventory.append(my_item) | ||
self.inventory.remove(my_item) | ||
self.inventory.append(their_item) | ||
friend.inventory.remove(their_item) | ||
Comment on lines
+32
to
+35
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. Consider using the Vendor add & remove functions here. |
||
return True | ||
return False | ||
|
||
def swap_first_item(self, friend): | ||
if len(self.inventory) > 0 and len(friend.inventory) > 0: | ||
return self.swap_items(friend, self.inventory[0], 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. Great code re-use! |
||
return False | ||
|
||
def get_best_by_category(self, category = ""): | ||
max_condition = -1 | ||
best_item = None | ||
category_items = self.get_by_category(category) | ||
for item in category_items: | ||
if item.condition > max_condition: | ||
max_condition = item.condition | ||
best_item = item | ||
return best_item | ||
|
||
def swap_best_by_category(self, other, my_priority, their_priority): | ||
my_best_cat_item = self.get_best_by_category(their_priority) | ||
their_best_cat_item = other.get_best_by_category(my_priority) | ||
if my_best_cat_item != None and their_best_cat_item != None: | ||
return self.swap_items(other, my_best_cat_item, their_best_cat_item) | ||
Comment on lines
+55
to
+58
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. Excellent use of helper functions! Question - is the error checking on line 57 needed? What happens if it's not there? |
||
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.
This function is repeating some of the work that's done in the Item constructor. Consider using
super().__init__(...)
as a way to DRY up code in subclasses when possible.