Each player object has a dictionary of slots in which clothing items can appear; each slot is a deque (from collections, as above). A very basic object might look something like this:
Code: Select all
player = {"hat": [], "mask": [], "shirt": [], "pants": [], "shoes": []}
A clothes object would have a list of slots in which it appears, like:
Code: Select all
glasses = Clothing("mask")
balaclava = Clothing("hat", "mask")
dress = Clothing("shirt", "boots")
Code: Select all
def addClothing(item):
for slot in item:
player[slot].append(item)
When you want to take off an item of clothing, you go down the list of slots and check each slot the clothing appears in to make sure it's the last item in the list. If it's not, you can't take it off (because you have to take something else off first).
Code: Select all
def removeClothing(item):
for slot in item:
if player[slot][-1] != item:
print(f"You can't take {item.name} off yet; you're wearing something over it.")
return False
# we don't have to check again because we already verified it's there
for slot in item:
player[slot].pop()
print(f"You removed {item.name}.")
return True