«¡Conexión exitosa desde la App!»
/* Diseño del juego – Estilo limpio y médico */
.nback-wrapper { font-family: Arial, sans-serif; text-align: center; max-width: 400px; margin: 0 auto; padding: 20px; }
.nback-grid { display: grid; grid-template-columns: repeat(3, 80px); gap: 10px; justify-content: center; margin-bottom: 20px; }
.nback-cell { width: 80px; height: 80px; background-color: #e0e4e8; border-radius: 8px; transition: background-color 0.1s; }
.active-cell { background-color: #0056b3; } /* Color azul médico cuando se ilumina */
.btn-game { padding: 12px 24px; font-size: 16px; margin: 5px; border: none; border-radius: 5px; cursor: pointer; color: white; background-color: #28a745; font-weight: bold; }
.btn-start { background-color: #007bff; }
#mensaje { margin-top: 15px; font-weight: bold; color: #333; height: 20px; }
Entrenamiento Visual N-Back
N = 1 (Presiona si la posición actual es IGUAL a la posición anterior)
Aciertos: 0
let historialPosiciones = [];
let intervaloJuego;
let score = 0;
let turnoActual = 0;
let respondioEsteTurno = false;
function iniciarJuego() {
historialPosiciones = [];
score = 0;
turnoActual = 0;
document.getElementById(‘score’).innerText = score;
document.getElementById(‘mensaje’).innerText = «¡Concéntrate!»;
// Si ya hay un juego corriendo, lo detenemos
clearInterval(intervaloJuego);
// Configurar el temporizador: cambia cada 2 segundos (2000 ms)
intervaloJuego = setInterval(siguienteTurno, 2000);
siguienteTurno(); // Lanzar el primer turno de inmediato
}
function siguienteTurno() {
respondioEsteTurno = false;
document.getElementById(‘mensaje’).innerText = «»;
// Apagar todas las celdas
for(let i=0; i {
document.getElementById(‘cell-‘ + nuevaPosicion).classList.remove(‘active-cell’);
}, 1000); // Se apaga rápido para forzar a la memoria a retenerlo
turnoActual++;
// Detener el juego después de 20 turnos (ronda rápida)
if(turnoActual > 20) {
clearInterval(intervaloJuego);
document.getElementById(‘mensaje’).innerText = «¡Ronda terminada! Aciertos: » + score;
}
}
function comprobarCoincidencia() {
if(historialPosiciones.length < 2 || respondioEsteTurno) return;
respondioEsteTurno = true;
let actual = historialPosiciones[historialPosiciones.length – 1];
let anterior = historialPosiciones[historialPosiciones.length – 2];
if(actual === anterior) {
score++;
document.getElementById('score').innerText = score;
document.getElementById('mensaje').innerText = "¡Correcto!";
document.getElementById('mensaje').style.color = "green";
} else {
document.getElementById('mensaje').innerText = "Fallo…";
document.getElementById('mensaje').style.color = "red";
}
}