Beispiel #1
0
def click_mine_interact(request):
#     data_dict = {}
    user = request.user;
    userProfile = UserProfile.objects.get(user= user)
    
    mine_index = request.POST.get('mine_index')
    mine_index = int(mine_index)
    panel_id = request.POST.get('panel_id')
    panel_id = int(panel_id)
    panel = Panel.objects.get(pk = panel_id)
    progress = panel.progress

    progress = progress[0:mine_index] + '1' + progress[mine_index+1:]
    panel.progress = progress
    panel.save()


    rows = panel.game.columns
    
    log = Log()
    log.game = panel.game
    log.group = panel.group
    log.panel = panel
    log.action = '\"Click (%d, %d)\"' % (mine_index/rows, mine_index % rows)  
    log.action_time = datetime.now()
    log.user_profile = userProfile
    log.save()
    
    response_data={}
    game = panel.game
    response_data['rowses'] = game.rows
    response_data['columns'] = game.columns
    response_data['progress'] = panel.progress
    response_data['wait_time'] = game.wait_time

    return HttpResponse(json.dumps(response_data), mimetype="application/json")
Beispiel #2
0
def switch_view(request, panel_id):
    data_dict = {}
    user = request.user;
    userProfile = UserProfile.objects.get(user= user)
    panel_id = int(panel_id)
    panel = Panel.objects.get(pk = panel_id)
    session_id = panel.session
    group_id = panel.group.id
    
    
    group_name = panel.group.name
    panel_name = panel.name
    
    game = panel.game
    count = 0
    for tmp in panel.progress:
        if tmp == '1':
            count += 1
    cost = utils.cost(game.switch_cost)
    if count < cost:
        #cannot switch
        log = Log()
        log.game = game
        log.group = panel.group
        log.panel = panel
        log.user_profile = userProfile
        log.action = '\"Switch failed, Not enough credit\"'
        log.action_time = datetime.now()
        log.save()
        data_dict['panel_id'] = panel_id 
        nextUrl = reverse('mine.views.mine_field_view', args=(panel_id,))
        return HttpResponseRedirect(nextUrl)
    else:
        log = Log()
        log.game = game
        log.group = panel.group
        log.panel = panel
        log.user_profile = userProfile
        log.action = '\"Go to Switch page, cost %s\"' % cost
        log.action_time = datetime.now()
        log.save()
        
    #cost
    index = 0
    for s in panel.progress:
        if cost == 0:
            break
        if s == '1':
            cost -= 1
        index += 1
        
    panel.progress = '0'*(index+1) + panel.progress[index+1:]
    panel.save()
    
    panels = Panel.objects.filter(group__id = group_id, session = session_id)
    panel_id_status_dict={}
    for panel in panels:
        progress = panel.progress
        count = 0
        for s in progress:
            if s == '1':
                count +=1
        
        panel_id_status_dict[panel.id] = {'current': count, 'total': len(progress), 'panel_name': panel.name}
    panel_id_status_json = json.dumps(panel_id_status_dict)
    data_dict['panel_id_status_json'] = panel_id_status_json
    data_dict['panel_id'] = panel_id
    
    data_dict['group_name'] = group_name
    data_dict['panel_name'] = panel_name
    
    return render(request, 'switch.html', data_dict)