Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c0207197fb | |||
| 5113b960d2 | |||
| 8453735727 | |||
| fdd1ba8272 | |||
| 111a101037 | |||
| 71b7337dba | |||
| dc5c04b693 | |||
| 29eb70b626 | |||
| 5bf5b7a3bc | |||
| e8accf949e | |||
| fa883cde39 | |||
| ae213a3d12 | |||
| cd0685f41c | |||
| e3395a017c | |||
| 396aca8b03 | |||
| c6db380ef9 | |||
| 8d5d7da615 | |||
| 7f70112f63 | |||
| a66ac7086d | |||
| eed77db62f | |||
| 83545152bb | |||
| 71fb45b94c | |||
| 5b6352b4ee | |||
| 7e1344a395 | |||
| db5061ec7f | |||
| 737b76e83b | |||
| 3705a9ea9e | |||
| 72134b405c | |||
| 2531ef321a | |||
| 5446352cf9 |
+5
-2
@@ -22,7 +22,7 @@
|
|||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
<a href="index.php" class="btn btn-outline-secondary d-inline-flex align-items-center gap-2">
|
<a href="index.php" class="btn btn-outline-secondary d-inline-flex align-items-center gap-2">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-left" viewBox="0 0 16 16">
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-left" viewBox="0 0 16 16">
|
||||||
<path fill-rule="evenodd" d="M15 8a.5.5 0 0 0-.5-.5H2.707l3.147-3.146a.5.5 0 1 0-.708-.708l-4 4a.5.5 0 0 0 0 .708l4 4a.5.5 0 0 0 .708-.708L2.707 8.5H14.5A.5.5 0 0 0 15 8"/>
|
<path fill-rule="evenodd" d="M15 8a.5.5 0 0 0-.5-.5H2.707l3.147-3.146a.5.5 0 1 0-.708-.708l-4 4a.5.5 0 0 0 0 .708l4 4a.5.5 0 0 0 .708-.708L2.707 8.5H14.5A.5.5 0 0 0 15 8" />
|
||||||
</svg>
|
</svg>
|
||||||
Volver al Inicio
|
Volver al Inicio
|
||||||
</a>
|
</a>
|
||||||
@@ -71,7 +71,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancelar</button>
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancelar</button>
|
||||||
<button type="button" class="btn btn-kahoot-login" id="btnCrearSala">Crear sala</button>
|
<button type="button" class="btn btn-kahoot-register" id="btnCrearSala">Crear sala</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -100,7 +100,10 @@
|
|||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
<script src="js/jquery-4.0.0.min.js"></script>
|
<script src="js/jquery-4.0.0.min.js"></script>
|
||||||
|
<script src="js/sala.js"></script>
|
||||||
<script src="js/buscadorSala.js"></script>
|
<script src="js/buscadorSala.js"></script>
|
||||||
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
session_start();
|
session_start();
|
||||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/conexionBD.php';
|
require_once __DIR__ . '/../includes/conexionBD.php';
|
||||||
|
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ if (is_array($conexion)) {
|
|||||||
switch ($orden) {
|
switch ($orden) {
|
||||||
case 'comprobarEstado':
|
case 'comprobarEstado':
|
||||||
try {
|
try {
|
||||||
// Contar jugadores totales apuntados en los equipos de esta partida
|
// 1. Contar cuántos jugadores hay asignados en esta partida
|
||||||
$stmt = $conexion->prepare("
|
$stmt = $conexion->prepare("
|
||||||
SELECT COUNT(exu.idUsuario) AS total_jugadores
|
SELECT COUNT(exu.idUsuario) AS total_jugadores
|
||||||
FROM equipoxpartida exp
|
FROM equipoxpartida exp
|
||||||
@@ -38,7 +38,7 @@ switch ($orden) {
|
|||||||
|
|
||||||
$preguntasTotalesEsperadas = $totalJugadores * 10;
|
$preguntasTotalesEsperadas = $totalJugadores * 10;
|
||||||
|
|
||||||
// Contar respuestas dadas en la partida
|
// 2. Contar cuántas respuestas reales se han guardado
|
||||||
$stmtRespuestas = $conexion->prepare("
|
$stmtRespuestas = $conexion->prepare("
|
||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM respuestaalmacenada ra
|
FROM respuestaalmacenada ra
|
||||||
@@ -50,17 +50,16 @@ switch ($orden) {
|
|||||||
|
|
||||||
$terminada = ($respuestasRespondidas >= $preguntasTotalesEsperadas && $preguntasTotalesEsperadas > 0);
|
$terminada = ($respuestasRespondidas >= $preguntasTotalesEsperadas && $preguntasTotalesEsperadas > 0);
|
||||||
|
|
||||||
// Cuando la partida finaliza, se actualizan los históricos
|
// 3. Si ha terminado, guardamos los datos históricos una sola vez
|
||||||
if ($terminada && !isset($_SESSION['partidas_procesadas'][$idPartida])) {
|
if ($terminada && !isset($_SESSION['partidas_procesadas'][$idPartida])) {
|
||||||
|
|
||||||
$conexion->beginTransaction();
|
$conexion->beginTransaction();
|
||||||
|
|
||||||
// CÁLCULO DE VELOCIDAD PREGUNTA A PREGUNTA EN SESIÓN
|
// --- CÁLCULO DE VELOCIDAD ---
|
||||||
if (!isset($_SESSION['primeros_en_acertar'][$idPartida])) {
|
if (!isset($_SESSION['primeros_en_acertar'][$idPartida])) {
|
||||||
$_SESSION['primeros_en_acertar'][$idPartida] = [];
|
$_SESSION['primeros_en_acertar'][$idPartida] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vemos quién fue el primero
|
|
||||||
$stmtVelocidad = $conexion->prepare("
|
$stmtVelocidad = $conexion->prepare("
|
||||||
SELECT ra.idPartidaxPregunta, ra.idUsuario
|
SELECT ra.idPartidaxPregunta, ra.idUsuario
|
||||||
FROM respuestaalmacenada ra
|
FROM respuestaalmacenada ra
|
||||||
@@ -81,8 +80,7 @@ switch ($orden) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualizamos la base de datos
|
// Consulta de aciertos
|
||||||
// Buscamos los aciertos de cada jugador en la partida actual
|
|
||||||
$stmtAciertos = $conexion->prepare("
|
$stmtAciertos = $conexion->prepare("
|
||||||
SELECT ra.idUsuario, exu.idEquipo, COUNT(*) as aciertos_partida
|
SELECT ra.idUsuario, exu.idEquipo, COUNT(*) as aciertos_partida
|
||||||
FROM respuestaalmacenada ra
|
FROM respuestaalmacenada ra
|
||||||
@@ -90,12 +88,12 @@ switch ($orden) {
|
|||||||
INNER JOIN respuesta r ON ra.idRespuesta = r.idRespuesta
|
INNER JOIN respuesta r ON ra.idRespuesta = r.idRespuesta
|
||||||
INNER JOIN equipoxusuario exu ON ra.idUsuario = exu.idUsuario
|
INNER JOIN equipoxusuario exu ON ra.idUsuario = exu.idUsuario
|
||||||
WHERE pxp.idPartida = :idPartida AND r.correcta = 1
|
WHERE pxp.idPartida = :idPartida AND r.correcta = 1
|
||||||
GROUP BY ra.idUsuario
|
GROUP BY ra.idUsuario, exu.idEquipo
|
||||||
");
|
");
|
||||||
$stmtAciertos->execute([':idPartida' => $idPartida]);
|
$stmtAciertos->execute([':idPartida' => $idPartida]);
|
||||||
$jugadoresPartida = $stmtAciertos->fetchAll(PDO::FETCH_ASSOC);
|
$jugadoresPartida = $stmtAciertos->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
$updateAciertosGlobales = $conexion->prepare("
|
$updateAciertos = $conexion->prepare("
|
||||||
UPDATE usuario
|
UPDATE usuario
|
||||||
SET aciertos = aciertos + :nuevos_aciertos
|
SET aciertos = aciertos + :nuevos_aciertos
|
||||||
WHERE idUsuario = :idUsuario
|
WHERE idUsuario = :idUsuario
|
||||||
@@ -107,7 +105,6 @@ switch ($orden) {
|
|||||||
$idE = (int)$jp['idEquipo'];
|
$idE = (int)$jp['idEquipo'];
|
||||||
$nuevosAciertos = (int)$jp['aciertos_partida'];
|
$nuevosAciertos = (int)$jp['aciertos_partida'];
|
||||||
|
|
||||||
// Sumamos los aciertos al perfil del usuario
|
|
||||||
$updateAciertos->execute([
|
$updateAciertos->execute([
|
||||||
':nuevos_aciertos' => $nuevosAciertos,
|
':nuevos_aciertos' => $nuevosAciertos,
|
||||||
':idUsuario' => $idU
|
':idUsuario' => $idU
|
||||||
@@ -119,34 +116,42 @@ switch ($orden) {
|
|||||||
$puntosEquipos[$idE] += $nuevosAciertos;
|
$puntosEquipos[$idE] += $nuevosAciertos;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determinamos qué equipo ha obtenido más aciertos en la partida
|
if (!empty($puntosEquipos)) {
|
||||||
arsort($puntosEquipos);
|
arsort($puntosEquipos);
|
||||||
$idEquipoGanador = key($puntosEquipos);
|
$idEquipoGanador = key($puntosEquipos);
|
||||||
|
|
||||||
// Obtenemos todos los usuarios de la partida para asignar victorias/derrotas
|
$stmtMiembros = $conexion->prepare("
|
||||||
$stmtMiembros = $conexion->prepare("
|
SELECT exu.idUsuario, exu.idEquipo
|
||||||
SELECT exu.idUsuario, exu.idEquipo
|
FROM equipoxpartida exp
|
||||||
FROM equipoxpartida exp
|
INNER JOIN equipoxusuario exu ON exp.idEquipo = exu.idEquipo
|
||||||
INNER JOIN equipoxusuario exu ON exp.idEquipo = exu.idEquipo
|
WHERE exp.idPartida = :idPartida
|
||||||
WHERE exp.idPartida = :idPartida
|
");
|
||||||
");
|
$stmtMiembros->execute([':idPartida' => $idPartida]);
|
||||||
$stmtMiembros->execute([':idPartida' => $idPartida]);
|
$todosLosMiembros = $stmtMiembros->fetchAll(PDO::FETCH_ASSOC);
|
||||||
$todosLosMiembros = $stmtMiembros->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
|
|
||||||
$updateVictoria = $conexion->prepare("UPDATE usuario SET victorias = victorias + 1 WHERE idUsuario = :idUsuario");
|
$updateVictoria = $conexion->prepare("UPDATE usuario SET victorias = victorias + 1 WHERE idUsuario = :idUsuario");
|
||||||
$updateDerrota = $conexion->prepare("UPDATE usuario SET derrotas = derrotas + 1 WHERE idUsuario = :idUsuario");
|
$updateDerrota = $conexion->prepare("UPDATE usuario SET derrotas = derrotas + 1 WHERE idUsuario = :idUsuario");
|
||||||
|
|
||||||
foreach ($todosLosMiembros as $miembro) {
|
foreach ($todosLosMiembros as $miembro) {
|
||||||
$idU = (int)$miembro['idUsuario'];
|
$idU = (int)$miembro['idUsuario'];
|
||||||
$idE = (int)$miembro['idEquipo'];
|
$idE = (int)$miembro['idEquipo'];
|
||||||
|
|
||||||
if ($idE === $idEquipoGanador) {
|
if ($idE === $idEquipoGanador) {
|
||||||
$updateVictoria->execute([':idUsuario' => $idU]);
|
$updateVictoria->execute([':idUsuario' => $idU]);
|
||||||
} else {
|
} else {
|
||||||
$updateDerrota->execute([':idUsuario' => $idU]);
|
$updateDerrota->execute([':idUsuario' => $idU]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Marcar fecha fin de la partida para los históricos globales del grupo
|
||||||
|
$stmtFinalizar = $conexion->prepare("
|
||||||
|
UPDATE partida
|
||||||
|
SET fechaFin = NOW()
|
||||||
|
WHERE idPartida = :idPartida AND fechaFin IS NULL
|
||||||
|
");
|
||||||
|
$stmtFinalizar->execute([':idPartida' => $idPartida]);
|
||||||
|
|
||||||
$conexion->commit();
|
$conexion->commit();
|
||||||
$_SESSION['partidas_procesadas'][$idPartida] = true;
|
$_SESSION['partidas_procesadas'][$idPartida] = true;
|
||||||
}
|
}
|
||||||
@@ -160,7 +165,70 @@ switch ($orden) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
case 'registrarSalidaUsuario':
|
||||||
echo json_encode(['error' => 'Acción no permitida']);
|
try {
|
||||||
|
$idUsuario = (int)$_SESSION['idUsuario'];
|
||||||
|
$conexion->beginTransaction();
|
||||||
|
|
||||||
|
// A. LIBERACIÓN INMEDIATA DEL JUGADOR ACTUAL: Lo borramos de su equipo
|
||||||
|
$stmtSalir = $conexion->prepare("DELETE FROM equipoxusuario WHERE idUsuario = :idUsuario");
|
||||||
|
$stmtSalir->execute([':idUsuario' => $idUsuario]);
|
||||||
|
|
||||||
|
// B. CONTADOR DE ALUMNOS QUEDAN: Contamos cuántas personas quedan en los equipos de esta partida
|
||||||
|
$stmtContarQuedan = $conexion->prepare("
|
||||||
|
SELECT COUNT(exu.idUsuario)
|
||||||
|
FROM equipoxpartida exp
|
||||||
|
INNER JOIN equipoxusuario exu ON exp.idEquipo = exu.idEquipo
|
||||||
|
WHERE exp.idPartida = :idPartida
|
||||||
|
");
|
||||||
|
$stmtContarQuedan->execute([':idPartida' => $idPartida]);
|
||||||
|
$jugadoresRestantes = (int)$stmtContarQuedan->fetchColumn();
|
||||||
|
|
||||||
|
// C. DESTRUCCIÓN EN CADENA AUTOMÁTICA ATÓMICA (Si da 0, somos los últimos en salir)
|
||||||
|
if ($jugadoresRestantes === 0) {
|
||||||
|
// 1. Limpiar las respuestas almacenadas
|
||||||
|
$stmtBorrarRespuestas = $conexion->prepare("
|
||||||
|
DELETE ra FROM respuestaalmacenada ra
|
||||||
|
INNER JOIN partidaxpregunta pxp ON ra.idPartidaxPregunta = pxp.idPartidaxPregunta
|
||||||
|
WHERE pxp.idPartida = :idPartida
|
||||||
|
");
|
||||||
|
$stmtBorrarRespuestas->execute([':idPartida' => $idPartida]);
|
||||||
|
|
||||||
|
// 2. Limpiar las preguntas vinculadas a la partida
|
||||||
|
$stmtBorrarPreguntas = $conexion->prepare("DELETE FROM partidaxpregunta WHERE idPartida = :idPartida");
|
||||||
|
$stmtBorrarPreguntas->execute([':idPartida' => $idPartida]);
|
||||||
|
|
||||||
|
// 3. NUEVO: Obtener los IDs de los dos equipos que jugaban en esta partida antes de borrar la relación
|
||||||
|
$stmtObtenerEquipos = $conexion->prepare("SELECT idEquipo FROM equipoxpartida WHERE idPartida = :idPartida");
|
||||||
|
$stmtObtenerEquipos->execute([':idPartida' => $idPartida]);
|
||||||
|
$equiposDeLaPartida = $stmtObtenerEquipos->fetchAll(PDO::FETCH_COLUMN);
|
||||||
|
|
||||||
|
// 4. Limpiar la relación de equipos de la partida (tabla intermedia)
|
||||||
|
$stmtBorrarEquiposPartida = $conexion->prepare("DELETE FROM equipoxpartida WHERE idPartida = :idPartida");
|
||||||
|
$stmtBorrarEquiposPartida = $conexion->prepare("DELETE FROM equipoxpartida WHERE idPartida = :idPartida");
|
||||||
|
$stmtBorrarEquiposPartida->execute([':idPartida' => $idPartida]);
|
||||||
|
|
||||||
|
// 5. NUEVO: Borrar físicamente los equipos de la tabla 'equipo' si existen
|
||||||
|
if (!empty($equiposDeLaPartida)) {
|
||||||
|
// Creamos los marcadores (?, ?) de forma dinámica según los equipos que devuelva
|
||||||
|
$inQuery = implode(',', array_fill(0, count($equiposDeLaPartida), '?'));
|
||||||
|
$stmtBorrarEquiposFisicos = $conexion->prepare("DELETE FROM equipo WHERE idEquipo IN ($inQuery)");
|
||||||
|
$stmtBorrarEquiposFisicos->execute($equiposDeLaPartida);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6. Borrar físicamente la fila de la partida principal
|
||||||
|
$stmtBorrarSala = $conexion->prepare("DELETE FROM partida WHERE idPartida = :idPartida");
|
||||||
|
$stmtBorrarSala->execute([':idPartida' => $idPartida]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$conexion->commit();
|
||||||
|
echo json_encode(['exito' => true, 'usuarios_quedan' => $jugadoresRestantes]);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
if ($conexion->inTransaction()) {
|
||||||
|
$conexion->rollBack();
|
||||||
|
}
|
||||||
|
echo json_encode(['error' => $e->getMessage()]);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -77,8 +77,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.btn-unirse:hover {
|
.btn-unirse:hover {
|
||||||
background-color: #0f56ab;
|
background-color: #1f6f09;
|
||||||
color: white;
|
color: white;
|
||||||
|
transform: translateY(-2px);
|
||||||
}
|
}
|
||||||
|
|
||||||
.modal-kahoot {
|
.modal-kahoot {
|
||||||
|
|||||||
@@ -401,3 +401,18 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
.modal-kahoot {
|
||||||
|
border: none;
|
||||||
|
border-radius: 20px;
|
||||||
|
overflow: hidden;
|
||||||
|
box-shadow: 0 15px 40px rgba(0, 0, 0, 0.25);
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal-kahoot-header {
|
||||||
|
background-color: var(--kahoot-purple);
|
||||||
|
color: white;
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
+366
-292
@@ -1,435 +1,509 @@
|
|||||||
let usuarioYaEstaEnEquipo = false;
|
let intervaloBuscadorSalas = null;
|
||||||
|
let cargandoSalas = false;
|
||||||
|
|
||||||
$(document).ready(function () {
|
function iniciarActualizacionSalas() {
|
||||||
comprobarSalaUsuario();
|
if (intervaloBuscadorSalas) {
|
||||||
});
|
clearInterval(intervaloBuscadorSalas);
|
||||||
|
}
|
||||||
|
|
||||||
// 1. Comprobar si el usuario actual ya pertenece a una sala
|
cargarSalas();
|
||||||
function comprobarSalaUsuario() {
|
|
||||||
$("#cargandoSalas").remove();
|
|
||||||
|
|
||||||
$.ajax({
|
intervaloBuscadorSalas = setInterval(function () {
|
||||||
url: "controladores/controladorEquipoxUsuario.php",
|
if (!usuarioYaEstaEnEquipo) {
|
||||||
type: "POST",
|
|
||||||
dataType: "json",
|
|
||||||
data: { orden: "obtenerSalaUsuario" },
|
|
||||||
success: function (respuesta) {
|
|
||||||
if (respuesta.error || !respuesta.asociado) {
|
|
||||||
usuarioYaEstaEnEquipo = false;
|
|
||||||
$("#contenedorCrearSala").show();
|
|
||||||
cargarSalas();
|
|
||||||
} else {
|
|
||||||
usuarioYaEstaEnEquipo = true;
|
|
||||||
$("#contenedorCrearSala").hide(); // Ocultar "Crear Sala" si ya pertenece a una
|
|
||||||
cargarSalaUsuario(respuesta.idPartida);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error: function (xhr, status, error) {
|
|
||||||
console.error("Error al comprobar la sala del usuario:", error);
|
|
||||||
usuarioYaEstaEnEquipo = false;
|
|
||||||
cargarSalas();
|
cargarSalas();
|
||||||
},
|
}
|
||||||
});
|
}, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Cargar únicamente la sala en la que está metido el usuario
|
|
||||||
function cargarSalaUsuario(idPartida) {
|
|
||||||
$.ajax({
|
|
||||||
url: "controladores/controladorPartida.php",
|
|
||||||
type: "POST",
|
|
||||||
dataType: "json",
|
|
||||||
data: { orden: "buscar", idPartida: idPartida },
|
|
||||||
success: function (partida) {
|
|
||||||
if (partida.error) {
|
|
||||||
console.error(partida.error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$("#contenedorSalas").empty();
|
|
||||||
cargarInformacionSala(partida);
|
|
||||||
},
|
|
||||||
error: function (xhr, status, error) {
|
|
||||||
console.error("Error al obtener la sala del usuario:", error);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Cargar la lista completa de todas las salas
|
|
||||||
function cargarSalas() {
|
function cargarSalas() {
|
||||||
|
if (cargandoSalas) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cargandoSalas = true;
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "controladores/controladorPartida.php",
|
url: "controladores/controladorPartida.php",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
data: { orden: "listar" },
|
data: {
|
||||||
|
orden: "listar",
|
||||||
|
},
|
||||||
|
|
||||||
success: function (partidas) {
|
success: function (partidas) {
|
||||||
const contenedor = $("#contenedorSalas");
|
const contenedor = $("#contenedorSalas");
|
||||||
contenedor.empty();
|
|
||||||
|
|
||||||
if (!Array.isArray(partidas) || partidas.length === 0) {
|
if (!Array.isArray(partidas) || partidas.length === 0) {
|
||||||
contenedor.html(`
|
$(".sala-item").remove();
|
||||||
<div class="col-12 text-center">
|
|
||||||
<p class="text-muted">No hay salas disponibles actualmente.</p>
|
if ($("#mensajeSinSalas").length === 0) {
|
||||||
</div>
|
contenedor.append(`
|
||||||
`);
|
<div
|
||||||
|
id="mensajeSinSalas"
|
||||||
|
class="col-12 text-center">
|
||||||
|
|
||||||
|
<p class="text-muted">
|
||||||
|
No hay salas disponibles actualmente.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$("#mensajeSinSalas").remove();
|
||||||
|
|
||||||
|
const idsPartidas = partidas.map(function (partida) {
|
||||||
|
return String(partida.idPartida);
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".sala-item").each(function () {
|
||||||
|
const idPartida = String($(this).data("id-partida"));
|
||||||
|
|
||||||
|
if (!idsPartidas.includes(idPartida)) {
|
||||||
|
$(this).remove();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
partidas.forEach(function (partida) {
|
partidas.forEach(function (partida) {
|
||||||
cargarInformacionSala(partida);
|
cargarSalaBuscador(partida);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
error: function (xhr, status, error) {
|
error: function (xhr, status, error) {
|
||||||
console.error("Error al obtener las partidas:", error);
|
console.error(
|
||||||
|
"Error al obtener las partidas:",
|
||||||
|
error
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
complete: function () {
|
||||||
|
cargandoSalas = false;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Obtener equipos y jugadores asociados a una sala concreta
|
function cargarSalaBuscador(partida) {
|
||||||
function cargarInformacionSala(partida) {
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "controladores/controladorPartida.php",
|
url: "controladores/controladorPartida.php",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
data: { orden: "getEquipos", idPartida: partida.idPartida },
|
data: {
|
||||||
|
orden: "getEquipos",
|
||||||
|
idPartida: partida.idPartida,
|
||||||
|
},
|
||||||
|
|
||||||
success: function (equipos) {
|
success: function (equipos) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "controladores/controladorPartida.php",
|
url: "controladores/controladorPartida.php",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
data: { orden: "getJugadores", idPartida: partida.idPartida },
|
data: {
|
||||||
success: function (jugadores) {
|
orden: "getJugadores",
|
||||||
mostrarSala(partida, equipos, jugadores);
|
idPartida: partida.idPartida,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
success: function (jugadores) {
|
||||||
|
if (
|
||||||
|
!Array.isArray(jugadores) ||
|
||||||
|
jugadores.length === 0
|
||||||
|
) {
|
||||||
|
$(
|
||||||
|
`.sala-item[data-id-partida="${partida.idPartida}"]`
|
||||||
|
).remove();
|
||||||
|
|
||||||
|
comprobarSiNoHaySalas();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
actualizarSalaBuscador(
|
||||||
|
partida,
|
||||||
|
equipos,
|
||||||
|
jugadores
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
error: function (xhr, status, error) {
|
error: function (xhr, status, error) {
|
||||||
console.error("Error al obtener jugadores:", error);
|
console.error(
|
||||||
|
"Error al obtener jugadores:",
|
||||||
|
error
|
||||||
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
error: function (xhr, status, error) {
|
error: function (xhr, status, error) {
|
||||||
console.error("Error al obtener equipos:", error);
|
console.error(
|
||||||
|
"Error al obtener equipos:",
|
||||||
|
error
|
||||||
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. Renderizar el HTML de la sala y botones según estado
|
function comprobarSiNoHaySalas() {
|
||||||
function mostrarSala(partida, equipos, jugadores) {
|
if ($(".sala-item").length === 0) {
|
||||||
const contenedor = $("#contenedorSalas");
|
if ($("#mensajeSinSalas").length === 0) {
|
||||||
|
$("#contenedorSalas").append(`
|
||||||
|
<div
|
||||||
|
id="mensajeSinSalas"
|
||||||
|
class="col-12 text-center">
|
||||||
|
|
||||||
|
<p class="text-muted">
|
||||||
|
No hay salas disponibles actualmente.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function actualizarSalaBuscador(
|
||||||
|
partida,
|
||||||
|
equipos,
|
||||||
|
jugadores
|
||||||
|
) {
|
||||||
|
$("#mensajeSinSalas").remove();
|
||||||
|
|
||||||
|
const selectorSala =
|
||||||
|
`.sala-item[data-id-partida="${partida.idPartida}"]`;
|
||||||
|
|
||||||
|
const salaExistente = $(selectorSala);
|
||||||
|
|
||||||
|
if (salaExistente.length === 0) {
|
||||||
|
crearSalaBuscador(
|
||||||
|
partida,
|
||||||
|
equipos,
|
||||||
|
jugadores
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const equiposHTML =
|
||||||
|
generarEquiposHTML(
|
||||||
|
partida,
|
||||||
|
equipos,
|
||||||
|
jugadores
|
||||||
|
);
|
||||||
|
|
||||||
|
salaExistente
|
||||||
|
.find(".equipos")
|
||||||
|
.html(equiposHTML);
|
||||||
|
}
|
||||||
|
|
||||||
|
function crearSalaBuscador(
|
||||||
|
partida,
|
||||||
|
equipos,
|
||||||
|
jugadores
|
||||||
|
) {
|
||||||
|
$("#mensajeSinSalas").remove();
|
||||||
|
|
||||||
|
const equiposHTML =
|
||||||
|
generarEquiposHTML(
|
||||||
|
partida,
|
||||||
|
equipos,
|
||||||
|
jugadores
|
||||||
|
);
|
||||||
|
|
||||||
|
const salaHTML = `
|
||||||
|
<div
|
||||||
|
class="col-12 col-md-10 col-lg-8 sala-item"
|
||||||
|
data-id-partida="${partida.idPartida}">
|
||||||
|
|
||||||
|
<div class="sala card p-3 shadow-sm mb-4">
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="sala-header h4 text-center mb-3 text-white">
|
||||||
|
|
||||||
|
${escapeHTML(partida.nombrePartida)}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="sala-body">
|
||||||
|
|
||||||
|
<div class="equipos d-flex justify-content-around">
|
||||||
|
|
||||||
|
${equiposHTML}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
$("#contenedorSalas").append(salaHTML);
|
||||||
|
}
|
||||||
|
|
||||||
|
function generarEquiposHTML(
|
||||||
|
partida,
|
||||||
|
equipos,
|
||||||
|
jugadores
|
||||||
|
) {
|
||||||
let equiposHTML = "";
|
let equiposHTML = "";
|
||||||
|
|
||||||
equipos.forEach(function (equipo) {
|
equipos.forEach(function (equipo) {
|
||||||
const jugadoresEquipo = jugadores.filter(function (jugador) {
|
const jugadoresEquipo =
|
||||||
return jugador.idEquipo == equipo.idEquipo;
|
jugadores.filter(function (jugador) {
|
||||||
});
|
return (
|
||||||
|
jugador.idEquipo ==
|
||||||
|
equipo.idEquipo
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
let jugadoresHTML = "";
|
let jugadoresHTML = "";
|
||||||
|
|
||||||
if (jugadoresEquipo.length > 0) {
|
if (jugadoresEquipo.length > 0) {
|
||||||
jugadoresEquipo.forEach(function (jugador) {
|
jugadoresEquipo.forEach(function (jugador) {
|
||||||
const esHost = jugador.idUsuario == partida.idUsuario;
|
const esHost =
|
||||||
|
jugador.idUsuario ==
|
||||||
|
partida.idUsuario;
|
||||||
|
|
||||||
jugadoresHTML += `
|
jugadoresHTML += `
|
||||||
<div class="jugador border border-2 d-flex align-items-center justify-content-between ${
|
<div
|
||||||
esHost ? "jugador-host" : ""
|
class="jugador border border-2 d-flex align-items-center justify-content-between">
|
||||||
}">
|
|
||||||
<div>
|
|
||||||
<span class="avatar">${esHost ? '<i class="bi bi-award-fill"></i>' : '<i class="bi bi-person-fill"></i>'}</span>
|
|
||||||
${escapeHTML(jugador.nombreUsuario)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
${
|
<div>
|
||||||
esHost
|
|
||||||
? `<span class="badge bg-warning text-dark ms-2">HOST</span>`
|
<span class="avatar">
|
||||||
: ""
|
|
||||||
}
|
${
|
||||||
</div>
|
esHost
|
||||||
`;
|
? '<i class="bi bi-award-fill"></i>'
|
||||||
|
: '<i class="bi bi-person-fill"></i>'
|
||||||
|
}
|
||||||
|
|
||||||
|
</span>
|
||||||
|
|
||||||
|
${escapeHTML(
|
||||||
|
jugador.nombreUsuario
|
||||||
|
)}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
${
|
||||||
|
esHost
|
||||||
|
? `
|
||||||
|
<span
|
||||||
|
class="badge bg-warning text-dark ms-2">
|
||||||
|
|
||||||
|
HOST
|
||||||
|
|
||||||
|
</span>
|
||||||
|
`
|
||||||
|
: ""
|
||||||
|
}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
jugadoresHTML = `<div class="text-muted small">Sin jugadores</div>`;
|
jugadoresHTML = `
|
||||||
|
<div class="text-muted small">
|
||||||
|
Sin jugadores
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Botón "Unirse" solo visible si NO pertenece a ningún equipo
|
|
||||||
let botonUnirseHTML = "";
|
let botonUnirseHTML = "";
|
||||||
|
|
||||||
if (!usuarioYaEstaEnEquipo) {
|
if (!usuarioYaEstaEnEquipo) {
|
||||||
botonUnirseHTML = `
|
botonUnirseHTML = `
|
||||||
<button type="button" class="btn-unirse w-100 btn-unirse-equipo mt-2"
|
<button
|
||||||
data-id-partida="${partida.idPartida}"
|
type="button"
|
||||||
data-id-equipo="${equipo.idEquipo}">
|
class="btn-unirse w-100 btn-unirse-equipo mt-2"
|
||||||
|
data-id-partida="${partida.idPartida}"
|
||||||
|
data-id-equipo="${equipo.idEquipo}">
|
||||||
|
|
||||||
Unirse
|
Unirse
|
||||||
|
|
||||||
</button>
|
</button>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
equiposHTML += `
|
equiposHTML += `
|
||||||
<div class="equipo me-2 ms-2 p-3 border rounded">
|
<div
|
||||||
<h6>${escapeHTML(equipo.nombreEquipo)}</h6>
|
class="equipo me-2 ms-2 p-3 border rounded">
|
||||||
|
|
||||||
|
<h6>
|
||||||
|
${escapeHTML(
|
||||||
|
equipo.nombreEquipo
|
||||||
|
)}
|
||||||
|
</h6>
|
||||||
|
|
||||||
<div class="jugadores mb-2">
|
<div class="jugadores mb-2">
|
||||||
|
|
||||||
${jugadoresHTML}
|
${jugadoresHTML}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
${botonUnirseHTML}
|
${botonUnirseHTML}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Acciones disponibles si el usuario YA ESTÁ dentro de esta sala
|
return equiposHTML;
|
||||||
// Acciones disponibles si el usuario YA ESTÁ dentro de esta sala
|
|
||||||
let accionesSalaHTML = "";
|
|
||||||
|
|
||||||
if (usuarioYaEstaEnEquipo) {
|
|
||||||
const esHost = partida.idUsuario == idUsuarioSesion;
|
|
||||||
let botonIniciarHTML = "";
|
|
||||||
|
|
||||||
// Solo el host puede iniciar la partida
|
|
||||||
if (esHost) {
|
|
||||||
botonIniciarHTML = `
|
|
||||||
<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 = `
|
|
||||||
<div class="sala-acciones text-center mt-4 pt-3 border-top d-flex justify-content-center gap-3">
|
|
||||||
|
|
||||||
<button type="button"
|
|
||||||
class="btn btn-outline-danger btn-abandonar-sala"
|
|
||||||
data-id-partida="${partida.idPartida}"
|
|
||||||
data-es-host="${esHost}">
|
|
||||||
Abandonar sala
|
|
||||||
</button>
|
|
||||||
|
|
||||||
${botonIniciarHTML}
|
|
||||||
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const salaHTML = `
|
|
||||||
<div class="col-12 col-md-10 col-lg-8">
|
|
||||||
<div class="sala card p-3 shadow-sm mb-4">
|
|
||||||
<div class="sala-header h4 text-center mb-3 text-white">
|
|
||||||
${escapeHTML(partida.nombrePartida)}
|
|
||||||
</div>
|
|
||||||
<div class="sala-body">
|
|
||||||
<div class="equipos d-flex justify-content-around">
|
|
||||||
${equiposHTML}
|
|
||||||
</div>
|
|
||||||
${accionesSalaHTML}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
|
|
||||||
contenedor.append(salaHTML);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6. Evento: Unirse a un Equipo
|
|
||||||
$(document).on("click", ".btn-unirse-equipo", function () {
|
|
||||||
const boton = $(this);
|
|
||||||
const idEquipo = boton.data("id-equipo");
|
|
||||||
const idPartida = boton.data("id-partida");
|
|
||||||
|
|
||||||
boton.prop("disabled", true).text("Uniéndose...");
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: "controladores/controladorEquipoxUsuario.php",
|
|
||||||
type: "POST",
|
|
||||||
dataType: "json",
|
|
||||||
data: {
|
|
||||||
orden: "registrarUsuarioEnEquipo",
|
|
||||||
idEquipo: idEquipo,
|
|
||||||
},
|
|
||||||
success: function (respuesta) {
|
|
||||||
if (respuesta.error) {
|
|
||||||
alert(respuesta.error);
|
|
||||||
boton.prop("disabled", false).text("Unirse");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
usuarioYaEstaEnEquipo = true;
|
|
||||||
$("#contenedorCrearSala").hide();
|
|
||||||
$("#contenedorSalas").empty();
|
|
||||||
cargarSalaUsuario(idPartida);
|
|
||||||
},
|
|
||||||
error: function (xhr, status, error) {
|
|
||||||
console.error("Error al unirse al equipo:", error);
|
|
||||||
alert("No se ha podido unir al equipo.");
|
|
||||||
boton.prop("disabled", false).text("Unirse");
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// 7. Evento: Abandonar Sala
|
|
||||||
// Guardamos temporalmente el botón presionado
|
|
||||||
let botonAbandonarReferencia = null;
|
|
||||||
|
|
||||||
// A. Al hacer clic en el botón "Abandonar sala" de la tarjeta, abrimos el modal
|
|
||||||
$(document).on("click", ".btn-abandonar-sala", function () {
|
|
||||||
botonAbandonarReferencia = $(this);
|
|
||||||
|
|
||||||
const esHost = $(this).data("es-host") === true || $(this).data("es-host") === "true";
|
|
||||||
const titulo = $("#modalAbandonarSalaLabel");
|
|
||||||
const mensaje = $("#modalAbandonarSalaMensaje");
|
|
||||||
const botonConfirmar = $("#btnConfirmarAbandonar");
|
|
||||||
|
|
||||||
if (esHost) {
|
|
||||||
titulo.text("¿Abandonar la sala?");
|
|
||||||
mensaje.text(
|
|
||||||
"Si abandonas la sala como anfitrión, la partida terminará para todos los jugadores.",
|
|
||||||
);
|
|
||||||
botonConfirmar.text("Sí, abandonar");
|
|
||||||
} else {
|
|
||||||
titulo.text("¿Abandonar la sala?");
|
|
||||||
mensaje.text(
|
|
||||||
"Si sales de la sala, perderás tu lugar en el equipo.",
|
|
||||||
);
|
|
||||||
botonConfirmar.text("Sí, salir");
|
|
||||||
}
|
|
||||||
|
|
||||||
const modal = new bootstrap.Modal(
|
|
||||||
document.getElementById("modalAbandonarSala"),
|
|
||||||
);
|
|
||||||
|
|
||||||
modal.show();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// B. Al hacer clic en "Sí, salir" dentro del modal Kahoot
|
|
||||||
$(document).on("click", "#btnConfirmarAbandonar", function () {
|
|
||||||
const modalEl = document.getElementById("modalAbandonarSala");
|
|
||||||
const modalInstance = bootstrap.Modal.getInstance(modalEl);
|
|
||||||
|
|
||||||
const btnConfirmar = $(this);
|
|
||||||
btnConfirmar.prop("disabled", true).text("Saliendo...");
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: "controladores/controladorEquipoxUsuario.php",
|
|
||||||
type: "POST",
|
|
||||||
dataType: "json",
|
|
||||||
data: { orden: "salirDeSala" },
|
|
||||||
success: function (respuesta) {
|
|
||||||
btnConfirmar.prop("disabled", false).text("Sí, salir");
|
|
||||||
|
|
||||||
if (modalInstance) {
|
|
||||||
modalInstance.hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (respuesta.error) {
|
|
||||||
alert(respuesta.error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restablecemos la interfaz a la lista completa de salas
|
|
||||||
usuarioYaEstaEnEquipo = false;
|
|
||||||
$("#contenedorCrearSala").show();
|
|
||||||
cargarSalas();
|
|
||||||
},
|
|
||||||
error: function (xhr, status, error) {
|
|
||||||
console.error("Error al salir de la sala:", error);
|
|
||||||
alert("No se pudo salir de la sala.");
|
|
||||||
btnConfirmar.prop("disabled", false).text("Sí, salir");
|
|
||||||
if (modalInstance) {
|
|
||||||
modalInstance.hide();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
// 8. Evento: Crear Sala
|
|
||||||
$("#btnCrearSala").on("click", function () {
|
$("#btnCrearSala").on("click", function () {
|
||||||
const nombreSala = $("#nombreSala").val().trim();
|
const nombreSala =
|
||||||
const nombreEquipo1 = $("#nombreEquipo1").val().trim();
|
$("#nombreSala").val().trim();
|
||||||
const nombreEquipo2 = $("#nombreEquipo2").val().trim();
|
|
||||||
|
const nombreEquipo1 =
|
||||||
|
$("#nombreEquipo1").val().trim();
|
||||||
|
|
||||||
|
const nombreEquipo2 =
|
||||||
|
$("#nombreEquipo2").val().trim();
|
||||||
|
|
||||||
let valido = true;
|
let valido = true;
|
||||||
$(".mensaje-error-sala").remove();
|
|
||||||
$(".input-kahoot").removeClass("is-invalid");
|
|
||||||
|
|
||||||
if (nombreSala === "" || nombreSala.length < 3) {
|
$(".mensaje-error-sala").remove();
|
||||||
|
|
||||||
|
$(".input-kahoot")
|
||||||
|
.removeClass("is-invalid");
|
||||||
|
|
||||||
|
if (
|
||||||
|
nombreSala === "" ||
|
||||||
|
nombreSala.length < 3
|
||||||
|
) {
|
||||||
mostrarError(
|
mostrarError(
|
||||||
"#nombreSala",
|
"#nombreSala",
|
||||||
"El nombre de la sala debe tener al menos 3 caracteres.",
|
"El nombre de la sala debe tener al menos 3 caracteres."
|
||||||
);
|
);
|
||||||
|
|
||||||
valido = false;
|
valido = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nombreEquipo1 === "" || nombreEquipo1.length < 2) {
|
if (
|
||||||
|
nombreEquipo1 === "" ||
|
||||||
|
nombreEquipo1.length < 2
|
||||||
|
) {
|
||||||
mostrarError(
|
mostrarError(
|
||||||
"#nombreEquipo1",
|
"#nombreEquipo1",
|
||||||
"El nombre del equipo debe tener al menos 2 caracteres.",
|
"El nombre del equipo debe tener al menos 2 caracteres."
|
||||||
);
|
);
|
||||||
|
|
||||||
valido = false;
|
valido = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nombreEquipo2 === "" || nombreEquipo2.length < 2) {
|
if (
|
||||||
|
nombreEquipo2 === "" ||
|
||||||
|
nombreEquipo2.length < 2
|
||||||
|
) {
|
||||||
mostrarError(
|
mostrarError(
|
||||||
"#nombreEquipo2",
|
"#nombreEquipo2",
|
||||||
"El nombre del equipo debe tener al menos 2 caracteres.",
|
"El nombre del equipo debe tener al menos 2 caracteres."
|
||||||
);
|
);
|
||||||
|
|
||||||
valido = false;
|
valido = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
nombreEquipo1 !== "" &&
|
nombreEquipo1 !== "" &&
|
||||||
nombreEquipo2 !== "" &&
|
nombreEquipo2 !== "" &&
|
||||||
nombreEquipo1.toLowerCase() === nombreEquipo2.toLowerCase()
|
nombreEquipo1.toLowerCase() ===
|
||||||
|
nombreEquipo2.toLowerCase()
|
||||||
) {
|
) {
|
||||||
mostrarError(
|
mostrarError(
|
||||||
"#nombreEquipo2",
|
"#nombreEquipo2",
|
||||||
"Los dos equipos deben tener nombres diferentes.",
|
"Los dos equipos deben tener nombres diferentes."
|
||||||
);
|
);
|
||||||
|
|
||||||
valido = false;
|
valido = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!valido) return;
|
if (!valido) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const boton = $("#btnCrearSala");
|
const boton = $("#btnCrearSala");
|
||||||
boton.prop("disabled", true).text("Creando sala...");
|
|
||||||
|
boton
|
||||||
|
.prop("disabled", true)
|
||||||
|
.text("Creando sala...");
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "controladores/controladorPartida.php",
|
url: "controladores/controladorPartida.php",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
|
|
||||||
data: {
|
data: {
|
||||||
orden: "crear",
|
orden: "crear",
|
||||||
nombrePartida: nombreSala,
|
nombrePartida: nombreSala,
|
||||||
nombreEquipo1: nombreEquipo1,
|
nombreEquipo1: nombreEquipo1,
|
||||||
nombreEquipo2: nombreEquipo2,
|
nombreEquipo2: nombreEquipo2,
|
||||||
},
|
},
|
||||||
|
|
||||||
success: function (respuesta) {
|
success: function (respuesta) {
|
||||||
if (respuesta.error) {
|
if (respuesta.error) {
|
||||||
alert(respuesta.error);
|
alert(respuesta.error);
|
||||||
boton.prop("disabled", false).text("Crear sala");
|
|
||||||
|
boton
|
||||||
|
.prop("disabled", false)
|
||||||
|
.text("Crear sala");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (respuesta.exito) {
|
if (respuesta.exito) {
|
||||||
$("#modalCrearSala").modal("hide");
|
$("#modalCrearSala").modal("hide");
|
||||||
|
|
||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
error: function (xhr, status, error) {
|
error: function (xhr, status, error) {
|
||||||
console.error("Error al crear la sala:", error);
|
console.error(
|
||||||
alert("No se ha podido crear la sala.");
|
"Error al crear la sala:",
|
||||||
boton.prop("disabled", false).text("Crear sala");
|
error
|
||||||
|
);
|
||||||
|
|
||||||
|
alert(
|
||||||
|
"No se ha podido crear la sala."
|
||||||
|
);
|
||||||
|
|
||||||
|
boton
|
||||||
|
.prop("disabled", false)
|
||||||
|
.text("Crear sala");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Auxiliares
|
function mostrarError(
|
||||||
function escapeHTML(texto) {
|
selector,
|
||||||
return $("<div>")
|
mensaje
|
||||||
.text(texto ?? "")
|
) {
|
||||||
.html();
|
|
||||||
}
|
|
||||||
|
|
||||||
function mostrarError(selector, mensaje) {
|
|
||||||
const input = $(selector);
|
const input = $(selector);
|
||||||
|
|
||||||
input.addClass("is-invalid");
|
input.addClass("is-invalid");
|
||||||
input.after(
|
|
||||||
`<div class="mensaje-error-sala text-danger mt-1 small">${mensaje}</div>`,
|
input.after(`
|
||||||
);
|
<div
|
||||||
|
class="mensaje-error-sala text-danger mt-1 small">
|
||||||
|
|
||||||
|
${mensaje}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
`);
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).on("input", ".input-kahoot", function () {
|
$(document).on(
|
||||||
$(this).removeClass("is-invalid");
|
"input",
|
||||||
$(this).next(".mensaje-error-sala").remove();
|
".input-kahoot",
|
||||||
});
|
function () {
|
||||||
|
$(this)
|
||||||
|
.removeClass("is-invalid");
|
||||||
|
|
||||||
|
$(this)
|
||||||
|
.next(".mensaje-error-sala")
|
||||||
|
.remove();
|
||||||
|
}
|
||||||
|
);
|
||||||
+5
-5
@@ -36,11 +36,11 @@ function renderizarTablaRanking(jugadores) {
|
|||||||
<thead class="table-dark">
|
<thead class="table-dark">
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col" style="width: 10%;">#</th>
|
<th scope="col" style="width: 10%;">#</th>
|
||||||
<th scope="col" class="text-start" style="width: 35%;">Jugador</th>
|
<th scope="col" class="text-start" style="width: 30%;"><i class="fa-solid fa-user"></i> <br> Jugador</th>
|
||||||
<th scope="col" style="width: 15%;"><i class="fa-solid fa-trophy text-warning me-1"></i> Vic</th>
|
<th scope="col" style="width: 15%;"><i class="fa-solid fa-trophy text-warning me-1"></i> <br> Victorias</th>
|
||||||
<th scope="col" style="width: 15%;"><i class="fa-solid fa-xmark text-danger me-1"></i> Der</th>
|
<th scope="col" style="width: 15%;"><i class="fa-solid fa-xmark text-danger me-1"></i> <br> Derrotas</th>
|
||||||
<th scope="col" style="width: 15%;"><i class="fa-solid fa-bullseye text-success me-1"></i> Aciertos</th>
|
<th scope="col" style="width: 15%;"><i class="fa-solid fa-bullseye text-success me-1"></i> <br> Aciertos</th>
|
||||||
<th scope="col" style="width: 10%;"><i class="fa-solid fa-percent text-info me-1"></i> % Vic</th>
|
<th scope="col" style="width: 15%;"><i class="fa-solid fa-medal text-info me-1"></i> <br> Efectividad</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|||||||
+1
-12
@@ -18,8 +18,6 @@ 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 () {
|
||||||
|
|
||||||
@@ -83,11 +81,6 @@ function cargarPreguntas() {
|
|||||||
|
|
||||||
// 2. Pintar la pregunta actual y sus respuestas
|
// 2. Pintar la pregunta actual y sus respuestas
|
||||||
function mostrarPregunta() {
|
function mostrarPregunta() {
|
||||||
console.log("entro en mostrarPregunta");
|
|
||||||
tiempoRespuesta = 0;
|
|
||||||
intervaloTiempo = setInterval(function () {
|
|
||||||
tiempoRespuesta++;
|
|
||||||
}, 100);
|
|
||||||
const pregunta = preguntas[indice];
|
const pregunta = preguntas[indice];
|
||||||
|
|
||||||
bloqueado = false;
|
bloqueado = false;
|
||||||
@@ -118,9 +111,6 @@ 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) {
|
||||||
console.log("entro en responder");
|
|
||||||
clearInterval(intervaloTiempo);
|
|
||||||
console.log("Tiempo de respuesta: " + tiempoRespuesta /10 + " segundos");
|
|
||||||
if (bloqueado) {
|
if (bloqueado) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -140,8 +130,7 @@ 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) {
|
||||||
|
|||||||
+72
-30
@@ -1,38 +1,80 @@
|
|||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
const idPartida = $("body").data("id-partida");
|
// Captura segura del ID de la partida desde el body de la página
|
||||||
|
const idPartida =
|
||||||
comprobarEstadoPartida(idPartida);
|
$("body").attr("data-id-partida") || $("body").data("id-partida");
|
||||||
|
|
||||||
const intervalo = setInterval(function () {
|
comprobarEstadoPartida(idPartida);
|
||||||
comprobarEstadoPartida(idPartida, intervalo);
|
|
||||||
}, 3000);
|
const intervalo = setInterval(function () {
|
||||||
|
comprobarEstadoPartida(idPartida, intervalo);
|
||||||
|
}, 3000);
|
||||||
});
|
});
|
||||||
|
|
||||||
function comprobarEstadoPartida(idPartida, intervalo = null) {
|
function comprobarEstadoPartida(idPartida, intervalo = null) {
|
||||||
$.ajax({
|
if (!idPartida || idPartida <= 0) return;
|
||||||
url: "controladores/controladorResultados.php",
|
|
||||||
type: "POST",
|
|
||||||
dataType: "json",
|
|
||||||
data: {
|
|
||||||
orden: "comprobarEstado",
|
|
||||||
idPartida: idPartida
|
|
||||||
},
|
|
||||||
success: function (respuesta) {
|
|
||||||
if (respuesta.error) {
|
|
||||||
console.error("Error:", respuesta.error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (respuesta.terminada) {
|
$.ajax({
|
||||||
if (intervalo !== null) clearInterval(intervalo);
|
url: "controladores/controladorResultados.php",
|
||||||
|
type: "POST",
|
||||||
$("#pantalla-espera").fadeOut(400, function() {
|
dataType: "json",
|
||||||
location.reload();
|
data: {
|
||||||
});
|
orden: "comprobarEstado",
|
||||||
}
|
idPartida: idPartida,
|
||||||
},
|
},
|
||||||
error: function () {
|
success: function (respuesta) {
|
||||||
console.log("Error de comunicación con el controlador.");
|
if (respuesta.error) {
|
||||||
|
console.error("Error del controlador:", respuesta.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (respuesta.terminada === true || respuesta.terminada === "true") {
|
||||||
|
if (intervalo !== null) {
|
||||||
|
clearInterval(intervalo);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
$("#pantalla-espera").hide();
|
||||||
|
$("#pantalla-resultados").show();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function () {
|
||||||
|
console.log("Esperando conexión con el servidor del Trivial...");
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// INTERCEPTOR DE SALIDA: Saca al usuario y destruye la sala en cascada
|
||||||
|
$(document).on("click", "#btnVolverInicio", function (e) {
|
||||||
|
e.preventDefault(); // Congelamos un instante la redirección
|
||||||
|
|
||||||
|
const urlDestino = $(this).attr("href");
|
||||||
|
// Leemos el ID de forma científica directamente desde el botón pulsado
|
||||||
|
const idPartida = $(this).attr("data-id");
|
||||||
|
|
||||||
|
if (!idPartida) {
|
||||||
|
window.location.href = urlDestino;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "controladores/controladorResultados.php",
|
||||||
|
type: "POST",
|
||||||
|
dataType: "json",
|
||||||
|
data: {
|
||||||
|
orden: "registrarSalidaUsuario",
|
||||||
|
idPartida: idPartida,
|
||||||
|
},
|
||||||
|
success: function (response) {
|
||||||
|
console.log(
|
||||||
|
"Servidor procesó la salida. Usuarios restantes: " +
|
||||||
|
response.usuarios_quedan,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
error: function (error) {
|
||||||
|
console.error("Error técnico al salir de la sala:", error);
|
||||||
|
},
|
||||||
|
complete: function () {
|
||||||
|
// Rompemos la pausa y mandamos al jugador al menú de inicio limpio
|
||||||
|
window.location.href = urlDestino;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
+550
@@ -0,0 +1,550 @@
|
|||||||
|
let usuarioYaEstaEnEquipo = false;
|
||||||
|
let intervaloSala = null;
|
||||||
|
let botonAbandonarReferencia = null;
|
||||||
|
|
||||||
|
$(document).ready(function () {
|
||||||
|
comprobarSalaUsuario();
|
||||||
|
});
|
||||||
|
|
||||||
|
function comprobarSalaUsuario() {
|
||||||
|
$("#cargandoSalas").remove();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "controladores/controladorEquipoxUsuario.php",
|
||||||
|
type: "POST",
|
||||||
|
dataType: "json",
|
||||||
|
data: {
|
||||||
|
orden: "obtenerSalaUsuario",
|
||||||
|
},
|
||||||
|
|
||||||
|
success: function (respuesta) {
|
||||||
|
if (respuesta.error || !respuesta.asociado) {
|
||||||
|
usuarioYaEstaEnEquipo = false;
|
||||||
|
|
||||||
|
$("#contenedorCrearSala").show();
|
||||||
|
|
||||||
|
iniciarActualizacionSalas();
|
||||||
|
} else {
|
||||||
|
usuarioYaEstaEnEquipo = true;
|
||||||
|
|
||||||
|
$("#contenedorCrearSala").hide();
|
||||||
|
|
||||||
|
cargarSalaUsuario(respuesta.idPartida);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
error: function (xhr, status, error) {
|
||||||
|
usuarioYaEstaEnEquipo = false;
|
||||||
|
|
||||||
|
if (intervaloSala) {
|
||||||
|
clearInterval(intervaloSala);
|
||||||
|
intervaloSala = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#contenedorSalas").empty();
|
||||||
|
|
||||||
|
$("#contenedorCrearSala").show();
|
||||||
|
|
||||||
|
iniciarActualizacionSalas();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function cargarSalaUsuario(idPartida) {
|
||||||
|
cargarSalaCompleta(idPartida);
|
||||||
|
|
||||||
|
if (intervaloSala) {
|
||||||
|
clearInterval(intervaloSala);
|
||||||
|
}
|
||||||
|
|
||||||
|
intervaloSala = setInterval(function () {
|
||||||
|
actualizarSalaUsuario(idPartida);
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
|
||||||
|
function cargarSalaCompleta(idPartida) {
|
||||||
|
$.ajax({
|
||||||
|
url: "controladores/controladorPartida.php",
|
||||||
|
type: "POST",
|
||||||
|
dataType: "json",
|
||||||
|
|
||||||
|
data: {
|
||||||
|
orden: "buscar",
|
||||||
|
idPartida: idPartida,
|
||||||
|
},
|
||||||
|
|
||||||
|
success: function (partida) {
|
||||||
|
if (partida.error) {
|
||||||
|
console.error(partida.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cargarInformacionSalaCompleta(partida);
|
||||||
|
},
|
||||||
|
|
||||||
|
error: function (xhr, status, error) {
|
||||||
|
console.error("Error al obtener la sala:", error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function cargarInformacionSalaCompleta(partida) {
|
||||||
|
$.ajax({
|
||||||
|
url: "controladores/controladorPartida.php",
|
||||||
|
type: "POST",
|
||||||
|
dataType: "json",
|
||||||
|
|
||||||
|
data: {
|
||||||
|
orden: "getEquipos",
|
||||||
|
idPartida: partida.idPartida,
|
||||||
|
},
|
||||||
|
|
||||||
|
success: function (equipos) {
|
||||||
|
$.ajax({
|
||||||
|
url: "controladores/controladorPartida.php",
|
||||||
|
type: "POST",
|
||||||
|
dataType: "json",
|
||||||
|
|
||||||
|
data: {
|
||||||
|
orden: "getJugadores",
|
||||||
|
idPartida: partida.idPartida,
|
||||||
|
},
|
||||||
|
|
||||||
|
success: function (jugadores) {
|
||||||
|
mostrarSala(partida, equipos, jugadores);
|
||||||
|
},
|
||||||
|
|
||||||
|
error: function (xhr, status, error) {
|
||||||
|
console.error("Error al obtener jugadores:", error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
error: function (xhr, status, error) {
|
||||||
|
console.error("Error al obtener equipos:", error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function actualizarSalaUsuario(idPartida) {
|
||||||
|
$.ajax({
|
||||||
|
url: "controladores/controladorPartida.php",
|
||||||
|
type: "POST",
|
||||||
|
dataType: "json",
|
||||||
|
|
||||||
|
data: {
|
||||||
|
orden: "buscar",
|
||||||
|
idPartida: idPartida,
|
||||||
|
},
|
||||||
|
|
||||||
|
success: function (partida) {
|
||||||
|
if (partida.error) {
|
||||||
|
console.error(partida.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cargarInformacionSala(partida);
|
||||||
|
},
|
||||||
|
|
||||||
|
error: function (xhr, status, error) {
|
||||||
|
console.error("Error al actualizar la sala:", error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function cargarInformacionSala(partida) {
|
||||||
|
$.ajax({
|
||||||
|
url: "controladores/controladorPartida.php",
|
||||||
|
type: "POST",
|
||||||
|
dataType: "json",
|
||||||
|
|
||||||
|
data: {
|
||||||
|
orden: "getEquipos",
|
||||||
|
idPartida: partida.idPartida,
|
||||||
|
},
|
||||||
|
|
||||||
|
success: function (equipos) {
|
||||||
|
$.ajax({
|
||||||
|
url: "controladores/controladorPartida.php",
|
||||||
|
type: "POST",
|
||||||
|
dataType: "json",
|
||||||
|
|
||||||
|
data: {
|
||||||
|
orden: "getJugadores",
|
||||||
|
idPartida: partida.idPartida,
|
||||||
|
},
|
||||||
|
|
||||||
|
success: function (jugadores) {
|
||||||
|
mostrarEquipos(partida, equipos, jugadores);
|
||||||
|
},
|
||||||
|
|
||||||
|
error: function (xhr, status, error) {
|
||||||
|
console.error("Error al obtener jugadores:", error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
error: function (xhr, status, error) {
|
||||||
|
console.error("Error al obtener equipos:", error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function mostrarSala(partida, equipos, jugadores) {
|
||||||
|
const contenedor = $("#contenedorSalas");
|
||||||
|
|
||||||
|
let equiposHTML = "";
|
||||||
|
|
||||||
|
equipos.forEach(function (equipo) {
|
||||||
|
const jugadoresEquipo = jugadores.filter(function (jugador) {
|
||||||
|
return jugador.idEquipo == equipo.idEquipo;
|
||||||
|
});
|
||||||
|
|
||||||
|
let jugadoresHTML = "";
|
||||||
|
|
||||||
|
if (jugadoresEquipo.length > 0) {
|
||||||
|
jugadoresEquipo.forEach(function (jugador) {
|
||||||
|
const esHost = jugador.idUsuario == partida.idUsuario;
|
||||||
|
|
||||||
|
jugadoresHTML += `
|
||||||
|
<div class="jugador border border-2 d-flex align-items-center justify-content-between ${
|
||||||
|
esHost ? "jugador-host" : ""
|
||||||
|
}">
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<span class="avatar">
|
||||||
|
${
|
||||||
|
esHost
|
||||||
|
? '<i class="bi bi-award-fill"></i>'
|
||||||
|
: '<i class="bi bi-person-fill"></i>'
|
||||||
|
}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
${escapeHTML(jugador.nombreUsuario)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
${
|
||||||
|
esHost
|
||||||
|
? `<span class="badge bg-warning text-dark ms-2">
|
||||||
|
HOST
|
||||||
|
</span>`
|
||||||
|
: ""
|
||||||
|
}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
jugadoresHTML = `
|
||||||
|
<div class="text-muted small">
|
||||||
|
Sin jugadores
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
equiposHTML += `
|
||||||
|
<div class="equipo me-2 ms-2 p-3 border rounded">
|
||||||
|
|
||||||
|
<h6>
|
||||||
|
${escapeHTML(equipo.nombreEquipo)}
|
||||||
|
</h6>
|
||||||
|
|
||||||
|
<div class="jugadores mb-2">
|
||||||
|
${jugadoresHTML}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
});
|
||||||
|
|
||||||
|
const esHost = partida.idUsuario == idUsuarioSesion;
|
||||||
|
|
||||||
|
let botonIniciarHTML = "";
|
||||||
|
|
||||||
|
if (esHost) {
|
||||||
|
botonIniciarHTML = `
|
||||||
|
<a
|
||||||
|
href="juego.php?idPartida=${partida.idPartida}"
|
||||||
|
class="btn btn-success btn-lg px-4">
|
||||||
|
|
||||||
|
<i class="bi bi-controller"></i>
|
||||||
|
¡Iniciar Partida!
|
||||||
|
|
||||||
|
</a>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const salaHTML = `
|
||||||
|
<div class="col-12 col-md-10 col-lg-8">
|
||||||
|
|
||||||
|
<div class="sala card p-3 shadow-sm mb-4">
|
||||||
|
|
||||||
|
<div class="sala-header h4 text-center mb-3 text-white">
|
||||||
|
${escapeHTML(partida.nombrePartida)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="sala-body">
|
||||||
|
|
||||||
|
<div class="equipos d-flex justify-content-around">
|
||||||
|
${equiposHTML}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="sala-acciones text-center mt-4 pt-3 border-top d-flex justify-content-center gap-3">
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="btn btn-outline-danger btn-abandonar-sala"
|
||||||
|
data-id-partida="${partida.idPartida}"
|
||||||
|
data-es-host="${esHost}">
|
||||||
|
|
||||||
|
Abandonar sala
|
||||||
|
|
||||||
|
</button>
|
||||||
|
|
||||||
|
${esHost ? botonIniciarHTML : ""}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
contenedor.html(salaHTML);
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).on("click", ".btn-unirse-equipo", function () {
|
||||||
|
const boton = $(this);
|
||||||
|
|
||||||
|
const idEquipo = boton.data("id-equipo");
|
||||||
|
const idPartida = boton.data("id-partida");
|
||||||
|
|
||||||
|
boton.prop("disabled", true).text("Uniéndose...");
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "controladores/controladorEquipoxUsuario.php",
|
||||||
|
type: "POST",
|
||||||
|
dataType: "json",
|
||||||
|
|
||||||
|
data: {
|
||||||
|
orden: "registrarUsuarioEnEquipo",
|
||||||
|
idEquipo: idEquipo,
|
||||||
|
},
|
||||||
|
|
||||||
|
success: function (respuesta) {
|
||||||
|
if (respuesta.error) {
|
||||||
|
alert(respuesta.error);
|
||||||
|
|
||||||
|
boton.prop("disabled", false).text("Unirse");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
usuarioYaEstaEnEquipo = true;
|
||||||
|
|
||||||
|
$("#contenedorCrearSala").hide();
|
||||||
|
$("#contenedorSalas").empty();
|
||||||
|
|
||||||
|
cargarSalaUsuario(idPartida);
|
||||||
|
},
|
||||||
|
|
||||||
|
error: function (xhr, status, error) {
|
||||||
|
console.error("Error al unirse al equipo:", error);
|
||||||
|
|
||||||
|
alert("No se ha podido unir al equipo.");
|
||||||
|
|
||||||
|
boton.prop("disabled", false).text("Unirse");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).on("click", ".btn-abandonar-sala", function () {
|
||||||
|
botonAbandonarReferencia = $(this);
|
||||||
|
|
||||||
|
const esHost =
|
||||||
|
$(this).data("es-host") === true ||
|
||||||
|
$(this).data("es-host") === "true";
|
||||||
|
|
||||||
|
const titulo = $("#modalAbandonarSalaLabel");
|
||||||
|
|
||||||
|
const mensaje = $("#modalAbandonarSalaMensaje");
|
||||||
|
|
||||||
|
const botonConfirmar = $("#btnConfirmarAbandonar");
|
||||||
|
|
||||||
|
if (esHost) {
|
||||||
|
titulo.text("¿Abandonar la sala?");
|
||||||
|
|
||||||
|
mensaje.text(
|
||||||
|
"Si abandonas la sala como anfitrión, la partida terminará para todos los jugadores.",
|
||||||
|
);
|
||||||
|
|
||||||
|
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.",
|
||||||
|
);
|
||||||
|
|
||||||
|
botonConfirmar.text("Sí, salir");
|
||||||
|
}
|
||||||
|
|
||||||
|
const modal = new bootstrap.Modal(
|
||||||
|
document.getElementById("modalAbandonarSala"),
|
||||||
|
);
|
||||||
|
|
||||||
|
modal.show();
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).on("click", "#btnConfirmarAbandonar", function () {
|
||||||
|
const modalEl =
|
||||||
|
document.getElementById("modalAbandonarSala");
|
||||||
|
|
||||||
|
const modalInstance =
|
||||||
|
bootstrap.Modal.getInstance(modalEl);
|
||||||
|
|
||||||
|
const btnConfirmar = $(this);
|
||||||
|
|
||||||
|
btnConfirmar
|
||||||
|
.prop("disabled", true)
|
||||||
|
.text("Saliendo...");
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "controladores/controladorEquipoxUsuario.php",
|
||||||
|
type: "POST",
|
||||||
|
dataType: "json",
|
||||||
|
|
||||||
|
data: {
|
||||||
|
orden: "salirDeSala",
|
||||||
|
},
|
||||||
|
|
||||||
|
success: function (respuesta) {
|
||||||
|
btnConfirmar
|
||||||
|
.prop("disabled", false)
|
||||||
|
.text("Sí, salir");
|
||||||
|
|
||||||
|
if (modalInstance) {
|
||||||
|
modalInstance.hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (respuesta.error) {
|
||||||
|
alert(respuesta.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
usuarioYaEstaEnEquipo = false;
|
||||||
|
|
||||||
|
if (intervaloSala) {
|
||||||
|
clearInterval(intervaloSala);
|
||||||
|
intervaloSala = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#contenedorSalas").empty();
|
||||||
|
|
||||||
|
$("#contenedorCrearSala").show();
|
||||||
|
|
||||||
|
iniciarActualizacionSalas();
|
||||||
|
},
|
||||||
|
|
||||||
|
error: function (xhr, status, error) {
|
||||||
|
console.error(
|
||||||
|
"Error al salir de la sala:",
|
||||||
|
error
|
||||||
|
);
|
||||||
|
|
||||||
|
alert("No se pudo salir de la sala.");
|
||||||
|
|
||||||
|
btnConfirmar
|
||||||
|
.prop("disabled", false)
|
||||||
|
.text("Sí, salir");
|
||||||
|
|
||||||
|
if (modalInstance) {
|
||||||
|
modalInstance.hide();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function escapeHTML(texto) {
|
||||||
|
return $("<div>")
|
||||||
|
.text(texto ?? "")
|
||||||
|
.html();
|
||||||
|
}
|
||||||
|
|
||||||
|
function mostrarEquipos(
|
||||||
|
partida,
|
||||||
|
equipos,
|
||||||
|
jugadores
|
||||||
|
) {
|
||||||
|
let equiposHTML = "";
|
||||||
|
|
||||||
|
equipos.forEach(function (equipo) {
|
||||||
|
const jugadoresEquipo =
|
||||||
|
jugadores.filter(function (jugador) {
|
||||||
|
return jugador.idEquipo == equipo.idEquipo;
|
||||||
|
});
|
||||||
|
|
||||||
|
let jugadoresHTML = "";
|
||||||
|
|
||||||
|
if (jugadoresEquipo.length > 0) {
|
||||||
|
jugadoresEquipo.forEach(function (jugador) {
|
||||||
|
const esHost =
|
||||||
|
jugador.idUsuario == partida.idUsuario;
|
||||||
|
|
||||||
|
jugadoresHTML += `
|
||||||
|
<div class="jugador border border-2 d-flex align-items-center justify-content-between ${
|
||||||
|
esHost ? "jugador-host" : ""
|
||||||
|
}">
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<span class="avatar">
|
||||||
|
${
|
||||||
|
esHost
|
||||||
|
? '<i class="bi bi-award-fill"></i>'
|
||||||
|
: '<i class="bi bi-person-fill"></i>'
|
||||||
|
}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
${escapeHTML(
|
||||||
|
jugador.nombreUsuario
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
${
|
||||||
|
esHost
|
||||||
|
? `<span class="badge bg-warning text-dark ms-2">
|
||||||
|
HOST
|
||||||
|
</span>`
|
||||||
|
: ""
|
||||||
|
}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
jugadoresHTML = `
|
||||||
|
<div class="text-muted small">
|
||||||
|
Sin jugadores
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
equiposHTML += `
|
||||||
|
<div class="equipo me-2 ms-2 p-3 border rounded">
|
||||||
|
|
||||||
|
<h6>
|
||||||
|
${escapeHTML(equipo.nombreEquipo)}
|
||||||
|
</h6>
|
||||||
|
|
||||||
|
<div class="jugadores mb-2">
|
||||||
|
${jugadoresHTML}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#contenedorSalas .equipos").html(equiposHTML);
|
||||||
|
}
|
||||||
+1
-1
@@ -293,7 +293,7 @@ $avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultPro
|
|||||||
Cancelar
|
Cancelar
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button type="submit" form="formCrearPregunta" class="btn btn-kahoot-login" id="btnCrearPregunta">
|
<button type="submit" form="formCrearPregunta" class="btn btn-kahoot-register" id="btnCrearPregunta">
|
||||||
<i class="bi bi-check-lg me-1"></i>
|
<i class="bi bi-check-lg me-1"></i>
|
||||||
Crear pregunta
|
Crear pregunta
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
+156
-156
@@ -1,156 +1,156 @@
|
|||||||
<?php
|
<?php
|
||||||
session_start();
|
session_start();
|
||||||
require_once 'includes/conexionBD.php';
|
require_once __DIR__ . '/includes/conexionBD.php';
|
||||||
|
|
||||||
$idPartida = intval($_GET['idPartida'] ?? 0);
|
$idPartida = intval($_GET['idPartida'] ?? 0);
|
||||||
if ($idPartida <= 0) {
|
if ($idPartida <= 0) {
|
||||||
die("Partida no válida.");
|
die("Partida no válida.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$conexion = conexionBD();
|
$conexion = conexionBD();
|
||||||
if (is_array($conexion)) {
|
if (is_array($conexion)) {
|
||||||
die("Error de conexión a la base de datos.");
|
die("Error de conexión a la base de datos.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtener listado de jugadores y sus equipos en esta partida
|
// Obtener listado de jugadores y sus equipos en esta partida
|
||||||
$stmt = $conexion->prepare("
|
$stmt = $conexion->prepare("
|
||||||
SELECT u.idUsuario, u.nombreUsuario, e.idEquipo, e.nombreEquipo
|
SELECT u.idUsuario, u.nombreUsuario, e.idEquipo, e.nombreEquipo
|
||||||
FROM equipoxpartida exp
|
FROM equipoxpartida exp
|
||||||
INNER JOIN equipoxusuario exu ON exp.idEquipo = exu.idEquipo
|
INNER JOIN equipoxusuario exu ON exp.idEquipo = exu.idEquipo
|
||||||
INNER JOIN usuario u ON exu.idUsuario = u.idUsuario
|
INNER JOIN usuario u ON exu.idUsuario = u.idUsuario
|
||||||
INNER JOIN equipo e ON exu.idEquipo = e.idEquipo
|
INNER JOIN equipo e ON exu.idEquipo = e.idEquipo
|
||||||
WHERE exp.idPartida = :idPartida
|
WHERE exp.idPartida = :idPartida
|
||||||
");
|
");
|
||||||
$stmt->execute([':idPartida' => $idPartida]);
|
$stmt->execute([':idPartida' => $idPartida]);
|
||||||
$listaJugadoresRaw = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$listaJugadoresRaw = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
$primerosEnAcertar = $_SESSION['primeros_en_acertar'][$idPartida] ?? [];
|
$primerosEnAcertar = $_SESSION['primeros_en_acertar'][$idPartida] ?? [];
|
||||||
|
|
||||||
$jugadoresFinales = [];
|
$jugadoresFinales = [];
|
||||||
$equiposFinales = [];
|
$equiposFinales = [];
|
||||||
|
|
||||||
// Respuestas de velocidad (+2 o +1)
|
// Respuestas de velocidad (+2 o +1) procesadas en la capa de la vista
|
||||||
foreach ($listaJugadoresRaw as $jugador) {
|
foreach ($listaJugadoresRaw as $jugador) {
|
||||||
$idU = (int)$jugador['idUsuario'];
|
$idU = (int)$jugador['idUsuario'];
|
||||||
$idE = (int)$jugador['idEquipo'];
|
$idE = (int)$jugador['idEquipo'];
|
||||||
|
|
||||||
$stmtRespuestas = $conexion->prepare("
|
$stmtRespuestas = $conexion->prepare("
|
||||||
SELECT ra.idPartidaxPregunta, r.correcta
|
SELECT ra.idPartidaxPregunta, r.correcta
|
||||||
FROM respuestaalmacenada ra
|
FROM respuestaalmacenada ra
|
||||||
INNER JOIN respuesta r ON ra.idRespuesta = r.idRespuesta
|
INNER JOIN respuesta r ON ra.idRespuesta = r.idRespuesta
|
||||||
INNER JOIN partidaxpregunta pxp ON ra.idPartidaxPregunta = pxp.idPartidaxPregunta
|
INNER JOIN partidaxpregunta pxp ON ra.idPartidaxPregunta = pxp.idPartidaxPregunta
|
||||||
WHERE pxp.idPartida = :idPartida AND ra.idUsuario = :idUsuario
|
WHERE pxp.idPartida = :idPartida AND ra.idUsuario = :idUsuario
|
||||||
");
|
");
|
||||||
$stmtRespuestas->execute([':idPartida' => $idPartida, ':idUsuario' => $idU]);
|
$stmtRespuestas->execute([':idPartida' => $idPartida, ':idUsuario' => $idU]);
|
||||||
$respuestasUsuario = $stmtRespuestas->fetchAll(PDO::FETCH_ASSOC);
|
$respuestasUsuario = $stmtRespuestas->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
$aciertos = 0;
|
$aciertos = 0;
|
||||||
$puntosTotalesJugador = 0;
|
$puntosTotalesJugador = 0;
|
||||||
|
|
||||||
foreach ($respuestasUsuario as $resp) {
|
foreach ($respuestasUsuario as $resp) {
|
||||||
if ((int)$resp['correcta'] === 1) {
|
if ((int)$resp['correcta'] === 1) {
|
||||||
$aciertos++;
|
$aciertos++;
|
||||||
$idPxp = $resp['idPartidaxPregunta'];
|
$idPxp = $resp['idPartidaxPregunta'];
|
||||||
|
|
||||||
// Si el ID de usuario coincide con el primero guardado de esa pregunta se lleva 2 puntos
|
if (isset($primerosEnAcertar[$idPxp]) && $primerosEnAcertar[$idPxp] === $idU) {
|
||||||
if (isset($primerosEnAcertar[$idPxp]) && $primerosEnAcertar[$idPxp] === $idU) {
|
$puntosTotalesJugador += 2;
|
||||||
$puntosTotalesJugador += 2;
|
} else {
|
||||||
} else {
|
$puntosTotalesJugador += 1;
|
||||||
$puntosTotalesJugador += 1;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
$jugadoresFinales[] = [
|
||||||
$jugadoresFinales[] = [
|
'nombre' => $jugador['nombreUsuario'],
|
||||||
'nombre' => $jugador['nombreUsuario'],
|
'equipo' => $jugador['nombreEquipo'],
|
||||||
'equipo' => $jugador['nombreEquipo'],
|
'aciertos' => $aciertos,
|
||||||
'aciertos' => $aciertos,
|
'puntos' => $puntosTotalesJugador
|
||||||
'puntos' => $puntosTotalesJugador
|
];
|
||||||
];
|
|
||||||
|
if (!isset($equiposFinales[$idE])) {
|
||||||
if (!isset($equiposFinales[$idE])) {
|
$equiposFinales[$idE] = [
|
||||||
$equiposFinales[$idE] = [
|
'nombre' => $jugador['nombreEquipo'],
|
||||||
'nombre' => $jugador['nombreEquipo'],
|
'puntos' => 0
|
||||||
'puntos' => 0
|
];
|
||||||
];
|
}
|
||||||
}
|
$equiposFinales[$idE]['puntos'] += $puntosTotalesJugador;
|
||||||
$equiposFinales[$idE]['puntos'] += $puntosTotalesJugador;
|
}
|
||||||
}
|
|
||||||
|
usort($jugadoresFinales, function($a, $b) { return $b['puntos'] <=> $a['puntos']; });
|
||||||
// Ordenar según la puntuación final de mayor a menor
|
usort($equiposFinales, function($a, $b) { return $b['puntos'] <=> $a['puntos']; });
|
||||||
usort($jugadoresFinales, function($a, $b) { return $b['puntos'] <=> $a['puntos']; });
|
?>
|
||||||
usort($equiposFinales, function($a, $b) { return $b['puntos'] <=> $a['puntos']; });
|
|
||||||
?>
|
<!DOCTYPE html>
|
||||||
|
<html lang="es">
|
||||||
<!DOCTYPE html>
|
<head>
|
||||||
<html lang="es">
|
<meta charset="UTF-8">
|
||||||
<head>
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<meta charset="UTF-8">
|
<title>Resultados - Trivial</title>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<link rel="stylesheet" href="css/resultados.css">
|
||||||
<title>Resultados - Trivial</title>
|
<script src="js/jquery-4.0.0.min.js"></script>
|
||||||
<link rel="stylesheet" href="css/resultados.css">
|
</head>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/jquery@4.0.0/dist/jquery.min.js"></script>
|
<body data-id-partida="<?php echo $idPartida; ?>">
|
||||||
</head>
|
|
||||||
<body data-id-partida="<?php echo $idPartida; ?>">
|
<div id="pantalla-espera" class="contenedor">
|
||||||
|
<h2>⌛ Esperando a que todos los jugadores terminen...</h2>
|
||||||
<div id="pantalla-espera" class="contenedor">
|
<p>Calculando estadísticas de velocidad y actualizando perfiles históricos en el servidor.</p>
|
||||||
<h2>⌛ Esperando a que todos los jugadores terminen...</h2>
|
<div class="loader"></div>
|
||||||
<p>Calculando estadísticas de velocidad y actualizando perfiles históricos en el servidor.</p>
|
</div>
|
||||||
<div class="loader"></div>
|
|
||||||
</div>
|
<div id="pantalla-resultados" class="contenedor" style="display:none;">
|
||||||
|
<h1>🏆 Resultados de la Partida 🏆</h1>
|
||||||
<div id="pantalla-resultados" class="contenedor" style="display:none;">
|
|
||||||
<h1>🏆 Resultados de la Partida 🏆</h1>
|
<h2>Clasificación por Equipos</h2>
|
||||||
|
<table class="tabla-ranking">
|
||||||
<h2>Clasificación por Equipos</h2>
|
<thead>
|
||||||
<table class="tabla-ranking">
|
<tr>
|
||||||
<thead>
|
<th>Posición</th>
|
||||||
<tr>
|
<th>Equipo</th>
|
||||||
<th>Posición</th>
|
<th>Puntos Totales</th>
|
||||||
<th>Equipo</th>
|
</tr>
|
||||||
<th>Puntos Totales</th>
|
</thead>
|
||||||
</tr>
|
<tbody>
|
||||||
</thead>
|
<?php foreach ($equiposFinales as $index => $eq): ?>
|
||||||
<tbody>
|
<tr class="<?php echo $index === 0 ? 'top-team' : ''; ?>">
|
||||||
<?php foreach ($equiposFinales as $index => $eq): ?>
|
<td>#<?php echo $index + 1; ?></td>
|
||||||
<tr class="<?php echo $index === 0 ? 'top-team' : ''; ?>">
|
<td><?php echo htmlspecialchars($eq['nombre']); ?></td>
|
||||||
<td>#<?php echo $index + 1; ?></td>
|
<td><strong><?php echo $eq['puntos']; ?> pts</strong></td>
|
||||||
<td><?php echo htmlspecialchars($eq['nombre']); ?></td>
|
</tr>
|
||||||
<td><strong><?php echo $eq['puntos']; ?> pts</strong></td>
|
<?php endforeach; ?>
|
||||||
</tr>
|
</tbody>
|
||||||
<?php endforeach; ?>
|
</table>
|
||||||
</tbody>
|
|
||||||
</table>
|
<h2>Rendimiento Individual</h2>
|
||||||
|
<table class="tabla-ranking">
|
||||||
<h2>Rendimiento Individual</h2>
|
<thead>
|
||||||
<table class="tabla-ranking">
|
<tr>
|
||||||
<thead>
|
<th>Posición</th>
|
||||||
<tr>
|
<th>Jugador</th>
|
||||||
<th>Posición</th>
|
<th>Equipo</th>
|
||||||
<th>Jugador</th>
|
<th>Aciertos</th>
|
||||||
<th>Equipo</th>
|
<th>Puntos Logrados</th>
|
||||||
<th>Aciertos</th>
|
</tr>
|
||||||
<th>Puntos Logrados</th>
|
</thead>
|
||||||
</tr>
|
<tbody>
|
||||||
</thead>
|
<?php foreach ($jugadoresFinales as $index => $jug): ?>
|
||||||
<tbody>
|
<tr class="<?php echo $index === 0 ? 'top-player' : ''; ?>">
|
||||||
<?php foreach ($jugadoresFinales as $index => $jug): ?>
|
<td>#<?php echo $index + 1; ?></td>
|
||||||
<tr class="<?php echo $index === 0 ? 'top-player' : ''; ?>">
|
<td><?php echo htmlspecialchars($jug['nombre']); ?></td>
|
||||||
<td>#<?php echo $index + 1; ?></td>
|
<td><?php echo htmlspecialchars($jug['equipo']); ?></td>
|
||||||
<td><?php echo htmlspecialchars($jug['nombre']); ?></td>
|
<td><?php echo $jug['aciertos']; ?> / 10</td>
|
||||||
<td><?php echo htmlspecialchars($jug['equipo']); ?></td>
|
<td><strong><?php echo $jug['puntos']; ?> pts</strong></td>
|
||||||
<td><?php echo $jug['aciertos']; ?> / 10</td>
|
</tr>
|
||||||
<td><strong><?php echo $jug['puntos']; ?> pts</strong></td>
|
<?php endforeach; ?>
|
||||||
</tr>
|
</tbody>
|
||||||
<?php endforeach; ?>
|
</table>
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
<div class="contenedor-boton">
|
||||||
<div class="contenedor-boton">
|
<a href="/triviagmatico/" id="btnVolverInicio" data-id="<?php echo $idPartida; ?>" class="btn-inicio">Volver al Inicio 🏠</a>
|
||||||
<a href="/triviagmatico/buscadorSala.php" class="btn-inicio">Volver al Inicio 🏠</a>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="js/resultados.js"></script>
|
<script src="js/resultados.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user