diff --git a/webapp/src/components/Game.css b/webapp/src/components/Game.css index 1e4d4c29..dca78363 100644 --- a/webapp/src/components/Game.css +++ b/webapp/src/components/Game.css @@ -17,3 +17,12 @@ button[title="btnsPreg"]{ background-color: rgba(41, 120, 152, 0.764); } +button[title="puntuacion"]:disabled{ + margin: 1em; + background-color: rgba(31, 60, 134, 0.764); + color: white; + padding-top: 0.4em; + padding-bottom: 0.2em; + font-size: 1.5em; +} + diff --git a/webapp/src/components/Game.js b/webapp/src/components/Game.js index 61933dd8..2d8815b0 100644 --- a/webapp/src/components/Game.js +++ b/webapp/src/components/Game.js @@ -17,6 +17,11 @@ const Game = () => { const [questionCounter, setQuestionCounter] = useState(0); const [incorrectCounter, setIncorrectCounter] = useState(0); + + const [numberOfQuestions, setNumberOfQuestions] = useState(10); + const [questionsToAnswer, setQuestionsToAnswer] = useState(10); + const [isFinished, setFinished] = useState(false); + const [percentage, setPercentage] = useState(0); // Temporizador const [seconds, setSeconds] = useState(120); // 2 minutes @@ -35,6 +40,14 @@ const Game = () => { return () => clearInterval(intervalId); }, []); + + + useEffect(() => { + if (isGameFinished() && !isFinished){ + finishGame(); + setFinished(true) +; } + }, [correctCounter]); // This method will call the create question service const handleShowQuestion = async () => { @@ -53,7 +66,16 @@ const Game = () => { button.onmouse = colorOnMousePreguntas; }); + // FIN DE LA PARTIDA + if (isGameFinished() && !isFinished){ + finishGame(); + setFinished(true); + } + + incrementQuestion(); + + }catch (error){ console.error('Error:', error); } @@ -80,27 +102,61 @@ const Game = () => { button.disabled = true; button.onmouse = null; }); + + + decrementQuestionsToAnswer(); - // Cambiar a la siguiente pregunta después de 3 segundos - setTimeout(() => { - handleShowQuestion(); - }, 1500); + + if (!isFinished){ + // Cambiar a la siguiente pregunta después de 3 segundos + setTimeout(() => { + handleShowQuestion(); + }, 1500); + } + + } + + const isGameFinished = () => { + return questionCounter >= numberOfQuestions; + } + + const finishGame = () => { + const buttons = document.querySelectorAll('button[title="btnsPreg"]'); + buttons.forEach(button => { + button.disabled = true; + button.onmouse = null; + }); + console.log("finishGame " + correctCounter); + 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 = () => { - setCorrectCounter(correctCounter + 1); + setCorrectCounter(correct => correct + 1); }; const incrementIncorrect = () => { - setIncorrectCounter(incorrectCounter + 1); + setIncorrectCounter(incorrect => incorrect + 1); + } + + const decrementQuestionsToAnswer = () => { + setQuestionsToAnswer(toAnswer => toAnswer - 1); } const incrementQuestion = () => { - setQuestionCounter(questionCounter + 1); + setQuestionCounter(qc => qc + 1); } return ( + + {!isFinished && ( Saber y Ganar Juego @@ -116,14 +172,23 @@ const Game = () => { ))} + )} + {!isFinished && ( + + )} + {!isFinished && ( - + )} + {!isFinished && ( + )}
@@ -133,6 +198,29 @@ const Game = () => {
+ + + {isFinished && ( +
+ + + Partida finalizada. ¡Gracias por jugar! + +
+ +
+
+
+ )} + + + {/* */} + +
); }; diff --git a/webapp/src/components/MainPage.css b/webapp/src/components/MainPage.css new file mode 100644 index 00000000..c210f19c --- /dev/null +++ b/webapp/src/components/MainPage.css @@ -0,0 +1,12 @@ +div[title="main"]{ + display: grid; + grid-template-columns: 1fr; +} + +div[title="main"]>button{ + margin: 1em; + padding: 0.5em; + background-color: rgba(31, 60, 134, 0.764); + color: white; + font-size: 1em; +} \ No newline at end of file diff --git a/webapp/src/components/MainPage.js b/webapp/src/components/MainPage.js index 99e34b01..09ecef3c 100644 --- a/webapp/src/components/MainPage.js +++ b/webapp/src/components/MainPage.js @@ -1,5 +1,7 @@ -import { Container, Typography, Button} from '@mui/material'; -import { useNavigate} from 'react-router-dom'; +import React, { useState } from 'react'; +import { Container, Typography, TextField, Button, Snackbar } from '@mui/material'; +import { useNavigate, useParams } from 'react-router-dom'; +import './MainPage.css'; const MainPage = () => { const navigate = useNavigate(); @@ -16,7 +18,7 @@ const MainPage = () => { return ( -
+
¡Bienvenido a WIQ 2024!