diff --git a/frontend/pages/riichi/chap5.html b/frontend/pages/riichi/chap5.html index 23baeea..e9dd59a 100644 --- a/frontend/pages/riichi/chap5.html +++ b/frontend/pages/riichi/chap5.html @@ -298,9 +298,9 @@ } #call-panel { - position: fixed; - bottom: 20px; - left: 50%; + position: absolute; + bottom: -57%; + left: 61%; transform: translateX(-50%); display: none; gap: 10px; @@ -420,6 +420,7 @@ let game; let isDistributing = false; let canPlayerAct = false; + let lastDiscarder = -1; // Charger le menu fetch('/components/menu.html') .then(r => r.text()) @@ -623,6 +624,7 @@ // Défausser la tuile piochée (index === tiles.length) canPlayerAct = false; + lastDiscarder = 0; game.discard(0, game.hands[0].tiles.length); game.nextTurn(); updateTurnIndicator(); @@ -670,6 +672,43 @@ } } + async function continueBotPlay() { + // Continue la boucle des bots après une réponse du joueur + canPlayerAct = false; + + while (game.turn !== 0) { + await new Promise(resolve => setTimeout(resolve, 500)); + game.draw(game.turn); + renderHands(); + // Pause aléatoire pour simuler la réflexion + const randomDelay = 1000 + Math.random() * 1000; + await new Promise(resolve => setTimeout(resolve, randomDelay)); + + // Défausser le bot + game.botPlay(); + renderDiscards(); + + // Vérifier si le joueur peut faire un appel + if (game.canPon(0)) { + // Le joueur peut faire un pon, lui proposer + canPlayerAct = true; + showCallPanelForPon(); + return; // Attendre la réponse du joueur + } + + // Sinon, passer au joueur suivant + game.nextTurn(); + updateTurnIndicator(); + renderHands(); + } + + // C'est au tour du joueur - il pioche d'abord + await new Promise(resolve => setTimeout(resolve, 500)); + game.draw(0); + renderHands(); + canPlayerAct = true; + } + async function playBotsSequentially() { // Le joueur ne peut plus agir pendant que les bots jouent canPlayerAct = false; @@ -682,18 +721,30 @@ // Pause aléatoire pour simuler la réflexion const randomDelay = 1000 + Math.random() * 1000; await new Promise(resolve => setTimeout(resolve, randomDelay)); + + // Défausser le bot game.botPlay(); + renderDiscards(); + + // Vérifier si le joueur peut faire un appel + if (game.canPon(0)) { + // Le joueur peut faire un pon, lui proposer + canPlayerAct = true; + showCallPanelForPon(); + return; // Attendre la réponse du joueur + } + + // Sinon, passer au joueur suivant game.nextTurn(); updateTurnIndicator(); renderHands(); - renderDiscards(); } + // C'est au tour du joueur - il pioche d'abord await new Promise(resolve => setTimeout(resolve, 500)); game.draw(0); renderHands(); canPlayerAct = true; - showCallPanel(); } function updateTurnIndicator() { @@ -711,11 +762,24 @@ document.getElementById('call-panel').style.display = 'none'; } + function showCallPanelForPon() { + const callPanel = document.getElementById('call-panel'); + + // Afficher seulement Pon et Skip + document.getElementById('pon-button').style.display = 'block'; + document.getElementById('chii-button').style.display = 'none'; + document.getElementById('kan-button').style.display = 'none'; + document.getElementById('tsumo-button').style.display = 'none'; + document.getElementById('ron-button').style.display = 'none'; + + callPanel.style.display = 'flex'; + } + function showCallPanel() { const callPanel = document.getElementById('call-panel'); // Ne pas afficher les appels si c'est le joueur qui vient de défausser - if (game.turn === 0) { + if (lastDiscarder === 0) { callPanel.style.display = 'none'; return; } @@ -756,18 +820,21 @@ updateTurnIndicator(); renderHands(); renderDiscards(); - playBotsSequentially(); + continueBotPlay(); }); document.getElementById('skip-button').addEventListener('click', () => { if (!canPlayerAct) return; canPlayerAct = false; hideCallPanel(); - playBotsSequentially(); + continueBotPlay(); }); - renderHands(); - updateTurnIndicator(); + // Ne pas rendre les mains si le jeu n'a pas commencé + if (game) { + renderHands(); + updateTurnIndicator(); + } });