• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python GameLevel.GameLevel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中models.GameLevel.GameLevel的典型用法代码示例。如果您正苦于以下问题:Python GameLevel类的具体用法?Python GameLevel怎么用?Python GameLevel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: create_team

    def create_team(self):
        ''' Admins can create teams manually '''
        try:
            name = self.get_argument('team_name', '')
            if Team.by_name(name) is not None:
                raise ValidationError("Team already exists")
            team = Team()
            team.name = self.get_argument('team_name', '')
            team.motto = self.get_argument('motto', '')
            if not self.config.banking:
                team.money = 0
            level_0 = GameLevel.by_number(0)
            if not level_0:
                level_0 = GameLevel.all()[0]
            team.game_levels.append(level_0)
            self.dbsession.add(team)
            self.dbsession.commit()

            # Avatar
            avatar_select = self.get_argument('team_avatar_select', '')
            if avatar_select and len(avatar_select) > 0:
                team._avatar = avatar_select
            elif hasattr(self.request, 'files') and 'avatar' in self.request.files:
                team.avatar = self.request.files['avatar'][0]['body']
            self.dbsession.add(team)
            self.dbsession.commit()
            self.redirect('/admin/users')
        except ValidationError as error:
            self.render("admin/create/team.html", errors=[str(error), ])
开发者ID:moloch--,项目名称:RootTheBox,代码行数:29,代码来源:AdminGameObjectHandlers.py


示例2: edit_game_level

 def edit_game_level(self):
     ''' Update game level objects '''
     errors = []
     level = GameLevel.by_uuid(self.get_argument('uuid'))
     try:
         new_number = int(self.get_argument('number', ''))
         new_buyout = int(self.get_argument('buyout', ''))
         if level.number != new_number and GameLevel.by_number(new_number) is None:
             level.number = new_number
             self.dbsession.add(level)
             # Fix the linked-list
             game_levels = sorted(GameLevel.all())
             index = 0
             for game_level in game_levels[:-1]:
                 game_level.next_level_id = game_levels[index + 1].id
                 self.dbsession.add(game_level)
                 index += 1
             game_levels[0].number = 0
             self.dbsession.add(game_levels[0])
             game_levels[-1].next_level_id = None
             self.dbsession.add(game_levels[-1])
         if GameLevel.by_number(new_number) is not None:
             errors.append("GameLevel number is not unique")
         if level.buyout != new_buyout:
             level.buyout = new_buyout
             self.dbsession.add(level)
         self.dbsession.commit()
     except ValueError:
         errors.append("That was not a number ...")
     self.render("admin/view/game_levels.html", errors=errors)
开发者ID:AdaFormacion,项目名称:RootTheBox,代码行数:30,代码来源:AdminHandlers.py


示例3: create_game_level

 def create_game_level(self):
     '''
     Creates a new level in the database, the levels are basically a
     linked-list where each level points to the next, and the last points to
     None.  This function creates a new level and sorts everything based on
     the 'number' attrib
     '''
     try:
         new_level = GameLevel()
         new_level.number = self.get_argument('level_number', '')
         new_level.buyout = self.get_argument('buyout', 0)
         new_level.name = self.get_argument('name', None)
         new_level._type = self.get_argument('type', 'buyout')
         new_level._reward = self.get_argument('reward', 0)
         if new_level._type == "progress":
             new_level.buyout = min(new_level.buyout, 100)
         elif new_level._type == "none":
             new_level.buyout = 0
         if new_level._type != "none" and new_level.buyout == 0:
             new_level._type = "none"
         self.dbsession.add(new_level)
         self.dbsession.flush()
         game_levels = sorted(GameLevel.all())
         for index, level in enumerate(game_levels[:-1]):
             level.next_level_id = game_levels[index + 1].id
             self.dbsession.add(level)
         if game_levels[0].number != 0:
             game_levels[0].number = 0
         self.dbsession.add(game_levels[0])
         game_levels[-1].next_level_id = None
         self.dbsession.add(game_levels[-1])
         self.dbsession.commit()
         self.redirect('/admin/view/game_levels')
     except ValidationError as error:
         self.render('admin/create/game_level.html', errors=[str(error), ])
开发者ID:moloch--,项目名称:RootTheBox,代码行数:35,代码来源:AdminGameObjectHandlers.py


示例4: edit_game_level

 def edit_game_level(self):
     ''' Update game level objects '''
     try:
         level = GameLevel.by_uuid(self.get_argument('uuid', ''))
         if level is None:
             raise ValidationError("Game level does not exist")
         if int(self.get_argument('number', level.number)) != level.number:
             level.number = self.get_argument('number')
         level.buyout = self.get_argument('buyout', '1')
         self.dbsession.add(level)
         self.dbsession.flush()
         # Fix the linked-list
         game_levels = sorted(GameLevel.all())
         for index, game_level in enumerate(game_levels[:-1]):
             game_level.next_level_id = game_levels[index + 1].id
             self.dbsession.add(game_level)
         if game_levels[0].number != 0:
             game_levels[0].number = 0
         self.dbsession.add(game_levels[0])
         game_levels[-1].next_level_id = None
         self.dbsession.add(game_levels[-1])
         self.dbsession.add(level)
         self.dbsession.commit()
         self.redirect('/admin/view/game_levels')
     except ValueError:
         raise ValidationError("That was not a number ...")
     except ValidationError as error:
         self.render("admin/view/game_levels.html", errors=[str(error), ])
开发者ID:jinghli,项目名称:RootTheBox,代码行数:28,代码来源:AdminGameObjectHandlers.py


示例5: create_box

 def create_box(self):
     ''' Create a box object '''
     try:
         game_level = self.get_argument('game_level', '')
         corp_uuid = self.get_argument('corporation_uuid', '')
         if Box.by_name(self.get_argument('name', '')) is not None:
             raise ValidationError("Box name already exists")
         elif Corporation.by_uuid(corp_uuid) is None:
             raise ValidationError("Corporation does not exist")
         elif GameLevel.by_number(game_level) is None:
             raise ValidationError("Game level does not exist")
         else:
             corp = Corporation.by_uuid(corp_uuid)
             level = GameLevel.by_number(game_level)
             box = Box(corporation_id=corp.id, game_level_id=level.id)
             box.name = self.get_argument('name', '')
             box.description = self.get_argument('description', '')
             box.autoformat = self.get_argument('autoformat', '') == 'true'
             box.difficulty = self.get_argument('difficulty', '')
             self.dbsession.add(box)
             self.dbsession.commit()
             if hasattr(self.request, 'files') and 'avatar' in self.request.files:
                 box.avatar = self.request.files['avatar'][0]['body']
             self.dbsession.commit()
             self.redirect('/admin/view/game_objects')
     except ValidationError as error:
         self.render('admin/create/box.html', errors=[str(error), ])
开发者ID:jinghli,项目名称:RootTheBox,代码行数:27,代码来源:AdminGameObjectHandlers.py


示例6: success_capture

    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,代码行数:53,代码来源:MissionsHandler.py


示例7: export_game_objects

 def export_game_objects(self, root):
     '''
     Exports the game objects to an XML doc.
     For the record, I hate XML with a passion.
     '''
     levels_elem = ET.SubElement(root, "gamelevels")
     levels_elem.set("count", str(GameLevel.count()))
     for level in GameLevel.all()[1:]:
         level.to_xml(levels_elem)
     corps_elem = ET.SubElement(root, "corporations")
     corps_elem.set("count", str(Corporation.count()))
     for corp in Corporation.all():
         corp.to_xml(corps_elem)
开发者ID:jinghli,项目名称:RootTheBox,代码行数:13,代码来源:AdminGameHandlers.py


示例8: buyout

 def buyout(self):
     ''' Buyout and unlock a level '''
     user = self.get_current_user()
     level = GameLevel.by_uuid(self.get_argument('uuid', ''))
     if level is not None and user is not None:
         if level.buyout <= user.team.money:
             logging.info("%s (%s) payed buyout for level #%d" % (
                 user.handle, user.team.name, level.number
             ))
             user.team.game_levels.append(level)
             user.team.money -= level.buyout
             self.dbsession.add(user.team)
             self.dbsession.commit()
             event = self.event_manager.create_unlocked_level_event(user, level)
             self.new_events.append(event)
             self.redirect("/user/missions")
         else:
             self.render("missions/view.html",
                 team=user.team,
                 errors=["You do not have enough money to unlock this level"]
             )
     else:
         self.render("missions/view.html",
             team=user.team,
             errors=["Level does not exist"]
         )
开发者ID:AdaFormacion,项目名称:RootTheBox,代码行数:26,代码来源:MissionsHandler.py


示例9: create_team

 def create_team(self):
     ''' Create a new team in the database '''
     team = Team()
     team.name = self.get_argument('team_name', '')
     team.motto = self.get_argument('motto', '')
     level_0 = GameLevel.all()[0]
     team.game_levels.append(level_0)
     self.dbsession.add(team)
     self.dbsession.commit()
     self.redirect('/admin/view/user_objects')
开发者ID:AdaFormacion,项目名称:RootTheBox,代码行数:10,代码来源:AdminHandlers.py


示例10: create_team

 def create_team(self):
     ''' Create a new team '''
     if self.config.public_teams:
         team = Team()
         team.name = self.get_argument('team_name', '')
         team.motto = self.get_argument('motto', '')
         level_0 = GameLevel.all()[0]
         team.game_levels.append(level_0)
         return team
     else:
         raise ValidationError("Public teams are not enabled")
开发者ID:WeiEast,项目名称:RootTheBox,代码行数:11,代码来源:PublicHandlers.py


示例11: del_game_level

 def del_game_level(self):
     ''' Deletes a game level, and fixes the linked list '''
     game_level = GameLevel.by_uuid(self.get_argument('uuid', ''))
     if game_level is not None:
         game_levels = sorted(GameLevel.all())
         game_levels.remove(game_level)
         for index, level in enumerate(game_levels[:-1]):
             level.next_level_id = game_levels[index + 1].id
             self.dbsession.add(level)
         if game_levels[0].number != 0:
             game_levels[0].number = 0
         self.dbsession.add(game_levels[0])
         game_levels[-1].next_level_id = None
         self.dbsession.add(game_levels[-1])
         self.dbsession.delete(game_level)
         self.dbsession.commit()
         self.redirect('/admin/view/game_levels')
     else:
         self.render('admin/view/game_levels.html',
                     errors=["Game level does not exist in database."]
                     )
开发者ID:moloch--,项目名称:RootTheBox,代码行数:21,代码来源:AdminGameObjectHandlers.py


示例12: to_dict

 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,代码行数:12,代码来源:Box.py


示例13: create_box

def create_box(corp=None):
    if corp is None:
        corp = create_corp()
    game_level = GameLevel.all()[0]
    box = Box(corporation_id=corp.id, game_level_id=game_level.id)
    box.name = "TestBox"
    box.description = "Some description"
    box.difficuly = "Easy"
    corp.boxes.append(box)
    dbsession.add(box)
    dbsession.commit()
    return box, corp
开发者ID:AdaFormacion,项目名称:RootTheBox,代码行数:12,代码来源:Helpers.py


示例14: create_team

 def create_team(self):
     ''' Create a new team '''
     if not self.config.teams:
         team = Team.by_name(self.get_argument('handle', ''))
         if team is None:
             team = Team()
             team.name = self.get_argument('handle', '')
         else:
             logging.info("Team %s already exists - Player Mode: reset team." % team.name)
             team.flags = []
             team.hints = []
             team.boxes = []
             team.items = []
             team.game_levels = []
             team.purchased_source_code = []
         team.motto = self.get_argument('motto', '')
         if self.config.banking:
             team.money = self.config.starting_team_money
         else:
             team.money = 0
         level_0 = GameLevel.by_number(0)
         if not level_0:
             level_0 = GameLevel.all()[0]
         team.game_levels.append(level_0)
         return team
     elif self.config.public_teams:
         if Team.by_name(self.get_argument('team_name', '')) is not None:
             raise ValidationError("This team name is already registered.  Use team code to join that team.")
         team = Team()
         team.name = self.get_argument('team_name', '')
         team.motto = self.get_argument('motto', '')
         if not self.config.banking:
             team.money = 0
         level_0 = GameLevel.by_number(0)
         if not level_0:
             level_0 = GameLevel.all()[0]
         team.game_levels.append(level_0)
         return team
     else:
         raise ValidationError("Public teams are not enabled")
开发者ID:moloch--,项目名称:RootTheBox,代码行数:40,代码来源:PublicHandlers.py


示例15: box_level

 def box_level(self):
     ''' Changes a boxs level '''
     errors = []
     box = Box.by_uuid(self.get_argument('box_uuid'))
     level = GameLevel.by_uuid(self.get_argument('level_uuid'))
     if box is not None and level is not None:
         box.game_level_id = level.id
         self.dbsession.add(box)
         self.dbsession.commit()
     elif box is None:
         errors.append("Box does not exist")
     elif level is None:
         errors.append("GameLevel does not exist")
     self.render("admin/view/game_levels.html", errors=errors)
开发者ID:AdaFormacion,项目名称:RootTheBox,代码行数:14,代码来源:AdminHandlers.py


示例16: _make_level

 def _make_level(self, level_number):
     '''
     Creates a new level in the database, the levels are basically a
     linked-list where each level points to the next, and the last points to
     None.  This function creates a new level and sorts everything based on
     the 'number' attrib
     '''
     new_level = GameLevel()
     new_level.number = level_number
     new_level.buyout = self.get_argument('buyout', '')
     game_levels = GameLevel.all()
     game_levels.append(new_level)
     game_levels = sorted(game_levels)
     index = 0
     for level in game_levels[:-1]:
         level.next_level_id = game_levels[index + 1].id
         self.dbsession.add(level)
         index += 1
     game_levels[0].number = 0
     self.dbsession.add(game_levels[0])
     game_levels[-1].next_level_id = None
     self.dbsession.add(game_levels[-1])
     self.dbsession.commit()
开发者ID:AdaFormacion,项目名称:RootTheBox,代码行数:23,代码来源:AdminHandlers.py


示例17: _make_box

 def _make_box(self, level_number):
     ''' Creates a box in the database '''
     corp = Corporation.by_uuid(self.get_argument('corporation_uuid'))
     level = GameLevel.by_number(level_number)
     box = Box(corporation_id=corp.id, game_level_id=level.id)
     box.name = self.get_argument('name', '')
     box.description = self.get_argument('description', '')
     box.autoformat = self.get_argument('autoformat', '') == 'true'
     box.difficulty = self.get_argument('difficulty', '')
     self.dbsession.add(box)
     self.dbsession.commit()
     if 'avatar' in self.request.files:
         box.avatar = self.request.files['avatar'][0]['body']
     return box
开发者ID:AdaFormacion,项目名称:RootTheBox,代码行数:14,代码来源:AdminHandlers.py


示例18: create_box

 def create_box(self):
     ''' Create a box object '''
     try:
         game_level = self.get_argument('game_level', '')
         corp_uuid = self.get_argument('corporation_uuid', '')
         if Box.by_name(self.get_argument('name', '')) is not None:
             raise ValidationError("Box name already exists")
         elif Corporation.by_uuid(corp_uuid) is None:
             raise ValidationError("Corporation does not exist")
         elif GameLevel.by_number(game_level) is None:
             raise ValidationError("Game level does not exist")
         else:
             corp = Corporation.by_uuid(corp_uuid)
             level = GameLevel.by_number(game_level)
             box = Box(corporation_id=corp.id, game_level_id=level.id)
             box.name = self.get_argument('name', '')
             box.description = self.get_argument('description', '')
             box.flag_submission_type = FlagsSubmissionType[self.get_argument('flag_submission_type','')]
             box.difficulty = self.get_argument('difficulty', '')
             box.operating_system = self.get_argument('operating_system', '?')
             cat = Category.by_uuid(self.get_argument('category_uuid', ''))
             if cat is not None:
                 box.category_id = cat.id
             else:
                 box.category_id = None
             # Avatar
             avatar_select = self.get_argument('box_avatar_select', '')
             if avatar_select and len(avatar_select) > 0:
                 box._avatar = avatar_select
             elif hasattr(self.request, 'files') and 'avatar' in self.request.files:
                 box.avatar = self.request.files['avatar'][0]['body']
             self.dbsession.add(box)
             self.dbsession.commit()
             self.redirect("/admin/view/game_objects#%s" % box.uuid)
     except ValidationError as error:
         self.render('admin/create/box.html', errors=[str(error), ])
开发者ID:moloch--,项目名称:RootTheBox,代码行数:36,代码来源:AdminGameObjectHandlers.py


示例19: create_game_level

 def create_game_level(self):
     ''' Creates a game level '''
     try:
         lvl = self.get_argument('level_number', '')
         game_level = abs(int(lvl)) if lvl.isdigit() else 0
         if GameLevel.by_number(game_level) is not None:
             self.render('admin/create/game_level.html',
                 errors=["Game level number must be unique"]
             )
         else:
             self._make_level(game_level)
             self.redirect('/admin/view/game_levels')
     except ValueError:
         self.render('admin/create/game_level.html',
             errors=["Invalid level number"]
         )
开发者ID:AdaFormacion,项目名称:RootTheBox,代码行数:16,代码来源:AdminHandlers.py


示例20: create_team

 def create_team(self):
     ''' Admins can create teams manually '''
     try:
         name = self.get_argument('team_name', '')
         motto = self.get_argument('motto', '')
         if Team.by_name(name) is not None:
             raise ValidationError("Team already exists")
         team = Team()
         team.name = self.get_argument('team_name', '')
         team.motto = self.get_argument('motto', '')
         level_0 = GameLevel.all()[0]
         self.dbsession.add(team)
         self.dbsession.commit()
         self.redirect('/admin/users')
     except ValidationError as error:
         self.render("admin/create/team.html", errors=[str(error), ])
开发者ID:AnarKyx01,项目名称:RootTheBox,代码行数:16,代码来源:AdminGameObjectHandlers.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python Team.Team类代码示例发布时间:2022-05-27
下一篇:
Python DAO.DAO类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap