|
|
|
@ -21,6 +21,9 @@ import { json } from "body-parser";
|
|
|
|
|
import html2canvas from 'html2canvas';
|
|
|
|
|
import jsPDF from 'jspdf';
|
|
|
|
|
import {basePath} from "../AdressSetup"
|
|
|
|
|
import GameCreator from "../model/GameCreator";
|
|
|
|
|
import Stub from "../model/Stub";
|
|
|
|
|
import EnigmeDuJourCreator from "../model/EnigmeDuJourCreator";
|
|
|
|
|
import { useIntl } from "react-intl";
|
|
|
|
|
|
|
|
|
|
interface MyGraphComponentProps {
|
|
|
|
@ -33,7 +36,7 @@ interface MyGraphComponentProps {
|
|
|
|
|
addToHistory: (message : string) => void
|
|
|
|
|
solo : boolean
|
|
|
|
|
isDaily : boolean
|
|
|
|
|
isEasy: boolean
|
|
|
|
|
difficulty: string
|
|
|
|
|
setNetwork: (network: Network) => void
|
|
|
|
|
showLast: boolean
|
|
|
|
|
setNetworkEnigme: (networkEnigme: Map<number, Pair<Indice, boolean>[]>) => void
|
|
|
|
@ -51,12 +54,15 @@ interface MyGraphComponentProps {
|
|
|
|
|
putGreyBackground : () => void
|
|
|
|
|
putCorrectBackground : () => void
|
|
|
|
|
putImposssibleGrey : () => void
|
|
|
|
|
setChangeGraph : (func: (nbNodes: number, nbIndices: number) => void) => void
|
|
|
|
|
|
|
|
|
|
handleTurn :() => void
|
|
|
|
|
|
|
|
|
|
lang: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let askedWrongBot = false
|
|
|
|
|
let lastSocketId= ""
|
|
|
|
|
let lastAskingPlayer = 0
|
|
|
|
|
let lastNodeId = -1
|
|
|
|
|
let first = true
|
|
|
|
@ -64,14 +70,10 @@ let askedWrongLocal = false
|
|
|
|
|
let mapIndexPersons: Map<number, Person[]> = new Map<number, Person[]>()
|
|
|
|
|
let touchedPlayer = -1
|
|
|
|
|
let botIndex = -1
|
|
|
|
|
let askedWrongBot = false
|
|
|
|
|
let lastSocketId= ""
|
|
|
|
|
let firstLap = true
|
|
|
|
|
let cptHistory = 0
|
|
|
|
|
let lastNodes: NodePerson[] = []
|
|
|
|
|
let cptEndgame = 0
|
|
|
|
|
let firstEnigme = true
|
|
|
|
|
let firstIndex = true
|
|
|
|
|
let endgame= false
|
|
|
|
|
let firstHistory = true
|
|
|
|
|
let cptSquare = 0
|
|
|
|
@ -79,14 +81,14 @@ let cptOnAskedWrong = 0
|
|
|
|
|
let cptPlayerLeft = 0
|
|
|
|
|
let firstPlayer = 0
|
|
|
|
|
let cptBug = 0
|
|
|
|
|
let cptUseEffect = 0
|
|
|
|
|
let testPlayers: Player[] = []
|
|
|
|
|
let testTemps = 0
|
|
|
|
|
let testFirst = false
|
|
|
|
|
let gameStartTmp = true
|
|
|
|
|
let index = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange, playerTouched, setPlayerTouched, changecptTour, solo, isDaily, isEasy, addToHistory, showLast, setNetwork, setNetworkEnigme, setPlayerIndex, askedWrong, setAskedWrong, importToPdf, setImportToPdf, importToJSON, setImportToJSON, setPutCorrectBackground, setPutGreyBackground, setPutImposssibleGrey, putCorrectBackground, putGreyBackground, putImposssibleGrey, handleTurn, lang}) => {
|
|
|
|
|
let cptTour: number = 0
|
|
|
|
|
const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange, playerTouched, setPlayerTouched, changecptTour, solo, isDaily, difficulty, addToHistory, showLast, setNetwork, setNetworkEnigme, setPlayerIndex, askedWrong, setAskedWrong, importToPdf, setImportToPdf, importToJSON, setImportToJSON, setPutCorrectBackground, setPutGreyBackground, setPutImposssibleGrey, putCorrectBackground, putGreyBackground, putImposssibleGrey, handleTurn, setChangeGraph, lang}) => {
|
|
|
|
|
let cptTour: number = 1
|
|
|
|
|
|
|
|
|
|
//* Gestion du temps :
|
|
|
|
|
let initMtn = 0
|
|
|
|
@ -97,7 +99,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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, nodesC, temps} = useGame();
|
|
|
|
|
const { indices, indice, person, personNetwork, setNodeIdData, players, setPlayersData, askedPersons, setActualPlayerIndexData, room, actualPlayerIndex, turnPlayerIndex, setIndicesData, setWinnerData, dailyEnigme, setNbCoupData, settempsData, setNetworkDataData, setSeedData, nodesC, temps, setPersonData, setPersonNetworkData, setDailyEnigmeData, gameStart, setGameStartData} = useGame();
|
|
|
|
|
const params = new URLSearchParams(window.location.search);
|
|
|
|
|
|
|
|
|
|
const navigate = useNavigate();
|
|
|
|
@ -117,10 +119,12 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
settempsData(testTemps)
|
|
|
|
|
testTemps += 0.5
|
|
|
|
|
|
|
|
|
|
cptBug ++
|
|
|
|
|
if (cptBug > 10){
|
|
|
|
|
cptBug = 0
|
|
|
|
|
socket.emit("who plays", room)
|
|
|
|
|
if (!solo){
|
|
|
|
|
cptBug ++
|
|
|
|
|
if (cptBug > 10){
|
|
|
|
|
cptBug = 0
|
|
|
|
|
socket.emit("who plays", room)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -138,12 +142,10 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
testPlayers = players
|
|
|
|
|
console.log(testPlayers)
|
|
|
|
|
}, [players])
|
|
|
|
|
|
|
|
|
|
useEffect(() =>{
|
|
|
|
|
touchedPlayer=playerTouched
|
|
|
|
|
console.log(playerTouched)
|
|
|
|
|
if (touchedPlayer == -1){
|
|
|
|
|
if (!askedWrongLocal){
|
|
|
|
|
putCorrectBackground()
|
|
|
|
@ -182,17 +184,45 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
|
|
|
|
|
let playerIndex: number = turnPlayerIndex
|
|
|
|
|
|
|
|
|
|
if (firstIndex){
|
|
|
|
|
firstIndex=false
|
|
|
|
|
setPlayerIndex(playerIndex)
|
|
|
|
|
}
|
|
|
|
|
let index = 0
|
|
|
|
|
for (let i=0; i<players.length; i++){
|
|
|
|
|
if(players[i].id == socket.id){
|
|
|
|
|
index=i
|
|
|
|
|
break
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
gameStartTmp=gameStart
|
|
|
|
|
if (gameStartTmp){
|
|
|
|
|
setGameStartData(false)
|
|
|
|
|
console.log(gameStart)
|
|
|
|
|
setLastIndex(turnPlayerIndex)
|
|
|
|
|
setPlayerIndex(playerIndex)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (let i=0; i<players.length; i++){
|
|
|
|
|
if(players[i].id == socket.id){
|
|
|
|
|
index=i
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
first = false
|
|
|
|
|
endgame= false
|
|
|
|
|
if (!solo){
|
|
|
|
|
for(let i = 0; i<indices.length; i++){
|
|
|
|
|
mapIndexPersons.set(i, [])
|
|
|
|
|
}
|
|
|
|
|
if (actualPlayerIndex==0){
|
|
|
|
|
players.forEach((p, index) =>{
|
|
|
|
|
if (p instanceof Bot && personNetwork!=null){
|
|
|
|
|
p.index=index
|
|
|
|
|
p.initiateMap(personNetwork)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
setActualPlayerIndexData(index)
|
|
|
|
|
if (playerIndex == actualPlayerIndex){
|
|
|
|
|
handleTurnBarTextChange(intl.formatMessage({ id: 'game.yourTurn' }))
|
|
|
|
|
handleShowTurnBar(true)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, [gameStart])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() =>{
|
|
|
|
|
//* Gestion du sound des tours :
|
|
|
|
@ -309,31 +339,6 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
}
|
|
|
|
|
}, [lastIndex])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (first){
|
|
|
|
|
first = false
|
|
|
|
|
endgame= false
|
|
|
|
|
if (!solo){
|
|
|
|
|
for(let i = 0; i<indices.length; i++){
|
|
|
|
|
mapIndexPersons.set(i, [])
|
|
|
|
|
}
|
|
|
|
|
if (actualPlayerIndex==0){
|
|
|
|
|
players.forEach((p, index) =>{
|
|
|
|
|
if (p instanceof Bot && personNetwork!=null){
|
|
|
|
|
p.index=index
|
|
|
|
|
p.initiateMap(personNetwork)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
setActualPlayerIndexData(index)
|
|
|
|
|
if (playerIndex == actualPlayerIndex){
|
|
|
|
|
handleTurnBarTextChange(intl.formatMessage({ id: 'game.yourTurn' }))
|
|
|
|
|
handleShowTurnBar(true)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (importToPdf){
|
|
|
|
|
setImportToPdf(false)
|
|
|
|
@ -372,10 +377,29 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
}
|
|
|
|
|
}, [importToJSON])
|
|
|
|
|
|
|
|
|
|
const changeGraph = (nbNodes: number, nbIndices: number) => {
|
|
|
|
|
//todo différencier les deux
|
|
|
|
|
const [networkPerson, choosenPerson, choosenIndices] = GameCreator.CreateGame(nbIndices, nbNodes)
|
|
|
|
|
setPersonData(choosenPerson)
|
|
|
|
|
setPersonNetworkData(networkPerson)
|
|
|
|
|
setIndicesData(choosenIndices)
|
|
|
|
|
const map = EnigmeDuJourCreator.createEnigme(networkPerson, choosenIndices, choosenPerson, Stub.GenerateIndice())
|
|
|
|
|
setDailyEnigmeData(map)
|
|
|
|
|
addToHistory("<----- [Tour " + 1 +"/"+networkPerson.getPersons().length + "] ----->");
|
|
|
|
|
changecptTour(1)
|
|
|
|
|
testTemps=0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (personNetwork == null){
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (solo){
|
|
|
|
|
setChangeGraph(() => changeGraph)
|
|
|
|
|
}
|
|
|
|
|
const graph = GraphCreator.CreateGraph(personNetwork)
|
|
|
|
|
|
|
|
|
|
let n = graph.nodesPerson;
|
|
|
|
@ -430,7 +454,9 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
|
|
|
|
|
if (isDaily){
|
|
|
|
|
setNetworkEnigme(dailyEnigme)
|
|
|
|
|
if (!isEasy){
|
|
|
|
|
console.log(difficulty)
|
|
|
|
|
if (difficulty === "hard" || difficulty=== "intermediate"){
|
|
|
|
|
console.log(dailyEnigme)
|
|
|
|
|
dailyEnigme.forEach((pairs, index) => {
|
|
|
|
|
pairs.forEach((pair) => {
|
|
|
|
|
//@ts-ignore
|
|
|
|
@ -443,7 +469,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
else if (difficulty === "easy"){
|
|
|
|
|
if (firstHistory){
|
|
|
|
|
firstHistory=false
|
|
|
|
|
indices.forEach((indice, index) => {
|
|
|
|
@ -573,7 +599,6 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
socket.on("node checked",(id, works, askedIndex, newPlayerIndex, socketId) => {
|
|
|
|
|
console.log("coucou")
|
|
|
|
|
cptBug=0
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
const node = nodes.get().find((n) => id == n.id)
|
|
|
|
@ -582,7 +607,6 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
playerIndex = newPlayerIndex
|
|
|
|
|
setPlayerIndex(playerIndex)
|
|
|
|
|
setLastIndex(newPlayerIndex)
|
|
|
|
|
console.log(newPlayerIndex)
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
if (mapIndexPersons.get(askedIndex)?.find((p) => p.getId() == id) == undefined){
|
|
|
|
|
//@ts-ignore
|
|
|
|
@ -736,7 +760,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
else {
|
|
|
|
|
if (firstLap){
|
|
|
|
|
firstLap=false
|
|
|
|
|
if (!isDaily){
|
|
|
|
|
if (solo && (difficulty === "intermediate" || !isDaily)){
|
|
|
|
|
addToHistory("<----- ["+ intl.formatMessage({ id: 'turn' }) +" " + 1 +"/"+networkData.nodes.length + "] ----->");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1061,9 +1085,11 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
if(isDaily){
|
|
|
|
|
// TODO: verif difficulté et add les stats
|
|
|
|
|
// TODO: verif pour facile et difficile, si réussi en one shot ou non
|
|
|
|
|
if(isEasy){
|
|
|
|
|
if(difficulty==="easy"){
|
|
|
|
|
manager.userService.addEasyEnigmaStats(user.pseudo, 1, testTemps - 0.5);
|
|
|
|
|
}
|
|
|
|
|
else if (difficulty === "intermediate"){
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
manager.userService.addHardEnigmaStats(user.pseudo, 1, testTemps - 0.5);
|
|
|
|
|
}
|
|
|
|
@ -1093,11 +1119,29 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
navigate(`${basePath}/endgame?solo=true&daily=${isDaily}`)
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
addToHistory(personTest.getName() + intl.formatMessage({ id: 'history.NotCoupable' }));
|
|
|
|
|
cptTour ++; // On Incrémente le nombre de tour du joueur
|
|
|
|
|
const tour = cptTour+1;
|
|
|
|
|
addToHistory("<----- ["+ intl.formatMessage({ id: 'turn' }) + " " + tour +"/"+networkData.nodes.length + "] ----->");
|
|
|
|
|
changecptTour(cptTour); // On le transmet a la page précédente avec la fonction
|
|
|
|
|
if (isDaily){
|
|
|
|
|
if (difficulty==="intermediate"){
|
|
|
|
|
addToHistory(personTest.getName() + intl.formatMessage({ id: 'history.NotCoupable' }));
|
|
|
|
|
cptTour ++; // On Incrémente le nombre de tour du joueur
|
|
|
|
|
addToHistory("<----- ["+ intl.formatMessage({ id: 'turn' }) + " " + cptTour +"/"+networkData.nodes.length + "] ----->");
|
|
|
|
|
changecptTour(cptTour); // On le transmet a la page précédente avec la fonction
|
|
|
|
|
}
|
|
|
|
|
else if (difficulty==="easy"){
|
|
|
|
|
cptTour ++; // On Incrémente le nombre de tour du joueur
|
|
|
|
|
changecptTour(cptTour); // On le transmet a la page précédente avec la fonction
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
navigate(`${basePath}/endgame?solo=true&daily=true`)
|
|
|
|
|
setNetworkDataData(networkData)
|
|
|
|
|
setWinnerData(null)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
addToHistory(personTest.getName() + intl.formatMessage({ id: 'history.NotCoupable' })); //TODO préciser le nombre d'indice qu'il a de juste
|
|
|
|
|
cptTour ++; // On Incrémente le nombre de tour du joueur
|
|
|
|
|
addToHistory("<----- [Tour " + cptTour +"/"+networkData.nodes.length + "] ----->");
|
|
|
|
|
changecptTour(cptTour); // On le transmet a la page précédente avec la fonction
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1109,7 +1153,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
|
|
|
|
|
setPlayerTouched(-1)
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}, []); // Le tableau vide signifie que cela ne s'exécutera qu'une fois après le premier rendu
|
|
|
|
|
}, [personNetwork]); // Le tableau vide signifie que cela ne s'exécutera qu'une fois après le premier rendu
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|