fin du jeu manque plus que l'affichage

pull/81/head
Thomas Chazot 1 year ago
parent 423e487e14
commit 18694b9ab6

@ -39,13 +39,14 @@ let lastSocketId= ""
let firstLap = true let firstLap = true
let cptHistory = 0 let cptHistory = 0
let lastNodes: NodePerson[] = [] let lastNodes: NodePerson[] = []
let firstEnigme = true
const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange, playerTouched, setPlayerTouched, changecptTour, solo, addToHistory, showLast, setNetwork}) => { const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange, playerTouched, setPlayerTouched, changecptTour, solo, addToHistory, showLast, setNetwork}) => {
let cptTour: number = 0 let cptTour: number = 0
const {user} = useAuth() const {user} = useAuth()
const { indices, indice, person, personNetwork, setNodeIdData, players, askedPersons, setActualPlayerIndexData, room, actualPlayerIndex, turnPlayerIndex, setTurnPlayerIndexData, setWinnerData } = useGame(); const { indices, indice, person, personNetwork, setNodeIdData, players, askedPersons, setActualPlayerIndexData, room, actualPlayerIndex, turnPlayerIndex, setTurnPlayerIndexData, setWinnerData, dailyEnigme } = useGame();
const params = new URLSearchParams(window.location.search); const params = new URLSearchParams(window.location.search);
const navigate = useNavigate(); const navigate = useNavigate();
@ -258,6 +259,26 @@ let cptTour: number = 0
setNetwork(network) setNetwork(network)
dailyEnigme.forEach((pairs, index) => {
pairs.forEach((pair) => {
const i = indices.findIndex((indice) => pair.first.getId() === indice.getId())
console.log(index)
const node = networkData.nodes.get().find((n) => index == n.id)
if (node != undefined){
networkData.nodes.update({id: node.id, label: node.label + positionToEmoji(i, pair.second)})
const test = networkData.nodes.get().find((n) => index == n.id)
if (test!=undefined){
console.log(test.label)
}
}
})
});
indices.forEach((i, index) => {
console.log(i.ToString("fr") + " => " + positionToEmoji(index, true))
})
if (!solo){ if (!solo){
socket.on("asked all", (id) =>{ socket.on("asked all", (id) =>{
const pers = personNetwork.getPersons().find((p) => p.getId() == id) const pers = personNetwork.getPersons().find((p) => p.getId() == id)

@ -1,5 +1,6 @@
import React, { createContext, useContext, useState, ReactNode } from 'react'; import React, { createContext, useContext, useState, ReactNode } from 'react';
import Indice from '../model/Indices/Indice'; import Indice from '../model/Indices/Indice';
import Pair from '../model/Pair';
import Person from '../model/Person'; import Person from '../model/Person';
import PersonNetwork from '../model/PersonsNetwork'; import PersonNetwork from '../model/PersonsNetwork';
import Player from '../model/Player'; import Player from '../model/Player';
@ -17,6 +18,7 @@ interface GameContextProps {
room: string; room: string;
onlyFalse: boolean onlyFalse: boolean
winner: Player | null winner: Player | null
dailyEnigme: Map<number, Pair<Indice, boolean>[]>
setIndicesData: (newIndices: Indice[]) => void; setIndicesData: (newIndices: Indice[]) => void;
setIndiceData: (newIndice: Indice) => void; setIndiceData: (newIndice: Indice) => void;
setPersonData: (newPerson: Person) => void; setPersonData: (newPerson: Person) => void;
@ -30,6 +32,7 @@ interface GameContextProps {
setOnlyFalseData: (newOnlyFalse: boolean) => void setOnlyFalseData: (newOnlyFalse: boolean) => void
setWinnerData: (winner: Player) => void setWinnerData: (winner: Player) => void
reset: () => void reset: () => void
setDailyEnigmeData: (map: Map<number, Pair<Indice, boolean>[]>) => void
} }
const GameContext = createContext<GameContextProps | undefined>(undefined); const GameContext = createContext<GameContextProps | undefined>(undefined);
@ -51,6 +54,7 @@ export const GameProvider: React.FC<GameProviderProps> = ({ children }) => {
const [room, setRoom] = useState<string>("") const [room, setRoom] = useState<string>("")
const [onlyFalse, setOnlyFalse] = useState<boolean>(false) const [onlyFalse, setOnlyFalse] = useState<boolean>(false)
const [winner, setWinner] = useState<Player | null>(null) const [winner, setWinner] = useState<Player | null>(null)
const [dailyEnigme, setDailyEnigme] = useState<Map<number, Pair<Indice, boolean>[]>>(new Map())
const setIndicesData = (newIndices: Indice[]) => { const setIndicesData = (newIndices: Indice[]) => {
@ -102,6 +106,10 @@ export const GameProvider: React.FC<GameProviderProps> = ({ children }) => {
setWinner(winner) setWinner(winner)
} }
const setDailyEnigmeData = (map: Map<number, Pair<Indice, boolean>[]>) => {
setDailyEnigme(map)
}
const reset = () => { const reset = () => {
setIndices([]) setIndices([])
setActualPlayerIndex(-1) setActualPlayerIndex(-1)
@ -117,7 +125,7 @@ export const GameProvider: React.FC<GameProviderProps> = ({ children }) => {
} }
return ( return (
<GameContext.Provider value={{ indices, setIndicesData, indice, setIndiceData, person, setPersonData, personNetwork, setPersonNetworkData, players, setPlayersData, nodeId, setNodeIdData, askedPersons, setAskedPersonsData, actualPlayerIndex, setActualPlayerIndexData, turnPlayerIndex, setTurnPlayerIndexData, room, setRoomData, onlyFalse, setOnlyFalseData, winner, setWinnerData, reset }}> <GameContext.Provider value={{ indices, setIndicesData, indice, setIndiceData, person, setPersonData, personNetwork, setPersonNetworkData, players, setPlayersData, nodeId, setNodeIdData, askedPersons, setAskedPersonsData, actualPlayerIndex, setActualPlayerIndexData, turnPlayerIndex, setTurnPlayerIndexData, room, setRoomData, onlyFalse, setOnlyFalseData, winner, setWinnerData, reset, dailyEnigme, setDailyEnigmeData }}>
{children} {children}
</GameContext.Provider> </GameContext.Provider>
); );

@ -26,11 +26,15 @@ import { PlayerProps } from '../types/Player';
import Player from '../model/Player'; import Player from '../model/Player';
import Human from '../model/User'; import Human from '../model/User';
import User from '../model/User'; import User from '../model/User';
import EnigmeDuJourCreator from '../model/EnigmeDuJourCreator';
import Stub from '../model/Stub';
let first = true
function Play() { function Play() {
const theme=useTheme() const theme=useTheme()
const {isLoggedIn, login, user, setUserData } = useAuth(); const {isLoggedIn, login, user, setUserData } = useAuth();
const {setDailyEnigmeData} = useGame()
useEffect(() => { useEffect(() => {
const fetchUserInformation = async () => { const fetchUserInformation = async () => {
@ -92,6 +96,11 @@ function Play() {
setPersonNetworkData(networkPerson) setPersonNetworkData(networkPerson)
setIndicesData(choosenIndices) setIndicesData(choosenIndices)
setIndicesData(choosenIndices) setIndicesData(choosenIndices)
if (first){
first = false
const map = EnigmeDuJourCreator.createEnigme(networkPerson, choosenIndices, choosenPerson, Stub.GenerateIndice())
setDailyEnigmeData(map)
}
navigate('/game?solo=true'); navigate('/game?solo=true');
} }

@ -55,7 +55,7 @@
"color_start": "Le suspect a les cheveux", "color_start": "Le suspect a les cheveux",
"color_end": "", "color_end": "",
"nb_friends_indice_start": "Le suspect", "nb_friends_indice_start": "Le suspect a",
"nb_friends_indice_end": "amis", "nb_friends_indice_end": "amis",
"nb_sports_indice_start": "Le suspect pratique", "nb_sports_indice_start": "Le suspect pratique",

@ -0,0 +1,74 @@
import IndiceTesterFactory from "./Factory/IndiceTesterFactory";
import Indice from "./Indices/Indice";
import Pair from "./Pair";
import Person from "./Person";
import PersonNetwork from "./PersonsNetwork";
class EnigmeDuJourCreator{
static createEnigme(personNetwork: PersonNetwork, choosenIndices: Indice[], choosenPerson: Person, allIndices: Indice[]): Map<number, Pair<Indice, boolean>[]>{
const map = new Map<number, Pair<Indice, boolean>[]>()
personNetwork.getPersons().forEach((p) =>{
map.set(p.getId(), [])
})
console.log("START ENIGME")
choosenIndices.forEach((choosenIndice) => {
const choosenIndiceTester = IndiceTesterFactory.Create(choosenIndice)
const modifiedPersons: Pair<Person, boolean>[] = []
let possibleIndices: Indice[] = [...allIndices]
let i = 0
while (possibleIndices.length != 1){
let tmpPossibleIndices: Indice[] = [...possibleIndices]
let choosenPair : Pair<Person, boolean> = new Pair(personNetwork.getPersons()[0], true)
for(const person of personNetwork.getPersons().filter((p) => p.getId() !== choosenPerson.getId())){
const veryTmpIndice = [...possibleIndices]
if (!choosenIndiceTester.Works(person)){
possibleIndices.forEach((possibleIndice, index) =>{
const tester = IndiceTesterFactory.Create(possibleIndice)
if (tester.Works(person)){
const t = veryTmpIndice.findIndex((tmpIndice) => tmpIndice.getId() == possibleIndice.getId())
if (t != -1){
veryTmpIndice.splice(t, 1)
}
}
})
if (veryTmpIndice.length<tmpPossibleIndices.length){
tmpPossibleIndices = veryTmpIndice
choosenPair = new Pair(person, false)
}
}
else{
possibleIndices.forEach((possibleIndice, index) =>{
const tester = IndiceTesterFactory.Create(possibleIndice)
if (!tester.Works(person)){
const t = veryTmpIndice.findIndex((tmpIndice) => tmpIndice.getId() == possibleIndice.getId())
if (t != -1){
veryTmpIndice.splice(t, 1)
}
}
})
if (veryTmpIndice.length<tmpPossibleIndices.length){
tmpPossibleIndices = veryTmpIndice
choosenPair = new Pair(person, true)
}
}
}
possibleIndices = [...tmpPossibleIndices]
modifiedPersons.push(choosenPair)
console.log(possibleIndices)
}
console.log("choosenIndice => " + choosenIndice.ToString("fr"))
console.log("possibleIndices => " + possibleIndices[0].ToString("fr"))
modifiedPersons.forEach((pair) =>{
map.get(pair.first.getId())?.push(new Pair(choosenIndice, pair.second))
})
})
return map
}
}
export default EnigmeDuJourCreator

@ -22,20 +22,14 @@ class Stub{
let test = 7 let test = 7
for (let i: Color=0; i<5; i++){ for (let i: Color=0; i<5; i++){
for (let j: Color=0; j<5; j++){ for (let j: Color=i + 1; j<5; j++){
if (j==i){
continue
}
indices.push(new ColorIndice(test, [i, j])) indices.push(new ColorIndice(test, [i, j]))
test++ test++
} }
} }
for (let i: Sport=0; i<5; i++){ for (let i: Sport=0; i<5; i++){
for (let j: Sport=0; j<5; j++){ for (let j: Sport=i + 1; j<5; j++){
if (j==i){
continue
}
indices.push(new SportIndice(test, [i, j])) indices.push(new SportIndice(test, [i, j]))
test++ test++
} }

@ -22,7 +22,6 @@
"Riley", "Riley",
"Layla", "Layla",
"Stella", "Stella",
"Aurora",
"Natalie", "Natalie",
"Zoe", "Zoe",
"Lucy", "Lucy",
@ -48,7 +47,6 @@
"Bella", "Bella",
"Sadie", "Sadie",
"Hailey", "Hailey",
"Aurora",
"Liam", "Liam",
"Noah", "Noah",
"Oliver", "Oliver",
@ -69,7 +67,6 @@
"Jack", "Jack",
"Jayden", "Jayden",
"Owen", "Owen",
"Noah",
"Ethan", "Ethan",
"Mason", "Mason",
"Logan", "Logan",
@ -93,4 +90,3 @@
"Julian" "Julian"
] ]
} }
Loading…
Cancel
Save