本文整理匯總了Python中family.Family.add_mom方法的典型用法代碼示例。如果您正苦於以下問題:Python Family.add_mom方法的具體用法?Python Family.add_mom怎麽用?Python Family.add_mom使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類family.Family
的用法示例。
在下文中一共展示了Family.add_mom方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: open
# 需要導入模塊: from family import Family [as 別名]
# 或者: from family.Family import add_mom [as 別名]
#.........這裏部分代碼省略.........
def __eq__(self, other):
"""
check if two villagers are the same
"""
return self.id == other.id
def birthday(self):
"""
Every year, advance villager's age and refresh stats
"""
self.age += 1
# update age group and label
for group in self.__class__.age_groups:
if self.age <= group[1]: # child or infant
self.age_group = self.__class__.age_groups.index(group)
self.age_label = self.__class__.age_labels[self.age_group]
break
else:
pass
if self.age == self.adulthood:
self.grow_up()
#elif self.age > self.adulthood:
#if self.spouse is None:
#self.check_mate()
def die(self):
"""
You have died!
Notify your family.
If male, remove from prof list
"""
self.village.remove_villager(self)
#print "{0} HAS DIED!".format(self)
def grow_up(self):
""" upon reaching adulthood males start family and look for mate.
females go onto Prospects list.
can set profession manually.
"""
if self.gender == 'm':
prior_family = self.family
self.family = Family(self.village, self.family.house, dad=self)
prior_family.remove_kid(self)
elif self.gender == 'f':
pass
self.check_mate()
return self
def check_mate(self): # har har har
""" grab mate from prospects list, if available
Called from grow_up and on yearly update when adult is single.
Villagers do not remarry if spouse dies.
Single women go on prospects list.
Single men search prospects list for mate.
If one available, she and her kids join his family.
"""
# WOMAN
if self.gender == 'f' and self not in self.village.prospects:
self.village.prospects.append(self)
# MAN
elif self.gender == 'm' and self.village.prospects:
bride = self.village.prospects.pop()
prior_family = bride.family
self.family.add_mom(bride)
prior_family.remove_kid(bride)
prior_family.update_stats()
#prior_family.mom = None
#if bride is not prior_family.mom: # just a kid growing up
#else: # she's a widow. Get kids, if any.
#import pdb; pdb.set_trace()
#if bride.family.kids:
#for kid in bride.family.kids:
#self.family.kids.append(kid)
##kid.family = self.family
#for kid in self.family:
#kid.family = self.family
#bride.family.kids = []
def force_grow_up(self):
""" Advances villager to adulthood.
Used when populating village for first time with villagers.
"""
while self.age is not self.adulthood:
self.birthday()
self.hp = 1000
return self
def give_birth(self):
""" create new villager and add them to family
"""
baby = Villager(self.village, self.family)
return baby