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 @@
+
{{ participant.score }} Punkte
-{{ participant.score }} Punkte
+ {% if participant == my_participant or request.session.mode == "learn"%} ++{{ participant.last_score }} Punkte
+ {% endif %} +