From f30c984342ccc58adbfcd0b8ef70cf23f2f2bc10 Mon Sep 17 00:00:00 2001 From: ben8 Date: Fri, 23 May 2025 19:22:41 +0200 Subject: [PATCH] =?UTF-8?q?counter=20f=C3=BCr=20Punkte=20und=20Optikverbes?= =?UTF-8?q?serungen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- django/play/consumers.py | 3 +- django/play/consumers/game.py | 1 + .../0012_quizgameparticipant_last_score.py | 18 +++ django/play/models.py | 1 + django/play/views.py | 4 + .../templates/play/game/score_overview.html | 120 +++++++++++++++--- 6 files changed, 127 insertions(+), 20 deletions(-) create mode 100644 django/play/migrations/0012_quizgameparticipant_last_score.py diff --git a/django/play/consumers.py b/django/play/consumers.py index 090d975..b4f52a2 100644 --- a/django/play/consumers.py +++ b/django/play/consumers.py @@ -129,6 +129,7 @@ class GameConsumer(AsyncWebsocketConsumer): time_factor = time_remaining / 30000 # 30 seconds max score = int(base_score * (0.5 + 0.5 * time_factor)) + participant.last_score=score participant.score += score participant.last_answer_correct = is_correct participant.save() @@ -460,7 +461,7 @@ class LobbyConsumer(AsyncWebsocketConsumer): if answer == correct_answer: # Base score for correct answer + bonus for speed score = 1000 + int(time_remaining * 10) # 10 points per remaining second - + participant.last_score= score participant.score += score participant.save() return score diff --git a/django/play/consumers/game.py b/django/play/consumers/game.py index 985412b..d4fa0ff 100644 --- a/django/play/consumers/game.py +++ b/django/play/consumers/game.py @@ -233,6 +233,7 @@ class GameConsumer(AsyncWebsocketConsumer): answer_obj.time_remaining = time_remaining answer_obj.save() + participant.last_score = score participant.score += score participant.last_answer_correct = is_correct participant.save() diff --git a/django/play/migrations/0012_quizgameparticipant_last_score.py b/django/play/migrations/0012_quizgameparticipant_last_score.py new file mode 100644 index 0000000..e75b880 --- /dev/null +++ b/django/play/migrations/0012_quizgameparticipant_last_score.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.7 on 2025-05-22 15:26 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('play', '0011_quizgame_updated_at'), + ] + + operations = [ + migrations.AddField( + model_name='quizgameparticipant', + name='last_score', + field=models.IntegerField(default=0, verbose_name='Letzte_Punkte'), + ), + ] diff --git a/django/play/models.py b/django/play/models.py index c63736d..98a381d 100644 --- a/django/play/models.py +++ b/django/play/models.py @@ -43,6 +43,7 @@ class QuizGameParticipant(models.Model): display_name = models.CharField(verbose_name="Anzeigename", max_length=15) quiz_game = models.ForeignKey(QuizGame, on_delete=models.CASCADE, related_name="participants") score = models.IntegerField(verbose_name="Punkte", default=0) + last_score = models.IntegerField(verbose_name="Letzte_Punkte", default=0) avatar = models.CharField(max_length=200, blank=True, default="") last_heartbeat = models.DateTimeField(auto_now_add=True) last_answer = models.IntegerField(null=True, blank=True) diff --git a/django/play/views.py b/django/play/views.py index f1d8b3e..edce002 100644 --- a/django/play/views.py +++ b/django/play/views.py @@ -57,6 +57,7 @@ def lobby(request, join_code): if not participant.quiz_game.join_code == join_code: # Teilnehmer dem richtigen Spiel hinzufügen participant.quiz_game = quiz_game participant.score = 0 # Reset score when joining new game + participant.last_score = 0 participant.save() except QuizGameParticipant.DoesNotExist: return redirect('play:create_participant', join_code=join_code) @@ -83,6 +84,7 @@ def create_participant(request, join_code): if participant.quiz_game.join_code != join_code: participant.quiz_game = quiz_game participant.score = 0 # Reset score when joining new game + participant.last_score = 0 participant.save() return redirect('play:lobby', join_code=join_code) except QuizGameParticipant.DoesNotExist: @@ -103,6 +105,7 @@ def create_participant(request, join_code): participant.display_name = display_name participant.quiz_game = quiz_game participant.score = 0 # Initialize score + participant.last_score = 0 participant.save() response = HttpResponseRedirect(reverse('play:lobby', kwargs={'join_code': join_code})) @@ -340,6 +343,7 @@ def selected_mode(request, join_code): participant.participant_id=host_id participant.quiz_game = quiz_game participant.score = 0 # Initialize score + participant.last_score = 0 participant.save() quiz_game.current_state = "question" quiz_game.question_start_time = timezone.now() diff --git a/django/templates/play/game/score_overview.html b/django/templates/play/game/score_overview.html index 32165c0..71664fb 100644 --- a/django/templates/play/game/score_overview.html +++ b/django/templates/play/game/score_overview.html @@ -27,12 +27,12 @@

Punktestand

-
+
{% for participant in participants %} {% if participant == my_participant or is_host %} -
-
-

+

+
+
{% if forloop.counter == 1 %} 🥇 {% elif forloop.counter == 2 %} @@ -42,22 +42,102 @@ {% else %} {{ forloop.counter }}. {% endif %} - {{ participant.display_name }} -

-

{{ participant.score }} Punkte

-
- {% if participant.last_answer_correct %} - {% if participant == my_participant or request.session.mode == "learn" %} -
Hier erscheint gleich dein Feedback...
+ {{ participant.display_name }} +
+ +

{{ participant.score }} Punkte

+ {% if participant == my_participant or request.session.mode == "learn"%} +

+{{ participant.last_score }} Punkte

+ {% endif %} +
+ + + + + {% if participant == my_participant or request.session.mode == "learn" %} + {% if participant.last_answer_correct %} + +
+ + + + + + +
+ Hier erscheint gleich dein Feedback... +
+ +
{% elif participant.last_answer_correct == False %} - {% if participant == my_participant or request.session.mode == "learn" %} -
Hier erscheint gleich dein Feedback...
- {% endif %} - + + +
+ + + + + +
+ Hier erscheint gleich dein Feedback... +
+
+ + {% endif %} {% endif %}
+ {% endif %} {% endfor %}
@@ -65,11 +145,11 @@ {% if is_host %} {% if is_last_question %} - {% else %} - {% endif %} @@ -103,7 +183,8 @@ }); // Warten bevor Animation startet - await sleep(1500); // <<< hier die 5 Sekunden Pause + await sleep(1500); // <<< hier die Pause + // Transition-Eigenschaft setzen nach Render-Zyklus requestAnimationFrame(() => { @@ -119,6 +200,7 @@ if (index === top3.length - 1) { triggerConfetti(); + } }, index * 1500); // Zeitversetzt aufdecken });