Skip to content

Commit

Permalink
Añado feedback al acertar o fallar preguntas
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro-C-M committed Apr 30, 2024
1 parent 712cb36 commit c73bc59
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
17 changes: 16 additions & 1 deletion webapp/src/components/game/AnswersBlock.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Box } from "@chakra-ui/react";
import React, { useEffect, useState } from 'react';
import { AnswerButton } from './AnswerButton.jsx';
import { useToast } from '@chakra-ui/react'

//onAnswerSelect es la funcion de QuestionArea que se ejecuta al hacer click en boton
export function AnswersBlock({ respuestas, correcta ,onAnswerSelect,isGameEnded, darkMode}){

const [respuestasAleatorizadas, setRespuestasAleatorizadas] = useState([]);


const toast = useToast();
let respuestasCopy = respuestas;

//Colores de los botones para que tengan orden random
Expand All @@ -30,12 +32,25 @@ export function AnswersBlock({ respuestas, correcta ,onAnswerSelect,isGameEnded,
}, [respuestasCopy]);

const handleButtonClick = (respuesta) => {

if (isGameEnded) {
return;
}
if (respuesta === correcta) {
toast({
title: 'Acierto',
status: 'success',
duration: 1000,
isClosable: true,
})
onAnswerSelect(true);
} else {
toast({
title: 'Fallo',
status: 'error',
duration: 1000,
isClosable: true,
})
onAnswerSelect(false);
}
};
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/components/game/BasicGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,10 @@ class BasicGame extends GameMode {
}

incrementCorrectas(){

this.correctas++;
}

incrementIncorrectas(){
this.incorrectas++;
}
Expand Down
1 change: 0 additions & 1 deletion webapp/src/components/game/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Spinner, Box} from "@chakra-ui/react";
import BasicGame from './BasicGame';
import { useTranslation } from 'react-i18next';


function Game({darkMode,gameMode=new BasicGame()}) {
const [correctAnswers, setCorrectAnswers] = useState(0);
const [incorrectAnswers, setIncorrectAnswers] = useState(0);
Expand Down

0 comments on commit c73bc59

Please sign in to comment.