|
|
|
@ -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<MyGraphComponentProps> = ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange, playerTouched, setPlayerTouched, changecptTour, solo, isDaily, isEasy, addToHistory, showLast, setNetwork, setNetworkEnigme, setPlayerIndex, askedWrong, setAskedWrong}) => {
|
|
|
|
@ -62,7 +68,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({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<MyGraphComponentProps> = ({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<MyGraphComponentProps> = ({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<MyGraphComponentProps> = ({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<MyGraphComponentProps> = ({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<MyGraphComponentProps> = ({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<MyGraphComponentProps> = ({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<MyGraphComponentProps> = ({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<MyGraphComponentProps> = ({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<MyGraphComponentProps> = ({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<MyGraphComponentProps> = ({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<MyGraphComponentProps> = ({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<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
askedWrongBot=false
|
|
|
|
|
endgame = true
|
|
|
|
|
firstHistory=true
|
|
|
|
|
cptBug=0
|
|
|
|
|
try{
|
|
|
|
|
if(isLoggedIn){
|
|
|
|
|
if(!solo){
|
|
|
|
@ -719,6 +799,8 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({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){
|
|
|
|
|