prepare("SELECT nombre, banner_1, banner_2, banner_3, banner_4, background_image, fullscreen_icon, reverso_default, ruleta_id FROM juegos_config WHERE juego_id = ? LIMIT 1"); $stmt->bind_param("i", $juego_id); $stmt->execute(); $config = $stmt->get_result()->fetch_assoc(); $stmt->close(); if (!$config) { die("Config del juego no encontrada (juego_id=$juego_id)."); } // 2) Cargar cartas activas (traseras a emparejar). Puedes manejar n pares desde la BD. $cartas = []; $res = $conn->prepare("SELECT id, nombre, imagen_trasera, COALESCE(imagen_frontal, '') AS imagen_frontal FROM cartas WHERE juego_id = ? AND activo = 1"); $res->bind_param("i", $juego_id); $res->execute(); $q = $res->get_result(); while ($row = $q->fetch_assoc()) { $cartas[] = $row; } $res->close(); if (!$cartas) { die("No hay cartas activas para este juego (juego_id=$juego_id)."); } // Reverso por defecto (lado frontal que se ve al inicio) $reverso = $config['reverso_default'] ?: '/memoria/images/back.png'; // Generar parejas: duplico la lista de cartas. Si tienes más de 12, puedes recortar. $base = $cartas; shuffle($base); $max_pairs = 6; // cambia si quieres más o menos pares $base = array_slice($base, 0, $max_pairs); // Duplicar para formar pares y asignar una clave de pareja consistente $deck = []; $pair_idx = 1; foreach ($base as $c) { $key = 'pair_' . $pair_idx++; $deck[] = ['key'=>$key, 'back'=>$c['imagen_trasera'], 'front'=>$c['imagen_frontal'] ?: $reverso]; $deck[] = ['key'=>$key, 'back'=>$c['imagen_trasera'], 'front'=>$c['imagen_frontal'] ?: $reverso]; } shuffle($deck); // Pasar al front la config necesaria $CONFIG_JS = [ 'juego_id' => $juego_id, 'ruleta_id' => (int)$config['ruleta_id'], 'banners' => [ 'banner_1' => $config['banner_1'] ?: null, 'banner_2' => $config['banner_2'] ?: null, 'banner_3' => $config['banner_3'] ?: null, 'banner_4' => $config['banner_4'] ?: null, ], 'background_image' => $config['background_image'] ?: null, 'fullscreen_icon' => $config['fullscreen_icon'] ?: null, ]; ?>