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


Python Resources.save方法代码示例

本文整理汇总了Python中resources.Resources.save方法的典型用法代码示例。如果您正苦于以下问题:Python Resources.save方法的具体用法?Python Resources.save怎么用?Python Resources.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在resources.Resources的用法示例。


在下文中一共展示了Resources.save方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: receive_resources

# 需要导入模块: from resources import Resources [as 别名]
# 或者: from resources.Resources import save [as 别名]
 def receive_resources(self, resources):
     """
     add the resources to the village
     create a new object resources with this values and return it
     """
     max_resources = self.max_resources_storage()
     transfered_resources = Resources(
         food=min(
             resources.food,
             max_resources.food - int(self.resources.food),
             ),
         wood=min(
             resources.wood,
             max_resources.wood - int(self.resources.wood),
             ),
         silex=min(
             resources.silex,
             max_resources.silex - int(self.resources.silex),
             ),
         skin=min(
             resources.skin,
             max_resources.skin - int(self.resources.skin),
             ),
     )
     #need to create a new instance of resources to remember for the report
     transfered_resources.pk = None
     transfered_resources.save()
     self.resources += transfered_resources
     self.resources.save()
     self.plan_next_starvation()
     return transfered_resources
开发者ID:raphael-boucher,项目名称:dolmen,代码行数:33,代码来源:village.py

示例2: create_tribe

# 需要导入模块: from resources import Resources [as 别名]
# 或者: from resources.Resources import save [as 别名]
    def create_tribe(name, user, carte):
        """
        Initialise une tribe (à utiliser après la création d'un compte)

        """
        tribe = Tribe(name=name, leader=user)
        tribe.save()

        resources_initiales = Resources(
                wood=INIT_TRIBE_RESOURCES['wood'],
                food=INIT_TRIBE_RESOURCES['food'],
                silex=INIT_TRIBE_RESOURCES['silex'],
                skin=INIT_TRIBE_RESOURCES['skin']
                )

        resources_initiales.save()
        village = Village.create_village(tribe, first=True)

        inhabitants = Group.objects.create(
                position=village.position,
                village=village,
                )
        village.inhabitants = inhabitants
        for key in INIT_TRIBE_UNITS:
            new_pile = UnitStack(
                    unit_type=UnitType.objects.get(identifier__iexact=key),
                    group=inhabitants,
                    number=INIT_TRIBE_UNITS[key],
                    )
            new_pile.save()
        village.update_income()

        return tribe
开发者ID:raphael-boucher,项目名称:dolmen,代码行数:35,代码来源:tribe.py

示例3: take_resources

# 需要导入模块: from resources import Resources [as 别名]
# 或者: from resources.Resources import save [as 别名]
 def take_resources(self, village_or_group, resources_dict):
     """
     Substract the max resources up to resources_dict content to the
     village_or_group’s resources and set it in a new resources object
     which is returned
     """
     for key in resources_dict:
         resources_dict[key] = max(resources_dict[key], 0)
     available_resources = village_or_group.resources
     wanted_resources = Resources.dict_to_resources(resources_dict)
     if available_resources >= wanted_resources:
         available_resources -= wanted_resources
         available_resources.save()
         wanted_resources.save()
         return wanted_resources
     else:
         received_resources = Resources()
         for key in wanted_resources:
             amount = min(wanted_resources[key], available_resources[key])
             received_resources[key] = amount
             available_resources -= amount
         available_resources.save()
         received_resources.save()
         return received_resources()
开发者ID:raphael-boucher,项目名称:dolmen,代码行数:26,代码来源:group.py


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