Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c0207197fb | |||
| 5113b960d2 | |||
| 8453735727 | |||
| fdd1ba8272 |
+4
-1
@@ -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>
|
||||||
@@ -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>
|
||||||
@@ -121,7 +121,6 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
gap: 15px;
|
gap: 15px;
|
||||||
text-decoration: none;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-play-kahoot:hover {
|
.btn-play-kahoot:hover {
|
||||||
|
|||||||
+101
-364
@@ -1,442 +1,179 @@
|
|||||||
/* ==========================================================================
|
/* ==========================================================================
|
||||||
VARIABLES DEL PROYECTO
|
ESTILOS GENERALES Y FONDO
|
||||||
========================================================================== */
|
========================================================================== */
|
||||||
|
|
||||||
:root {
|
|
||||||
--kahoot-purple: #46178f;
|
|
||||||
--kahoot-purple-dark: #35116f;
|
|
||||||
--kahoot-blue: #1368ce;
|
|
||||||
--kahoot-blue-dark: #0c4891;
|
|
||||||
--kahoot-red: #e21b3c;
|
|
||||||
--kahoot-yellow: #ffa602;
|
|
||||||
--kahoot-yellow-dark: #d88900;
|
|
||||||
--kahoot-green: #26890c;
|
|
||||||
--kahoot-green-hover: #1f6f09;
|
|
||||||
|
|
||||||
--background: #f2f2f2;
|
|
||||||
--text-dark: #333333;
|
|
||||||
--text-muted: #666666;
|
|
||||||
--white: #ffffff;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ==========================================================================
|
|
||||||
ESTILOS GENERALES
|
|
||||||
========================================================================== */
|
|
||||||
|
|
||||||
* {
|
* {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
box-shadow: none;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
font-family: 'Fredoka', sans-serif;
|
font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
|
||||||
background-color: var(--background);
|
background-color: #f0f4f8;
|
||||||
color: var(--text-dark);
|
color: #2c3e50;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
padding: 30px 20px;
|
padding: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Contenedor principal estilo tarjeta */
|
||||||
/* ==========================================================================
|
|
||||||
CONTENEDOR PRINCIPAL
|
|
||||||
========================================================================== */
|
|
||||||
|
|
||||||
.contenedor {
|
.contenedor {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 1000px;
|
max-width: 900px;
|
||||||
margin: 0 auto;
|
background: #ffffff;
|
||||||
background-color: var(--white);
|
padding: 40px;
|
||||||
border-radius: 20px;
|
border-radius: 16px;
|
||||||
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.10);
|
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ==========================================================================
|
|
||||||
PANTALLA DE ESPERA
|
|
||||||
========================================================================== */
|
|
||||||
|
|
||||||
#pantalla-espera {
|
|
||||||
padding: 70px 30px;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
animation: fadeIn 0.5s ease-in-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pantalla-espera h2 {
|
h1 {
|
||||||
color: var(--kahoot-purple);
|
font-size: 2.5rem;
|
||||||
font-size: 2rem;
|
color: #1a365d;
|
||||||
font-weight: 700;
|
margin-bottom: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-size: 1.6rem;
|
||||||
|
color: #2b6cb0;
|
||||||
|
margin-top: 30px;
|
||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
|
text-align: left;
|
||||||
|
border-bottom: 2px solid #e2e8f0;
|
||||||
|
padding-bottom: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pantalla-espera p {
|
p {
|
||||||
color: var(--text-muted);
|
|
||||||
font-size: 1.1rem;
|
font-size: 1.1rem;
|
||||||
margin-bottom: 35px;
|
color: #718096;
|
||||||
|
margin-bottom: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ==========================================================================
|
/* ==========================================================================
|
||||||
LOADER
|
PANTALLA DE ESPERA Y ANIMACIÓN DE CARGA (LOADER)
|
||||||
========================================================================== */
|
========================================================================== */
|
||||||
|
#pantalla-espera {
|
||||||
|
padding: 60px 20px;
|
||||||
|
}
|
||||||
|
|
||||||
.loader {
|
.loader {
|
||||||
width: 65px;
|
width: 60px;
|
||||||
height: 65px;
|
height: 60px;
|
||||||
margin: 0 auto;
|
border: 6px solid #e2e8f0;
|
||||||
|
border-top: 6px solid #3182ce;
|
||||||
border: 7px solid #e5e5e5;
|
|
||||||
border-top-color: var(--kahoot-purple);
|
|
||||||
|
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
|
margin: 0 auto;
|
||||||
animation: spin 1s linear infinite;
|
animation: spin 1.2s linear infinite;
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes spin {
|
@keyframes spin {
|
||||||
from {
|
0% { transform: rotate(0deg); }
|
||||||
transform: rotate(0deg);
|
100% { transform: rotate(360deg); }
|
||||||
}
|
|
||||||
|
|
||||||
to {
|
|
||||||
transform: rotate(360deg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ==========================================================================
|
/* ==========================================================================
|
||||||
CABECERA DE RESULTADOS
|
TABLAS DE CLASIFICACIÓN (RANKING)
|
||||||
========================================================================== */
|
========================================================================== */
|
||||||
|
|
||||||
#pantalla-resultados {
|
|
||||||
padding: 40px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pantalla-resultados h1 {
|
|
||||||
text-align: center;
|
|
||||||
color: var(--kahoot-yellow);
|
|
||||||
font-size: 2.6rem;
|
|
||||||
font-weight: 700;
|
|
||||||
margin-bottom: 35px;
|
|
||||||
|
|
||||||
text-shadow: 2px 2px 0 rgba(70, 23, 143, 0.10);
|
|
||||||
}
|
|
||||||
|
|
||||||
#pantalla-resultados h2 {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 10px;
|
|
||||||
|
|
||||||
font-size: 1.5rem;
|
|
||||||
font-weight: 700;
|
|
||||||
|
|
||||||
margin-top: 35px;
|
|
||||||
margin-bottom: 15px;
|
|
||||||
|
|
||||||
padding-bottom: 10px;
|
|
||||||
border-bottom: 3px solid #eee;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ==========================================================================
|
|
||||||
TABLAS
|
|
||||||
========================================================================== */
|
|
||||||
|
|
||||||
.tabla-ranking {
|
.tabla-ranking {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-collapse: separate;
|
border-collapse: collapse;
|
||||||
border-spacing: 0;
|
margin-bottom: 20px;
|
||||||
|
font-size: 1.05rem;
|
||||||
overflow: hidden;
|
|
||||||
|
|
||||||
background-color: #fff;
|
|
||||||
|
|
||||||
border: 2px solid #eeeeee;
|
|
||||||
border-radius: 15px;
|
|
||||||
|
|
||||||
margin-bottom: 30px;
|
|
||||||
|
|
||||||
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.06);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tabla-ranking th,
|
||||||
/* Cabecera */
|
.tabla-ranking td {
|
||||||
|
padding: 16px 20px;
|
||||||
.tabla-ranking thead th {
|
|
||||||
background-color: var(--kahoot-purple);
|
|
||||||
color: white;
|
|
||||||
|
|
||||||
padding: 15px 18px;
|
|
||||||
|
|
||||||
font-size: 0.95rem;
|
|
||||||
font-weight: 700;
|
|
||||||
|
|
||||||
text-transform: uppercase;
|
|
||||||
letter-spacing: 0.3px;
|
|
||||||
|
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tabla-ranking thead th:first-child {
|
.tabla-ranking th {
|
||||||
border-top-left-radius: 12px;
|
background-color: #2d3748;
|
||||||
|
color: #ffffff;
|
||||||
|
font-weight: 600;
|
||||||
|
text-transform: uppercase;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tabla-ranking thead th:last-child {
|
/* Alinear los puntos y aciertos a la derecha para mejor lectura numérica */
|
||||||
border-top-right-radius: 12px;
|
.tabla-ranking th:last-child,
|
||||||
|
.tabla-ranking td:last-child {
|
||||||
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tabla-ranking tr {
|
||||||
/* Celdas */
|
border-bottom: 1px solid #e2e8f0;
|
||||||
|
transition: background-color 0.2s;
|
||||||
.tabla-ranking tbody td {
|
|
||||||
padding: 16px 18px;
|
|
||||||
|
|
||||||
font-size: 1rem;
|
|
||||||
font-weight: 500;
|
|
||||||
|
|
||||||
border-bottom: 1px solid #eeeeee;
|
|
||||||
|
|
||||||
color: var(--text-dark);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Última fila */
|
|
||||||
|
|
||||||
.tabla-ranking tbody tr:last-child td {
|
|
||||||
border-bottom: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Hover */
|
|
||||||
|
|
||||||
.tabla-ranking tbody tr {
|
|
||||||
transition:
|
|
||||||
transform 0.15s ease,
|
|
||||||
background-color 0.15s ease;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.tabla-ranking tbody tr:hover {
|
.tabla-ranking tbody tr:hover {
|
||||||
background-color: #f7f3ff;
|
background-color: #f7fafc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ==========================================================================
|
/* ==========================================================================
|
||||||
COLUMNA DE POSICIÓN
|
RESALTADO DE GANADORES (1º PUESTO)
|
||||||
========================================================================== */
|
========================================================================== */
|
||||||
|
/* Fila del Equipo Ganador y Jugador Ganador */
|
||||||
.tabla-ranking tbody td:first-child {
|
|
||||||
font-weight: 700;
|
|
||||||
color: var(--kahoot-purple);
|
|
||||||
width: 100px;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ==========================================================================
|
|
||||||
PUNTOS
|
|
||||||
========================================================================== */
|
|
||||||
|
|
||||||
.tabla-ranking td strong {
|
|
||||||
color: var(--kahoot-green);
|
|
||||||
font-size: 1.15rem;
|
|
||||||
font-weight: 700;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ==========================================================================
|
|
||||||
EQUIPO / JUGADOR GANADOR
|
|
||||||
========================================================================== */
|
|
||||||
|
|
||||||
.tabla-ranking tr.top-team,
|
.tabla-ranking tr.top-team,
|
||||||
.tabla-ranking tr.top-player {
|
.tabla-ranking tr.top-player {
|
||||||
background-color: #fff7df !important;
|
background-color: #fefcbf !important; /* Amarillo suave */
|
||||||
font-weight: 700;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Cambiar el color del texto del puesto #1 a dorado/corona */
|
||||||
/* Línea lateral amarilla */
|
|
||||||
|
|
||||||
.tabla-ranking tr.top-team td:first-child,
|
.tabla-ranking tr.top-team td:first-child,
|
||||||
.tabla-ranking tr.top-player td:first-child {
|
.tabla-ranking tr.top-player td:first-child {
|
||||||
color: var(--kahoot-yellow-dark);
|
color: #b7791f;
|
||||||
font-size: 1.15rem;
|
font-size: 1.2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tabla-ranking td strong {
|
||||||
/* Puntos del ganador */
|
color: #2f855a; /* Verde para destacar los aciertos conseguidos */
|
||||||
|
font-size: 1.1rem;
|
||||||
.tabla-ranking tr.top-team td strong,
|
|
||||||
.tabla-ranking tr.top-player td strong {
|
|
||||||
color: var(--kahoot-green);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ==========================================================================
|
/* ==========================================================================
|
||||||
BOTÓN VOLVER AL INICIO
|
EFECTOS VISUALES SUAVES
|
||||||
========================================================================== */
|
========================================================================== */
|
||||||
|
@keyframes fadeIn {
|
||||||
.contenedor-boton {
|
from { opacity: 0; transform: translateY(10px); }
|
||||||
display: flex;
|
to { opacity: 1; transform: translateY(0); }
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
margin-top: 40px;
|
|
||||||
padding-top: 10px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
/* Botón */
|
ESTILOS DEL BOTÓN DE RETORNO A INICIO
|
||||||
|
========================================================================== */
|
||||||
|
.contenedor-boton {
|
||||||
|
margin-top: 40px;
|
||||||
|
padding-top: 20px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
.btn-inicio {
|
.btn-inicio {
|
||||||
display: inline-flex;
|
display: inline-block;
|
||||||
align-items: center;
|
background-color: #3182ce; /* Azul corporativo */
|
||||||
justify-content: center;
|
color: #ffffff;
|
||||||
gap: 10px;
|
padding: 14px 28px;
|
||||||
|
|
||||||
min-width: 240px;
|
|
||||||
|
|
||||||
padding: 15px 28px;
|
|
||||||
|
|
||||||
background-color: var(--kahoot-blue);
|
|
||||||
color: white;
|
|
||||||
|
|
||||||
border: none;
|
|
||||||
border-bottom: 5px solid var(--kahoot-blue-dark);
|
|
||||||
|
|
||||||
border-radius: 12px;
|
|
||||||
|
|
||||||
font-family: 'Fredoka', sans-serif;
|
|
||||||
font-size: 1.1rem;
|
font-size: 1.1rem;
|
||||||
font-weight: 700;
|
font-weight: 600;
|
||||||
|
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
border-radius: 8px;
|
||||||
box-shadow: 0 5px 10px rgba(19, 104, 206, 0.25);
|
box-shadow: 0 4px 6px rgba(49, 130, 206, 0.2);
|
||||||
|
transition: background-color 0.2s, transform 0.2s, box-shadow 0.2s;
|
||||||
transition: all 0.15s ease;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Hover */
|
|
||||||
|
|
||||||
.btn-inicio:hover {
|
.btn-inicio:hover {
|
||||||
background-color: #0f56ab;
|
background-color: #2b6cb0; /* Azul ligeramente más oscuro al pasar el cursor */
|
||||||
color: white;
|
box-shadow: 0 6px 12px rgba(43, 108, 176, 0.3);
|
||||||
|
transform: translateY(-2px); /* Pequeño salto hacia arriba */
|
||||||
transform: translateY(-3px);
|
|
||||||
|
|
||||||
box-shadow: 0 8px 15px rgba(19, 104, 206, 0.30);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Click */
|
|
||||||
|
|
||||||
.btn-inicio:active {
|
.btn-inicio:active {
|
||||||
transform: translateY(3px);
|
transform: translateY(0); /* Vuelve a su posición normal al pulsar */
|
||||||
|
box-shadow: 0 2px 4px rgba(43, 108, 176, 0.2);
|
||||||
border-bottom-width: 2px;
|
|
||||||
|
|
||||||
box-shadow: 0 3px 6px rgba(19, 104, 206, 0.20);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ==========================================================================
|
|
||||||
RESPONSIVE
|
|
||||||
========================================================================== */
|
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
|
||||||
|
|
||||||
body {
|
|
||||||
padding: 15px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pantalla-resultados {
|
|
||||||
padding: 25px 15px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pantalla-resultados h1 {
|
|
||||||
font-size: 2rem;
|
|
||||||
margin-bottom: 25px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pantalla-resultados h2 {
|
|
||||||
font-size: 1.3rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tabla-ranking {
|
|
||||||
font-size: 0.9rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tabla-ranking thead th,
|
|
||||||
.tabla-ranking tbody td {
|
|
||||||
padding: 12px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tabla-ranking thead th {
|
|
||||||
font-size: 0.75rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tabla-ranking tbody td {
|
|
||||||
font-size: 0.9rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tabla-ranking td strong {
|
|
||||||
font-size: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-inicio {
|
|
||||||
width: 100%;
|
|
||||||
min-width: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ==========================================================================
|
|
||||||
MÓVILES PEQUEÑOS
|
|
||||||
========================================================================== */
|
|
||||||
|
|
||||||
@media (max-width: 500px) {
|
|
||||||
|
|
||||||
body {
|
|
||||||
padding: 10px 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pantalla-espera {
|
|
||||||
padding: 50px 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pantalla-espera h2 {
|
|
||||||
font-size: 1.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pantalla-espera p {
|
|
||||||
font-size: 0.95rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pantalla-resultados {
|
|
||||||
padding: 20px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pantalla-resultados h1 {
|
|
||||||
font-size: 1.7rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pantalla-resultados h2 {
|
|
||||||
font-size: 1.15rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tabla-ranking {
|
|
||||||
display: block;
|
|
||||||
overflow-x: auto;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tabla-ranking thead th,
|
|
||||||
.tabla-ranking tbody td {
|
|
||||||
padding: 10px 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.contenedor-boton {
|
|
||||||
margin-top: 25px;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+352
-278
@@ -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
|
|
||||||
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();
|
|
||||||
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();
|
||||||
},
|
|
||||||
});
|
intervaloBuscadorSalas = setInterval(function () {
|
||||||
|
if (!usuarioYaEstaEnEquipo) {
|
||||||
|
cargarSalas();
|
||||||
|
}
|
||||||
|
}, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Cargar únicamente la sala en la que está metido el usuario
|
function cargarSalas() {
|
||||||
function cargarSalaUsuario(idPartida) {
|
if (cargandoSalas) {
|
||||||
$.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;
|
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
|
cargandoSalas = true;
|
||||||
function cargarSalas() {
|
|
||||||
$.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) {
|
||||||
|
contenedor.append(`
|
||||||
|
<div
|
||||||
|
id="mensajeSinSalas"
|
||||||
|
class="col-12 text-center">
|
||||||
|
|
||||||
|
<p class="text-muted">
|
||||||
|
No hay salas disponibles actualmente.
|
||||||
|
</p>
|
||||||
|
|
||||||
</div>
|
</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>
|
<div>
|
||||||
<span class="avatar">${esHost ? '<i class="bi bi-award-fill"></i>' : '<i class="bi bi-person-fill"></i>'}</span>
|
|
||||||
${escapeHTML(jugador.nombreUsuario)}
|
<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
|
esHost
|
||||||
? `<span class="badge bg-warning text-dark ms-2">HOST</span>`
|
? `
|
||||||
|
<span
|
||||||
|
class="badge bg-warning text-dark ms-2">
|
||||||
|
|
||||||
|
HOST
|
||||||
|
|
||||||
|
</span>
|
||||||
|
`
|
||||||
: ""
|
: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
</div>
|
</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
|
||||||
|
type="button"
|
||||||
|
class="btn-unirse w-100 btn-unirse-equipo mt-2"
|
||||||
data-id-partida="${partida.idPartida}"
|
data-id-partida="${partida.idPartida}"
|
||||||
data-id-equipo="${equipo.idEquipo}">
|
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í, 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();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// 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();
|
||||||
|
}
|
||||||
|
);
|
||||||
+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);
|
||||||
|
}
|
||||||
+3
-8
@@ -86,24 +86,19 @@ usort($equiposFinales, function($a, $b) { return $b['puntos'] <=> $a['puntos'];
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Resultados - Trivial</title>
|
<title>Resultados - Trivial</title>
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Fredoka:wght@400;500;600;700&display=swap" rel="stylesheet">
|
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.1/font/bootstrap-icons.min.css">
|
|
||||||
<link rel="stylesheet" href="css/index.css">
|
|
||||||
<link rel="stylesheet" href="css/resultados.css">
|
<link rel="stylesheet" href="css/resultados.css">
|
||||||
<script src="js/jquery-4.0.0.min.js"></script>
|
<script src="js/jquery-4.0.0.min.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body data-id-partida="<?php echo $idPartida; ?>">
|
<body data-id-partida="<?php echo $idPartida; ?>">
|
||||||
|
|
||||||
<div id="pantalla-espera" class="contenedor">
|
<div id="pantalla-espera" class="contenedor">
|
||||||
<h2> <i class="bi bi-hourglass"></i> Esperando a que todos los jugadores terminen...</h2>
|
<h2>⌛ Esperando a que todos los jugadores terminen...</h2>
|
||||||
<p>Calculando estadísticas de velocidad y actualizando perfiles históricos en el servidor.</p>
|
<p>Calculando estadísticas de velocidad y actualizando perfiles históricos en el servidor.</p>
|
||||||
<div class="loader"></div>
|
<div class="loader"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="pantalla-resultados" class="contenedor" style="display:none;">
|
<div id="pantalla-resultados" class="contenedor" style="display:none;">
|
||||||
<h1> <i class="bi bi-trophy-fill"></i> Resultados de la Partida <i class="bi bi-trophy-fill"></i> </h1>
|
<h1>🏆 Resultados de la Partida 🏆</h1>
|
||||||
|
|
||||||
<h2>Clasificación por Equipos</h2>
|
<h2>Clasificación por Equipos</h2>
|
||||||
<table class="tabla-ranking">
|
<table class="tabla-ranking">
|
||||||
@@ -151,7 +146,7 @@ usort($equiposFinales, function($a, $b) { return $b['puntos'] <=> $a['puntos'];
|
|||||||
|
|
||||||
|
|
||||||
<div class="contenedor-boton">
|
<div class="contenedor-boton">
|
||||||
<a href="<?= $_ENV['urlBase'] ?>/" id="btnVolverInicio" data-id="<?php echo $idPartida; ?>" class="btn btn-play-kahoot"> <i class="bi bi-arrow-left"></i> Volver al Inicio <i class="bi bi-house-fill"></i> </a>
|
<a href="/triviagmatico/" id="btnVolverInicio" data-id="<?php echo $idPartida; ?>" class="btn-inicio">Volver al Inicio 🏠</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user