TBG.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:ThatBeanGame 作者: tuchfarber 项目源码 文件源码
def create_new_game():
    '''Creates new player and game, returns game id'''
    post_data: Dict = request.get_json()
    try:
        player: Player = Player(post_data['name'])
    except KeyError:
        abort(400, util.error('Name not supplied'))

    try:
        game_type: str = post_data['game_type']
    except KeyError:
        abort(400, util.error('Game type not supplied'))
    if game_type not in ('public', 'private'):
        abort(400, util.error('Invalid game type parameter'))

    game: Game = Game(game_type)
    game.add_player(player)
    games[game.id] = game
    clients[player.token] = game.id
    response = make_response(jsonify({'game': game.id}))
    response.set_cookie('tbg_token', player.token, max_age=6000)
    return response
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号