Example #1
0
def game_board (gameId):
    memberIds = []



    msg = GameInfoRequest()
    msg.gameId = gameId
    try:
        game_info_response = gameservice.send(msg)
        if isinstance(game_info_response, GameError):
            return jsonify(result=(game_info_response.description, game_info_response.code))
        else:
            for player in game_info_response.game.players:
                if player.userId != session['userId']:
                    memberIds.append(player.userId)
            multiple_player_response = userservice.get_multiple_users(GetMultipleUsersRequest(userIds=memberIds))
            if (isinstance(multiple_player_response, GetMultipleUsersResponse)):
                print multiple_player_response
                pass

            # return jsonify({ "gameId" : game_info_response.game.gameId,
            #                  "players" : [ { "userId" : player.userId,
            #                                 "state" : player.state,
            #                                 "x" : player.x,
            #                                 "y" : player.y,
            #                                 "question" : player.question,
            #                                 "alternatives" : [a for a in player.alternatives],
            #                                 "answeredCorrectly" : player.answeredCorrectly } for player in game_info_response.game.players ],
            #                  "board" : [b for b in game_info_response.game.board ]
            #               })
    except TimeoutError as e:
        return jsonify(result = "Timeout")

    return render_template('game_board.html',friends=list(multiple_player_response.users), gameId=gameId, userId=session['userId'])
Example #2
0
def game_info():
    print "game info "
    gameId = request.form.get('gameId',0, type=int)
    msg = GameInfoRequest()
    msg.gameId = gameId
    try:
        game_info_response = gameservice.send(msg)
        if isinstance(game_info_response, GameError):
            return jsonify(result=(game_info_response.description, game_info_response.code))
        else:
            return jsonify({ "gameId" : game_info_response.game.gameId,
                             "players" : [ { "userId" : player.userId,
                                            "state" : player.state,
                                            "x" : player.x,
                                            "y" : player.y,
                                            "score": player.score,
                                            #"question" : player.question,
                                            #"alternatives" : [a for a in player.alternatives],
                                            "answeredCorrectly" : player.answeredCorrectly } for player in game_info_response.game.players ],
                             "board" : [b for b in game_info_response.game.board ]
                          })
    except TimeoutError as e:
        return jsonify(result = "Timeout")