diff --git a/django/play/views.py b/django/play/views.py index 6887cc0..b332d9e 100644 --- a/django/play/views.py +++ b/django/play/views.py @@ -84,6 +84,13 @@ def create_game(request, quiz_id): game.quiz_id = quiz game.host_id = game.generate_unique_id() 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.set_cookie('host_id', game.host_id, max_age=3600) diff --git a/django/templates/play/game/question_host.html b/django/templates/play/game/question_host.html index 7a4f17c..1f8c4b0 100644 --- a/django/templates/play/game/question_host.html +++ b/django/templates/play/game/question_host.html @@ -17,14 +17,19 @@ -
+
{% for option in question_data.options %} -
+
+ {% endfor %}
+ + +
{% endblock %} @@ -125,5 +130,39 @@ })); 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 + })); + } {% endblock %} \ No newline at end of file