Zwischenstand Lernmodus
This commit is contained in:
@@ -84,6 +84,13 @@ def create_game(request, quiz_id):
|
|||||||
game.quiz_id = quiz
|
game.quiz_id = quiz
|
||||||
game.host_id = game.generate_unique_id()
|
game.host_id = game.generate_unique_id()
|
||||||
game.save()
|
game.save()
|
||||||
|
|
||||||
|
participant = QuizGameParticipant()
|
||||||
|
participant.display_name = "DU"
|
||||||
|
participant.participant_id=game.host_id
|
||||||
|
participant.quiz_game = game
|
||||||
|
participant.score = 0 # Initialize score
|
||||||
|
participant.save()
|
||||||
|
|
||||||
response = HttpResponseRedirect(reverse('play:lobby', kwargs={'join_code': game.join_code}))
|
response = HttpResponseRedirect(reverse('play:lobby', kwargs={'join_code': game.join_code}))
|
||||||
response.set_cookie('host_id', game.host_id, max_age=3600)
|
response.set_cookie('host_id', game.host_id, max_age=3600)
|
||||||
|
|||||||
@@ -17,14 +17,19 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="grid grid-cols-2 gap-4">
|
<div class="grid grid-cols-2 gap-4" id="options-container">
|
||||||
{% for option in question_data.options %}
|
{% for option in question_data.options %}
|
||||||
<div class="p-4 bg-gray-100 rounded-lg" data-correct="{{ option.is_correct }}">
|
<button
|
||||||
|
class="p-4 bg-gray-100 hover:bg-blue-100 rounded-lg transition-colors duration-200 answer-option"
|
||||||
|
data-index="{{ forloop.counter0 }}"
|
||||||
|
onclick="submitAnswer({{ forloop.counter0 }});">
|
||||||
<p class="text-lg">{{ option.value }}</p>
|
<p class="text-lg">{{ option.value }}</p>
|
||||||
<p id="option-count-{{ forloop.counter0 }}" class="text-gray-600 hidden">0 Antworten</p>
|
</button>
|
||||||
</div>
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -125,5 +130,39 @@
|
|||||||
}));
|
}));
|
||||||
updateTimer();
|
updateTimer();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
let hasAnswered = false;
|
||||||
|
const participantId = '{{ host_id }}';
|
||||||
|
|
||||||
|
|
||||||
|
function submitAnswer(optionIndex) {
|
||||||
|
if (hasAnswered) return;
|
||||||
|
|
||||||
|
hasAnswered = true;
|
||||||
|
const now = Date.now();
|
||||||
|
const timeRemaining = Math.max(0, questionDuration - (now - questionStartTime));
|
||||||
|
|
||||||
|
// Disable all options and highlight selected
|
||||||
|
const options = document.getElementsByClassName('answer-option');
|
||||||
|
for (let option of options) {
|
||||||
|
option.disabled = true;
|
||||||
|
option.classList.remove('hover:bg-blue-100');
|
||||||
|
if (parseInt(option.dataset.index) === optionIndex) {
|
||||||
|
option.classList.remove('bg-gray-100');
|
||||||
|
option.classList.add('bg-blue-600', 'text-white');
|
||||||
|
} else {
|
||||||
|
option.classList.add('opacity-50');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send answer to server
|
||||||
|
gameSocket.send(JSON.stringify({
|
||||||
|
type: 'submit_answer',
|
||||||
|
participant_id: participantId,
|
||||||
|
answer: optionIndex,
|
||||||
|
time_remaining: timeRemaining
|
||||||
|
}));
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user