Add sincronizacion de jugadores en partida
This commit is contained in:
+89
-12
@@ -118,7 +118,12 @@ function mostrarPregunta() {
|
||||
// 3. El usuario pulsa una respuesta: se guarda y se enseña si ha acertado
|
||||
function responder($botonPulsado) {
|
||||
clearInterval(intervaloTiempo);
|
||||
console.log("Tiempo de respuesta: " + tiempoRespuesta / 10 + " segundos");
|
||||
|
||||
console.log(
|
||||
"Tiempo de respuesta: " +
|
||||
tiempoRespuesta / 10 +
|
||||
" segundos"
|
||||
);
|
||||
|
||||
if (bloqueado) {
|
||||
return;
|
||||
@@ -127,7 +132,29 @@ function responder($botonPulsado) {
|
||||
bloqueado = true;
|
||||
|
||||
const pregunta = preguntas[indice];
|
||||
const idRespuesta = parseInt($botonPulsado.attr("data-id-respuesta"), 10);
|
||||
|
||||
const idRespuesta = parseInt(
|
||||
$botonPulsado.attr("data-id-respuesta"),
|
||||
10
|
||||
);
|
||||
|
||||
console.log("PREGUNTA ACTUAL:", pregunta);
|
||||
console.log(
|
||||
"idPartidaxPregunta:",
|
||||
pregunta.idPartidaxPregunta
|
||||
);
|
||||
console.log(
|
||||
"idRespuesta:",
|
||||
idRespuesta
|
||||
);
|
||||
console.log(
|
||||
"tiempoRespuesta:",
|
||||
tiempoRespuesta
|
||||
);
|
||||
console.log(
|
||||
"idPartida:",
|
||||
idPartida
|
||||
);
|
||||
|
||||
$("#respuestas").addClass("bloqueado");
|
||||
|
||||
@@ -135,46 +162,96 @@ function responder($botonPulsado) {
|
||||
url: URL_CONTROLADOR,
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
|
||||
data: {
|
||||
orden: "responder",
|
||||
idPartida: idPartida,
|
||||
idPartidaxPregunta: pregunta.idPartidaxPregunta,
|
||||
idRespuesta: idRespuesta,
|
||||
tiempoRespuesta: tiempoRespuesta,
|
||||
idRespuesta: idRespuesta,
|
||||
tiempoRespuesta: tiempoRespuesta
|
||||
},
|
||||
|
||||
success: function (datos) {
|
||||
|
||||
console.log("RESPUESTA DEL SERVIDOR:", datos);
|
||||
|
||||
if (datos.error) {
|
||||
// No se guardó: dejamos que vuelva a intentarlo
|
||||
$("#feedback").text(datos.error).removeClass("ok").addClass("ko");
|
||||
|
||||
$("#feedback")
|
||||
.text(datos.error)
|
||||
.removeClass("ok")
|
||||
.addClass("ko");
|
||||
|
||||
$("#respuestas").removeClass("bloqueado");
|
||||
|
||||
bloqueado = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
pregunta.respondida = true;
|
||||
mostrarFeedback($botonPulsado, datos);
|
||||
|
||||
mostrarFeedback(
|
||||
$botonPulsado,
|
||||
datos
|
||||
);
|
||||
|
||||
setTimeout(function () {
|
||||
if (datos.terminada || indice >= preguntas.length - 1) {
|
||||
|
||||
if (
|
||||
datos.terminada ||
|
||||
indice >= preguntas.length - 1
|
||||
) {
|
||||
terminar();
|
||||
} else {
|
||||
|
||||
indice++;
|
||||
$("#respuestas").removeClass("bloqueado");
|
||||
|
||||
$("#respuestas")
|
||||
.removeClass("bloqueado");
|
||||
|
||||
mostrarPregunta();
|
||||
}
|
||||
|
||||
}, PAUSA_FEEDBACK);
|
||||
},
|
||||
error: function () {
|
||||
|
||||
error: function (xhr, status, error) {
|
||||
|
||||
console.error(
|
||||
"ERROR AJAX RESPONDER"
|
||||
);
|
||||
|
||||
console.error(
|
||||
"HTTP:",
|
||||
xhr.status
|
||||
);
|
||||
|
||||
console.error(
|
||||
"ERROR:",
|
||||
error
|
||||
);
|
||||
|
||||
console.error(
|
||||
"RESPUESTA:",
|
||||
xhr.responseText
|
||||
);
|
||||
|
||||
$("#feedback")
|
||||
.text("No se pudo guardar la respuesta. Inténtalo de nuevo.")
|
||||
.text(
|
||||
"No se pudo guardar la respuesta. Inténtalo de nuevo."
|
||||
)
|
||||
.removeClass("ok")
|
||||
.addClass("ko");
|
||||
|
||||
$("#respuestas").removeClass("bloqueado");
|
||||
|
||||
bloqueado = false;
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Marca la respuesta correcta en verde y atenúa el resto
|
||||
function mostrarFeedback($botonPulsado, datos) {
|
||||
$("#respuestas .btn-answer").each(function () {
|
||||
|
||||
Reference in New Issue
Block a user