diff --git a/poker-paf/Css/GmCss.backup b/poker-paf/Css/gameCss.backup similarity index 100% rename from poker-paf/Css/GmCss.backup rename to poker-paf/Css/gameCss.backup diff --git a/poker-paf/Js/Game.js b/poker-paf/Js/Game.js index 941c8d3..8053816 100644 --- a/poker-paf/Js/Game.js +++ b/poker-paf/Js/Game.js @@ -9,7 +9,7 @@ let playersData = []; async function SqlRequest(action, params = {}) { try { - const response = await fetch('../Php/RequestsHandler.php', { + const response = await fetch('RequestsHandler.php', { method: 'POST', headers: { 'Content-Type': 'application/json' @@ -37,7 +37,7 @@ window.onload = async function() { gameData = await getGame(); playersData = await getPlayers(); - document.getElementById('title_page').textContent = "Table de Poker - " + gameData.name; + document.getElementById('title_page').textContent = gameData.name + " - Poker PAF"; updateClientInterface(); } @@ -257,7 +257,7 @@ async function declareWinner(playerId) {

${playersData.find(player => player.id == playerId).name} gagne la partie et remporte ${gameData.last_bet} 🪙 !

- + `; } @@ -293,7 +293,7 @@ async function deleteGame() { const response = await SqlRequest('delete_game', { game_id: gameData.id }); if (response.success) { console.log("Partie supprimée avec succès.", response.success); - window.location.replace('../index.html'); + window.location.replace('index.html'); } else { console.error("Erreur lors de la suppression du jeu :", response.error); } diff --git a/poker-paf/Js/Index.js b/poker-paf/Js/Index.js index 8d30713..7d5a28e 100644 --- a/poker-paf/Js/Index.js +++ b/poker-paf/Js/Index.js @@ -3,7 +3,7 @@ async function SqlRequest(action, params = {}) { try { - const response = await fetch('Php/RequestsHandler.php', { + const response = await fetch('RequestsHandler.php', { method: 'POST', headers: { 'Content-Type': 'application/json' @@ -63,7 +63,8 @@ for (const game of games) {

Start Money: ${game.start_money}

Blind: ${game.start_blind}

- + +
${playersHtml} @@ -83,6 +84,31 @@ async function getPlayers(id) { return players; } - +async function joinGameAsAdmin(gameId) { + // Redirige vers la page de connexion admin avec le gameId en paramètre + window.location.href = `admin-login.html?game_id=${gameId}`; +} + +// Récupérer le formulaire de admin-login +const adminLoginForm = document.getElementById('admin-login-form'); + +if (adminLoginForm) { + adminLoginForm.addEventListener('submit', async function(event) { + event.preventDefault(); + const password = document.getElementById('admin-password').value; + const urlParams = new URLSearchParams(window.location.search); + const gameId = urlParams.get('game_id'); + const response = await SqlRequest('adminLogin', { + password: password, + game_id: gameId + }); + + if (response.success) { + window.location.href = `admin-game.html?game_id=${gameId}`; + } else { + alert("Identifiants incorrects. Veuillez réessayer."); + } + }); +} diff --git a/poker-paf/Js/admin-game.js b/poker-paf/Js/admin-game.js new file mode 100644 index 0000000..d32576f --- /dev/null +++ b/poker-paf/Js/admin-game.js @@ -0,0 +1,307 @@ + + +// Fonction et variables essentiel + +const activePlayerLabel = document.getElementById('active-player-name'); +let gameData = null; +let currentPlayer = null; +let playersData = []; + +async function SqlRequest(action, params = {}) { + try { + const response = await fetch('../Php/RequestsHandler.php', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + action: action, + params: params + }) + }); + + const resultat = await response.json(); + + if (resultat.success) { + return resultat; + } else { + console.error("Erreur :", resultat.error); + } + } catch (erreur) { + console.error("Erreur de communication :", erreur); + } +} + +// Fonctions pour démarrer la page +window.onload = async function() { + SqlRequest('is_admin').then(result => { + if (!result.is_admin) { + alert("Vous n'avez pas les droits pour accéder à cette page."); + window.location.href = 'index.html'; + } + }); + gameData = await getGame(); + playersData = await getPlayers(); + + document.getElementById('title_page').textContent = "Vue Administrateur - " + gameData.name + " - PokerPaf"; + updateClientInterface(); +} + +async function updateClientInterface() { + setupPlayers(); + getCurrentPlayer(); + + activePlayerLabel.textContent = `${currentPlayer.name} (${currentPlayer.money} 🪙)`; +} + +async function setupPlayers() { + const PokerTable = document.getElementById('table'); + PokerTable.innerHTML = ''; // Clear existing players + let newHtml = ``; + + newHtml += ` +
+
${gameData.pot}
+
Mise: ${gameData.last_bet}
+
+ `; + + playersData.forEach((player, index) => { + newHtml += ` +
+
+ ${player.is_dealer ? '
D
' : ''} + + J${index + 1} : ${player.name} + ${player.money} 🪙
+ Mise: ${player.current_bet} 🪙 +
+
+ `; + }); + + PokerTable.innerHTML = newHtml; +} + +async function getGame(id = null) { + let gameId; + if (id === null) { + const urlParams = new URLSearchParams(window.location.search); + gameId = urlParams.get('game_id'); + } else { + gameId = id; + } + + const response = await SqlRequest('getGame', { game_id: gameId }); + if (response.success) { + return response.game; + } else { + console.error("Erreur lors de la récupération du jeu :", response.error); + return null; + } +} + +async function getPlayers() { + const response = await SqlRequest('getPlayers', { game_id: gameData.id }); + if (response.success) { + return response.players; + } else { + console.error("Erreur lors de la récupération des joueurs :", response.error); + return []; + } +} + +async function getCurrentPlayer() { + currentPlayer = playersData.find(player => player.id === gameData.current_player_id); +} + +// ----------------------------------------------------- + + + +// Fonctions pour les actions +async function changePlayer(id = null) { + if (id === null) { + const response = await SqlRequest('next_player', { game_id: gameData.id, current_player_id: gameData.current_player_id }); + if (response.success) { + gameData.current_player_id = response.next_player_id; + } else { + console.error("Erreur lors du passage au joueur suivant :", response.error); + } + } else { + const response = await SqlRequest('set_current_player', { game_id: gameData.id, player_id: id }); + if (response.success) { + gameData.current_player_id = id; + } else { + console.error("Erreur lors du changement de joueur :", response.error); + } + } + updateClientInterface(); +} + +async function playerFold() { + const response = await SqlRequest('fold', { player_id: gameData.current_player_id }); + if (response.success) { + playersData = await getPlayers(); + changePlayer(); + } else { + console.error("Erreur lors du fold :", response.error); + } +} + +async function playerRaise() { + const betAmount = parseInt(document.getElementById('raise-amount').value); + + if (betAmount <= 0) { + alert("Veuillez entrer un montant de mise valide."); + return; + } + const amount = betAmount + gameData.last_bet - currentPlayer.current_bet; + + if (currentPlayer.money < amount) { + alert("Vous n'avez pas assez d'argent pour cette mise."); + return; + } + + const response = await SqlRequest('raise', { game_id: gameData.id, player_id: gameData.current_player_id, amount: amount, current_bet: currentPlayer.current_bet }); + if (response.success) { + gameData.last_bet = currentPlayer.current_bet + amount; + gameData.pot += amount; + playersData = await getPlayers(); + changePlayer(); + } else { + console.error("Erreur lors du raise :", response.error); + } +} + +async function playerFollow() { + if (currentPlayer.current_bet >= gameData.last_bet) { + changePlayer(); + return; + } + + let delta_amount = gameData.last_bet - currentPlayer.current_bet; + if (currentPlayer.money < delta_amount) { + delta_amount = currentPlayer.money; + } + + const response = await SqlRequest('follow', { game_id: gameData.id, player_id: gameData.current_player_id, amount: delta_amount }); + if (response.success) { + gameData.pot += delta_amount; + playersData = await getPlayers(); + changePlayer(); + } else { + console.error("Erreur lors du follow :", response.error); + } +} + +async function playerAllIn() { + const response = await SqlRequest('all_in', { game_id: gameData.id, player_id: gameData.current_player_id }); + if (response.success) { + gameData = await getGame(gameData.id); + playersData = await getPlayers(); + changePlayer(); + } else { + console.error("Erreur lors du all-in :", response.error); + } +} + +// ----------------------------------------------------- + + + +// Fonctions pour les actions administratives +async function endGame() { + const container = document.querySelector('.table-container'); + + if (!container) { + console.error("Conteneur .table-container introuvable"); + return; + } + + if (document.querySelector('.win-panel')) return; + + const winOverlay = document.createElement('div'); + winOverlay.className = 'win-overlay'; + const winPanel = document.createElement('div'); + winPanel.className = 'win-panel'; + winPanel.innerHTML = ` +

🏆 La partie est terminée ! 🏆
Qui a gagné ?

+
+ `; + + winOverlay.appendChild(winPanel); + container.appendChild(winOverlay); + + const area = document.getElementById('winner-buttons-area'); + const playerElements = document.querySelectorAll('.player-slot'); + + playerElements.forEach(slot => { + const id = slot.getAttribute('data-id'); + const name = slot.querySelector('.player-name').textContent.split(': ')[1]; + + const btn = document.createElement('button'); + btn.className = 'btn-win'; + btn.innerText = name; + btn.onclick = () => declareWinner(id); + area.appendChild(btn); + }); + + document.getElementById('end-game-screen').style.display = 'flex'; + container.classList.add('blur-effect'); +} + +async function declareWinner(playerId) { + const container = document.querySelector('.table-container'); + container.classList.remove('blur-effect'); + + const response = await SqlRequest('declare_winner', { game_id: gameData.id, player_id: playerId }); + if (response.success) { + const winPanel = document.querySelector('.win-panel'); + if (winPanel) { + winPanel.innerHTML = ` + + +

${playersData.find(player => player.id == playerId).name} gagne la partie et remporte ${gameData.last_bet} 🪙 !

+ + + `; + } + } else { + console.error("Erreur lors de la déclaration du gagnant :", response.error); + } +} + +async function StartNewGame() { + window.location.reload(); +} + +async function addMoney() { + let amount = parseInt(document.getElementById('money-amount').value); + if (isNaN(amount)) { + alert("Veuillez entrer un montant valide."); + return; + } + + const response = await SqlRequest('add_money', { player_id: gameData.current_player_id, amount: amount }); + if (response.success) { + playersData = await getPlayers(); + updateClientInterface(); + } else { + console.error("Erreur lors de l'ajout d'argent :", response.error); + } +} + +async function deleteGame() { + const confirmation = confirm("Êtes-vous sûr de vouloir supprimer cette partie ? Cette action est irréversible."); + if (!confirmation) return; + + const response = await SqlRequest('delete_game', { game_id: gameData.id }); + if (response.success) { + console.log("Partie supprimée avec succès.", response.success); + window.location.replace('index.html'); + } else { + console.error("Erreur lors de la suppression du jeu :", response.error); + } +} + diff --git a/poker-paf/Php/RequestsHandler.php b/poker-paf/RequestsHandler.php similarity index 92% rename from poker-paf/Php/RequestsHandler.php rename to poker-paf/RequestsHandler.php index 67d8f75..05f0a7e 100644 --- a/poker-paf/Php/RequestsHandler.php +++ b/poker-paf/RequestsHandler.php @@ -226,6 +226,25 @@ switch ($action) { $response = ['success' => true, 'games' => $games]; break; + case 'adminLogin': + $stmt = $pdo->prepare("SELECT * FROM admins WHERE game_id = ? AND password = ?"); + $stmt->execute([$params['game_id'], $params['password']]); + $admin = $stmt->fetch(PDO::FETCH_ASSOC); + if ($admin) { + $response = ['success' => true]; + session_start(); + $_SESSION['admin_logged_in'] = true; + $_SESSION['game_id'] = $params['game_id']; + } else { + $response = ['error' => 'Mot de passe incorrect']; + } + break; + + case 'is_admin': + session_start(); + $response = ['is_admin' => isset($_SESSION['admin_logged_in']) && $_SESSION['admin_logged_in'] === true]; + break; + default: $response = ['error' => 'Action inconnue']; } diff --git a/poker-paf/Html/Game.html b/poker-paf/admin-game.html similarity index 91% rename from poker-paf/Html/Game.html rename to poker-paf/admin-game.html index 1770c61..8c02da1 100644 --- a/poker-paf/Html/Game.html +++ b/poker-paf/admin-game.html @@ -7,7 +7,7 @@ - + @@ -22,7 +22,7 @@ - ⬅ Quitter + ⬅ Quitter
@@ -49,7 +49,7 @@
- + diff --git a/poker-paf/admin-login.html b/poker-paf/admin-login.html new file mode 100644 index 0000000..438ac58 --- /dev/null +++ b/poker-paf/admin-login.html @@ -0,0 +1,16 @@ + + + Connexion Administrateur - PokerPaf + + + +

Admin Login

+
+ + +

+ +
+ + + \ No newline at end of file diff --git a/poker-paf/Html/Config.html b/poker-paf/config.html similarity index 84% rename from poker-paf/Html/Config.html rename to poker-paf/config.html index 5429f9a..8a28ea1 100644 --- a/poker-paf/Html/Config.html +++ b/poker-paf/config.html @@ -2,15 +2,15 @@ - Configuration Poker + Créer une partie - PokerPaf - +
- +

Configuration de la partie

@@ -39,5 +39,5 @@
- + \ No newline at end of file diff --git a/poker-paf/game.html b/poker-paf/game.html new file mode 100644 index 0000000..91feafe --- /dev/null +++ b/poker-paf/game.html @@ -0,0 +1,55 @@ + + + + + + + + + + + + + +
+
+
+ + +
+ +
MISE ACTUELLE:
+ + + + ⬅ Quitter +
+ +
+
+
+
+
Mise:
+
+
+
+ +
+

Au tour de :

+ +
+ + +
+ + +
+ +
+
+
+ + + + + diff --git a/poker-paf/index.html b/poker-paf/index.html index 62c27bb..6ae13a5 100644 --- a/poker-paf/index.html +++ b/poker-paf/index.html @@ -3,19 +3,19 @@ - Poker PAF + Accueil -PokerPaf - +

Welcome to Poker PAF

-

+

Parties en cours :

- + \ No newline at end of file