Пример #1
0
def get_score(request, game_name):
    g = Game.objects.filter(name=game_name)[0]
    ranking = []
    for rank in g.ranking:
        try:
            ranking.append({'name': rank['profile'].username,'score':rank['score']})
        except:
            pass #no existe el jugador
    return json_to_response(ranking)
Пример #2
0
def set_score(request, game_name):
    play = get_object_or_404(SavedPlay, pk=request.session['current_play_id_for_%s' % game_name])
    if request.user.is_authenticated():
        user = get_object_or_404(Profile, username=request.user.profile.username)
        state = simplejson.JSONDecoder().decode(user.current_state)
        state[game_name] = request.GET.getlist('state')
        user.current_state = simplejson.dumps(state)
        user.save()
    if play.score < int(request.GET['score']):
        play.score = request.GET['score']
        play.save()
    return json_to_response({'status':200})
Пример #3
0
def log_action(request, game_name):
    play = get_object_or_404(SavedPlay, pk=request.session['current_play_id_for_%s' % game_name])
    
    log = request.POST.get('log','')
    for line in StringIO(log.encode('utf-8')):
        ev = simplejson.JSONDecoder().decode(line)
        entry = LogEntry(savedplay=play, type=ev['type'],
                         ms=ev['time'], order=ev['order'], _data='')
        entry.data = ev['data']
        entry.save()
    
    return json_to_response({'status':200})
Пример #4
0
def new_play(request, game_name):
    profile = request.user.profile if request.user.is_authenticated() else None
    obj = SavedPlay.objects.create(profile = profile, ip = request.META['REMOTE_ADDR'],
                                   game = request.game, score = 0)
    request.session['current_play_id_for_%s' % game_name] = obj.id
    return json_to_response({'play_id': obj.id})
Пример #5
0
def school_end_stage(request,game_name):
    user = get_object_or_404(Profile, username=request.user.profile.username)
    user.last_session_date = date.today()
    user.current_school_game = user.current_school_game+1
    user.save()
    return json_to_response({'status':200})