From faa5408f179d94616fc10e9fa143b7c6f6702920 Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Fri, 8 Dec 2023 15:10:14 +0100 Subject: [PATCH 1/2] new seed pour tuto + nom pour les bots pour l'immersion + autres fix --- cryptide_project/server/socket_io/server.js | 51 ++++++++++++------- .../src/Components/GraphContainer.tsx | 3 +- .../src/Components/PersonStatus.tsx | 2 +- .../src/Components/PlayerList.tsx | 4 +- .../src/Components/TutorialGraph.tsx | 2 +- cryptide_project/src/Pages/EndGame.tsx | 16 +++--- cryptide_project/src/Pages/Lobby.tsx | 36 ++++++++----- cryptide_project/src/Pages/Tutorial.tsx | 2 +- cryptide_project/src/res/botNames.json | 22 ++++++++ 9 files changed, 90 insertions(+), 48 deletions(-) create mode 100644 cryptide_project/src/res/botNames.json diff --git a/cryptide_project/server/socket_io/server.js b/cryptide_project/server/socket_io/server.js index ae793dc..1bf3a75 100644 --- a/cryptide_project/server/socket_io/server.js +++ b/cryptide_project/server/socket_io/server.js @@ -25,12 +25,18 @@ io.on('connection', (socket) => { console.log(socket.id); 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) + try{ + 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) + } + catch{ + console.log("error") + } + }); socket.on("give network", (networkPerson, person, indices, start, room, nodes, playerId) => { @@ -145,17 +151,23 @@ io.on('connection', (socket) => { }) socket.on("who plays", (room) => { - 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 + try{ + 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) } + catch{ + + } + }) socket.on("disconnect", () =>{ @@ -216,9 +228,14 @@ 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) + try{ + map.get(room).actualPlayer=playerIndex + map.get(room).lastWorks=works + io.to(room).emit("node checked", id, works, color, playerIndex, socket.id) + } + catch{ + console.log("error") + } }) socket.on("put correct background", (id) =>{ diff --git a/cryptide_project/src/Components/GraphContainer.tsx b/cryptide_project/src/Components/GraphContainer.tsx index 77e0d1b..e83fe26 100644 --- a/cryptide_project/src/Components/GraphContainer.tsx +++ b/cryptide_project/src/Components/GraphContainer.tsx @@ -477,7 +477,6 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS p.indice=indices[index] p.index=index p.initiateMap(personNetwork) - console.log(p.indice.ToString("fr")) } }) } @@ -488,7 +487,6 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS bot.indice=indices[i] bot.index=index bot.initiateMap(personNetwork) - console.log(bot.indice.ToString("fr")) } } if (i==playerIndex){ @@ -520,6 +518,7 @@ const MyGraphComponent: React.FC = ({onNodeClick, handleS setPlayerIndex(index) setLastIndex(index) if (actualPlayerIndex==index){ + handleTurnBarTextChange("À vous de jouer") handleShowTurnBar(true) } }) diff --git a/cryptide_project/src/Components/PersonStatus.tsx b/cryptide_project/src/Components/PersonStatus.tsx index e4ea131..f313e63 100644 --- a/cryptide_project/src/Components/PersonStatus.tsx +++ b/cryptide_project/src/Components/PersonStatus.tsx @@ -112,7 +112,7 @@ const PersonStatus: React.FC = ({img = Person, state= Person, {/* */}
-
{actualPlayerIndex !== index ? (name.substring(0, name.length - 2).length > 7 ? name.substring(0, name.length - 2).substring(0, 7) + '...' : name.substring(0, name.length - 2)) : 'vous'}
+
{actualPlayerIndex !== index ? (name.length > 18 ? name.substring(0, 15) + '...' : name) : 'vous'}
); diff --git a/cryptide_project/src/Components/PlayerList.tsx b/cryptide_project/src/Components/PlayerList.tsx index 6b44f8f..ed26e9c 100644 --- a/cryptide_project/src/Components/PlayerList.tsx +++ b/cryptide_project/src/Components/PlayerList.tsx @@ -39,9 +39,7 @@ const PlayerList: React.FC = ({ players, playerTouched, setPlay = ({showLast, setNetwork, setP direction: 'LR', // LR (Left to Right) ou autre selon votre préférence sortMethod: 'hubsize' }, - randomSeed: 2 + randomSeed: 3 }, physics: { enabled: true, diff --git a/cryptide_project/src/Pages/EndGame.tsx b/cryptide_project/src/Pages/EndGame.tsx index 2f5c76b..3e72f2c 100644 --- a/cryptide_project/src/Pages/EndGame.tsx +++ b/cryptide_project/src/Pages/EndGame.tsx @@ -146,15 +146,13 @@ function EndGame() { */}
- {losingPlayers.map((player, index) => ( -
- {player.id !== winner?.id && ( -
- {}} index={index} playerIndex={-2} showCircle={false} askedWrong={false}/> - {!indicenull && (
{indices[players.findIndex((p) => p.id == player?.id)].ToString("fr")}
)} -
- )} -
+ {players.map((player, index) => ( + player.id !== winner?.id && ( +
+ {}} index={index} playerIndex={-2} showCircle={false} askedWrong={false}/> + {!indicenull && (
{indices[players.findIndex((p) => p.id == player?.id)].ToString("fr")}
)} +
+ ) ))}
diff --git a/cryptide_project/src/Pages/Lobby.tsx b/cryptide_project/src/Pages/Lobby.tsx index 3070545..df747cd 100644 --- a/cryptide_project/src/Pages/Lobby.tsx +++ b/cryptide_project/src/Pages/Lobby.tsx @@ -66,7 +66,13 @@ function Lobby() { const room = params.get('room'); function addBot(){ - socket.emit("lobby joined", room, new EasyBot("botId" + Math.floor(Math.random() * 1000), "Bot" + Math.floor(Math.random() * 100), "").toJson()) + let json = require("../res/botNames.json") + const tabNames = [...json.names] + let name = tabNames[Math.floor(Math.random() * tabNames.length)] + while (players.find((p) => p.pseudo === name) != undefined){ + name = tabNames[Math.floor(Math.random() * tabNames.length)] + } + socket.emit("lobby joined", room, new EasyBot(name, name, "").toJson()) } //* nb Node @@ -213,23 +219,25 @@ function Lobby() { function StartGame(){ - const [networkPerson, choosenPerson, choosenIndices] = GameCreator.CreateGame(players.length, enteredNumber) - setPersonData(choosenPerson) - setPersonNetworkData(networkPerson) - setIndicesData(choosenIndices) - let users = players.filter((p) => p instanceof User) - let u = users[Math.floor(Math.random() * users.length)] - let start = players.findIndex((p) => p.id == u.id) - if (start == -1){ - start = 0 + if (players.length > 2){ + const [networkPerson, choosenPerson, choosenIndices] = GameCreator.CreateGame(players.length, enteredNumber) + setPersonData(choosenPerson) + setPersonNetworkData(networkPerson) + setIndicesData(choosenIndices) + let users = players.filter((p) => p instanceof User) + let u = users[Math.floor(Math.random() * users.length)] + let start = players.findIndex((p) => p.id == u.id) + if (start == -1){ + start = 0 + } + socket.emit('network created', JSON.stringify(networkPerson, null, 2), JSON.stringify(choosenPerson), JSON.stringify(choosenIndices), room, start); } - socket.emit('network created', JSON.stringify(networkPerson, null, 2), JSON.stringify(choosenPerson), JSON.stringify(choosenIndices), room, start); } const copyGameLink = () => { setShow(!show) - const gameLink = "http://172.20.10.4:3000/lobby?room="+ room; + const gameLink = basePath + "/lobby?room="+ room; navigator.clipboard.writeText(gameLink) .then(() => { console.log('Lien copié avec succès !'); @@ -240,7 +248,7 @@ function Lobby() { }; const textAreaRef = useRef(null); - const linkToCopy = "http://172.20.10.4:3000/lobby?room="+ room + const linkToCopy = basePath + "/lobby?room="+ room const handleCopyClick = () => { setShow(!show) if(textAreaRef.current != null){ @@ -345,7 +353,7 @@ function Lobby() { onChange={handleNumberChange} min={20} max={60}/> - diff --git a/cryptide_project/src/Pages/Tutorial.tsx b/cryptide_project/src/Pages/Tutorial.tsx index a82ab0c..6be1ff2 100644 --- a/cryptide_project/src/Pages/Tutorial.tsx +++ b/cryptide_project/src/Pages/Tutorial.tsx @@ -128,7 +128,7 @@ const Tutorial = ({locale, changeLocale}) => { if (user == null){ return } - setPlayersData([user, new EasyBot("Bot1", "Bot1", ImgBot), new EasyBot("Bot2", "Bot2", ImgBot)]) + setPlayersData([user, new EasyBot("Scooby-Doo", "Scooby-Doo", ImgBot), new EasyBot("Batman", "Batman", ImgBot)]) }, []) diff --git a/cryptide_project/src/res/botNames.json b/cryptide_project/src/res/botNames.json new file mode 100644 index 0000000..e7f7b11 --- /dev/null +++ b/cryptide_project/src/res/botNames.json @@ -0,0 +1,22 @@ +{ + "names": [ + "Sherlock Holmes", + "Inspecteur Gadget", + "Scooby-Doo", + "Marple", + "Spocky", + "Phoenix", + "Batman", + "James Bond", + "Sherlockio", + "Verra", + "Hercule Poirot", + "Colombo", + "MacGyver", + "Lupin", + "D. Conan", + "Pr. Layton", + "Dr. Watson" + ] + } + \ No newline at end of file From 6fe508e0946f74a7abc9938f11c1bd84427c6c85 Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Fri, 8 Dec 2023 16:42:01 +0100 Subject: [PATCH 2/2] pp en ligne --- cryptide_project/src/Components/PlayerList.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cryptide_project/src/Components/PlayerList.tsx b/cryptide_project/src/Components/PlayerList.tsx index ed26e9c..ef2f5dc 100644 --- a/cryptide_project/src/Components/PlayerList.tsx +++ b/cryptide_project/src/Components/PlayerList.tsx @@ -5,6 +5,8 @@ import Player from '../model/Player'; import { useTheme } from '../Style/ThemeContext'; import PersonStatus from './PersonStatus'; import Person from '../res/img/Person.png' +import BotImg from '../res/img/bot.png' + import { socket } from '../SocketConfig'; @@ -36,7 +38,7 @@ const PlayerList: React.FC = ({ players, playerTouched, setPlay //@ts-ignore players.map((player, index) => ( //player.id!=socket.id && -