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


Python Match.make_unique_gamename方法代码示例

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


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

示例1: newgame

# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import make_unique_gamename [as 别名]
def newgame():
    """Create new game from request. Commit new game to db, save to fold.

    Form Parameters:
        name: new game name
        player{1,2,..}: players to add (e.g. /newgame?player1=joe&player2=sally)
        add_gems: gems to add to default (e.g. rgbbb)

    If game exists, redirect to game with that name.
    """
    # PARSE FORM INPUTS
    args = request.form or request.args
    suggested_name = args.get('game') or 'default' #TODO make default name
    name = Match.make_unique_gamename(suggested_name)
    players = [player for k, player in args.items() if 'player' in k and player]
    add_gems = args.get('add_gems') or ""
    # MAKE SURE PLAYERS EXIST
    users = []
    for pname in players:
        u = User.query.filter_by(nickname=pname).first()
        if not u: return "invalid player name, %s"%pname  #TODO better error handling
        else: users.append(u)
    # Get ongoing match names
    active_matches = [m.name for m in Match.query.filter_by(is_active=True)]
    if name not in active_matches:
        print players
        print type(players)
        # create game
        args = pickle.load(open('game_args.pickle', 'rb'))
        G = MutableGame(*args)
        G.start(players, add_gems)
        # create db entry
        m = Match(name=name, is_active=True, creator=g.user.id, game=G, summary=str(G))
        m.players.extend(users)
        db.session.add(m)
        db.session.commit()
        # save initial copy of game and add to game dict
        #G.save(savedir + '/' + name)

    return redirect('/game/%s'%name)
开发者ID:machow,项目名称:splendid-serv,代码行数:42,代码来源:views.py


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