diff --git a/poker-paf/game.php b/poker-paf/game.php index 3c85336..77b1bb3 100644 --- a/poker-paf/game.php +++ b/poker-paf/game.php @@ -122,6 +122,15 @@ foreach ($players as $p) { let current_blind = 0; let blinds = {}; // On stocke les mises en cours ici let money = {}; // On stocke le solde des joueurs ici + let players = []; // On stocke les infos des joueurs ici + + // --- RECUPERATION DES DONNEES DE BASE AU CHARGEMENT --- + + // On ajoute les joueurs dans + + getActualPlayerBlind(); // On récupère les blinds pour chaque joueur + getActualPlayerMoney(); // On récupère les soldes pour chaque joueur + // --- LES FONCTIONS DE JEU (Logique visuelle) --- @@ -257,6 +266,88 @@ foreach ($players as $p) { } } + function getActualPlayerMoney() { + let formData = new FormData(); + formData.append('game_id', actualGameID); + + fetch('get_player_money.php', { + method: 'POST', + body: formData + }) + .then(r => r.json()) + .then(data => { + if (data.success) { + players.push({ + id: data.player_id, + money: data.money + }); + } else { + alert("Erreur : " + data.message); + } + }) + .catch(err => console.error("Erreur fetch:", err)); + } + + function getActualPlayerBlind() { + let formData = new FormData(); + formData.append('game_id', actualGameID); + + fetch('get_player_blind.php', { + method: 'POST', + body: formData + }) + .then(r => r.json()) + .then(data => { + if (data.success) { + players.push({ + id: data.player_id, + blind: data.blind + }); + } else { + alert("Erreur : " + data.message); + } + }) + .catch(err => console.error("Erreur fetch:", err)); + } + + function getActualGameBlind() { + let formData = new FormData(); + formData.append('game_id', actualGameID); + + fetch('get_actual_game_blind.php', { + method: 'POST', + body: formData + }) + .then(r => r.json()) + .then(data => { + if (data.success) { + currentBlind = data.blind; // On met à jour l'affichage de la blind + } else { + alert("Erreur : " + data.message); + } + }) + .catch(err => console.error("Erreur fetch:", err)); + } + + function getTotalGameBlind() { + let formData = new FormData(); + formData.append('game_id', actualGameID); + + fetch('get_total_blind.php', { + method: 'POST', + body: formData + }) + .then(r => r.json()) + .then(data => { + if (data.success) { + totalBlind = data.total_blind; // On met à jour l'affichage du pot total + } else { + alert("Erreur : " + data.message); + } + }) + .catch(err => console.error("Erreur fetch:", err)); + } + \ No newline at end of file diff --git a/poker-paf/get_actual_game_blind.php b/poker-paf/get_actual_game_blind.php new file mode 100644 index 0000000..8d7da5a --- /dev/null +++ b/poker-paf/get_actual_game_blind.php @@ -0,0 +1,19 @@ +prepare("SELECT last_bet FROM games WHERE id = ?"); + $stmt->execute([$game_id]); + $game = $stmt->fetch(); + $last_bet = $game['last_bet']; + + echo json_encode(['success' => true, 'blind' => $last_bet]); + +} catch (Exception $e) { + echo json_encode(['success' => false, 'message' => $e->getMessage()]); +} +?> \ No newline at end of file diff --git a/poker-paf/get_player_blind.php b/poker-paf/get_player_blind.php new file mode 100644 index 0000000..dda3ff3 --- /dev/null +++ b/poker-paf/get_player_blind.php @@ -0,0 +1,25 @@ +prepare("SELECT current_player_id FROM games WHERE id = ?"); + $stmt->execute([$game_id]); + $game = $stmt->fetch(); + $current_player_id = $game['current_player_id']; + + // 2. Récupérer la blind du joueur actuel + $stmt = $db->prepare("SELECT current_bet FROM players WHERE id = ?"); + $stmt->execute([$current_player_id]); + $player = $stmt->fetch(); + $blind = $player['current_bet']; + + echo json_encode(['success' => true, 'blind' => $blind, 'player_id' => $current_player_id]); + +} catch (Exception $e) { + echo json_encode(['success' => false, 'message' => $e->getMessage()]); +} +?> \ No newline at end of file diff --git a/poker-paf/get_player_money.php b/poker-paf/get_player_money.php new file mode 100644 index 0000000..4d98f8b --- /dev/null +++ b/poker-paf/get_player_money.php @@ -0,0 +1,25 @@ +prepare("SELECT current_player_id FROM games WHERE id = ?"); + $stmt->execute([$game_id]); + $game = $stmt->fetch(); + $current_player_id = $game['current_player_id']; + + // 2. Récupérer l'argent du joueur actuel + $stmt = $db->prepare("SELECT money FROM players WHERE id = ?"); + $stmt->execute([$current_player_id]); + $player = $stmt->fetch(); + $money = $player['money']; + + echo json_encode(['success' => true, 'money' => $money, 'player_id' => $current_player_id]); + +} catch (Exception $e) { + echo json_encode(['success' => false, 'message' => $e->getMessage()]); +} +?> \ No newline at end of file diff --git a/poker-paf/get_total_game_blind.php b/poker-paf/get_total_game_blind.php new file mode 100644 index 0000000..ed34e0c --- /dev/null +++ b/poker-paf/get_total_game_blind.php @@ -0,0 +1,19 @@ +prepare("SELECT pot FROM games WHERE id = ?"); + $stmt->execute([$game_id]); + $game = $stmt->fetch(); + $pot = $game['pot']; + + echo json_encode(['success' => true, 'total_blind' => $pot]); + +} catch (Exception $e) { + echo json_encode(['success' => false, 'message' => $e->getMessage()]); +} +?> \ No newline at end of file