Skip to content

Commit

Permalink
Merge pull request #176 from Arquisoft/review2-changes
Browse files Browse the repository at this point in the history
Question counter
  • Loading branch information
Pelayori authored Apr 8, 2024
2 parents 33e6e90 + fa421b3 commit b23dc62
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/uniovi/controllers/GameController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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> player = playerService.getUserByUsername(principal.getName());
return player.orElse(null);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,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:
1 change: 1 addition & 0 deletions src/main/resources/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,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:


1 change: 1 addition & 0 deletions src/main/resources/messages_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,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:
3 changes: 2 additions & 1 deletion src/main/resources/messages_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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 :

2 changes: 1 addition & 1 deletion src/main/resources/static/css/game.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
margin-bottom: 10%;
}

.points {
.points, .questionCounter {
font-size: 2em;
color: white;
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/templates/game/basicGame.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
<span class="" th:text="#{game.points}"></span>
<b id="gamePoints" th:inline="text" th:text="${session.gameSession.score}"></b>
</p>
<p class="questionCounter text-right mr-3">
<span class="" th:text="#{game.currentQuestion}"></span>
<b id="questionNumber" th:inline="text">
<span id="currentQuestion" th:text="${session.gameSession.answeredQuestions.size()+1}"></span>
/
<span id="totalQuestions" th:text="${session.gameSession.questionsToAnswer.size()}"></span>
</b>
</p>
<div id="gameFrame" th:replace="~{game/fragments/gameFrame}"></div>

<footer th:replace="~{fragments/footer}"></footer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ <h1 class="text-center" th:text="#{game.finish}"></h1>
<script>
$(document).ready(function () {
$(".points").remove();
$(".questionCounter").remove();
});
</script>
</div>
13 changes: 13 additions & 0 deletions src/main/resources/templates/game/fragments/questionResult.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ <h1 class="text-center" th:text="#{${messageKey}}" style="font-size: 2em;"></h1>
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
Expand All @@ -43,12 +44,24 @@ <h1 class="text-center" th:text="#{${messageKey}}" style="font-size: 2em;"></h1>
}
}

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

Expand Down

0 comments on commit b23dc62

Please sign in to comment.