当前位置: 首页>>代码示例>>Python>>正文


Python Family.add_mom方法代码示例

本文整理汇总了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
开发者ID:ctasims,项目名称:village-people,代码行数:104,代码来源:villager.py


注:本文中的family.Family.add_mom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。