Skip to content

Commit

Permalink
Merge pull request #448 from Arquisoft/ediciones
Browse files Browse the repository at this point in the history
edits game
  • Loading branch information
uo277310 authored May 1, 2024
2 parents 14ba7fd + c535b49 commit e63b297
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions webapp/src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ const Game = ({ username, totalQuestions, timeLimit, themes }) => {
const [error, setError] = useState('');
const [correctQuestions, setCorrectQuestions] = useState(0);
const [timer, setTimer] = useState(0);
const [themesSelected, setThemesSelected] = useState(themes);
const [numberClics, setNumberClics] = useState(0);
const [finished, setFinished] = useState(false);
const [selectedAnswer, setSelectedAnswer] = useState('');
const [selectedOption, setSelectedOption] = useState(null); // Opción seleccionada actualmente
const [almacenado, setAlmacenado] = useState(false);
const pricePerQuestion = 25;
const delayBeforeNextQuestion = 3000; // 3 segundos de retardo antes de pasar a la siguiente pregunta
const themesSelected = themes;

const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || 'http://localhost:8000';

function getRandomIndex(length) {
Expand Down Expand Up @@ -57,7 +58,7 @@ const Game = ({ username, totalQuestions, timeLimit, themes }) => {
.map(([tema]) => tema);
const randomIndex = getRandomIndex(temas.length);
const temaAleatorio = temas[randomIndex];
console.log(selectedAnswer);

const response = await axios.get(`${apiEndpoint}/getRandomQuestion${temaAleatorio}`);
setQuestion(response.data);
const respuestas = [...response.data.incorrectas, response.data.correcta];
Expand All @@ -69,7 +70,7 @@ const Game = ({ username, totalQuestions, timeLimit, themes }) => {
};

obtenerPreguntaAleatoria();
}, [apiEndpoint, setQuestion, setRespuestasAleatorias, setError, themesSelected, selectedAnswer]);
}, [apiEndpoint, setQuestion, setRespuestasAleatorias, setError, themesSelected]);

const handleTimeRemaining = () => {
let minsR = Math.floor((timeLimit - timer) / 60);
Expand Down Expand Up @@ -111,7 +112,7 @@ const Game = ({ username, totalQuestions, timeLimit, themes }) => {
const respuestas = [...response.data.incorrectas, response.data.correcta];
setRespuestasAleatorias(respuestas.sort(randomSort).slice(0, 4)); // Mostrar solo 4 respuestas
} catch (error) {
console.error("Error al obtener la pregunta aleatoria", error);
console.error("Error al obtener la pregunta aleatoria "+selectedAnswer, error);
setError('Error al obtener la pregunta aleatoria');
}
};
Expand Down Expand Up @@ -158,6 +159,9 @@ const Game = ({ username, totalQuestions, timeLimit, themes }) => {
});
} catch (error) {
setError(error.response.data.error);
if (timeLimit>15000) {
setThemesSelected(themes);
}
}
};

Expand Down

0 comments on commit e63b297

Please sign in to comment.