From 391a3829fe5a5fca826a1c8bd3aef16fd5098fd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20D=C3=ADaz=20N=C3=BA=C3=B1ez?= Date: Mon, 8 Apr 2024 10:39:40 +0200 Subject: [PATCH 1/2] Question counter view. --- src/main/resources/messages.properties | 1 + src/main/resources/messages_en.properties | 1 + src/main/resources/messages_es.properties | 1 + src/main/resources/messages_fr.properties | 3 ++- src/main/resources/static/css/game.css | 2 +- src/main/resources/templates/game/basicGame.html | 8 ++++++++ 6 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 06e28cf3..03f59600 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -110,4 +110,5 @@ timeRunOut.result=¡Se acabó el tiempo! No te preocupes, sigue intentándolo. game.continue=Siguiente pregunta answer.correct=La respuesta correcta era: game.points=Puntos: +game.currentQuestion=Pregunta: game.finish=El juego ha terminado. Tu puntuación ha sido: \ No newline at end of file diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index 7d663d90..0d7a4e1f 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -110,6 +110,7 @@ timeRunOut.result=Time's up! Don't worry, keep trying. game.continue=Next question answer.correct=Correct answer was: game.points=Points: +game.currentQuestion=Question: game.finish=The game has finished. Your score is: diff --git a/src/main/resources/messages_es.properties b/src/main/resources/messages_es.properties index 40491b13..67653de3 100644 --- a/src/main/resources/messages_es.properties +++ b/src/main/resources/messages_es.properties @@ -111,4 +111,5 @@ timeRunOut.result=¡Se acabó el tiempo! No te preocupes, sigue intentándolo. game.continue=Siguiente pregunta answer.correct=La respuesta correcta era: game.points=Puntos: +game.currentQuestion=Pregunta: game.finish=El juego ha terminado. Tu puntuación ha sido: \ No newline at end of file diff --git a/src/main/resources/messages_fr.properties b/src/main/resources/messages_fr.properties index 90021f7e..1f5d2b22 100644 --- a/src/main/resources/messages_fr.properties +++ b/src/main/resources/messages_fr.properties @@ -108,6 +108,7 @@ failedAnswer.result=Réponse incorrecte, ne vous découragez pas et continuez à timeRunOut.result=Temps écoulé ! Ne vous inquiétez pas, continuez à essayer. game.continue=Question suivante answer.correct=La réponse correcte était : -game.points=Points : +game.points=Points: +game.currentQuestion=Question: game.finish=Le jeu est terminé. Votre score est : diff --git a/src/main/resources/static/css/game.css b/src/main/resources/static/css/game.css index 263cec64..af9a92b1 100644 --- a/src/main/resources/static/css/game.css +++ b/src/main/resources/static/css/game.css @@ -28,7 +28,7 @@ margin-bottom: 10%; } -.points { +.points, .questionCounter { font-size: 2em; color: white; } diff --git a/src/main/resources/templates/game/basicGame.html b/src/main/resources/templates/game/basicGame.html index c53e5148..43c37fad 100644 --- a/src/main/resources/templates/game/basicGame.html +++ b/src/main/resources/templates/game/basicGame.html @@ -9,6 +9,14 @@

+

+ + + + / + + +

From fa421b33a4f7e7236db8628ae16a2613603b072c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20D=C3=ADaz=20N=C3=BA=C3=B1ez?= Date: Mon, 8 Apr 2024 10:40:20 +0200 Subject: [PATCH 2/2] Question counter funcionality. --- .../java/com/uniovi/controllers/GameController.java | 10 ++++++++++ .../templates/game/fragments/gameFinished.html | 1 + .../templates/game/fragments/questionResult.html | 13 +++++++++++++ 3 files changed, 24 insertions(+) diff --git a/src/main/java/com/uniovi/controllers/GameController.java b/src/main/java/com/uniovi/controllers/GameController.java index 2e7d0ef3..fc4a2cae 100644 --- a/src/main/java/com/uniovi/controllers/GameController.java +++ b/src/main/java/com/uniovi/controllers/GameController.java @@ -149,6 +149,16 @@ public String getPoints(HttpSession session) { return "0"; } + @GetMapping("/game/currentQuestion") + @ResponseBody + public String getCurrentQuestion(HttpSession session) { + GameSession gameSession = (GameSession) session.getAttribute("gameSession"); + if (gameSession != null) + return String.valueOf(gameSession.getAnsweredQuestions().size()+1); + else + return "0"; + } + private Player getLoggedInPlayer(Principal principal) { Optional player = playerService.getUserByUsername(principal.getName()); return player.orElse(null); diff --git a/src/main/resources/templates/game/fragments/gameFinished.html b/src/main/resources/templates/game/fragments/gameFinished.html index ee10d9e6..dd264b15 100644 --- a/src/main/resources/templates/game/fragments/gameFinished.html +++ b/src/main/resources/templates/game/fragments/gameFinished.html @@ -16,6 +16,7 @@

\ No newline at end of file diff --git a/src/main/resources/templates/game/fragments/questionResult.html b/src/main/resources/templates/game/fragments/questionResult.html index 1db7fe88..f8b2ab13 100644 --- a/src/main/resources/templates/game/fragments/questionResult.html +++ b/src/main/resources/templates/game/fragments/questionResult.html @@ -19,6 +19,7 @@

let activeTimeout = setTimeout(function () { clearInterval(interval); // Ensure the interval is cleared when the timeout completes $("#gameFrame").load('/game/update'); + updateQuestionCounter(); }, timeoutPeriod); timeoutPeriod = timeoutPeriod - updateInterval * 2; // Adjust the timeout period to account for the update interval @@ -43,12 +44,24 @@

} } + function updateQuestionCounter() { + $.ajax({ + type: "GET", + url: "/game/currentQuestion", + success: function (response) { + if (!isNaN(response)) + $("#currentQuestion").text(response); + } + }); + } + $("#continueBtn").off('click').on('click', function () { if (activeTimeout) { clearTimeout(activeTimeout); clearInterval(interval); } $("#gameFrame").load("/game/update"); + updateQuestionCounter(); }); }