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(); }); }