From 79a6a18f1087bbcbf1faf4aa3d6eb6de4f3f9ad8 Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Thu, 30 Nov 2023 14:00:01 +0100 Subject: [PATCH 1/6] =?UTF-8?q?lobbies=20dynamique=20+=20change=20=C3=A0?= =?UTF-8?q?=20chaque=20mouvement=20dans=20un=20lobby=20+=20variable=20pour?= =?UTF-8?q?=20savoir=20s'ils=20ont=20commenc=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cryptide_project/server/server.js | 24 ++++++++++++------ .../src/Components/LobbyContainer.tsx | 7 +++--- cryptide_project/src/Pages/Lobbies.tsx | 25 ++++++++++++++----- cryptide_project/src/Pages/Lobby.tsx | 2 +- 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/cryptide_project/server/server.js b/cryptide_project/server/server.js index 725ea1a..aaf6865 100644 --- a/cryptide_project/server/server.js +++ b/cryptide_project/server/server.js @@ -25,6 +25,10 @@ io.on('connection', (socket) => { socket.on('network created', (network, person, indices, room, start) =>{ io.to(room).emit("game created", network, person, indices, start) + map.get(room).started = true + const playerArray = Array.from(map.entries()).map(([key, value]) => ({ key, value })) + const playerJson = JSON.stringify(playerArray); + io.emit("request lobbies", playerJson) }); socket.on("lobby joined", (room, player) =>{ @@ -33,10 +37,10 @@ io.on('connection', (socket) => { socket.join(room) } if (map.get(room) == undefined){ - map.set(room, [{type: player.type, id: socket.id, pseudo: player.pseudo, profilePicture: player.profilePicture}]) + map.set(room, {tab: [{type: player.type, id: socket.id, pseudo: player.pseudo, profilePicture: player.profilePicture}], started: false}) } else{ - const tab = map.get(room) + const tab = map.get(room).tab for(let i = 0; i { } if (player.type!=="User"){ - map.get(room).push({type: player.type, id: player.id, pseudo: player.pseudo, profilePicture: player.profilePicture}) + tab.push({type: player.type, id: player.id, pseudo: player.pseudo, profilePicture: player.profilePicture}) } else{ - map.get(room).push({type: player.type, id: socket.id, pseudo: player.pseudo, profilePicture: player.profilePicture}) + tab.push({type: player.type, id: socket.id, pseudo: player.pseudo, profilePicture: player.profilePicture}) } } io.to(room).emit("new player", map.get(room)) const playerArray = Array.from(map.entries()).map(([key, value]) => ({ key, value })) const playerJson = JSON.stringify(playerArray); - io.to(socket.id).emit("request lobbies", playerJson) + io.emit("request lobbies", playerJson) }) socket.on("request lobbies", () => { @@ -65,7 +69,7 @@ io.on('connection', (socket) => { socket.on("bot deleted", (bot, room) =>{ - const tab = map.get(room) + const tab = map.get(room).tab for(let i = 0; i { io.to(room).emit("new player", map.get(room)) const playerArray = Array.from(map.entries()).map(([key, value]) => ({ key, value })) const playerJson = JSON.stringify(playerArray); - io.to(socket.id).emit("request lobbies", playerJson) + io.emit("request lobbies", playerJson) }) @@ -100,7 +104,7 @@ io.on('connection', (socket) => { socket.on("disconnect", () =>{ for (const k of map.keys()){ - const tab = map.get(k) + const tab = map.get(k).tab for (let i = 0; i { } } } + const playerArray = Array.from(map.entries()).map(([key, value]) => ({ key, value })) + const playerJson = JSON.stringify(playerArray); + io.emit("request lobbies", playerJson) }) socket.on("node checked", (id, works, color, room, playerIndex) =>{ @@ -147,5 +154,6 @@ io.on('connection', (socket) => { socket.on("end game", (winnerIndex, room) =>{ io.to(room).emit("end game", winnerIndex) + map.delete(room) }) }); diff --git a/cryptide_project/src/Components/LobbyContainer.tsx b/cryptide_project/src/Components/LobbyContainer.tsx index 8a184f3..4c4fe51 100644 --- a/cryptide_project/src/Components/LobbyContainer.tsx +++ b/cryptide_project/src/Components/LobbyContainer.tsx @@ -13,15 +13,13 @@ interface LobbyContainerProps { roomNum : string HeadPlayer : Player nbPlayer : number + setFirst: (first: boolean) => void //? mettre un "nbplayermax" si le nombre de joueur max peut etre fixé ? } -const LobbyContainer: React.FC = ({roomNum, HeadPlayer, nbPlayer}) => { +const LobbyContainer: React.FC = ({roomNum, HeadPlayer, nbPlayer, setFirst}) => { const theme=useTheme(); - - - const navigate = useNavigate(); const dest = '/lobby?room=' + roomNum; @@ -39,6 +37,7 @@ const LobbyContainer: React.FC = ({roomNum, HeadPlayer, nbP else{ if (nbPlayer < 6) { socket.off("request lobbies") + setFirst(true) navigate(dest); } else { handleShow() diff --git a/cryptide_project/src/Pages/Lobbies.tsx b/cryptide_project/src/Pages/Lobbies.tsx index 0ffd2ad..ed11e0d 100644 --- a/cryptide_project/src/Pages/Lobbies.tsx +++ b/cryptide_project/src/Pages/Lobbies.tsx @@ -16,11 +16,13 @@ class LobbyDataProps { roomNum : string headPlayer: Player nbPlayer: number + started: boolean - constructor(roomNum: string, player: Player, nbPlayer: number){ + constructor(roomNum: string, player: Player, nbPlayer: number, started: boolean){ this.roomNum = roomNum this.headPlayer = player this.nbPlayer = nbPlayer + this.started=started } } @@ -28,7 +30,7 @@ function Lobbies() { const theme=useTheme(); - + const [first, setFirst] = useState(true) const [lobbyData, setLobbyData] = useState([]) @@ -39,20 +41,30 @@ function Lobbies() { lobby.headPlayer.pseudo.toLowerCase().includes(searchTerm.toLowerCase()) ); - useEffect(() => { - socket.emit("request lobbies") + const setFirstData = (first: boolean) => { + setFirst(first) + } + if (first){ + setFirst(false) + socket.emit("request lobbies") + } + + useEffect(() => { socket.on("request lobbies", (map) => { + console.log("wesh") const jsonMap = JSON.parse(map) const tmpTab: LobbyDataProps[]=[] for(const item of jsonMap){ - tmpTab.push(new LobbyDataProps(item.key, JSONParser.JSONToPlayer(item.value[0]), item.value.length)) + tmpTab.push(new LobbyDataProps(item.key, JSONParser.JSONToPlayer(item.value.tab[0]), item.value.tab.length, item.value.started)) } - setLobbyData(tmpTab ) + setLobbyData(tmpTab) }) }) + + return(

Bienvenue dans le lobby des lobbies

@@ -70,6 +82,7 @@ function Lobbies() { roomNum={lobby.roomNum} HeadPlayer={lobby.headPlayer} nbPlayer={lobby.nbPlayer} + setFirst={setFirstData} /> ))}
diff --git a/cryptide_project/src/Pages/Lobby.tsx b/cryptide_project/src/Pages/Lobby.tsx index adefb48..3241675 100644 --- a/cryptide_project/src/Pages/Lobby.tsx +++ b/cryptide_project/src/Pages/Lobby.tsx @@ -137,7 +137,7 @@ function Lobby() { socket.on("new player", (tab) =>{ const tmpTab: Player[] = [] - for (const p of tab){ + for (const p of tab.tab){ tmpTab.push(JSONParser.JSONToPlayer(p)) } console.log(tmpTab) From 4b0ecfac59d3dba3f4e18c6507667ac37651414a Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Thu, 30 Nov 2023 17:04:01 +0100 Subject: [PATCH 2/6] =?UTF-8?q?Bot=20prend=20la=20place=20des=20joueurs=20?= =?UTF-8?q?qui=20quittent=20+=20quand=20bot=20bug=20timer=20de=205=20sc=20?= =?UTF-8?q?et=20demande=20au=20serveur=20=C3=A0=20qui=20c'est=20de=20jouer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cryptide_project/server/server.js | 79 ++++++++++++++-- .../src/Components/GraphContainer.tsx | 94 +++++++++++++++++-- cryptide_project/src/Pages/InGame.tsx | 14 ++- cryptide_project/src/Pages/Lobbies.tsx | 2 +- cryptide_project/src/Pages/Lobby.tsx | 10 +- cryptide_project/src/Pages/Play.tsx | 17 +++- 6 files changed, 195 insertions(+), 21 deletions(-) diff --git a/cryptide_project/server/server.js b/cryptide_project/server/server.js index aaf6865..d5d80ed 100644 --- a/cryptide_project/server/server.js +++ b/cryptide_project/server/server.js @@ -26,6 +26,7 @@ io.on('connection', (socket) => { socket.on('network created', (network, person, indices, room, start) =>{ io.to(room).emit("game created", network, person, indices, start) map.get(room).started = true + map.get(room).actualPlayer=start const playerArray = Array.from(map.entries()).map(([key, value]) => ({ key, value })) const playerJson = JSON.stringify(playerArray); io.emit("request lobbies", playerJson) @@ -37,7 +38,7 @@ io.on('connection', (socket) => { socket.join(room) } if (map.get(room) == undefined){ - map.set(room, {tab: [{type: player.type, id: socket.id, pseudo: player.pseudo, profilePicture: player.profilePicture}], started: false}) + map.set(room, {tab: [{type: player.type, id: socket.id, pseudo: player.pseudo, profilePicture: player.profilePicture}], started: false, actualPlayer: 0}) } else{ const tab = map.get(room).tab @@ -102,14 +103,66 @@ io.on('connection', (socket) => { io.to(askingPlayer.id).emit("asked wrong") }) + socket.on("who plays", (room) => { + let player = map.get(room).actualPlayer + if (map.get(room).tab[player].type != "User"){ + player = player + 1 + if (player == map.get(room).tab.length){ + player=0 + } + } + console.log(player) + io.to(room).emit("who plays", player) + }) + socket.on("disconnect", () =>{ for (const k of map.keys()){ - const tab = map.get(k).tab - for (let i = 0; i p.type=="User").length == 0){ + const tab = map.get(k) + for (let i = 0; i p.type=="User").length == 0){ + map.delete(k) + } + } + } + } + const playerArray = Array.from(map.entries()).map(([key, value]) => ({ key, value })) + const playerJson = JSON.stringify(playerArray); + io.emit("request lobbies", playerJson) + }) + + + socket.on("player quit", () => { + for (const k of map.keys()){ + const tab = map.get(k) + for (let i = 0; i p.type=="User").length == 0){ map.delete(k) } } @@ -121,6 +174,7 @@ io.on('connection', (socket) => { }) socket.on("node checked", (id, works, color, room, playerIndex) =>{ + map.get(room).actualPlayer=playerIndex io.to(room).emit("node checked", id, works, color, playerIndex, socket.id) }) @@ -157,3 +211,14 @@ io.on('connection', (socket) => { map.delete(room) }) }); + + +function comparePlayersByType(a, b) { + if (a.type < b.type) { + return -1; + } else if (a.type > b.type) { + return 1; + } else { + return 0; + } +} diff --git a/cryptide_project/src/Components/GraphContainer.tsx b/cryptide_project/src/Components/GraphContainer.tsx index 17e588e..58362de 100644 --- a/cryptide_project/src/Components/GraphContainer.tsx +++ b/cryptide_project/src/Components/GraphContainer.tsx @@ -14,6 +14,9 @@ import NodePerson from "../model/Graph/NodePerson"; import { useAuth } from "../Contexts/AuthContext"; import Indice from "../model/Indices/Indice"; import Pair from "../model/Pair"; +import Player from "../model/Player"; +import JSONParser from "../JSONParser"; +import User from "../model/User"; interface MyGraphComponentProps { onNodeClick: (shouldShowChoiceBar: boolean) => void; @@ -53,6 +56,9 @@ let endgame= false let firstHistory = true let cptSquare = 0 let cptOnAskedWrong = 0 +let cptPlayerLeft = 0 +let firstPlayer = 0 +let cptBug = 0 const MyGraphComponent: React.FC = ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange, playerTouched, setPlayerTouched, changecptTour, solo, isDaily, isEasy, addToHistory, showLast, setNetwork, setNetworkEnigme, setPlayerIndex, askedWrong, setAskedWrong}) => { @@ -62,7 +68,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS let initMtn = 0 const {isLoggedIn, user, manager} = useAuth(); - const { indices, indice, person, personNetwork, setNodeIdData, players, askedPersons, setActualPlayerIndexData, room, actualPlayerIndex, turnPlayerIndex, setTurnPlayerIndexData, setWinnerData, dailyEnigme, setNbCoupData, settempsData, setNetworkDataData, setSeedData} = useGame(); + const { indices, indice, person, personNetwork, setNodeIdData, players, setPlayersData, askedPersons, setActualPlayerIndexData, room, actualPlayerIndex, turnPlayerIndex, setTurnPlayerIndexData, setWinnerData, dailyEnigme, setNbCoupData, settempsData, setNetworkDataData, setSeedData} = useGame(); const params = new URLSearchParams(window.location.search); const navigate = useNavigate(); @@ -76,6 +82,14 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS setElapsedTime((prevElapsedTime) => prevElapsedTime + 0.5); settempsData(elapsedTime) + cptBug ++ + console.log(cptBug) + if (cptBug > 10){ + cptBug = 0 + socket.emit("who plays", room) + } + + // Vérifiez si la durée est écoulée, puis arrêtez le timer if (endgame) { clearInterval(intervalId); @@ -140,7 +154,8 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS } useEffect(() =>{ - if (actualPlayerIndex==0){ + cptBug=0 + if (actualPlayerIndex==firstPlayer){ const bot = players[lastIndex] if(bot instanceof Bot && botIndex != lastIndex){ botIndex = lastIndex @@ -176,7 +191,6 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS socket.emit("node checked", personIndex, works, playerIndex, room, nextPlayerIndex) const ind = bot.placeSquare(personNetwork, players) if (ind == -1 ){ - addToHistory(lastIndex.toString() + "177") socket.emit("can't put square", lastIndex, room) return } @@ -211,7 +225,6 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS socket.emit("node checked", personIndex, false, choosedPlayerIndex, room, lastIndex) const ind = bot.placeSquare(personNetwork, players) if (ind == -1 ){ - addToHistory(lastIndex.toString() + "212") socket.emit("can't put square", playerIndex, room) return } @@ -231,7 +244,6 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS if (!tester.Works(person)){ const ind = bot.placeSquare(personNetwork, players) if (ind == -1 ){ - addToHistory(lastIndex.toString() + "232") socket.emit("can't put square", playerIndex, room) return } @@ -319,7 +331,6 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS direction: 'LR', // LR (Left to Right) ou autre selon votre préférence sortMethod: 'hubsize' }, - distanceMin: 500, // Set the minimum distance between nodes //randomSeed: 2 }, physics: { @@ -368,6 +379,59 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS } } + socket.on("player left ingame", (tab, i) => { + cptPlayerLeft ++ + if (cptPlayerLeft % 2 == 0){ + const tmpTab: Player[] = [] + for (const p of tab.tab){ + tmpTab.push(JSONParser.JSONToPlayer(p)) + } + if (i==firstPlayer){ + console.log(tmpTab) + for(let index = 0; index < tmpTab.length; index++){ + const test = tmpTab[index] + if (test instanceof User){ + firstPlayer=index + break + } + } + console.log(firstPlayer) + if (actualPlayerIndex==firstPlayer){ + tmpTab.forEach((p, index) =>{ + if (p instanceof Bot && personNetwork!=null){ + p.indice=indices[index] + p.index=index + p.initiateMap(personNetwork) + console.log(p.indice.ToString("fr")) + } + }) + } + } + else{ + const bot = tmpTab[i] + if (bot instanceof Bot && personNetwork != null){ + bot.indice=indices[i] + bot.index=index + bot.initiateMap(personNetwork) + console.log(bot.indice.ToString("fr")) + } + } + if (i==playerIndex){ + playerIndex = lastIndex + 1 + if(playerIndex == players.length){ + playerIndex = 0 + } + setPlayerIndex(playerIndex) + setLastIndex(playerIndex) + if (playerIndex===actualPlayerIndex){ + handleTurnBarTextChange("À vous de jouer") + handleShowTurnBar(true) + } + } + setPlayersData(tmpTab) + } + }) + socket.on("reset graph", () => { console.log("reset graph") initialOptions.physics.enabled = true @@ -375,6 +439,16 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS }) if (!solo){ + + socket.on("who plays", (index) => { + playerIndex=index + setPlayerIndex(index) + setLastIndex(index) + if (actualPlayerIndex==index){ + handleShowTurnBar(true) + } + }) + socket.on("asked all", (id) =>{ //@ts-ignore const pers = personNetwork.getPersons().find((p) => p.getId() == id) @@ -401,12 +475,15 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS }) socket.on("node checked",(id, works, askedIndex, newPlayerIndex, socketId) => { + cptBug=0 //@ts-ignore const node = nodes.get().find((n) => id == n.id) if (node!=undefined){ onNodeClick(false) playerIndex = newPlayerIndex setPlayerIndex(playerIndex) + setLastIndex(newPlayerIndex) + console.log(newPlayerIndex) //@ts-ignore if (mapIndexPersons.get(askedIndex)?.find((p) => p.getId() == id) == undefined){ //@ts-ignore @@ -488,6 +565,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS }) socket.on("can't put square", (askingPlayer) => { + cptBug=0 cptOnAskedWrong ++ if (cptOnAskedWrong % 2 == 0){ addToHistory(players[askingPlayer].pseudo + " ne peut plus poser de carré") @@ -510,6 +588,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS socket.on("asked", (nodeId, askingPlayer) => { + if (askingPlayer.id !== lastAskingPlayer || nodeId !== lastNodeId ){ lastAskingPlayer = askingPlayer.id lastNodeId = nodeId @@ -645,6 +724,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS askedWrongBot=false endgame = true firstHistory=true + cptBug=0 try{ if(isLoggedIn){ if(!solo){ @@ -719,6 +799,8 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS network.on("click", async (params) => { if(params.nodes.length > 0){ + console.log(actualPlayerIndex + " => " + playerIndex) + console.log(playerTouched) setNodeIdData(params.nodes[0]) // addToHistory("Le joueur a cliqué") //! TEST DEBUG if (!solo){ diff --git a/cryptide_project/src/Pages/InGame.tsx b/cryptide_project/src/Pages/InGame.tsx index 422bca8..a578db4 100644 --- a/cryptide_project/src/Pages/InGame.tsx +++ b/cryptide_project/src/Pages/InGame.tsx @@ -28,7 +28,7 @@ import Ceye from "../res/icon/hidden.png"; import JSZip from 'jszip'; /* nav */ -import { Link } from 'react-router-dom'; +import { Link, Navigate, useNavigate, useNavigationType } from 'react-router-dom'; /* Boostrap */ import Button from 'react-bootstrap/Button'; @@ -50,13 +50,25 @@ import {generateLatexCode, generateLatexCodeEnigme} from '../Script/LatexScript' import Pair from '../model/Pair'; import Indice from '../model/Indices/Indice'; +let cptNavigation = 0 + //@ts-ignore const InGame = ({locale, changeLocale}) => { const theme = useTheme(); + const navigate = useNavigate() const params = new URLSearchParams(window.location.search); + + const navigationType = useNavigationType() + cptNavigation++ + if (cptNavigation % 2 == 0){ + if (navigationType.toString() == "POP"){ + socket.emit("player quit") + navigate("/play") + } + } //* Gestion solo let IsSolo: boolean = true diff --git a/cryptide_project/src/Pages/Lobbies.tsx b/cryptide_project/src/Pages/Lobbies.tsx index ed11e0d..58895a6 100644 --- a/cryptide_project/src/Pages/Lobbies.tsx +++ b/cryptide_project/src/Pages/Lobbies.tsx @@ -61,7 +61,7 @@ function Lobbies() { } setLobbyData(tmpTab) }) - }) + }, []) diff --git a/cryptide_project/src/Pages/Lobby.tsx b/cryptide_project/src/Pages/Lobby.tsx index 3241675..75ac642 100644 --- a/cryptide_project/src/Pages/Lobby.tsx +++ b/cryptide_project/src/Pages/Lobby.tsx @@ -130,8 +130,8 @@ function Lobby() { setIndicesData(choosenIndices) first = true gameStarted = true - socket.off("player left") - socket.off("new player") + //socket.off("player left") + //socket.off("new player") navigate('/game?solo=false&daily=false'); }); @@ -146,9 +146,10 @@ function Lobby() { socket.on("player left", (tab, i) => { const tmpTab: Player[] = [] - for (const p of tab){ + for (const p of tab.tab){ tmpTab.push(JSONParser.JSONToPlayer(p)) } + console.log(tmpTab) setPlayersData(tmpTab) }) @@ -214,7 +215,7 @@ function Lobby() { // ))} -
+ {(players.length < 6) &&
+ }
diff --git a/cryptide_project/src/Pages/Play.tsx b/cryptide_project/src/Pages/Play.tsx index 5c28831..a0fc893 100644 --- a/cryptide_project/src/Pages/Play.tsx +++ b/cryptide_project/src/Pages/Play.tsx @@ -2,7 +2,6 @@ import React, { useEffect, useRef, useState } from 'react'; /* Context */ import { useAuth } from '../Contexts/AuthContext'; - /* Style */ import './Play.css'; import { useTheme } from '../Style/ThemeContext'; @@ -13,7 +12,7 @@ import ButtonImgNav from "../Components/ButtonImgNav"; /* Img */ /* Icon */ import { socket } from '../SocketConfig'; -import { useNavigate } from 'react-router-dom'; +import { NavigationType, useNavigate, useNavigationType } from 'react-router-dom'; import GameCreator from '../model/GameCreator'; import { useGame } from '../Contexts/GameContext'; import ScoreBoard from '../Components/ScoreBoard'; @@ -32,6 +31,9 @@ import Button from 'react-bootstrap/Button'; import ButtonGroup from 'react-bootstrap/ButtonGroup'; +let cptNavigation = 0 + + function Play() { let first = true @@ -41,6 +43,16 @@ function Play() { const target = useRef(null); + const navigationType = useNavigationType() + cptNavigation++ + if (cptNavigation % 2 == 0){ + if (navigationType.toString() == "POP"){ + socket.emit("player quit") + } + } + + + useEffect(() => { const fetchUserInformation = async () => { try { @@ -108,6 +120,7 @@ function Play() { } }, [isLoggedIn]); + const [room, setRoom] = useState(null); const navigate = useNavigate(); From 4e5a743862dd950b2c272c655a550b06df2e71fc Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Fri, 1 Dec 2023 12:45:47 +0100 Subject: [PATCH 3/6] =?UTF-8?q?On=20peut=20quitter=20et=20=C3=AAtre=20remp?= =?UTF-8?q?lac=C3=A9=20par=20un=20bot=20+=20si=20on=20est=20connect=C3=A9?= =?UTF-8?q?=20et=20qu'on=20revient=20et=20bah=20pouf=20on=20est=20de=20nou?= =?UTF-8?q?veau=20dedans?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cryptide_project/server/server.js | 76 ++++++++++++------ .../src/Components/GraphContainer.tsx | 51 ++++++++---- cryptide_project/src/Contexts/GameContext.tsx | 12 ++- cryptide_project/src/JSONParser.ts | 11 +++ cryptide_project/src/Pages/Lobby.tsx | 55 ++++++++++++- cryptide_project/src/server/db/socialgraph.db | Bin 28672 -> 28672 bytes 6 files changed, 163 insertions(+), 42 deletions(-) diff --git a/cryptide_project/server/server.js b/cryptide_project/server/server.js index d5d80ed..05bdb0e 100644 --- a/cryptide_project/server/server.js +++ b/cryptide_project/server/server.js @@ -14,6 +14,7 @@ const io = socketIO(server, { }); +let lastSocketJoined = "" const map = new Map() server.listen(3002, () => { @@ -32,34 +33,63 @@ io.on('connection', (socket) => { io.emit("request lobbies", playerJson) }); + socket.on("give network", (networkPerson, person, indices, start, room, nodes, playerId) => { + io.to(playerId).emit("join during game", networkPerson, person, indices, start, map.get(room).tab, nodes) + }) + socket.on("lobby joined", (room, player) =>{ - console.log(player) - if (player.type=="User"){ - socket.join(room) - } - if (map.get(room) == undefined){ - map.set(room, {tab: [{type: player.type, id: socket.id, pseudo: player.pseudo, profilePicture: player.profilePicture}], started: false, actualPlayer: 0}) - } - else{ - const tab = map.get(room).tab - for(let i = 0; i ({ key, value })) + const playerJson = JSON.stringify(playerArray); + io.emit("request lobbies", playerJson) } - io.to(room).emit("new player", map.get(room)) - const playerArray = Array.from(map.entries()).map(([key, value]) => ({ key, value })) - const playerJson = JSON.stringify(playerArray); - io.emit("request lobbies", playerJson) }) socket.on("request lobbies", () => { @@ -112,7 +142,7 @@ io.on('connection', (socket) => { } } console.log(player) - io.to(room).emit("who plays", player) + io.to(room).emit("who plays", player, map.get(room).lastWorks) }) socket.on("disconnect", () =>{ @@ -129,7 +159,6 @@ io.on('connection', (socket) => { } else{ tab.tab[i].type="EasyBot" - tab.tab[i].pseudo="TmpBot" io.to(k).emit("player left ingame", tab, i) } if (tab.tab.filter((p) => p.type=="User").length == 0){ @@ -145,6 +174,7 @@ io.on('connection', (socket) => { socket.on("player quit", () => { + lastSocketJoined="" for (const k of map.keys()){ const tab = map.get(k) for (let i = 0; i { } else{ tab.tab[i].type="EasyBot" - tab.tab[i].pseudo="TmpBot" io.to(k).emit("player left ingame", tab, i) } if (tab.tab.filter((p) => p.type=="User").length == 0){ @@ -175,6 +204,7 @@ io.on('connection', (socket) => { socket.on("node checked", (id, works, color, room, playerIndex) =>{ map.get(room).actualPlayer=playerIndex + map.get(room).lastWorks=works io.to(room).emit("node checked", id, works, color, playerIndex, socket.id) }) diff --git a/cryptide_project/src/Components/GraphContainer.tsx b/cryptide_project/src/Components/GraphContainer.tsx index 58362de..8091f35 100644 --- a/cryptide_project/src/Components/GraphContainer.tsx +++ b/cryptide_project/src/Components/GraphContainer.tsx @@ -17,6 +17,7 @@ import Pair from "../model/Pair"; import Player from "../model/Player"; import JSONParser from "../JSONParser"; import User from "../model/User"; +import { json } from "body-parser"; interface MyGraphComponentProps { onNodeClick: (shouldShowChoiceBar: boolean) => void; @@ -59,6 +60,7 @@ let cptOnAskedWrong = 0 let cptPlayerLeft = 0 let firstPlayer = 0 let cptBug = 0 +let cptUseEffect = 0 const MyGraphComponent: React.FC = ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange, playerTouched, setPlayerTouched, changecptTour, solo, isDaily, isEasy, addToHistory, showLast, setNetwork, setNetworkEnigme, setPlayerIndex, askedWrong, setAskedWrong}) => { @@ -68,7 +70,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS 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} = useGame(); + const { indices, indice, person, personNetwork, setNodeIdData, players, setPlayersData, askedPersons, setActualPlayerIndexData, room, actualPlayerIndex, turnPlayerIndex, setTurnPlayerIndexData, setWinnerData, dailyEnigme, setNbCoupData, settempsData, setNetworkDataData, setSeedData, nodesC} = useGame(); const params = new URLSearchParams(window.location.search); const navigate = useNavigate(); @@ -83,7 +85,6 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS settempsData(elapsedTime) cptBug ++ - console.log(cptBug) if (cptBug > 10){ cptBug = 0 socket.emit("who plays", room) @@ -287,19 +288,6 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS } } - //* fonction qui reinitialise le graphe - const resGraph = () => { //? comment accéder au nework ?? - const savedGraphStateString = localStorage.getItem('graphState'); - if (savedGraphStateString !== null) { - const savedGraphState = JSON.parse(savedGraphStateString); - //network.setData(savedGraphState); - } else { - // La clé 'graphState' n'existe pas dans le localStorage, prenez une action en conséquence. - console.log("ayoooooo"); - } - - }; - useEffect(() => { if (personNetwork == null){ return @@ -319,7 +307,10 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS return; } // Charger les données dans le graph - const nodes = new DataSet(graph.nodesPerson); + let nodes = new DataSet(graph.nodesPerson); + if (nodesC.length != 0){ + nodes = new DataSet(nodesC) + } // Configuration des options du Graphe const initialOptions = { @@ -379,12 +370,38 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS } } + socket.on("give network", (playerId) => { + socket.emit("give network", JSON.stringify(personNetwork, null, 2), JSON.stringify(person), JSON.stringify(indices), playerIndex, room, JSON.stringify(nodes.get()), playerId); + }) + + socket.on("player joined ingame", (tab) => { + const tmpTab: Player[] = [] + let ind =0 + for (const p of tab){ + if (p.type === "User"){ + tmpTab.push(JSONParser.JSONToPlayer(p)) + } + else{ + tmpTab.push(players[ind]) + } + ind ++ + } + setPlayersData(tmpTab) + }) + socket.on("player left ingame", (tab, i) => { cptPlayerLeft ++ if (cptPlayerLeft % 2 == 0){ const tmpTab: Player[] = [] + let ind =0 for (const p of tab.tab){ + if (ind === i || p.type === "User"){ tmpTab.push(JSONParser.JSONToPlayer(p)) + } + else{ + tmpTab.push(players[ind]) + } + ind ++ } if (i==firstPlayer){ console.log(tmpTab) @@ -395,7 +412,6 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS break } } - console.log(firstPlayer) if (actualPlayerIndex==firstPlayer){ tmpTab.forEach((p, index) =>{ if (p instanceof Bot && personNetwork!=null){ @@ -762,6 +778,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS socket.off("put correct background") socket.off("put grey background") socket.off("put imossible grey") + socket.off("who plays") navigate("/endgame") } diff --git a/cryptide_project/src/Contexts/GameContext.tsx b/cryptide_project/src/Contexts/GameContext.tsx index 3dba918..9910e73 100644 --- a/cryptide_project/src/Contexts/GameContext.tsx +++ b/cryptide_project/src/Contexts/GameContext.tsx @@ -1,4 +1,6 @@ import React, { createContext, useContext, useState, ReactNode } from 'react'; +import { DataSet, Edge } from 'vis-network'; +import NodePerson from '../model/Graph/NodePerson'; import Indice from '../model/Indices/Indice'; import Pair from '../model/Pair'; import Person from '../model/Person'; @@ -23,6 +25,7 @@ interface GameContextProps { temps : number networkData: any seed: number | string; + nodesC: NodePerson[] setIndicesData: (newIndices: Indice[]) => void; setIndiceData: (newIndice: Indice) => void; setPersonData: (newPerson: Person) => void; @@ -41,6 +44,7 @@ interface GameContextProps { settempsData: (newtemps : number) => void setNetworkDataData: (networkData: any) => void setSeedData: (seed: number | string) => void + setNodesData: (nodes: NodePerson[]) => void } const GameContext = createContext(undefined); @@ -67,6 +71,12 @@ export const GameProvider: React.FC = ({ children }) => { const [temps, settemps] = useState(0); const [networkData, setNetworkData] = useState(null); const [seed, setSeed] = useState(0); + const [nodesC, setNodes] = useState([]); + + + const setNodesData = (nodes: NodePerson[]) => { + setNodes(nodes) + } const setNetworkDataData = (networkData: any) => { setNetworkData(networkData); @@ -155,7 +165,7 @@ export const GameProvider: React.FC = ({ children }) => { } return ( - + {children} ); diff --git a/cryptide_project/src/JSONParser.ts b/cryptide_project/src/JSONParser.ts index d07560b..9f9e3f0 100644 --- a/cryptide_project/src/JSONParser.ts +++ b/cryptide_project/src/JSONParser.ts @@ -11,6 +11,8 @@ import Person from "./model/Person"; import PersonNetwork from "./model/PersonsNetwork"; import Player from "./model/Player"; import User from "./model/User"; +import NodePerson from "./model/Graph/NodePerson"; +import Font from "./model/Graph/Font"; class JSONParser{ @@ -93,6 +95,15 @@ class JSONParser{ throw new Error("PARSER unable to parse player: " + json.type); } } + + + static JSONToNodePersons(json: any): NodePerson[]{ + const tmpTab: NodePerson[] = [] + json.forEach((element: any) => { + tmpTab.push(new NodePerson(element.id, element.label, element.color, new Font(element.font.color, element.font.size, element.font.align), element.shape)) + }); + return tmpTab + } } export default JSONParser \ No newline at end of file diff --git a/cryptide_project/src/Pages/Lobby.tsx b/cryptide_project/src/Pages/Lobby.tsx index 75ac642..7083ec5 100644 --- a/cryptide_project/src/Pages/Lobby.tsx +++ b/cryptide_project/src/Pages/Lobby.tsx @@ -45,15 +45,17 @@ import SessionService from '../services/SessionService'; import { useRef } from 'react'; import Button from 'react-bootstrap/Button'; import Overlay from 'react-bootstrap/Overlay'; +import { DataSet } from 'vis-network'; let gameStarted = false +let firstLaunch = true function Lobby() { const theme=useTheme(); const navigate = useNavigate(); - const { indices, setIndicesData, indice, setIndiceData, person, setPersonData, personNetwork, setPersonNetworkData, players, setPlayersData, setActualPlayerIndexData, setTurnPlayerIndexData, setRoomData } = useGame(); + const { indices, setIndicesData, indice, setIndiceData, person, setPersonData, personNetwork, setPersonNetworkData, players, setPlayersData, setActualPlayerIndexData, setTurnPlayerIndexData, setRoomData, setNodesData } = useGame(); const {user, setUserData, manager, login} = useAuth() let first = true @@ -135,6 +137,42 @@ function Lobby() { navigate('/game?solo=false&daily=false'); }); + + socket.on("join during game", (jsonNetwork, jsonPersonString, jsonIndicesString, playerIndex, players, nodes)=> { + const jsonPerson = JSON.parse(jsonPersonString) + const networkPerson: PersonNetwork = JSONParser.JSONToNetwork(jsonNetwork) + const choosenOne: Person = networkPerson.getPersons().filter((i) => i.getId() == jsonPerson.id)[0] + const choosenIndices : Indice[] = JSONParser.JSONToIndices(jsonIndicesString) + for (let i=0; i{ const tmpTab: Player[] = [] for (const p of tab.tab){ @@ -144,6 +182,21 @@ function Lobby() { setPlayersData(tmpTab) }) + socket.on("room full", () => { + //TODO POP UP pour quand la room est pleine + navigate("/play") + }) + + socket.on("game started", () => { + //TODO POP UP pour quand la room est pleine + navigate("/play") + }) + + socket.on("game already started", () => { + //TODO POP UP pour quand la room est pleine + navigate("/play") + }) + socket.on("player left", (tab, i) => { const tmpTab: Player[] = [] for (const p of tab.tab){ diff --git a/cryptide_project/src/server/db/socialgraph.db b/cryptide_project/src/server/db/socialgraph.db index dee9ca357d4cf06633bf36dda55e43b4331a35e4..4205e72d8b162b8e02877ac7b39e8c4079e50cb9 100644 GIT binary patch delta 43 ucmZp8z}WDBae_2s)?~{y92^{s9PG>x20H)&KL^_Y delta 23 fcmZp8z}WDBae_2s#zYxs#*B>#o%xer#)|_0Z9)kv From 36b48ff6bf1534d50c7d227381a192d5da75d074 Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Fri, 1 Dec 2023 14:28:49 +0100 Subject: [PATCH 4/6] =?UTF-8?q?Bouton=20permettant=20=C3=A0=20l'utilisateu?= =?UTF-8?q?r=20qui=20a=20quitt=C3=A9=20une=20partie=20de=20revenir=20dedan?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cryptide_project/server/server.js | 97 ++++++++++-------- cryptide_project/src/Pages/Lobbies.tsx | 11 ++ cryptide_project/src/Pages/Play.tsx | 15 ++- cryptide_project/src/server/db/socialgraph.db | Bin 28672 -> 28672 bytes 4 files changed, 79 insertions(+), 44 deletions(-) diff --git a/cryptide_project/server/server.js b/cryptide_project/server/server.js index 05bdb0e..55d91e9 100644 --- a/cryptide_project/server/server.js +++ b/cryptide_project/server/server.js @@ -37,59 +37,70 @@ io.on('connection', (socket) => { io.to(playerId).emit("join during game", networkPerson, person, indices, start, map.get(room).tab, nodes) }) - socket.on("lobby joined", (room, player) =>{ - if (lastSocketJoined != player.id){ - lastSocketJoined=player.id - const game = map.get(room) - if (game !== undefined){ - if (game.tab.length == 6 && !game.started){ - io.to(socket.id).emit("room full") - return - } - if (game.started){ - for(const u of game.tab){ - if(u.type !== "User" && u.pseudo===player.pseudo){ - u.type = "User" - u.id=socket.id - io.to(game.tab[game.actualPlayer].id).emit("give network", socket.id) - io.to(room).emit("player joined ingame", game.tab) - socket.join(room) - return + socket.on("join back game", (player) => { + for (const k of map.keys()){ + const tab = map.get(k) + for (let i = 0; i{ + + const game = map.get(room) + if (game !== undefined){ + if (game.tab.length == 6 && !game.started){ + io.to(socket.id).emit("room full") + return } - - - if (game == undefined){ - map.set(room, {tab: [{type: player.type, id: socket.id, pseudo: player.pseudo, profilePicture: player.profilePicture}], started: false, actualPlayer: 0, lastWorks: false}) - socket.join(room) - } - else{ - const tab = game.tab - for(let i = 0; i ({ key, value })) - const playerJson = JSON.stringify(playerArray); - io.emit("request lobbies", playerJson) + + if (player.type!=="User"){ + tab.push({type: player.type, id: player.id, pseudo: player.pseudo, profilePicture: player.profilePicture}) + } + else{ + tab.push({type: player.type, id: socket.id, pseudo: player.pseudo, profilePicture: player.profilePicture}) + socket.join(room) + } } + io.to(room).emit("new player", map.get(room)) + const playerArray = Array.from(map.entries()).map(([key, value]) => ({ key, value })) + const playerJson = JSON.stringify(playerArray); + io.emit("request lobbies", playerJson) + }) socket.on("request lobbies", () => { diff --git a/cryptide_project/src/Pages/Lobbies.tsx b/cryptide_project/src/Pages/Lobbies.tsx index 58895a6..1635e34 100644 --- a/cryptide_project/src/Pages/Lobbies.tsx +++ b/cryptide_project/src/Pages/Lobbies.tsx @@ -10,6 +10,7 @@ import User from '../model/User'; import { socket } from '../SocketConfig'; import JSONParser from '../JSONParser'; import Person from '../model/Person'; +import { useNavigationType } from 'react-router-dom'; class LobbyDataProps { @@ -26,6 +27,8 @@ class LobbyDataProps { } } +let cptNavigation = 0 + function Lobbies() { const theme=useTheme(); @@ -46,6 +49,14 @@ function Lobbies() { setFirst(first) } + const navigationType = useNavigationType() + cptNavigation++ + if (cptNavigation % 2 == 0){ + if (navigationType.toString() == "POP"){ + socket.emit("player quit") + } + } + if (first){ setFirst(false) socket.emit("request lobbies") diff --git a/cryptide_project/src/Pages/Play.tsx b/cryptide_project/src/Pages/Play.tsx index a0fc893..d5df326 100644 --- a/cryptide_project/src/Pages/Play.tsx +++ b/cryptide_project/src/Pages/Play.tsx @@ -108,6 +108,7 @@ function Play() { if (loggedIn){ login() setUserData(user) + socket.emit("join back game", user) } else{ loadImageAsync(defaultImg).then((blob) => { @@ -120,6 +121,14 @@ function Play() { } }, [isLoggedIn]); + const [goBackRoom, setGoBackRoom] = useState(-1) + + useEffect(() => { + socket.on("join back game", (room) => { + setGoBackRoom(room) + }) + }, []) + const [room, setRoom] = useState(null); const navigate = useNavigate(); @@ -169,6 +178,10 @@ function Play() { } }, [room, navigate]); + const goBack = () => { + navigate("/lobby?room=" + goBackRoom) + } + const [showOverlay, setShowOverlay] = useState(false); @@ -259,7 +272,7 @@ function Play() { - + {goBackRoom != -1 && }
diff --git a/cryptide_project/src/server/db/socialgraph.db b/cryptide_project/src/server/db/socialgraph.db index 4205e72d8b162b8e02877ac7b39e8c4079e50cb9..31dfec45cc4a867532bdcd445b8defef9b9069c5 100644 GIT binary patch delta 89 zcmZp8z}WDBae_2s&O{k!#+;1_3*&kDpEB_BS2FN_=YPjvxtT8^n_ozPm5qUslbw;t i{s99Ra8B;dkCFy5Ie`Eu!@|bE!NI}E!Ojd}umb=g8xa5i delta 73 zcmZp8z}WDBae_2s)C(QPS+J ZYz&;7oQ$08ENl!M92|@s?931bI{+e-5Lo~K From 9c9402c3bbc4b1ab0fc91a0bca4302e82d6936e5 Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Fri, 1 Dec 2023 14:57:08 +0100 Subject: [PATCH 5/6] =?UTF-8?q?les=20bots=20peuvent=20jouer=20apr=C3=A8s?= =?UTF-8?q?=20que=20quelqu'un=20ait=20quitt=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cryptide_project/server/server.js | 16 ++++--- .../src/Components/GraphContainer.tsx | 46 +++++++++++-------- .../src/Components/PersonStatus.tsx | 1 + 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/cryptide_project/server/server.js b/cryptide_project/server/server.js index 55d91e9..6d3511d 100644 --- a/cryptide_project/server/server.js +++ b/cryptide_project/server/server.js @@ -145,15 +145,17 @@ io.on('connection', (socket) => { }) socket.on("who plays", (room) => { - let player = map.get(room).actualPlayer - if (map.get(room).tab[player].type != "User"){ - player = player + 1 - if (player == map.get(room).tab.length){ - player=0 + if (map.get(room) !== undefined){ + let player = map.get(room).actualPlayer + if (map.get(room).tab[player].type != "User"){ + player = player + 1 + if (player == map.get(room).tab.length){ + player=0 + } } + console.log(player) + io.to(room).emit("who plays", player, map.get(room).lastWorks) } - console.log(player) - io.to(room).emit("who plays", player, map.get(room).lastWorks) }) socket.on("disconnect", () =>{ diff --git a/cryptide_project/src/Components/GraphContainer.tsx b/cryptide_project/src/Components/GraphContainer.tsx index 8091f35..af55ca0 100644 --- a/cryptide_project/src/Components/GraphContainer.tsx +++ b/cryptide_project/src/Components/GraphContainer.tsx @@ -61,6 +61,7 @@ let cptPlayerLeft = 0 let firstPlayer = 0 let cptBug = 0 let cptUseEffect = 0 +let testPlayers: Player[] = [] const MyGraphComponent: React.FC = ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange, playerTouched, setPlayerTouched, changecptTour, solo, isDaily, isEasy, addToHistory, showLast, setNetwork, setNetworkEnigme, setPlayerIndex, askedWrong, setAskedWrong}) => { @@ -102,8 +103,14 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS }, [elapsedTime, endgame]); + useEffect(() => { + testPlayers = players + console.log(testPlayers) + }, [players]) + useEffect(() =>{ touchedPlayer=playerTouched + console.log(playerTouched) if (touchedPlayer == -1){ if (!askedWrongLocal){ socket.emit("put correct background", socket.id) @@ -157,7 +164,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS useEffect(() =>{ cptBug=0 if (actualPlayerIndex==firstPlayer){ - const bot = players[lastIndex] + const bot = testPlayers[lastIndex] if(bot instanceof Bot && botIndex != lastIndex){ botIndex = lastIndex if (personNetwork!=null){ @@ -181,7 +188,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS } const tester = IndiceTesterFactory.Create(indices[playerIndex]) const works = tester.Works(person) - socket.emit("asked all 1by1", person.getId(), players[playerIndex].id) + socket.emit("asked all 1by1", person.getId(), testPlayers[playerIndex].id) if (i==players.length){ socket.emit("node checked", personIndex, works, playerIndex, room, nextPlayerIndex) } @@ -190,7 +197,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS } if(!works){ socket.emit("node checked", personIndex, works, playerIndex, room, nextPlayerIndex) - const ind = bot.placeSquare(personNetwork, players) + const ind = bot.placeSquare(personNetwork, testPlayers) if (ind == -1 ){ socket.emit("can't put square", lastIndex, room) return @@ -209,7 +216,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS } else{ if (person!=undefined){ - if (players[choosedPlayerIndex] instanceof Bot){ + if (testPlayers[choosedPlayerIndex] instanceof Bot){ console.log("BOT") const tester = IndiceTesterFactory.Create(indices[choosedPlayerIndex]) const works = tester.Works(person) @@ -224,7 +231,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS else{ console.log(lastIndex + " interroge " + choosedPlayerIndex + " a propos de " + person.getName() + " et dit non") socket.emit("node checked", personIndex, false, choosedPlayerIndex, room, lastIndex) - const ind = bot.placeSquare(personNetwork, players) + const ind = bot.placeSquare(personNetwork, testPlayers) if (ind == -1 ){ socket.emit("can't put square", playerIndex, room) return @@ -239,11 +246,11 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS } else{ console.log(choosedPlayerIndex + " => Pas bot" ) - socket.emit("ask player", personIndex, players[choosedPlayerIndex].id, players[lastIndex]) + socket.emit("ask player", personIndex, testPlayers[choosedPlayerIndex].id, testPlayers[lastIndex]) console.log(lastIndex + " interroge " + +choosedPlayerIndex + " sur " + personNetwork.getPersons()[personIndex].getName()) const tester = IndiceTesterFactory.Create(indices[choosedPlayerIndex]) if (!tester.Works(person)){ - const ind = bot.placeSquare(personNetwork, players) + const ind = bot.placeSquare(personNetwork, testPlayers) if (ind == -1 ){ socket.emit("can't put square", playerIndex, room) return @@ -382,7 +389,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS tmpTab.push(JSONParser.JSONToPlayer(p)) } else{ - tmpTab.push(players[ind]) + tmpTab.push(testPlayers[ind]) } ind ++ } @@ -399,12 +406,11 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS tmpTab.push(JSONParser.JSONToPlayer(p)) } else{ - tmpTab.push(players[ind]) + tmpTab.push(testPlayers[ind]) } ind ++ } if (i==firstPlayer){ - console.log(tmpTab) for(let index = 0; index < tmpTab.length; index++){ const test = tmpTab[index] if (test instanceof User){ @@ -508,7 +514,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS if (p!=undefined && tab != undefined){ tab.push(p) if (actualPlayerIndex == 0){ - players.forEach((player) => { + testPlayers.forEach((player) => { if (player instanceof Bot){ player.newInformation(p, askedIndex, works) } @@ -522,7 +528,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS cptHistory++ if (cptHistory % 2 == 0){ lastNodes.push(node) - addToHistory(players[askedIndex].pseudo + " à mis un " + positionToEmoji(askedIndex, works) + " à " + personNetwork.getPersons()[id].getName()) + addToHistory(testPlayers[askedIndex].pseudo + " à mis un " + positionToEmoji(askedIndex, works) + " à " + personNetwork.getPersons()[id].getName()) } } @@ -584,7 +590,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS cptBug=0 cptOnAskedWrong ++ if (cptOnAskedWrong % 2 == 0){ - addToHistory(players[askingPlayer].pseudo + " ne peut plus poser de carré") + addToHistory(testPlayers[askingPlayer].pseudo + " ne peut plus poser de carré") playerIndex = askingPlayer + 1 if(playerIndex == players.length){ playerIndex = 0 @@ -629,8 +635,8 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS socket.emit("node checked", nodeId, true, actualPlayerIndex, room, playerIndex) } else{ - let index = players.findIndex((p) => p.id == askingPlayer.id) - if (players[index] instanceof Bot){ + let index = testPlayers.findIndex((p) => p.id == askingPlayer.id) + if (testPlayers[index] instanceof Bot){ index = playerIndex + 1 if(index == players.length){ index = 0 @@ -816,9 +822,9 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS network.on("click", async (params) => { if(params.nodes.length > 0){ - console.log(actualPlayerIndex + " => " + playerIndex) - console.log(playerTouched) + console.log(touchedPlayer) setNodeIdData(params.nodes[0]) + console.log(players) // addToHistory("Le joueur a cliqué") //! TEST DEBUG if (!solo){ if (askedWrongLocal){ @@ -848,7 +854,9 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS } else if(touchedPlayer != -1 && playerIndex == actualPlayerIndex && touchedPlayer = ({onNodeClick, handleS } else{ if (touchedPlayer >= 0){ - console.log(touchedPlayer) + console.log("CE N'EST PAS UN BOT") //@ts-ignore 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/PersonStatus.tsx b/cryptide_project/src/Components/PersonStatus.tsx index 7ec2942..4bf7415 100644 --- a/cryptide_project/src/Components/PersonStatus.tsx +++ b/cryptide_project/src/Components/PersonStatus.tsx @@ -51,6 +51,7 @@ const PersonStatus: React.FC = ({img = Person, state= Person, function onTouch(){ if (IsActualPlayer && !askedWrong){ setPlayerTouched(index) + setTouchedPlayer(index) } } From 2cbdc018698dd094712dc3b0108641296f6e656d Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Fri, 1 Dec 2023 15:06:09 +0100 Subject: [PATCH 6/6] retourner jouer sans avoir besoin de recharger la page --- cryptide_project/src/Pages/Play.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cryptide_project/src/Pages/Play.tsx b/cryptide_project/src/Pages/Play.tsx index d5df326..83106db 100644 --- a/cryptide_project/src/Pages/Play.tsx +++ b/cryptide_project/src/Pages/Play.tsx @@ -119,6 +119,9 @@ function Play() { } }) } + else{ + socket.emit("join back game", user) + } }, [isLoggedIn]); const [goBackRoom, setGoBackRoom] = useState(-1)