add tiempo de respuesta

This commit is contained in:
2026-10-01 12:53:45 +02:00
parent 111a101037
commit e9cf7c8fcf
+12 -2
View File
@@ -18,9 +18,10 @@ let preguntas = [];
let indice = 0; // pregunta que se está mostrando let indice = 0; // pregunta que se está mostrando
let bloqueado = false; // true mientras se envía una respuesta o se ve el feedback let bloqueado = false; // true mientras se envía una respuesta o se ve el feedback
let numeroAciertos = 0; // número de aciertos del jugador let numeroAciertos = 0; // número de aciertos del jugador
let tiempoRespuesta = 0;
let intervaloTiempo;
$(document).ready(function () { $(document).ready(function () {
// Obtenemos el idPartida de la URL // Obtenemos el idPartida de la URL
// Ejemplo: juego.php?idPartida=3 // Ejemplo: juego.php?idPartida=3
@@ -83,6 +84,11 @@ function cargarPreguntas() {
function mostrarPregunta() { function mostrarPregunta() {
const pregunta = preguntas[indice]; const pregunta = preguntas[indice];
tiempoRespuesta = 0;
intervaloTiempo = setInterval(function () {
tiempoRespuesta++;
}, 100);
bloqueado = false; bloqueado = false;
$("#textoPregunta").text(pregunta.nombrePregunta); $("#textoPregunta").text(pregunta.nombrePregunta);
@@ -111,6 +117,9 @@ function mostrarPregunta() {
// 3. El usuario pulsa una respuesta: se guarda y se enseña si ha acertado // 3. El usuario pulsa una respuesta: se guarda y se enseña si ha acertado
function responder($botonPulsado) { function responder($botonPulsado) {
clearInterval(intervaloTiempo);
console.log("Tiempo de respuesta: " + tiempoRespuesta / 10 + " segundos");
if (bloqueado) { if (bloqueado) {
return; return;
} }
@@ -130,7 +139,8 @@ function responder($botonPulsado) {
orden: "responder", orden: "responder",
idPartida: idPartida, idPartida: idPartida,
idPartidaxPregunta: pregunta.idPartidaxPregunta, idPartidaxPregunta: pregunta.idPartidaxPregunta,
idRespuesta: idRespuesta, idRespuesta: idRespuesta,
tiempoRespuesta: tiempoRespuesta,
}, },
success: function (datos) { success: function (datos) {
if (datos.error) { if (datos.error) {