这与我今天早些时候提出的问题相连(“List” Object Not Callable,Syntax Error for Text-Based RPG)。现在我的困境在于将草药添加到玩家的草药列表中。
self.herb = []
是起始草药列表。函数collectPlants:
def collectPlants(self):
if self.state == 'normal':
print"%s spends an hour looking for medicinal plants." % self.name
if random.choice([0,1]):
foundHerb = random.choice(herb_dict)
print "You find some %s." % foundHerb[0]
self.herb.append(foundHerb)
print foundHerb
else: print"%s doesn't find anything useful." % self.name
foundHerb 是随机选择。如何以简洁的方式将此项目添加到列表中(目前它打印草药名称,然后是“无”)并允许使用几种相同的草药?
这是草药类:
class herb:
def __init__(self, name, effect):
self.name = name
self.effect = effect
草药样本清单(警告:未成熟):
herb_dict = [
("Aloe Vera", Player().health = Player().health + 2),
("Cannabis", Player().state = 'high'),
("Ergot", Player().state = 'tripping')
]