diff --git a/cryptide_project/server/server.js b/cryptide_project/server/server.js index a7e6c5b..ce93336 100644 --- a/cryptide_project/server/server.js +++ b/cryptide_project/server/server.js @@ -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 22e33ea..18bd2d7 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"; + interface MyGraphComponentProps { onNodeClick: (shouldShowChoiceBar: boolean) => void; handleShowTurnBar: (shouldShowTurnBar: boolean) => void @@ -50,6 +51,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, setNetworkEnigme, setPlayerIndex, askedWrong, setAskedWrong}) => { @@ -434,12 +437,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) + } + } }) @@ -516,14 +566,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"}) + } } } } @@ -532,6 +594,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()){ @@ -653,9 +716,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 @@ -693,7 +763,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS } } else{ - if (touchedPlayer > 0){ + if (touchedPlayer >= 0){ console.log(touchedPlayer) //@ts-ignore socket.emit("ask player", params.nodes[0], players[touchedPlayer].id, players.find((p) => p.id === socket.id, actualPlayerIndex)) 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}