Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 77e512be5b |
@@ -1,118 +1,79 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
|
||||
require_once '../clases/claseJuego.php';
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
// Comprobamos que haya un usuario conectado
|
||||
|
||||
// Hay que estar logueado y decir de qué partida se trata
|
||||
if (!isset($_SESSION['idUsuario'])) {
|
||||
echo json_encode([
|
||||
'error' => 'Debes iniciar sesión para jugar.'
|
||||
]);
|
||||
|
||||
echo json_encode(['error' => 'Debes iniciar sesión para jugar.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$idUsuario = (int) $_SESSION['idUsuario'];
|
||||
|
||||
// Comprobamos que se haya indicado la partida
|
||||
|
||||
if (!isset($_POST['idPartida'])) {
|
||||
echo json_encode([
|
||||
'error' => 'No se ha indicado la partida.'
|
||||
]);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$idPartida = intval($_POST['idPartida']);
|
||||
$idUsuario = (int)$_SESSION['idUsuario'];
|
||||
$idPartida = intval($_POST['idPartida'] ?? 0);
|
||||
|
||||
if ($idPartida <= 0) {
|
||||
echo json_encode([
|
||||
'error' => 'La partida indicada no es válida.'
|
||||
]);
|
||||
|
||||
echo json_encode(['error' => 'No se ha indicado la partida.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Comprobamos que el usuario pertenezca a la partida
|
||||
|
||||
$perteneceAPartida = Juego::usuarioEnPartida($idPartida,$idUsuario);
|
||||
// Solo pueden jugar los usuarios que están en uno de los equipos de la partida
|
||||
$perteneceAPartida = Juego::usuarioEnPartida($idPartida, $idUsuario);
|
||||
|
||||
if (is_array($perteneceAPartida)) {
|
||||
echo json_encode($perteneceAPartida);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
if (!$perteneceAPartida) {
|
||||
echo json_encode([
|
||||
'error' => 'No formas parte de esta partida.'
|
||||
]);
|
||||
|
||||
echo json_encode(['error' => 'No formas parte de esta partida.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Comprobamos la orden
|
||||
|
||||
$orden = $_POST['orden'] ?? '';
|
||||
|
||||
switch ($orden) {
|
||||
|
||||
// CARGAR LAS PREGUNTAS DE LA PARTIDA
|
||||
switch ($_POST['orden'] ?? '') {
|
||||
|
||||
// Devuelve las 10 preguntas con sus respuestas (sin marcar la correcta)
|
||||
case 'cargarPreguntas':
|
||||
|
||||
$resultado = Juego::cargarPreguntas($idPartida, $idUsuario);
|
||||
echo json_encode($resultado);
|
||||
echo json_encode(Juego::cargarPreguntas($idPartida, $idUsuario));
|
||||
|
||||
break;
|
||||
|
||||
// REGISTRAR RESPUESTA
|
||||
|
||||
// Guarda la respuesta del usuario y dice si ha acertado
|
||||
case 'responder':
|
||||
|
||||
if (!isset($_POST['idPartidaxPregunta']) || !isset($_POST['idRespuesta'])){
|
||||
echo json_encode([
|
||||
'error' => 'Faltan datos para registrar la respuesta.'
|
||||
]);
|
||||
$idPartidaxPregunta = intval($_POST['idPartidaxPregunta'] ?? 0);
|
||||
$idRespuesta = intval($_POST['idRespuesta'] ?? 0);
|
||||
|
||||
if ($idPartidaxPregunta <= 0 || $idRespuesta <= 0) {
|
||||
echo json_encode(['error' => 'Faltan datos para registrar la respuesta.']);
|
||||
break;
|
||||
}
|
||||
|
||||
$idPartidaxPregunta = intval($_POST['idPartidaxPregunta']);
|
||||
|
||||
$idRespuesta = intval($_POST['idRespuesta']);
|
||||
|
||||
if ($idPartidaxPregunta <= 0 || $idRespuesta <= 0){
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'Los datos de la respuesta no son válidos.'
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Registramos la respuesta del usuario
|
||||
|
||||
$resultado = Juego::registrarRespuesta($idPartida, $idUsuario, $idPartidaxPregunta, $idRespuesta);
|
||||
|
||||
echo json_encode($resultado);
|
||||
echo json_encode(
|
||||
Juego::registrarRespuesta(
|
||||
$idPartida,
|
||||
$idUsuario,
|
||||
$idPartidaxPregunta,
|
||||
$idRespuesta
|
||||
)
|
||||
);
|
||||
|
||||
break;
|
||||
|
||||
// Finalizar la partida y registrar los aciertos del usuario
|
||||
|
||||
// Recibe los aciertos del jugador al terminar sus 10 preguntas,
|
||||
// para que resultados.php los pueda usar al montar la hoja de resultados
|
||||
case 'finalizarPartida':
|
||||
|
||||
$aciertos = intval($_POST['aciertos'] ?? 0);
|
||||
|
||||
// Guardamos los aciertos en la sesión
|
||||
|
||||
if (!isset($_SESSION['aciertosPorPartida'])) {
|
||||
|
||||
$_SESSION['aciertosPorPartida'] = [];
|
||||
}
|
||||
|
||||
@@ -120,21 +81,16 @@ switch ($orden) {
|
||||
|
||||
echo json_encode([
|
||||
'exito' => 'Aciertos registrados correctamente.',
|
||||
|
||||
'idPartida' => $idPartida,
|
||||
|
||||
'aciertos' => $aciertos
|
||||
]);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
|
||||
echo json_encode([
|
||||
'error' => 'La orden indicada no existe.'
|
||||
]);
|
||||
echo json_encode(['error' => 'La orden indicada no existe.']);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
// Redirección si el usuario no ha iniciado sesión
|
||||
if (!isset($_SESSION['idUsuario'])) {
|
||||
header('Location: login.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
$nombreUsuario = htmlspecialchars($_SESSION['nombreUsuario'] ?? 'Usuario');
|
||||
$avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultProfile.jpeg');
|
||||
?>
|
||||
+1
-13
@@ -20,18 +20,7 @@ let bloqueado = false; // true mientras se envía una respuesta o se ve el feedb
|
||||
let numeroAciertos = 0; // número de aciertos del jugador
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
// Obtenemos el idPartida de la URL
|
||||
// Ejemplo: juego.php?idPartida=3
|
||||
|
||||
const parametros = new URLSearchParams(window.location.search);
|
||||
|
||||
idPartida = parseInt(parametros.get("idPartida"), 10);
|
||||
|
||||
if (!idPartida || idPartida < 1) {
|
||||
mostrarError("La partida indicada no es válida.");
|
||||
return;
|
||||
}
|
||||
idPartida = parseInt($("body").data("id-partida"), 10);
|
||||
|
||||
// Un solo listener para todos los botones de respuesta
|
||||
$("#respuestas").on("click", ".btn-answer", function () {
|
||||
@@ -114,7 +103,6 @@ function responder($botonPulsado) {
|
||||
if (bloqueado) {
|
||||
return;
|
||||
}
|
||||
|
||||
bloqueado = true;
|
||||
|
||||
const pregunta = preguntas[indice];
|
||||
|
||||
@@ -1,6 +1,22 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// Hay que estar logueado para jugar
|
||||
if (!isset($_SESSION['idUsuario'])) {
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// La partida llega por la URL: juego.php?idPartida=3
|
||||
$idPartida = filter_input(INPUT_GET, 'idPartida', FILTER_VALIDATE_INT);
|
||||
|
||||
if (!$idPartida || $idPartida < 1) {
|
||||
header('Location: buscadorSala.php');
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="es">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
@@ -8,48 +24,28 @@
|
||||
<title>Proyecto Trivial</title>
|
||||
<link rel="stylesheet" href="css/juego.css">
|
||||
<link rel="icon" type="image/svg+xml" href="img/favicon/favicon.svg">
|
||||
|
||||
</head>
|
||||
<body data-id-partida="<?= (int)$idPartida ?>">
|
||||
|
||||
<body>
|
||||
|
||||
<!-- CABECERA Y PROGRESO -->
|
||||
|
||||
<!-- Progreso: "Pregunta 3 de 10" + barra -->
|
||||
<div class="game-header">
|
||||
|
||||
<span id="contadorPregunta">
|
||||
Cargando…
|
||||
</span>
|
||||
|
||||
<span id="contadorPregunta">Cargando…</span>
|
||||
</div>
|
||||
|
||||
<div class="progress-track">
|
||||
|
||||
<div class="progress-fill" id="barraProgreso"></div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- PREGUNTA -->
|
||||
|
||||
<!-- Contenedor de la Pregunta (lo rellena js/juego.js) -->
|
||||
<div class="question-container">
|
||||
|
||||
<div id="textoPregunta">
|
||||
Cargando preguntas…
|
||||
</div>
|
||||
|
||||
<div id="textoPregunta">Cargando preguntas…</div>
|
||||
<div id="feedback" class="feedback" aria-live="polite"></div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- RESPUESTAS -->
|
||||
|
||||
<!-- Contenedor de Respuestas (Estilo Kahoot, lo rellena js/juego.js) -->
|
||||
<div class="answers-grid" id="respuestas"></div>
|
||||
|
||||
<!-- JAVASCRIPT -->
|
||||
|
||||
<script src="js/jquery-4.0.0.min.js"></script>
|
||||
<script src="js/juego.js"></script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+2
-12
@@ -1,17 +1,7 @@
|
||||
<?php
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
// Redirección si el usuario no ha iniciado sesión
|
||||
if (!isset($_SESSION['idUsuario'])) {
|
||||
header('Location: login.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
$nombreUsuario = htmlspecialchars($_SESSION['nombreUsuario'] ?? 'Usuario');
|
||||
$avatarUsuario = htmlspecialchars($_SESSION['avatar'] ?? 'img/avatars/defaultProfile.jpeg');
|
||||
require_once '/controladores/controladorPerfil.php';
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="es">
|
||||
|
||||
|
||||
+1
-1
@@ -89,7 +89,7 @@ usort($equiposFinales, function($a, $b) { return $b['puntos'] <=> $a['puntos'];
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Resultados - Trivial</title>
|
||||
<link rel="stylesheet" href="css/resultados.css">
|
||||
<script src="https://cdn.jsdelivr.net/npm/jquery@4.0.0/dist/jquery.min.js"></script>
|
||||
<script src="https://jquery.com"></script>
|
||||
</head>
|
||||
<body data-id-partida="<?php echo $idPartida; ?>">
|
||||
|
||||
|
||||
Reference in New Issue
Block a user