From e1e7d6ef5c53b66ae0be006b98b2ae6bc2fa3e3f Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Wed, 29 Nov 2023 15:03:45 +0100 Subject: [PATCH] =?UTF-8?q?Utilisateur=20ne=20peut=20plus=20poser=20un=20c?= =?UTF-8?q?arr=C3=A9=20lorsqu'il=20y=20a=20des=20d=C3=A9j=C3=A0=20un=20car?= =?UTF-8?q?r=C3=A9=20et=20s'ils=20ne=20peuvent=20plus=20en=20poser=20passe?= =?UTF-8?q?=20son=20tour?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cryptide_project/server/server.js | 6 +- .../src/Components/GraphContainer.tsx | 94 ++++++++++++++++--- .../src/Components/PlayerList.tsx | 4 +- 3 files changed, 89 insertions(+), 15 deletions(-) diff --git a/cryptide_project/server/server.js b/cryptide_project/server/server.js index a7e6c5b..32253a8 100644 --- a/cryptide_project/server/server.js +++ b/cryptide_project/server/server.js @@ -7,7 +7,7 @@ const app = express(); const server = http.createServer(app); const io = socketIO(server, { cors: { - origin: ["http://172.20.10.4:3000", "http://localhost:3000"], // Remplacez par l'URL de votre application React + origin: ["http://172.20.10.4:3000", "http://172.20.10.4:3000"], // Remplacez par l'URL de votre application React methods: ["GET", "POST"], credentials: true } @@ -114,6 +114,10 @@ io.on('connection', (socket) => { io.to(id).emit("put imossible grey") }) + socket.on("can't put square", (askingPlayer, room) => { + io.to(room).emit("can't put square" , askingPlayer) + }) + socket.on("opacity activated", (id) => { io.to(id).emit("opacity activated") }) diff --git a/cryptide_project/src/Components/GraphContainer.tsx b/cryptide_project/src/Components/GraphContainer.tsx index 786be8a..8732854 100644 --- a/cryptide_project/src/Components/GraphContainer.tsx +++ b/cryptide_project/src/Components/GraphContainer.tsx @@ -14,6 +14,7 @@ import NodePerson from "../model/Graph/NodePerson"; import { useAuth } from "../Contexts/AuthContext"; import Indice from "../model/Indices/Indice"; import Pair from "../model/Pair"; +import { tab } from "@testing-library/user-event/dist/tab"; interface MyGraphComponentProps { onNodeClick: (shouldShowChoiceBar: boolean) => void; @@ -51,6 +52,8 @@ let firstEnigme = true let firstIndex = true let endgame= false let firstHistory = true +let cptSquare = 0 +let cptOnAskedWrong = 0 const MyGraphComponent: React.FC = ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange, playerTouched, setPlayerTouched, changecptTour, solo, isDaily, isEasy, addToHistory, showLast, setNetwork, setPlayerIndex, setNetworkEnigme, askedWrong, setAskedWrong}) => { @@ -402,12 +405,59 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS }) socket.on("asked wrong", () =>{ - askedWrongLocal= true - setAskedWrong(true) - askedWrongBot=true - handleShowTurnBar(true) - handleTurnBarTextChange("Mauvais choix, posez un carré !") - socket.emit("put grey background", socket.id, actualPlayerIndex) + cptSquare++ + if (cptSquare % 2 == 0){ + if (indice==null){ + return + } + const tester = IndiceTesterFactory.Create(indice) + const tabPossible: Person[] = [] + for(const person of personNetwork.getPersons()){ + const node = nodes.get().find((n) => n.id == person.getId()) + if (node != undefined) { + let isSquare = false + players.forEach((p, index) => { + if (node.label.includes(positionToEmoji(index, false))){ + isSquare=true + } + }) + if (!tester.Works(person) && !isSquare){ + tabPossible.push(person) + } + } + } + if (tabPossible.length>0){ + askedWrongLocal= true + setAskedWrong(true) + askedWrongBot=true + handleShowTurnBar(true) + handleTurnBarTextChange("Mauvais choix, posez un carré !") + socket.emit("put grey background", socket.id, actualPlayerIndex) + } + else{ + socket.emit("can't put square", actualPlayerIndex, room) + } + } + }) + + socket.on("can't put square", (askingPlayer) => { + cptOnAskedWrong ++ + if (cptOnAskedWrong % 2 == 0){ + addToHistory(players[askingPlayer].pseudo + " ne peut plus poser de carré") + playerIndex = askingPlayer + 1 + if(playerIndex == players.length){ + playerIndex = 0 + } + setPlayerIndex(playerIndex) + if (playerIndex === actualPlayerIndex){ + handleTurnBarTextChange("À vous de jouer") + handleShowTurnBar(true) + } + else{ + handleShowTurnBar(false) + socket.emit("put correct background", socket.id) + } + } }) @@ -481,14 +531,26 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS const tab = mapIndexPersons.get(player) if (tab != undefined){ if (player != actualPlayerIndex){ + console.log("player != actualPlayerIndex") for(const person of personNetwork.getPersons().filter((p) => tab.includes(p))){ networkData.nodes.update({id: person.getId(), color: "#808080"}) } } else if(indice != null){ + //Pour poser un carré const tester = IndiceTesterFactory.Create(indice) - for(const person of personNetwork.getPersons().filter((p) => tab.includes(p) || tester.Works(p))){ - networkData.nodes.update({id: person.getId(), color: "#808080"}) + for(const person of personNetwork.getPersons()){ + const node = nodes.get().find((n) => n.id == person.getId()) + if (node == undefined) continue + let isSquare = false + players.forEach((p, index) => { + if (node.label.includes(positionToEmoji(index, false))){ + isSquare=true + } + }) + if (tab.includes(person) || tester.Works(person) || isSquare){ + networkData.nodes.update({id: person.getId(), color: "#808080"}) + } } } } @@ -497,6 +559,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS socket.on("put imossible grey", ()=>{ if (personNetwork != null && indice!=null){ + console.log("impossible grey") const tabNodes: any = [] const tester = IndiceTesterFactory.Create(indice) for (const pers of personNetwork.getPersons()){ @@ -592,7 +655,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS } if (a==indices.length){ //networkData.nodes.update({id: p.getId(), label: p.getName() + "\n🔵"}) - //console.log(p) + console.log(p) } }); @@ -616,9 +679,16 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS if (!solo){ if (askedWrongLocal){ const person = personNetwork?.getPersons().find((p) => p.getId() == params.nodes[0]) - if (person !== undefined && indice !== null){ + const node = nodes.get().find((n) => n.id == params.nodes[0]) + if (person !== undefined && indice !== null && node!=undefined){ const tester = IndiceTesterFactory.Create(indice) - if (!tester.Works(person) && !askedPersons.includes(person)){ + let isSquare = false + players.forEach((p, index) => { + if (node.label.includes(positionToEmoji(index, false))){ + isSquare=true + } + }) + if (!tester.Works(person) && !askedPersons.includes(person) && !isSquare){ playerIndex = actualPlayerIndex + 1 if(playerIndex == players.length){ playerIndex = 0 @@ -655,7 +725,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS } } else{ - if (touchedPlayer > 0){ + if (touchedPlayer >= 0){ console.log(touchedPlayer) socket.emit("ask player", params.nodes[0], players[touchedPlayer].id, players.find((p) => p.id === socket.id, actualPlayerIndex)) socket.emit("put correct background", socket.id) diff --git a/cryptide_project/src/Components/PlayerList.tsx b/cryptide_project/src/Components/PlayerList.tsx index 34efe30..6d0da30 100644 --- a/cryptide_project/src/Components/PlayerList.tsx +++ b/cryptide_project/src/Components/PlayerList.tsx @@ -1,6 +1,6 @@ import React from 'react'; -import { colorToEmoji, positionToColor } from '../ColorHelper'; +import { colorToEmoji, positionToColor, positionToEmoji } from '../ColorHelper'; import Player from '../model/Player'; import { useTheme } from '../Style/ThemeContext'; import PersonStatus from './PersonStatus'; @@ -39,7 +39,7 @@ const PlayerList: React.FC = ({ players, playerTouched, setPlay key={index} name={player.pseudo + " " + - colorToEmoji(positionToColor(index), true)} + positionToEmoji(index, true)} playerTouched={playerTouched} setPlayerTouched={setPlayerTouched} index={index}