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


Python MemcachedDatabase.get_squares方法代码示例

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


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

示例1: __init__

# 需要导入模块: from database.memcached_database import MemcachedDatabase [as 别名]
# 或者: from database.memcached_database.MemcachedDatabase import get_squares [as 别名]
class AdminHandler:
    '''Handles the requests related to GUI.'''

    def __init__(self):
        self._authenticator = Authenticator()
        self._database = MemcachedDatabase()

    def execute_command(self, password, command, args):
        '''Executes the specified command.'''
        if not isinstance(password, str):
            raise InvalidArgumentsError("Expected {0} as password, found {1}.".format(type(str), type(password)))

        self._authenticator.authenticate_admin(password)

        if command == "map_data":
            return self._get_map_data(args)

    def _get_map_data(self, args):
        '''Returns the information about the world's map.

        @args: Should be a list of locations. Each location is a string
            in the form of "x,y".
        '''
        squares = self._database.get_squares(args)

        result = {}
        for location, square in squares.items():
            robot_id = square.get_robot_id()
            if robot_id is not None:
                robot = self._database.get_robot(robot_id)
                robot_info = {'name': robot.get_name(),
                              'has_water': robot.get_has_water(),
                              'energy': robot.get_energy(),
                              'life': robot.get_life(),
                              'honor': robot.get_honor()}
            else:
                robot_info = None

            plant = square.get_plant()
            if plant is not None:
                plant_info = {'water_level': plant.get_water_level(),
                              'matured': plant.is_matured(),
                              'age': plant.get_age()}
            else:
                plant_info = None

            result[location] = {'surface_type': square.get_type(),
                                'plant': plant_info,
                                'robot': robot_info}

        return result
开发者ID:aidin36,项目名称:beneath-a-binary-sky,代码行数:53,代码来源:admin_handler.py


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