本文整理汇总了Python中models.GameLevel.GameLevel类的典型用法代码示例。如果您正苦于以下问题:Python GameLevel类的具体用法?Python GameLevel怎么用?Python GameLevel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GameLevel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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), ])
示例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)
示例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), ])
示例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), ])
示例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), ])
示例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
示例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)
示例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"]
)
示例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')
示例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")
示例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."]
)
示例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,
}
示例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
示例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")
示例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)