From 6d93bfb1802dea7a72fa78e1412f24751c569d03 Mon Sep 17 00:00:00 2001 From: Pierre Ferreira Date: Mon, 11 Dec 2023 15:51:40 +0100 Subject: [PATCH] changement selon les indication de thomas, et ajout du soundeffect pour la win :loud_sound: --- .../src/Components/GraphContainer.tsx | 9 +++++--- cryptide_project/src/Pages/EndGame.tsx | 23 ++++++++++++++++++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/cryptide_project/src/Components/GraphContainer.tsx b/cryptide_project/src/Components/GraphContainer.tsx index 5fa59f5..8a5db1a 100644 --- a/cryptide_project/src/Components/GraphContainer.tsx +++ b/cryptide_project/src/Components/GraphContainer.tsx @@ -187,6 +187,10 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS } useEffect(() =>{ + //* Gestion du sound des tours : + if (actualPlayerIndex == lastIndex){ + handleTurn(); + } cptBug=0 if (actualPlayerIndex==firstPlayer){ const bot = testPlayers[lastIndex] @@ -207,9 +211,8 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS let i = 0 socket.emit("node checked", personIndex, true, lastIndex, room, lastIndex) while(playerIndex != lastIndex){ - //! Play sound ? - handleTurn(); - + // //! Play sound ? + // handleTurn(); i++ if (playerIndex == players.length){ playerIndex = 0 diff --git a/cryptide_project/src/Pages/EndGame.tsx b/cryptide_project/src/Pages/EndGame.tsx index 3e72f2c..05c1224 100644 --- a/cryptide_project/src/Pages/EndGame.tsx +++ b/cryptide_project/src/Pages/EndGame.tsx @@ -1,4 +1,4 @@ -import React, {useEffect} from 'react'; +import React, {useEffect, useState} from 'react'; /* Style */ @@ -11,6 +11,9 @@ import Person from '../res/img/Person.png'; import Leave from '../res/icon/leave.png'; import Replay from '../res/icon/replay.png'; +/* sound */ +import WinSound from '../res/Audio/win.wav'; + /* Component */ import PersonStatus from '../Components/PersonStatus'; import ButtonImgNav from '../Components/ButtonImgNav'; @@ -64,6 +67,11 @@ function EndGame() { } }; + useEffect(() => { + handleWinSound(); + }, []); + + useEffect(() => { const container = document.getElementById("vis-graph"); if (!container) { @@ -126,8 +134,21 @@ function EndGame() { indicenull = true; } + //* Sound + const [playTurnSound, setPlayTurnSound] = useState(false); + + const handleWinSound = () => { + setTimeout(() => { // on attend 1s avant de jouer le son + setPlayTurnSound(true); + }, 300); + + setTimeout(() => { // on attend 2s avant de remettre le son à false + setPlayTurnSound(false); + }, 2000); + }; return (
+ {playTurnSound &&