1 Commits

Author SHA1 Message Date
Isaac d994f09f7d Ajustado CSS de resultados.php para consistencia con el proyecto.
Importante: He cambiado la ruta del "Volver al inicio" a $_ENV['urlBase']
2026-10-01 13:46:40 +02:00
8 changed files with 431 additions and 204 deletions
+2 -9
View File
@@ -229,13 +229,7 @@ class Juego
* - la respuesta pertenece a esa pregunta * - la respuesta pertenece a esa pregunta
* - el usuario no ha respondido ya esa pregunta * - el usuario no ha respondido ya esa pregunta
*/ */
public static function registrarRespuesta( public static function registrarRespuesta($idPartida, $idUsuario, $idPartidaxPregunta, $idRespuesta)
$idPartida,
$idUsuario,
$idPartidaxPregunta,
$idRespuesta,
$tiempoRespuesta
)
{ {
$conexion = conexionBD(); $conexion = conexionBD();
if (is_array($conexion)) { if (is_array($conexion)) {
@@ -304,8 +298,7 @@ class Juego
null, null,
$idPartidaxPregunta, $idPartidaxPregunta,
$idUsuario, $idUsuario,
$idRespuesta, $idRespuesta
$tiempoRespuesta
); );
$guardado = $almacenada->guardarRespuesta(); $guardado = $almacenada->guardarRespuesta();
-2
View File
@@ -24,8 +24,6 @@ class Respuesta{
$consulta->bindParam(':idPregunta', $this->idPregunta); $consulta->bindParam(':idPregunta', $this->idPregunta);
$consulta->bindParam(':nombreRespuesta', $this->nombreRespuesta); $consulta->bindParam(':nombreRespuesta', $this->nombreRespuesta);
$consulta->bindParam(':correcta', $this->correcta); $consulta->bindParam(':correcta', $this->correcta);
$consulta->execute(); $consulta->execute();
$respuesta = [ $respuesta = [
'exito' => 'La respuesta se guardó correctamente.', 'exito' => 'La respuesta se guardó correctamente.',
+23 -33
View File
@@ -7,53 +7,43 @@ class RespuestaAlmacenada {
public $idPartidaxPregunta; public $idPartidaxPregunta;
public $idUsuario; public $idUsuario;
public $idRespuesta; public $idRespuesta;
public $tiempoRespuesta;
public function __construct($idRespuestaAlmacenada = null, $idPartidaxPregunta = null, $idUsuario = null, $idRespuesta = null, $tiempoRespuesta = null) { public function __construct($idRespuestaAlmacenada = null, $idPartidaxPregunta = null, $idUsuario = null, $idRespuesta = null) {
$this->idRespuestaAlmacenada = $idRespuestaAlmacenada; $this->idRespuestaAlmacenada = $idRespuestaAlmacenada;
$this->idPartidaxPregunta = $idPartidaxPregunta; $this->idPartidaxPregunta = $idPartidaxPregunta;
$this->idUsuario = $idUsuario; $this->idUsuario = $idUsuario;
$this->idRespuesta = $idRespuesta; $this->idRespuesta = $idRespuesta;
$this->tiempoRespuesta = $tiempoRespuesta;
} }
/** /**
* Guarda la respuesta que ha seleccionado un usuario en una pregunta de la partida. * Guarda la respuesta que ha seleccionado un usuario en una pregunta de la partida.
*/ */
public function guardarRespuesta() { public function guardarRespuesta() {
$conexion = conexionBD(); $conexion = conexionBD();
if (is_array($conexion)) return $conexion;
if (is_array($conexion)) { try {
return $conexion; $sql = "INSERT INTO respuestaalmacenada (idPartidaxPregunta, idUsuario, idRespuesta)
VALUES (:idPartidaxPregunta, :idUsuario, :idRespuesta)";
$consulta = $conexion->prepare($sql);
$consulta->bindParam(':idPartidaxPregunta', $this->idPartidaxPregunta);
$consulta->bindParam(':idUsuario', $this->idUsuario);
$consulta->bindParam(':idRespuesta', $this->idRespuesta);
$consulta->execute();
return [
'exito' => 'Respuesta del usuario almacenada correctamente.',
'exito_tecnico' => $conexion->lastInsertId()
];
} catch (PDOException $error) {
return [
'error' => 'Ocurrió un error al guardar la respuesta del jugador.',
'error_tecnico' => $error->getMessage()
];
}
} }
try {
$sql = "INSERT INTO respuestaalmacenada
(idPartidaxPregunta, idUsuario, idRespuesta, tiempoRespuesta)
VALUES
(:idPartidaxPregunta, :idUsuario, :idRespuesta, :tiempoRespuesta)";
$consulta = $conexion->prepare($sql);
$consulta->bindParam(':idPartidaxPregunta', $this->idPartidaxPregunta);
$consulta->bindParam(':idUsuario', $this->idUsuario);
$consulta->bindParam(':idRespuesta', $this->idRespuesta);
$consulta->bindParam(':tiempoRespuesta', $this->tiempoRespuesta);
$consulta->execute();
return [
'exito' => 'Respuesta almacenada correctamente.'
];
} catch (PDOException $error) {
return [
'error' => 'Ocurrió un error al guardar la respuesta.',
'error_tecnico' => $error->getMessage()
];
}
}
/** /**
* Obtiene los aciertos totales de un usuario en una partida específica. * Obtiene los aciertos totales de un usuario en una partida específica.
* Útil para calcular las estadísticas individuales al terminar el juego. * Útil para calcular las estadísticas individuales al terminar el juego.
+18 -31
View File
@@ -74,47 +74,34 @@ switch ($orden) {
case 'responder': case 'responder':
if ( if (!isset($_POST['idPartidaxPregunta']) || !isset($_POST['idRespuesta'])){
!isset($_POST['idPartidaxPregunta']) || echo json_encode([
!isset($_POST['idRespuesta']) || 'error' => 'Faltan datos para registrar la respuesta.'
!isset($_POST['tiempoRespuesta']) ]);
) {
echo json_encode([
'error' => 'Faltan datos para registrar la respuesta.'
]);
break; break;
} }
$idPartidaxPregunta = intval($_POST['idPartidaxPregunta']); $idPartidaxPregunta = intval($_POST['idPartidaxPregunta']);
$idRespuesta = intval($_POST['idRespuesta']);
$tiempoRespuesta = intval($_POST['tiempoRespuesta']);
if ( $idRespuesta = intval($_POST['idRespuesta']);
$idPartidaxPregunta <= 0 ||
$idRespuesta <= 0 || if ($idPartidaxPregunta <= 0 || $idRespuesta <= 0){
$tiempoRespuesta < 0
) { echo json_encode([
echo json_encode([ 'error' => 'Los datos de la respuesta no son válidos.'
'error' => 'Los datos de la respuesta no son válidos.' ]);
]);
break; break;
} }
// Registramos la respuesta del usuario junto con su tiempo de respuesta // Registramos la respuesta del usuario
$resultado = Juego::registrarRespuesta( $resultado = Juego::registrarRespuesta($idPartida, $idUsuario, $idPartidaxPregunta, $idRespuesta);
$idPartida,
$idUsuario,
$idPartidaxPregunta,
$idRespuesta,
$tiempoRespuesta
);
echo json_encode($resultado); echo json_encode($resultado);
break; break;
// Finalizar la partida y registrar los aciertos del usuario // Finalizar la partida y registrar los aciertos del usuario
+1
View File
@@ -121,6 +121,7 @@
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 {
+377 -114
View File
@@ -1,179 +1,442 @@
/* ========================================================================== /* ==========================================================================
ESTILOS GENERALES Y FONDO VARIABLES DEL PROYECTO
========================================================================== */ ========================================================================== */
: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: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; font-family: 'Fredoka', sans-serif;
background-color: #f0f4f8; background-color: var(--background);
color: #2c3e50; color: var(--text-dark);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh; min-height: 100vh;
padding: 20px; padding: 30px 20px;
} }
/* Contenedor principal estilo tarjeta */
.contenedor {
width: 100%;
max-width: 900px;
background: #ffffff;
padding: 40px;
border-radius: 16px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
text-align: center;
animation: fadeIn 0.5s ease-in-out;
}
h1 {
font-size: 2.5rem;
color: #1a365d;
margin-bottom: 30px;
}
h2 {
font-size: 1.6rem;
color: #2b6cb0;
margin-top: 30px;
margin-bottom: 15px;
text-align: left;
border-bottom: 2px solid #e2e8f0;
padding-bottom: 8px;
}
p {
font-size: 1.1rem;
color: #718096;
margin-bottom: 30px;
}
/* ========================================================================== /* ==========================================================================
PANTALLA DE ESPERA Y ANIMACIÓN DE CARGA (LOADER) CONTENEDOR PRINCIPAL
========================================================================== */ ========================================================================== */
#pantalla-espera {
padding: 60px 20px; .contenedor {
width: 100%;
max-width: 1000px;
margin: 0 auto;
background-color: var(--white);
border-radius: 20px;
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.10);
overflow: hidden;
} }
/* ==========================================================================
PANTALLA DE ESPERA
========================================================================== */
#pantalla-espera {
padding: 70px 30px;
text-align: center;
}
#pantalla-espera h2 {
color: var(--kahoot-purple);
font-size: 2rem;
font-weight: 700;
margin-bottom: 15px;
}
#pantalla-espera p {
color: var(--text-muted);
font-size: 1.1rem;
margin-bottom: 35px;
}
/* ==========================================================================
LOADER
========================================================================== */
.loader { .loader {
width: 60px; width: 65px;
height: 60px; height: 65px;
border: 6px solid #e2e8f0;
border-top: 6px solid #3182ce;
border-radius: 50%;
margin: 0 auto; margin: 0 auto;
animation: spin 1.2s linear infinite;
border: 7px solid #e5e5e5;
border-top-color: var(--kahoot-purple);
border-radius: 50%;
animation: spin 1s linear infinite;
} }
@keyframes spin { @keyframes spin {
0% { transform: rotate(0deg); } from {
100% { transform: rotate(360deg); } transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
} }
/* ========================================================================== /* ==========================================================================
TABLAS DE CLASIFICACIÓN (RANKING) CABECERA DE RESULTADOS
========================================================================== */ ========================================================================== */
.tabla-ranking {
width: 100%; #pantalla-resultados {
border-collapse: collapse; padding: 40px;
margin-bottom: 20px;
font-size: 1.05rem;
} }
.tabla-ranking th, #pantalla-resultados h1 {
.tabla-ranking td { text-align: center;
padding: 16px 20px; 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 {
width: 100%;
border-collapse: separate;
border-spacing: 0;
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);
}
/* Cabecera */
.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 th { .tabla-ranking thead th:first-child {
background-color: #2d3748; border-top-left-radius: 12px;
color: #ffffff;
font-weight: 600;
text-transform: uppercase;
font-size: 0.9rem;
letter-spacing: 0.5px;
} }
/* Alinear los puntos y aciertos a la derecha para mejor lectura numérica */ .tabla-ranking thead th:last-child {
.tabla-ranking th:last-child, border-top-right-radius: 12px;
.tabla-ranking td:last-child {
text-align: right;
} }
.tabla-ranking tr {
border-bottom: 1px solid #e2e8f0; /* Celdas */
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: #f7fafc; background-color: #f7f3ff;
} }
/* ========================================================================== /* ==========================================================================
RESALTADO DE GANADORES (1º PUESTO) COLUMNA DE POSICIÓN
========================================================================== */ ========================================================================== */
/* Fila del Equipo Ganador y Jugador Ganador */
.tabla-ranking tr.top-team, .tabla-ranking tbody td:first-child {
.tabla-ranking tr.top-player { font-weight: 700;
background-color: #fefcbf !important; /* Amarillo suave */ color: var(--kahoot-purple);
font-weight: bold; width: 100px;
} }
/* Cambiar el color del texto del puesto #1 a dorado/corona */
.tabla-ranking tr.top-team td:first-child, /* ==========================================================================
.tabla-ranking tr.top-player td:first-child { PUNTOS
color: #b7791f; ========================================================================== */
font-size: 1.2rem;
}
.tabla-ranking td strong { .tabla-ranking td strong {
color: #2f855a; /* Verde para destacar los aciertos conseguidos */ color: var(--kahoot-green);
font-size: 1.1rem; font-size: 1.15rem;
font-weight: 700;
} }
/* ==========================================================================
EFECTOS VISUALES SUAVES
========================================================================== */
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
/* ========================================================================== /* ==========================================================================
ESTILOS DEL BOTÓN DE RETORNO A INICIO EQUIPO / JUGADOR GANADOR
========================================================================== */ ========================================================================== */
.tabla-ranking tr.top-team,
.tabla-ranking tr.top-player {
background-color: #fff7df !important;
font-weight: 700;
}
/* Línea lateral amarilla */
.tabla-ranking tr.top-team td:first-child,
.tabla-ranking tr.top-player td:first-child {
color: var(--kahoot-yellow-dark);
font-size: 1.15rem;
}
/* Puntos del ganador */
.tabla-ranking tr.top-team td strong,
.tabla-ranking tr.top-player td strong {
color: var(--kahoot-green);
}
/* ==========================================================================
BOTÓN VOLVER AL INICIO
========================================================================== */
.contenedor-boton { .contenedor-boton {
display: flex;
justify-content: center;
align-items: center;
margin-top: 40px; margin-top: 40px;
padding-top: 20px; padding-top: 10px;
text-align: center;
} }
/* Botón */
.btn-inicio { .btn-inicio {
display: inline-block; display: inline-flex;
background-color: #3182ce; /* Azul corporativo */ align-items: center;
color: #ffffff; justify-content: center;
padding: 14px 28px; gap: 10px;
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: 600; font-weight: 700;
text-decoration: none; text-decoration: none;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(49, 130, 206, 0.2); box-shadow: 0 5px 10px rgba(19, 104, 206, 0.25);
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: #2b6cb0; /* Azul ligeramente más oscuro al pasar el cursor */ background-color: #0f56ab;
box-shadow: 0 6px 12px rgba(43, 108, 176, 0.3); color: white;
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(0); /* Vuelve a su posición normal al pulsar */ transform: translateY(3px);
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;
}
} }
+1 -11
View File
@@ -18,10 +18,9 @@ let preguntas = [];
let indice = 0; // pregunta que se está mostrando let indice = 0; // pregunta que se está mostrando
let bloqueado = false; // true mientras se envía una respuesta o se ve el feedback let bloqueado = false; // true mientras se envía una respuesta o se ve el feedback
let numeroAciertos = 0; // número de aciertos del jugador let numeroAciertos = 0; // número de aciertos del jugador
let tiempoRespuesta = 0;
let intervaloTiempo;
$(document).ready(function () { $(document).ready(function () {
// Obtenemos el idPartida de la URL // Obtenemos el idPartida de la URL
// Ejemplo: juego.php?idPartida=3 // Ejemplo: juego.php?idPartida=3
@@ -84,11 +83,6 @@ function cargarPreguntas() {
function mostrarPregunta() { function mostrarPregunta() {
const pregunta = preguntas[indice]; const pregunta = preguntas[indice];
tiempoRespuesta = 0;
intervaloTiempo = setInterval(function () {
tiempoRespuesta++;
}, 100);
bloqueado = false; bloqueado = false;
$("#textoPregunta").text(pregunta.nombrePregunta); $("#textoPregunta").text(pregunta.nombrePregunta);
@@ -117,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) {
clearInterval(intervaloTiempo);
console.log("Tiempo de respuesta: " + tiempoRespuesta / 10 + " segundos");
if (bloqueado) { if (bloqueado) {
return; return;
} }
@@ -140,7 +131,6 @@ function responder($botonPulsado) {
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) {
+8 -3
View File
@@ -86,19 +86,24 @@ 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>⌛ Esperando a que todos los jugadores terminen...</h2> <h2> <i class="bi bi-hourglass"></i> 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>🏆 Resultados de la Partida 🏆</h1> <h1> <i class="bi bi-trophy-fill"></i> Resultados de la Partida <i class="bi bi-trophy-fill"></i> </h1>
<h2>Clasificación por Equipos</h2> <h2>Clasificación por Equipos</h2>
<table class="tabla-ranking"> <table class="tabla-ranking">
@@ -146,7 +151,7 @@ usort($equiposFinales, function($a, $b) { return $b['puntos'] <=> $a['puntos'];
<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="<?= $_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>
</div> </div>
</div> </div>