From 78acdb32fda006ce5720f22f33b2c0b20c7aa000 Mon Sep 17 00:00:00 2001 From: uo264915 Date: Sat, 30 Mar 2024 14:03:43 +0100 Subject: [PATCH] Finalizacion del juego y mostrar puntuacion [APP] Configurar el fin de partida (Cuando se llega a X preguntas) Arquisoft/wiq_es2b#72 --- webapp/src/components/Game.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/webapp/src/components/Game.js b/webapp/src/components/Game.js index de9b0ebf..2d8815b0 100644 --- a/webapp/src/components/Game.js +++ b/webapp/src/components/Game.js @@ -43,9 +43,10 @@ const Game = () => { useEffect(() => { - if (isGameFinished()){ + if (isGameFinished() && !isFinished){ finishGame(); - } + setFinished(true) +; } }, [correctCounter]); // This method will call the create question service @@ -66,7 +67,8 @@ const Game = () => { }); // FIN DE LA PARTIDA - if (isGameFinished()){ + if (isGameFinished() && !isFinished){ + finishGame(); setFinished(true); } @@ -125,8 +127,14 @@ const Game = () => { button.onmouse = null; }); console.log("finishGame " + correctCounter); - var correctas = (correctCounter / numberOfQuestions); - setPercentage(correctas * 100); + var correctas = (correctCounter / numberOfQuestions) * 100; + console.log("corr1 " + correctas); + if (!Number.isInteger(percentage)){ + correctas = correctas.toFixed(2); + console.log("dentro " + correctas); + } + console.log("corr2 " + correctas); + setPercentage(correctas); } const incrementCorrect = () => { @@ -200,7 +208,7 @@ const Game = () => {