예제 #1
0
파일: api.py 프로젝트: yanske/ScavengerHunt
def game_info():
    print "Getting game info"
    try:
        game_id = request.args.get('game_id')
        return jsonify({
            'data': Game.get_by_key(game_id).serialize_objectives(),
            'status': 200
        })
    except:
        return getErrorJson(sys.exc_info())
예제 #2
0
def disconnect():
    player = Player.get_by_id(request.sid)
    if player:
        print player.name, "disconnected.", request.sid
        if player.active:
            game = Game.get_by_key(player.game_key)
            print "Deactivating player"
            game.deactivate_player(player)
    else:
        print "Someone disconnected", request.sid
예제 #3
0
def rank():
    player = Player.get_by_id(request.sid)
    print player.name, "requested its rank."

    game = Game.get_by_key(player.game_key)
    rank = game.get_player_rank(player)

    emit('rank',
         {'data': {
             'rank': rank,
             'num players': len(game.player_list())
         }})
예제 #4
0
파일: api.py 프로젝트: yanske/ScavengerHunt
def end_game():
    print "Ending game"

    try:
        data = json.loads(request.data)
        print data
        name = data['game_id']
        game = Game.get_by_key(game_id)
        game.end()

        return jsonify({'status': 200})

    except:
        return getErrorJson(sys.exc_info())
예제 #5
0
파일: api.py 프로젝트: yanske/ScavengerHunt
def start_game():
    print 'Starting game'

    try:
        data = json.loads(request.data)
        print data
        name = data['game_id']
        game = Game.get_by_key(game_id)
        game.start()

        return jsonify({'status': 200})

    except:
        return getErrorJson(sys.exc_info())
예제 #6
0
파일: api.py 프로젝트: yanske/ScavengerHunt
def delete_objective():
    print "Deleting objective"

    try:
        data = json.loads(request.data)
        print data
        game_id = data['game_id']
        game = Game.get_by_key(game_id)

        game.delete_objective(data['objective_id'])

        return jsonify({'status': 200})

    except:
        return getErrorJson(sys.exc_info())
예제 #7
0
def rank(message):
    player = Player.get_by_id(request.sid)
    print player.name, "completed an objective: ", message

    game = Game.get_by_key(player.game_key)
    print "game:", game.name
    objective = Objective.get_by_id(message['data']['objectiveId'])
    print "completing: ", objective.name

    if player.id in objective.players_completed:
        print "Player ", player.name, "is trying to complete objective", objective.name, "twice!"
        return

    time = message['data']['time']
    pic_url = message['data']['url']

    game.player_complete_objective(player, objective, time, pic_url)
    print "Process completed objective"
예제 #8
0
파일: api.py 프로젝트: yanske/ScavengerHunt
def add_objective():
    print 'Adding objective'

    try:
        data = json.loads(request.data)
        print data
        game_id = data['game_id']
        game = Game.get_by_key(game_id)

        name = data['objective']['name']
        description = data['objective']['description']
        location = data['objective']['location']
        objective = game.add_objective(location, name, description)

        return jsonify({'status': 200, 'id': objective.id})

    except:
        return getErrorJson(sys.exc_info())
예제 #9
0
파일: api.py 프로젝트: yanske/ScavengerHunt
def game_stats():
    print "Getting game stats"

    try:
        data = json.loads(request.data)
        print data
        game_id = data['game_id']
        game = Game.get_by_key(game_id)

        objective_stats = []
        for objective in game.objective_list():
            players_complete = [{
                'id': player_id,
                'name': Player.get_by_id(player_id).name
            } for player_id in objective.players_completed]

            objective_stats.append({
                'id': objective.id,
                'name': objective.name,
                'players_complete': players_complete
            })

        player_stats = []
        for player in game.player_list():
            player_info = player.serialize()
            player_info['rank'] = game.get_player_rank(player)
            player_stats.append(player_info)

        return jsonify({
            'data': {
                'objective_stats': objective_stats,
                'player_stats': player_stats
            },
            'status': 200
        })

    except:
        return getErrorJson(sys.exc_info())