From c5aa5ea930e9e0ee5a2454913dad469b8ae9756a Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Wed, 13 Dec 2023 15:17:50 +0100 Subject: [PATCH 1/4] choix du nombre de noeuds pour les modes solos --- .../src/Components/GraphContainer.tsx | 48 +++++++++++--- cryptide_project/src/Pages/InGame.tsx | 62 ++++++++++++++++--- .../src/model/EnigmeDuJourCreator.ts | 5 +- 3 files changed, 93 insertions(+), 22 deletions(-) diff --git a/cryptide_project/src/Components/GraphContainer.tsx b/cryptide_project/src/Components/GraphContainer.tsx index a664541..f5789b9 100644 --- a/cryptide_project/src/Components/GraphContainer.tsx +++ b/cryptide_project/src/Components/GraphContainer.tsx @@ -21,6 +21,9 @@ import { json } from "body-parser"; import html2canvas from 'html2canvas'; import jsPDF from 'jspdf'; import {basePath} from "../AdressSetup" +import GameCreator from "../model/GameCreator"; +import Stub from "../model/Stub"; +import EnigmeDuJourCreator from "../model/EnigmeDuJourCreator"; interface MyGraphComponentProps { onNodeClick: (shouldShowChoiceBar: boolean) => void; @@ -50,6 +53,10 @@ interface MyGraphComponentProps { putGreyBackground : () => void putCorrectBackground : () => void putImposssibleGrey : () => void + setChangeGraph : (func: (nbNodes: number) => void) => void + + nbNodes: number + handleTurn :() => void } @@ -80,16 +87,17 @@ let cptUseEffect = 0 let testPlayers: Player[] = [] let testTemps = 0 let testFirst = false +let testFirst2 = true -const MyGraphComponent: React.FC = ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange, playerTouched, setPlayerTouched, changecptTour, solo, isDaily, isEasy, addToHistory, showLast, setNetwork, setNetworkEnigme, setPlayerIndex, askedWrong, setAskedWrong, importToPdf, setImportToPdf, importToJSON, setImportToJSON, setPutCorrectBackground, setPutGreyBackground, setPutImposssibleGrey, putCorrectBackground, putGreyBackground, putImposssibleGrey, handleTurn}) => { - let cptTour: number = 0 +const MyGraphComponent: React.FC = ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange, playerTouched, setPlayerTouched, changecptTour, solo, isDaily, isEasy, addToHistory, showLast, setNetwork, setNetworkEnigme, setPlayerIndex, askedWrong, setAskedWrong, importToPdf, setImportToPdf, importToJSON, setImportToJSON, setPutCorrectBackground, setPutGreyBackground, setPutImposssibleGrey, putCorrectBackground, putGreyBackground, putImposssibleGrey, handleTurn, nbNodes, setChangeGraph}) => { + let cptTour: number = 1 //* Gestion du temps : let initMtn = 0 const {isLoggedIn, user, manager} = useAuth(); - const { indices, indice, person, personNetwork, setNodeIdData, players, setPlayersData, askedPersons, setActualPlayerIndexData, room, actualPlayerIndex, turnPlayerIndex, setTurnPlayerIndexData, setWinnerData, dailyEnigme, setNbCoupData, settempsData, setNetworkDataData, setSeedData, nodesC, temps} = useGame(); + const { indices, indice, person, personNetwork, setNodeIdData, players, setPlayersData, askedPersons, setActualPlayerIndexData, room, actualPlayerIndex, turnPlayerIndex, setIndicesData, setWinnerData, dailyEnigme, setNbCoupData, settempsData, setNetworkDataData, setSeedData, nodesC, temps, setPersonData, setPersonNetworkData, setDailyEnigmeData} = useGame(); const params = new URLSearchParams(window.location.search); const navigate = useNavigate(); @@ -109,10 +117,12 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS settempsData(testTemps) testTemps += 0.5 - cptBug ++ - if (cptBug > 10){ - cptBug = 0 - socket.emit("who plays", room) + if (!solo){ + cptBug ++ + if (cptBug > 10){ + cptBug = 0 + socket.emit("who plays", room) + } } @@ -364,10 +374,29 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS } }, [importToJSON]) + const changeGraph = (nbNodes: number) => { + //todo différencier les deux + const [networkPerson, choosenPerson, choosenIndices] = GameCreator.CreateGame(3, nbNodes) + setPersonData(choosenPerson) + setPersonNetworkData(networkPerson) + setIndicesData(choosenIndices) + const map = EnigmeDuJourCreator.createEnigme(networkPerson, choosenIndices, choosenPerson, Stub.GenerateIndice()) + setDailyEnigmeData(map) + addToHistory("<----- [Tour " + 1 +"/"+networkPerson.getPersons().length + "] ----->"); + changecptTour(1) + testTemps=0 + + + } + useEffect(() => { if (personNetwork == null){ return } + + if (solo){ + setChangeGraph(() => changeGraph) + } const graph = GraphCreator.CreateGraph(personNetwork) let n = graph.nodesPerson; @@ -1087,8 +1116,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS else{ addToHistory(personTest.getName() + " n'est pas le coupable !"); //TODO préciser le nombre d'indice qu'il a de juste cptTour ++; // On Incrémente le nombre de tour du joueur - const tour = cptTour+1; - addToHistory("<----- [Tour " + tour +"/"+networkData.nodes.length + "] ----->"); + addToHistory("<----- [Tour " + cptTour +"/"+networkData.nodes.length + "] ----->"); changecptTour(cptTour); // On le transmet a la page précédente avec la fonction } } @@ -1101,7 +1129,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS setPlayerTouched(-1) } }); - }, []); // Le tableau vide signifie que cela ne s'exécutera qu'une fois après le premier rendu + }, [personNetwork]); // Le tableau vide signifie que cela ne s'exécutera qu'une fois après le premier rendu return ( <> diff --git a/cryptide_project/src/Pages/InGame.tsx b/cryptide_project/src/Pages/InGame.tsx index 4a0d8d2..bab5aab 100644 --- a/cryptide_project/src/Pages/InGame.tsx +++ b/cryptide_project/src/Pages/InGame.tsx @@ -107,6 +107,8 @@ const InGame = ({locale, changeLocale}) => { const [putCorrectBackground, setPutCorrectBackground] = useState<() => void>(() => {}); const [putGreyBackgroud, setPutGreyBackground] = useState<() => void>(() => {}); const [putImposssibleGrey, setPutImposssibleGrey] = useState<() => void>(() => {}); + const [changeGraph, setChangeGraph] = useState<(nbNodes: number) => void>(() => {}); + const setPutCorrectBackgroundData = (func: () => void) => { @@ -121,6 +123,10 @@ const InGame = ({locale, changeLocale}) => { setPutImposssibleGrey(func) } + const setChangeGraphData = (func: (nbNodes: number) => void) => { + setChangeGraph(func) + } + const setImportToJSONData = (imp: boolean) => { setImportToJSON(imp) } @@ -255,7 +261,7 @@ const InGame = ({locale, changeLocale}) => { const handleCloseS = () => setShowS(false); const handleShowS = () => setShowS(true); - const [cptTour, setcptTour] = useState(0); + const [cptTour, setcptTour] = useState(1); const [LastVisible, setLastVisible] = useState(false); @@ -317,6 +323,14 @@ const InGame = ({locale, changeLocale}) => { const [playTurnSound, setPlayTurnSound] = useState(false); const [soundPreference, setSoundPreference] = useState(true); // utilisateur + const [enteredNumber, setEnteredNumber] = useState(25); + + //@ts-ignore + const handleNumberChange = (event) => { + const newNumber = Math.max(20, Math.min(60, parseInt(event.target.value, 10))); + setEnteredNumber(newNumber); + }; + const handleSoundPreferenceChange = () => { setSoundPreference(!soundPreference); console.log("changement des options du son : "+ soundPreference) @@ -365,7 +379,9 @@ const InGame = ({locale, changeLocale}) => { putCorrectBackground={putCorrectBackground} putGreyBackground={putGreyBackgroud} putImposssibleGrey={putImposssibleGrey} - handleTurn={handleTurn}/> + handleTurn={handleTurn} + setChangeGraph={setChangeGraphData} + nbNodes={enteredNumber}/> {playTurnSound &&