Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

edits game #448

Merged
merged 1 commit into from
May 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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