14 Commits

Author SHA1 Message Date
dbvictor2002 111a101037 Subir archivos a "js" 2026-10-01 12:42:03 +02:00
dbvictor2002 71b7337dba Subir archivos a "controladores" 2026-10-01 12:39:45 +02:00
jorge dc5c04b693 Merge branch 'main' of https://git.desarrolloalcala.com/jorge/triviagmatico 2026-10-01 12:37:29 +02:00
dbvictor2002 29eb70b626 Subir archivos a "/" 2026-10-01 12:33:57 +02:00
margarita 5bf5b7a3bc triviagmatico 30/09/26 a 13:30 2026-10-01 12:07:47 +02:00
jorge e8accf949e revert 7f70112f63
revert Merge pull request 'Fix inicia partida todos los usuarios' (#21) from partida into main

Reviewed-on: #21
2026-10-01 11:16:36 +02:00
jorge fa883cde39 revert eed77db62f
revert Subir archivos a "controladores"
2026-10-01 11:16:20 +02:00
jorge ae213a3d12 revert a66ac7086d
revert Subir archivos a "js"
2026-10-01 11:16:14 +02:00
jorge cd0685f41c revert 71fb45b94c
revert Merge branch 'main' of https://git.desarrolloalcala.com/jorge/triviagmatico
2026-10-01 11:15:10 +02:00
jorge e3395a017c revert 8d5d7da615
revert Merge pull request 'Resultados victor' (#25) from resultados_victor into main

Reviewed-on: #25
2026-10-01 11:13:07 +02:00
jorge 396aca8b03 revert c6db380ef9
revert Merge branch 'main' of https://git.desarrolloalcala.com/jorge/triviagmatico
2026-10-01 11:12:58 +02:00
jorge c6db380ef9 Merge branch 'main' of https://git.desarrolloalcala.com/jorge/triviagmatico 2026-10-01 10:53:03 +02:00
jorge 71fb45b94c Merge branch 'main' of https://git.desarrolloalcala.com/jorge/triviagmatico 2026-10-01 08:58:45 +02:00
jorge 2531ef321a cabecera mvc modificada 2026-09-30 11:08:09 +02:00
+10 -65
View File
@@ -3,43 +3,6 @@ let usuarioYaEstaEnEquipo = false;
$(document).ready(function () {
comprobarSalaUsuario();
});
// ==========================================================================
// DETECTOR DE INICIO DE PARTIDA PARA JUGADORES INVITADOS (1 VS 1)
// ==========================================================================
$(document).ready(function () {
// Solo activamos el vigilante si estamos en la página del buscador de salas
if (window.location.pathname.includes("buscadorSala.php")) {
setInterval(function () {
// 1. Preguntamos al servidor en qué partida está metido el usuario actual
$.ajax({
url: "controladores/controladorEquipoxUsuario.php",
type: "POST",
dataType: "json",
data: { orden: "obtenerSalaUsuario" },
success: function (sala) {
// Si el usuario está metido en una sala/partida activa...
if (sala.asociado && sala.idPartida) {
// 2. Comprobamos si el anfitrión ya ha iniciado esa partida concreta
$.ajax({
url: "controladores/controladorPartida.php",
type: "POST",
dataType: "json",
data: { orden: "buscar", idPartida: sala.idPartida },
success: function (partida) {
// Si 'fechaInicio' ya no es null, significa que el host le dio a "Jugar"
if (partida && partida.fechaInicio !== null) {
// Redirigimos instantáneamente al invitado a la pantalla del juego
window.location.href =
"juego.php?idPartida=" + sala.idPartida;
}
},
});
}
},
});
}, 2000); // Comprueba el estado de la partida automáticamente cada 2 segundos
}
});
// 1. Comprobar si el usuario actual ya pertenece a una sala
function comprobarSalaUsuario() {
@@ -216,12 +179,12 @@ function mostrarSala(partida, equipos, jugadores) {
// Solo el host puede iniciar la partida
if (esHost) {
// Así debe renderizarse el botón del host dentro de tu función mostrarSala() para que el AJAX funcione:
botonIniciarHTML = `
<button type="button" id="btnInicioJuego" data-id-partida="${partida.idPartida}" class="btn btn-success btn-lg px-4">
<i class="bi bi-controller"></i> ¡Iniciar Partida!
</button>
`;
<a href="juego.php?idPartida=${partida.idPartida}"
class="btn btn-success btn-lg px-4">
<i class="bi bi-controller"></i> ¡Iniciar Partida!
</a>
`;
}
accionesSalaHTML = `
@@ -303,8 +266,7 @@ let botonAbandonarReferencia = null;
$(document).on("click", ".btn-abandonar-sala", function () {
botonAbandonarReferencia = $(this);
const esHost =
$(this).data("es-host") === true || $(this).data("es-host") === "true";
const esHost = $(this).data("es-host") === true || $(this).data("es-host") === "true";
const titulo = $("#modalAbandonarSalaLabel");
const mensaje = $("#modalAbandonarSalaMensaje");
const botonConfirmar = $("#btnConfirmarAbandonar");
@@ -317,7 +279,9 @@ $(document).on("click", ".btn-abandonar-sala", function () {
botonConfirmar.text("Sí, terminar partida");
} else {
titulo.text("¿Abandonar la sala?");
mensaje.text("Si sales de la sala, perderás tu lugar en el equipo.");
mensaje.text(
"Si sales de la sala, perderás tu lugar en el equipo.",
);
botonConfirmar.text("Sí, salir");
}
@@ -328,6 +292,7 @@ $(document).on("click", ".btn-abandonar-sala", function () {
modal.show();
});
// B. Al hacer clic en "Sí, salir" dentro del modal Kahoot
$(document).on("click", "#btnConfirmarAbandonar", function () {
const modalEl = document.getElementById("modalAbandonarSala");
@@ -438,7 +403,6 @@ $("#btnCrearSala").on("click", function () {
if (respuesta.exito) {
$("#modalCrearSala").modal("hide");
location.reload();
}
},
@@ -469,22 +433,3 @@ $(document).on("input", ".input-kahoot", function () {
$(this).removeClass("is-invalid");
$(this).next(".mensaje-error-sala").remove();
});
$(document).on("click", "#btnInicioJuego", function () {
// 1. Capturamos el id de la partida de forma dinámica desde el botón que se ha pulsado
const idPartida = $(this).data("id-partida");
// 2. Enviamos la petición AJAX adecuada con TODOS los datos que el controlador espera recibir
$.ajax({
url: "controladores/controladorPartida.php",
type: "POST",
dataType: "json",
data: {
orden: "iniciar",
idPartida: idPartida,
},
error: function (error) {
console.error("Error al iniciar el juego por AJAX:", error);
},
});
});