當前位置: 首頁>>代碼示例>>Python>>正文


Python GameLevel.by_id方法代碼示例

本文整理匯總了Python中models.GameLevel.GameLevel.by_id方法的典型用法代碼示例。如果您正苦於以下問題:Python GameLevel.by_id方法的具體用法?Python GameLevel.by_id怎麽用?Python GameLevel.by_id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.GameLevel.GameLevel的用法示例。


在下文中一共展示了GameLevel.by_id方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: success_capture

# 需要導入模塊: from models.GameLevel import GameLevel [as 別名]
# 或者: from models.GameLevel.GameLevel import by_id [as 別名]
    def success_capture(self, flag, old_reward=None):
        if self.config.teams:
            teamval = "team's "
        else:
            teamval = ""
        user = self.get_current_user()
        old_reward = flag.value if old_reward is None else old_reward
        reward_dialog = flag.name + " answered correctly. "
        if self.config.banking:
            reward_dialog += "$" + str(old_reward) + " has been added to your " + teamval + "account."
        else:
            reward_dialog += str(old_reward) + " points added to your " + teamval + "score."
        success = [reward_dialog]

        # Check for Box Completion
        boxcomplete = True
        box = flag.box
        for boxflag in box.flags:
            if not boxflag in user.team.flags:
                boxcomplete = False
                break
        if boxcomplete:
            success.append("Congratulations! You have completed " + box.name + ".")

        # Check for Level Completion
        level = GameLevel.by_id(box.game_level_id)
        level_progress = len(user.team.level_flags(level.number)) /  float(len(level.flags))
        if level_progress == 1.0 and level not in user.team.game_levels:
            reward_dialog = ""
            if level._reward > 0:
                user.team.money += level._reward
                self.dbsession.add(user.team)
                self.dbsession.flush()
                self.dbsession.commit()
                if self.config.banking:
                    reward_dialog += "$" + str(level._reward) + " has been added to your " + teamval + "account."
                else:
                    reward_dialog += str(level._reward) + " points added to your " + teamval + "score."
            success.append("Congratulations! You have completed " + str(level.name) + ". " + reward_dialog)

        # Unlock next level if based on Game Progress
        next_level = GameLevel.by_id(level.next_level_id)
        if next_level and next_level._type == "progress" and level_progress * 100 >= next_level.buyout and next_level not in user.team.game_levels:
            logging.info("%s (%s) unlocked %s" % (
                    user.handle, user.team.name, next_level.name
                ))
            user.team.game_levels.append(next_level)
            self.dbsession.add(user.team)
            self.dbsession.commit()
            self.event_manager.level_unlocked(user, next_level)
            success.append("Congratulations! You have unlocked " + str(next_level.name))
        
        return success
開發者ID:moloch--,項目名稱:RootTheBox,代碼行數:55,代碼來源:MissionsHandler.py

示例2: to_dict

# 需要導入模塊: from models.GameLevel import GameLevel [as 別名]
# 或者: from models.GameLevel.GameLevel import by_id [as 別名]
 def to_dict(self):
     ''' Returns editable data as a dictionary '''
     corp = Corporation.by_id(self.corporation_id)
     game_level = GameLevel.by_id(self.game_level_id)
     return {
         'name': self.name,
         'uuid': self.uuid,
         'corporation': corp.uuid,
         'description': self._description,
         'difficulty': self.difficulty,
         'game_level': game_level.uuid,
     }
開發者ID:AdaFormacion,項目名稱:RootTheBox,代碼行數:14,代碼來源:Box.py

示例3: to_dict

# 需要導入模塊: from models.GameLevel import GameLevel [as 別名]
# 或者: from models.GameLevel.GameLevel import by_id [as 別名]
 def to_dict(self):
     ''' Returns editable data as a dictionary '''
     corp = Corporation.by_id(self.corporation_id)
     game_level = GameLevel.by_id(self.game_level_id)
     cat = Category.by_id(self.category_id)
     if cat:
         category = cat.uuid
     else:
         category = ""
     return {
         'name': self.name,
         'uuid': self.uuid,
         'corporation': corp.uuid,
         'category': category,
         'operating_system': self.operating_system,
         'description': self._description,
         'difficulty': self.difficulty,
         'game_level': game_level.uuid,
         'flag_submission_type': self.flag_submission_type,
         'flaglist': self.flaglist(self.id)
     }
開發者ID:moloch--,項目名稱:RootTheBox,代碼行數:23,代碼來源:Box.py

示例4: game_level

# 需要導入模塊: from models.GameLevel import GameLevel [as 別名]
# 或者: from models.GameLevel.GameLevel import by_id [as 別名]
 def game_level(self):
     return GameLevel.by_id(self.game_level_id)
開發者ID:brutalhonesty,項目名稱:RootTheBox,代碼行數:4,代碼來源:Box.py


注:本文中的models.GameLevel.GameLevel.by_id方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。