Exemple #1
0
def nonlinear_coordination(request, quest):
    player = request.user
    if request.method == 'POST':
        mission = get_object_or_404(Mission, pk=request.POST['mission_id'])
        if quest.started and not quest.is_game_over and not mission.is_completed(player):
            form = KeyForm(request.POST, quest=quest)
            if form.is_valid():
                key = form.cleaned_data["key"]
                right_key = mission.key
                is_right = len(right_key) > 0 and right_key == key
                keylog = Keylog(key=key, fix_time=timezone.now(), player=player,
                                mission=mission, is_right=is_right)
                if is_right:
                    keylog.points = mission.points
                keylog.save()
        if mission.order_number > 1:
            url = '{0}#m{1}'.format(resolve_url('coordination:quest_coordination', quest_id=quest.id),
                                    mission.order_number - 1)
        else:
            url = resolve_url('coordination:quest_coordination', quest_id=quest.id)
        return redirect(url)
    else:
        rest_quest = None
        missions = None
        mission_start = None
        mission_finish = None
        display_hints = None
        rest_hints = None
        form = None
        if quest.not_started:
            mission_start = quest.start_mission()
        else:
            if quest.started and not quest.is_game_over:
                rest_quest = get_timedelta(quest.game_over)
            form = KeyForm(quest=quest)
            count = 0
            missions = quest.missions().filter(order_number__gt=0, is_finish=False)
            for mission in missions:
                mission.wrong_keys = Keylog.wrong_keylogs_format(player, mission)
                is_completed = mission.is_completed(request.user)
                mission.is_completed = is_completed
                if not is_completed:
                    count += 1
            if missions and count == 0 or quest.is_game_over or quest.ended:
                mission_finish = quest.finish_mission()
            display_hints, rest_hints = Mission.hints_in_nl(quest, missions)
        points = Keylog.total_points(quest, player)
        messages = quest.messages().filter(is_show=True)
        context = {'quest': quest, 'messages': messages, 'missions': missions, 'mission_finish': mission_finish,
                   'mission_start': mission_start, 'rest_quest': rest_quest, 'points': points, 'form': form,
                   'display_hints': display_hints, 'rest_hints': rest_hints}
        return render(request, 'coordination/quests/coordination/nonlinear.html', context)
Exemple #2
0
def multilinear_coordination(request, quest):
    player = request.user
    if request.method == 'POST':
        mission = get_object_or_404(Mission, pk=request.POST['mission_id'])
        if quest.started and not quest.is_game_over and not mission.is_completed(player):
            form = KeyForm(request.POST, quest=quest)
            if form.is_valid():
                key = form.cleaned_data["key"]
                right_key = mission.key
                is_right = len(right_key) > 0 and right_key == key
                keylog = Keylog(key=key, fix_time=timezone.now(), player=player, mission=mission, is_right=is_right)
                if is_right:
                    keylog.points = mission.points
                    line = mission.quest
                    next_mission = Mission.objects.filter(quest=line, order_number=mission.order_number + 1).first()
                    current_mission = get_object_or_404(CurrentMission, mission__quest=line, player=player)
                    current_mission.mission = next_mission
                    current_mission.start_time = keylog.fix_time
                    current_mission.save()
                keylog.save()
        url = '{0}#m{1}'.format(resolve_url('coordination:quest_coordination', quest_id=quest.id), mission.id)
        return redirect(url)
    else:
        rest_quest = None
        lines = None
        mission_start = None
        mission_finish = None
        form = None
        if quest.not_started:
            mission_start = quest.start_mission()
        else:
            if quest.started and not quest.is_game_over:
                rest_quest = get_timedelta(quest.game_over)
            form = KeyForm(quest=quest)
            lines = quest.lines()
            for line in lines:
                current_mission = get_object_or_404(CurrentMission, mission__quest=line, player=player)
                line.mission = current_mission.mission
            if quest.is_game_over or quest.ended:
                mission_finish = quest.finish_mission()
        points = Keylog.total_points(quest, player)
        messages = quest.messages().filter(is_show=True)
        context = {'quest': quest, 'messages': messages, 'lines': lines, 'mission_finish': mission_finish,
                   'mission_start': mission_start, 'rest_quest': rest_quest, 'points': points, 'form': form}
        return render(request, 'coordination/quests/coordination/multilinear.html', context)