|
|
|
@ -25,15 +25,17 @@ import { colorToEmoji, positionToColor } from "../ColorHelper";
|
|
|
|
|
interface MyGraphComponentProps {
|
|
|
|
|
onNodeClick: (shouldShowChoiceBar: boolean) => void;
|
|
|
|
|
handleShowTurnBar: (shouldShowTurnBar: boolean) => void
|
|
|
|
|
handleTurnBarTextChange: (newTurnBarText: string) => void
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let lastAskingPlayer = 0
|
|
|
|
|
let lastNodeId = -1
|
|
|
|
|
let first = true
|
|
|
|
|
let askedWrong = false
|
|
|
|
|
|
|
|
|
|
const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleShowTurnBar}) => {
|
|
|
|
|
const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange}) => {
|
|
|
|
|
|
|
|
|
|
const { indices, indice, person, personNetwork, setNodeIdData, players, askedPersons, setActualPlayerIndexData, room, actualPlayerIndex, turnPlayerIndex } = useGame();
|
|
|
|
|
const { indices, indice, person, personNetwork, setNodeIdData, players, askedPersons, setActualPlayerIndexData, room, actualPlayerIndex, turnPlayerIndex, onlyFalse, setOnlyFalseData } = useGame();
|
|
|
|
|
|
|
|
|
|
let playerIndex: number = turnPlayerIndex
|
|
|
|
|
let index = 0
|
|
|
|
@ -50,7 +52,9 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
first = false
|
|
|
|
|
setActualPlayerIndexData(index)
|
|
|
|
|
if (playerIndex == thisPlayerIndex){
|
|
|
|
|
handleTurnBarTextChange("À vous de jouer")
|
|
|
|
|
handleShowTurnBar(true)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
indices.forEach(i => {
|
|
|
|
|
console.log(i.ToString("en"))
|
|
|
|
@ -96,20 +100,27 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
const networkData = { nodes: nodes, edges: graph.edges };
|
|
|
|
|
const network = new Network(container, networkData, initialOptions);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
socket.on("asked all", (id) =>{
|
|
|
|
|
const pers = personNetwork.getPersons().find((p) => p.getId() == id)
|
|
|
|
|
if (pers!=undefined){
|
|
|
|
|
askedPersons.push(pers)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
socket.on("node checked",(id, works, color, newPlayerIndex) => {
|
|
|
|
|
const node = nodes.get().find((n) => id == n.id)
|
|
|
|
|
if (node!=undefined){
|
|
|
|
|
onNodeClick(false)
|
|
|
|
|
playerIndex = newPlayerIndex
|
|
|
|
|
networkData.nodes.update({id: id, label: node.label + colorToEmoji(color, works)})
|
|
|
|
|
if (!node.label.includes(colorToEmoji(color, works))){
|
|
|
|
|
networkData.nodes.update({id: id, label: node.label + colorToEmoji(color, works)})
|
|
|
|
|
}
|
|
|
|
|
if (playerIndex === thisPlayerIndex){
|
|
|
|
|
handleTurnBarTextChange("À vous de jouer")
|
|
|
|
|
handleShowTurnBar(true)
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
handleShowTurnBar(false)
|
|
|
|
|
console.log("je passe bien ici ?????")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lastAskingPlayer = 0
|
|
|
|
@ -120,8 +131,16 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
console.log("player: " + askedPlayer + " already asked on node " + nodeId)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
socket.on("asked wrong", () =>{
|
|
|
|
|
setOnlyFalseData(true)
|
|
|
|
|
askedWrong = true
|
|
|
|
|
handleShowTurnBar(true)
|
|
|
|
|
handleTurnBarTextChange("Mauvais choix, posez un carré !")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
socket.on("asked", (nodeId, askingPlayer) => {
|
|
|
|
|
socket.on("asked", (nodeId, askingPlayer, askingPlayerIndex) => {
|
|
|
|
|
console.log(askingPlayerIndex)
|
|
|
|
|
if (askingPlayer.id !== lastAskingPlayer || nodeId !== lastNodeId ){
|
|
|
|
|
lastAskingPlayer = askingPlayer.id
|
|
|
|
|
lastNodeId = nodeId
|
|
|
|
@ -136,6 +155,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
const node = nodes.get().find((n) => nodeId == n.id)
|
|
|
|
|
if (node != undefined && indice != null){
|
|
|
|
|
var tester = IndiceTesterFactory.Create(indice)
|
|
|
|
|
let maybe = thisPlayerIndex
|
|
|
|
|
playerIndex = playerIndex + 1
|
|
|
|
|
if(playerIndex == players.length){
|
|
|
|
|
playerIndex = 0
|
|
|
|
@ -144,7 +164,12 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
socket.emit("node checked", nodeId, true, positionToColor(thisPlayerIndex), room, playerIndex)
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
socket.emit("node checked", nodeId, false, positionToColor(thisPlayerIndex), room, playerIndex)
|
|
|
|
|
maybe = maybe - 1
|
|
|
|
|
if(maybe == 0){
|
|
|
|
|
maybe = players.length - 1
|
|
|
|
|
}
|
|
|
|
|
socket.emit("node checked", nodeId, false, positionToColor(thisPlayerIndex), room, maybe)
|
|
|
|
|
socket.emit("asked wrong", askingPlayer, room)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -184,9 +209,26 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
|
|
|
|
|
if(params.nodes.length > 0){
|
|
|
|
|
setNodeIdData(params.nodes[0])
|
|
|
|
|
|
|
|
|
|
// Renvoyer un true pour afficher la choice bar
|
|
|
|
|
if (thisPlayerIndex == playerIndex){
|
|
|
|
|
if (askedWrong){
|
|
|
|
|
console.log(askedWrong)
|
|
|
|
|
const person = personNetwork?.getPersons().find((p) => p.getId() == params.nodes[0])
|
|
|
|
|
if (person !== undefined && indice !== null){
|
|
|
|
|
const tester = IndiceTesterFactory.Create(indice)
|
|
|
|
|
if (!tester.Works(person) && !askedPersons.includes(person)){
|
|
|
|
|
console.log(playerIndex)
|
|
|
|
|
playerIndex = thisPlayerIndex + 1
|
|
|
|
|
if(playerIndex == players.length){
|
|
|
|
|
playerIndex = 0
|
|
|
|
|
}
|
|
|
|
|
socket.emit("node checked", params.nodes[0], false, positionToColor(thisPlayerIndex), room, playerIndex)
|
|
|
|
|
askedPersons.push(person)
|
|
|
|
|
askedWrong = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (thisPlayerIndex == playerIndex){
|
|
|
|
|
onNodeClick(true)
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|