Example #1
0
def activate_game(gpk):
    game = Game.objects.get(pk=gpk)
    print '## Activating Game %s with ID %s ##' %(game.name,game.id)
    terms = Term.objects.filter(Q(genres__genre_name__in=[str(g.genre_name) for g in game.genres.all()]))
    t = terms[0]
    c = t.clues.all().order_by('clue_number')[0]
    AT = Active_Turn(active=True,game=game,clue=c)
    AT.save()
    user_games = Player_Game.objects.filter(Q(game__id=gpk))
    for user_game in user_games:
        turn = Turn(player_game=user_game,active_turn=AT)
        turn.save()
Example #2
0
def submit(request,gpk,ppk):
    if request.method=="POST":
        game = Game.objects.get(pk=gpk)
        player_games = Player_Game.objects.filter(Q(game__id=gpk,player__id=ppk))
        if len(player_games)>0:
            player_game = player_games[0]
            player_turn = Turn.objects.filter(Q(active_turn__active=True, player_game__player__id=ppk, player_game__game__id=gpk))[0]
            player_turn.guess = 'PASS' if request.POST.has_key('pass') else request.POST['answer']
            player_was_correct = player_turn.guess == player_turn.active_turn.clue.term.term_content
            print '## The Player Guessed %s for the term %s ##' % (player_turn.guess,player_turn.active_turn.clue.term.term_content,)
            player_turn.save()
            all_have_played = player_turn.active_turn.all_have_played()
            print '## All the players have played ##' if all_have_played else '## Still waiting on players ##'
            has_right_answer =  player_turn.active_turn.has_right_answer()
            if has_right_answer:
                print '## Someone got the answer right ##'
            else:
                print '## No one got the answer right ##'
            if all_have_played:
                clue = None
                if has_right_answer:
                    print '## We need a new term ##'
                else:
                    print '## We need a new clue ##'
                    clue = player_turn.active_turn.clue.get_next()
                if not clue:
                    print '## The term have no clues left ##'
                    clue = get_next_term(gpk)
                    if not clue:
                        game.active = False
                        game.save()
                        return HttpReponse("There were no more terms in the database")
                AT = player_turn.active_turn
                AT.active = False
                AT.save()
                AT = Active_Turn(game=game,clue = clue,active=True)
                AT.clue = clue
                AT.save()
                user_games = Player_Game.objects.filter(Q(game__id=gpk))
                for ug in user_games:
                    turn = Turn(player_game = ug, active_turn=AT)
                    turn.save()

            active_games   = Game.objects.filter(Q(active=True,player_game__accepted=True, player_game__player__id=ppk,player_game__turn__active_turn__active=True,player_game__turn__guess=None))
            inactive_games = Game.objects.filter(Q(active=False,player_game__accepted=True, player_game__player__id=ppk)|Q(active=True,player_game__accepted=True,player_game__player__id=ppk,player_game__turn__active_turn__active=True,player_game__turn__guess__isnull=False))
            new_games      = Game.objects.filter(Q(active__exact=False,player_game__player__id=ppk,player_game__accepted=False,player_game__declined=False))
            return render(request,'player/detail.html',{'message':('You were correct' if player_was_correct else 'You were incorrect'),'active_games':active_games,'inactive_games':inactive_games,'new_games':new_games})
        else:
            return HttpResponse("Something went wrong.  There were %s player_games found in the database for player %s" %(len(player_games),ppk))
    else:
        return HttpResponseRedirect("/game/%s/player/%s/" % (gpk,ppk,))
Example #3
0
def activate_game(gpk):
    game = Game.objects.get(pk=gpk)
    print '## Activating Game %s with ID %s ##' % (game.name, game.id)
    terms = Term.objects.filter(
        Q(genres__genre_name__in=[
            str(g.genre_name) for g in game.genres.all()
        ]))
    t = terms[0]
    c = t.clues.all().order_by('clue_number')[0]
    AT = Active_Turn(active=True, game=game, clue=c)
    AT.save()
    user_games = Player_Game.objects.filter(Q(game__id=gpk))
    for user_game in user_games:
        turn = Turn(player_game=user_game, active_turn=AT)
        turn.save()
Example #4
0
def submit(request, gpk, ppk):
    if request.method == "POST":
        game = Game.objects.get(pk=gpk)
        player_games = Player_Game.objects.filter(
            Q(game__id=gpk, player__id=ppk))
        if len(player_games) > 0:
            player_game = player_games[0]
            player_turn = Turn.objects.filter(
                Q(active_turn__active=True,
                  player_game__player__id=ppk,
                  player_game__game__id=gpk))[0]
            player_turn.guess = 'PASS' if request.POST.has_key(
                'pass') else request.POST['answer']
            player_was_correct = player_turn.guess == player_turn.active_turn.clue.term.term_content
            print '## The Player Guessed %s for the term %s ##' % (
                player_turn.guess,
                player_turn.active_turn.clue.term.term_content,
            )
            player_turn.save()
            all_have_played = player_turn.active_turn.all_have_played()
            print '## All the players have played ##' if all_have_played else '## Still waiting on players ##'
            has_right_answer = player_turn.active_turn.has_right_answer()
            if has_right_answer:
                print '## Someone got the answer right ##'
            else:
                print '## No one got the answer right ##'
            if all_have_played:
                clue = None
                if has_right_answer:
                    print '## We need a new term ##'
                else:
                    print '## We need a new clue ##'
                    clue = player_turn.active_turn.clue.get_next()
                if not clue:
                    print '## The term have no clues left ##'
                    clue = get_next_term(gpk)
                    if not clue:
                        game.active = False
                        game.save()
                        return HttpReponse(
                            "There were no more terms in the database")
                AT = player_turn.active_turn
                AT.active = False
                AT.save()
                AT = Active_Turn(game=game, clue=clue, active=True)
                AT.clue = clue
                AT.save()
                user_games = Player_Game.objects.filter(Q(game__id=gpk))
                for ug in user_games:
                    turn = Turn(player_game=ug, active_turn=AT)
                    turn.save()

            active_games = Game.objects.filter(
                Q(active=True,
                  player_game__accepted=True,
                  player_game__player__id=ppk,
                  player_game__turn__active_turn__active=True,
                  player_game__turn__guess=None))
            inactive_games = Game.objects.filter(
                Q(active=False,
                  player_game__accepted=True,
                  player_game__player__id=ppk)
                | Q(active=True,
                    player_game__accepted=True,
                    player_game__player__id=ppk,
                    player_game__turn__active_turn__active=True,
                    player_game__turn__guess__isnull=False))
            new_games = Game.objects.filter(
                Q(active__exact=False,
                  player_game__player__id=ppk,
                  player_game__accepted=False,
                  player_game__declined=False))
            return render(
                request, 'player/detail.html', {
                    'message': ('You were correct' if player_was_correct else
                                'You were incorrect'),
                    'active_games':
                    active_games,
                    'inactive_games':
                    inactive_games,
                    'new_games':
                    new_games
                })
        else:
            return HttpResponse(
                "Something went wrong.  There were %s player_games found in the database for player %s"
                % (len(player_games), ppk))
    else:
        return HttpResponseRedirect("/game/%s/player/%s/" % (
            gpk,
            ppk,
        ))