當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。