The way I'm trying to do this is to create clothing objects which have "style characteristics" as a property represented by an integer. So, for instance, a dress could have 2 elegance and 5 frilliness. Then, it's added to a list of what the player is wearing, and it's style characteristics are added to a running tally. Finally, the style characteristic tallies are checked against each other to see which one is dominant, and the player's overall style is determined.
So, if the player is wearing a dress which gives 2 elegance and 5 frilliness, but also shoes which give 3 elegance and a hat which gives 1 elegance, their overall style should be "elegant."
This is what I have so far:
Code: Select all
class Clothes:
def __init__(self, name, description, flashy=0, elegant=0, frilly=0):
self.name = name
self.desc = description
self.flashy = flashy
self.elegant = elegant
self.frilly = frilly
class Wardrobe:
def __init__(self, name):
self.name = name
self.flashy_index = 0
self.elegant_index = 0
self.frilly_index = 0
self.style = ""
self.wearing=[]
def check_style(self):
if self.flashy_index > self.elegant_index and self.flashy_index > self.frilly_index :
self.style = "flashy"
elif self.elegant_index > self.flashy_index and self.elegant_index > self.frilly_index :
self.style = "elegant"
elif self.frilly_index > self.elegant_index and self.frilly_index > self.flashy_index :
self.style = "frilly"
else :
self.style = "eclectic"
return
def remove(self, clothes):
if clothes in self.wearing:
self.wearing.remove(clothes)
self.flashy_index -= clothes.flashy
self.elegant_index -= elegant.flashy
self.frilly_index -= clothes.frilly
return
def wear(self, clothes):
self.wearing.append(clothes)
self.flashy_index += clothes.flashy
self.elegant_index += clothes.elegant
self.frilly_index += clothes.frilly
return
def remove_all(self):
list = [item for item in self.wearing]
if list!=[]:
for item in list:
self.wearing.remove(item)
self.flashy_index = 0
self.elegant_index = 0
self.frilly_index = 0
returnCode: Select all
$ player = Wardrobe("Player")
$ sundress = Clothes("Sundress", "a simple dress," 0, 0, 5)
$ player.wear(sundress)
$ style = player.check_style
"Your style is [style]."
Does anybody know what I'm doing wrong, and what I might do to fix it?
(Ideally, I'd also like to know how to display a list of what the player is wearing. Right now, when I try to do that by assigning player.wearing to a variable and printing the variable, I get [<store.Clothes instance at 0x04761738>])
EDIT: Accidentally left out a section of code. Have fixed it.