'Sala no encontrada']); } exit; } // Acciones de actualización (POST) if ($_SERVER['REQUEST_METHOD'] === 'POST') { $input = json_decode(file_get_contents('php://input'), true); $action = $input['action'] ?? ''; $room = preg_replace('/[^A-Z0-9]/', '', strtoupper($input['room'] ?? '')); $file = $roomsDir . '/room_' . $room . '.json'; if ($action == 'create') { $data = [ 'room' => $room, 'word' => strtoupper($input['word']), 'status' => 'waiting', 'players' => [], 'guesses' => [], 'maxLives' => 6, 'lastUpdate' => time() ]; file_put_contents($file, json_encode($data)); echo json_encode($data); } elseif ($action == 'join' && file_exists($file)) { $data = json_decode(file_get_contents($file), true); // Evitar duplicados simples por nombre $exists = false; foreach($data['players'] as $p) { if($p['name'] === $input['playerName']) $exists = true; } if(!$exists) { $data['players'][] = ['name' => $input['playerName'], 'id' => uniqid()]; file_put_contents($file, json_encode($data)); } echo json_encode($data); } elseif ($action == 'guess' && file_exists($file)) { $data = json_decode(file_get_contents($file), true); $letter = strtoupper($input['letter']); if (!in_array($letter, $data['guesses'])) { $data['guesses'][] = $letter; } file_put_contents($file, json_encode($data)); echo json_encode($data); } elseif ($action == 'start' && file_exists($file)) { $data = json_decode(file_get_contents($file), true); $data['status'] = 'playing'; file_put_contents($file, json_encode($data)); echo json_encode($data); } elseif ($action == 'reset' && file_exists($file)) { $data = json_decode(file_get_contents($file), true); $data['word'] = strtoupper($input['word']); $data['status'] = 'playing'; $data['guesses'] = []; file_put_contents($file, json_encode($data)); echo json_encode($data); } exit; } } ?> Ahorcado Pro Multiplayer

AHORCADO PRO

English Multiplayer

o entrar a una