|
|
@ -14,6 +14,7 @@ import NodePerson from "../model/Graph/NodePerson";
|
|
|
|
import { useAuth } from "../Contexts/AuthContext";
|
|
|
|
import { useAuth } from "../Contexts/AuthContext";
|
|
|
|
import Indice from "../model/Indices/Indice";
|
|
|
|
import Indice from "../model/Indices/Indice";
|
|
|
|
import Pair from "../model/Pair";
|
|
|
|
import Pair from "../model/Pair";
|
|
|
|
|
|
|
|
|
|
|
|
interface MyGraphComponentProps {
|
|
|
|
interface MyGraphComponentProps {
|
|
|
|
onNodeClick: (shouldShowChoiceBar: boolean) => void;
|
|
|
|
onNodeClick: (shouldShowChoiceBar: boolean) => void;
|
|
|
|
handleShowTurnBar: (shouldShowTurnBar: boolean) => void
|
|
|
|
handleShowTurnBar: (shouldShowTurnBar: boolean) => void
|
|
|
@ -50,6 +51,8 @@ let firstEnigme = true
|
|
|
|
let firstIndex = true
|
|
|
|
let firstIndex = true
|
|
|
|
let endgame= false
|
|
|
|
let endgame= false
|
|
|
|
let firstHistory = true
|
|
|
|
let firstHistory = true
|
|
|
|
|
|
|
|
let cptSquare = 0
|
|
|
|
|
|
|
|
let cptOnAskedWrong = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange, playerTouched, setPlayerTouched, changecptTour, solo, isDaily, isEasy, addToHistory, showLast, setNetwork, setNetworkEnigme, setPlayerIndex, askedWrong, setAskedWrong}) => {
|
|
|
|
const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange, playerTouched, setPlayerTouched, changecptTour, solo, isDaily, isEasy, addToHistory, showLast, setNetwork, setNetworkEnigme, setPlayerIndex, askedWrong, setAskedWrong}) => {
|
|
|
@ -434,12 +437,59 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
socket.on("asked wrong", () =>{
|
|
|
|
socket.on("asked wrong", () =>{
|
|
|
|
askedWrongLocal= true
|
|
|
|
cptSquare++
|
|
|
|
setAskedWrong(true)
|
|
|
|
if (cptSquare % 2 == 0){
|
|
|
|
askedWrongBot=true
|
|
|
|
if (indice==null){
|
|
|
|
handleShowTurnBar(true)
|
|
|
|
return
|
|
|
|
handleTurnBarTextChange("Mauvais choix, posez un carré !")
|
|
|
|
}
|
|
|
|
socket.emit("put grey background", socket.id, actualPlayerIndex)
|
|
|
|
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<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
const tab = mapIndexPersons.get(player)
|
|
|
|
const tab = mapIndexPersons.get(player)
|
|
|
|
if (tab != undefined){
|
|
|
|
if (tab != undefined){
|
|
|
|
if (player != actualPlayerIndex){
|
|
|
|
if (player != actualPlayerIndex){
|
|
|
|
|
|
|
|
console.log("player != actualPlayerIndex")
|
|
|
|
for(const person of personNetwork.getPersons().filter((p) => tab.includes(p))){
|
|
|
|
for(const person of personNetwork.getPersons().filter((p) => tab.includes(p))){
|
|
|
|
networkData.nodes.update({id: person.getId(), color: "#808080"})
|
|
|
|
networkData.nodes.update({id: person.getId(), color: "#808080"})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(indice != null){
|
|
|
|
else if(indice != null){
|
|
|
|
|
|
|
|
//Pour poser un carré
|
|
|
|
const tester = IndiceTesterFactory.Create(indice)
|
|
|
|
const tester = IndiceTesterFactory.Create(indice)
|
|
|
|
for(const person of personNetwork.getPersons().filter((p) => tab.includes(p) || tester.Works(p))){
|
|
|
|
for(const person of personNetwork.getPersons()){
|
|
|
|
networkData.nodes.update({id: person.getId(), color: "#808080"})
|
|
|
|
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<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
|
|
|
|
|
|
|
socket.on("put imossible grey", ()=>{
|
|
|
|
socket.on("put imossible grey", ()=>{
|
|
|
|
if (personNetwork != null && indice!=null){
|
|
|
|
if (personNetwork != null && indice!=null){
|
|
|
|
|
|
|
|
console.log("impossible grey")
|
|
|
|
const tabNodes: any = []
|
|
|
|
const tabNodes: any = []
|
|
|
|
const tester = IndiceTesterFactory.Create(indice)
|
|
|
|
const tester = IndiceTesterFactory.Create(indice)
|
|
|
|
for (const pers of personNetwork.getPersons()){
|
|
|
|
for (const pers of personNetwork.getPersons()){
|
|
|
@ -653,9 +716,16 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
if (!solo){
|
|
|
|
if (!solo){
|
|
|
|
if (askedWrongLocal){
|
|
|
|
if (askedWrongLocal){
|
|
|
|
const person = personNetwork?.getPersons().find((p) => p.getId() == params.nodes[0])
|
|
|
|
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)
|
|
|
|
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
|
|
|
|
playerIndex = actualPlayerIndex + 1
|
|
|
|
if(playerIndex == players.length){
|
|
|
|
if(playerIndex == players.length){
|
|
|
|
playerIndex = 0
|
|
|
|
playerIndex = 0
|
|
|
@ -693,7 +763,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
else{
|
|
|
|
if (touchedPlayer > 0){
|
|
|
|
if (touchedPlayer >= 0){
|
|
|
|
console.log(touchedPlayer)
|
|
|
|
console.log(touchedPlayer)
|
|
|
|
//@ts-ignore
|
|
|
|
//@ts-ignore
|
|
|
|
socket.emit("ask player", params.nodes[0], players[touchedPlayer].id, players.find((p) => p.id === socket.id, actualPlayerIndex))
|
|
|
|
socket.emit("ask player", params.nodes[0], players[touchedPlayer].id, players.find((p) => p.id === socket.id, actualPlayerIndex))
|
|
|
|