pull/109/head
Pierre Ferreira 2 years ago
commit f2d6b89d03

@ -42,7 +42,7 @@ steps:
IMAGENAME: mysql:latest IMAGENAME: mysql:latest
CONTAINERNAME: mysql CONTAINERNAME: mysql
COMMAND: create COMMAND: create
OVERWRITE: true #OVERWRITE: true
PRIVATE: false PRIVATE: false
CODEFIRST_CLIENTDRONE_ENV_MYSQL_ROOT_PASSWORD: CODEFIRST_CLIENTDRONE_ENV_MYSQL_ROOT_PASSWORD:
from_secret: MYSQL_ROOT_PASSWORD from_secret: MYSQL_ROOT_PASSWORD
@ -53,6 +53,9 @@ steps:
CODEFIRST_CLIENTDRONE_ENV_MYSQL_PASSWORD: CODEFIRST_CLIENTDRONE_ENV_MYSQL_PASSWORD:
from_secret: MYSQL_PASSWORD from_secret: MYSQL_PASSWORD
ADMINS: thomaschazot2,pierreferreira,baptistemarcel ADMINS: thomaschazot2,pierreferreira,baptistemarcel
when:
branch:
- CI/CD
- name: container-web - name: container-web
image: plugins/docker image: plugins/docker
@ -70,7 +73,7 @@ steps:
#depends_on: [ build ] #depends_on: [ build ]
when: when:
branch: branch:
- master - CI/CD
#container deployment #container deployment

@ -1,7 +1,6 @@
{ {
"name": "cryptide", "name": "cryptide",
"version": "1.0.0", "version": "1.0.0",
"homepage": "/containers/Crypteam-website/",
"dependencies": { "dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.4.2", "@fortawesome/fontawesome-svg-core": "^6.4.2",
"@fortawesome/free-regular-svg-icons": "^6.4.2", "@fortawesome/free-regular-svg-icons": "^6.4.2",

@ -9,7 +9,7 @@ const tmp2 = ADRESSE_WEBSERVER
const ADRESSE_WEBSITE = "" const ADRESSE_WEBSITE = ""
const basePath = process.env.REACT_APP_BASE_PATH || '/containers/Crypteam-website'; const basePath = process.env.REACT_APP_BASE_PATH || '';
const tmp3 = basePath const tmp3 = basePath

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

@ -26,6 +26,8 @@ interface GameContextProps {
networkData: any networkData: any
seed: number | string; seed: number | string;
nodesC: NodePerson[] nodesC: NodePerson[]
gameStart: boolean
setGameStartData : (newStart: boolean) => void
setIndicesData: (newIndices: Indice[]) => void; setIndicesData: (newIndices: Indice[]) => void;
setIndiceData: (newIndice: Indice) => void; setIndiceData: (newIndice: Indice) => void;
setPersonData: (newPerson: Person) => void; setPersonData: (newPerson: Person) => void;
@ -37,7 +39,7 @@ interface GameContextProps {
setTurnPlayerIndexData: (newTurnPlayerIndex: number) => void; setTurnPlayerIndexData: (newTurnPlayerIndex: number) => void;
setRoomData: (newRoom: string) => void; setRoomData: (newRoom: string) => void;
setOnlyFalseData: (newOnlyFalse: boolean) => void setOnlyFalseData: (newOnlyFalse: boolean) => void
setWinnerData: (winner: Player) => void setWinnerData: (winner: Player | null) => void
reset: () => void reset: () => void
setDailyEnigmeData: (map: Map<number, Pair<Indice, boolean>[]>) => void setDailyEnigmeData: (map: Map<number, Pair<Indice, boolean>[]>) => void
setNbCoupData: (newNbCoup : number) => void setNbCoupData: (newNbCoup : number) => void
@ -72,8 +74,13 @@ export const GameProvider: React.FC<GameProviderProps> = ({ children }) => {
const [networkData, setNetworkData] = useState<any>(null); const [networkData, setNetworkData] = useState<any>(null);
const [seed, setSeed] = useState<number | string>(0); const [seed, setSeed] = useState<number | string>(0);
const [nodesC, setNodes] = useState<NodePerson[]>([]); const [nodesC, setNodes] = useState<NodePerson[]>([]);
const [gameStart, setGameStart] = useState<boolean>(true)
const setGameStartData = (newStart: boolean) => {
setGameStart(newStart)
}
const setNodesData = (nodes: NodePerson[]) => { const setNodesData = (nodes: NodePerson[]) => {
setNodes(nodes) setNodes(nodes)
} }
@ -131,7 +138,7 @@ export const GameProvider: React.FC<GameProviderProps> = ({ children }) => {
setOnlyFalse(newOnlyFalse) setOnlyFalse(newOnlyFalse)
} }
const setWinnerData = (winner: Player) =>{ const setWinnerData = (winner: Player | null) =>{
setWinner(winner) setWinner(winner)
} }
@ -165,7 +172,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, dailyEnigme, setDailyEnigmeData, nbCoup, setNbCoupData, temps, settempsData, setNetworkDataData, networkData, seed, setSeedData, nodesC, setNodesData}}> <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, nbCoup, setNbCoupData, temps, settempsData, setNetworkDataData, networkData, seed, setSeedData, nodesC, setNodesData, gameStart, setGameStartData}}>
{children} {children}
</GameContext.Provider> </GameContext.Provider>
); );

@ -92,11 +92,12 @@ const InGame = ({locale, changeLocale}) => {
} }
let isEasy: boolean = true let difficulty: string = "";
const isEasytmp = params.get('easy'); let difficultyTmp = params.get('difficulty')
if (isEasytmp == "false"){ if (difficultyTmp !== null){
isEasy=false difficulty=difficultyTmp
} }
//* Historique //* Historique
const [history, setHistory] = useState<string[]>([]); const [history, setHistory] = useState<string[]>([]);
const [showLast, setShowLast] = useState(false) const [showLast, setShowLast] = useState(false)
@ -107,6 +108,8 @@ const InGame = ({locale, changeLocale}) => {
const [putCorrectBackground, setPutCorrectBackground] = useState<() => void>(() => {}); const [putCorrectBackground, setPutCorrectBackground] = useState<() => void>(() => {});
const [putGreyBackgroud, setPutGreyBackground] = useState<() => void>(() => {}); const [putGreyBackgroud, setPutGreyBackground] = useState<() => void>(() => {});
const [putImposssibleGrey, setPutImposssibleGrey] = useState<() => void>(() => {}); const [putImposssibleGrey, setPutImposssibleGrey] = useState<() => void>(() => {});
const [changeGraph, setChangeGraph] = useState<(nbNodes: number, nbIndices: number) => void>(() => {});
const setPutCorrectBackgroundData = (func: () => void) => { const setPutCorrectBackgroundData = (func: () => void) => {
@ -121,6 +124,10 @@ const InGame = ({locale, changeLocale}) => {
setPutImposssibleGrey(func) setPutImposssibleGrey(func)
} }
const setChangeGraphData = (func: (nbNodes: number, nbIndices: number) => void) => {
setChangeGraph(func)
}
const setImportToJSONData = (imp: boolean) => { const setImportToJSONData = (imp: boolean) => {
setImportToJSON(imp) setImportToJSON(imp)
} }
@ -255,7 +262,7 @@ const InGame = ({locale, changeLocale}) => {
const handleCloseS = () => setShowS(false); const handleCloseS = () => setShowS(false);
const handleShowS = () => setShowS(true); const handleShowS = () => setShowS(true);
const [cptTour, setcptTour] = useState(0); const [cptTour, setcptTour] = useState(1);
const [LastVisible, setLastVisible] = useState(false); const [LastVisible, setLastVisible] = useState(false);
@ -317,6 +324,22 @@ const InGame = ({locale, changeLocale}) => {
const [playTurnSound, setPlayTurnSound] = useState(false); const [playTurnSound, setPlayTurnSound] = useState(false);
const [soundPreference, setSoundPreference] = useState(true); // utilisateur const [soundPreference, setSoundPreference] = useState(true); // utilisateur
const [enteredNumber, setEnteredNumber] = useState(25);
const [enteredNumberIndices, setEnteredNumberIndices] = useState(3);
//@ts-ignore
const handleNumberChange = (event) => {
const newNumber = Math.max(20, Math.min(50, parseInt(event.target.value, 10)));
setEnteredNumber(newNumber);
};
//@ts-ignore
const handleNumberIndicesChange = (event) => {
const newNumber = Math.max(3, Math.min(6, parseInt(event.target.value, 10)));
setEnteredNumberIndices(newNumber);
};
const handleSoundPreferenceChange = () => { const handleSoundPreferenceChange = () => {
setSoundPreference(!soundPreference); setSoundPreference(!soundPreference);
console.log("changement des options du son : "+ soundPreference) console.log("changement des options du son : "+ soundPreference)
@ -346,7 +369,7 @@ const InGame = ({locale, changeLocale}) => {
addToHistory={addToHistory} addToHistory={addToHistory}
solo={IsSolo} solo={IsSolo}
isDaily={isDaily} isDaily={isDaily}
isEasy={isEasy} difficulty={difficulty}
setPlayerTouched={handleSetPlayerTouched} setPlayerTouched={handleSetPlayerTouched}
playerTouched={playerTouched} playerTouched={playerTouched}
setNetwork={setNetworkData} setNetwork={setNetworkData}
@ -366,12 +389,13 @@ const InGame = ({locale, changeLocale}) => {
putGreyBackground={putGreyBackgroud} putGreyBackground={putGreyBackgroud}
putImposssibleGrey={putImposssibleGrey} putImposssibleGrey={putImposssibleGrey}
handleTurn={handleTurn} handleTurn={handleTurn}
lang={locale}/> lang={locale}
setChangeGraph={setChangeGraphData}/>
</div> </div>
{playTurnSound && <audio src={turnSound} autoPlay />} {playTurnSound && <audio src={turnSound} autoPlay />}
{IsSolo && !isDaily && {IsSolo && (!isDaily || difficulty !== "hard") &&
<div className='nbLaps' style={{ <div className='nbLaps' style={{
backgroundColor: theme.colors.primary, backgroundColor: theme.colors.primary,
borderColor: theme.colors.secondary borderColor: theme.colors.secondary
@ -380,7 +404,7 @@ const InGame = ({locale, changeLocale}) => {
</div> </div>
} }
{(!isDaily || (isDaily && isEasy)) && {(!isDaily || (isDaily && (difficulty==="easy" || difficulty==="intermediate"))) &&
<div className='historique' id="history-container"> <div className='historique' id="history-container">
{history.map((item, index) => ( {history.map((item, index) => (
<div key={index}>{item}</div> <div key={index}>{item}</div>
@ -402,6 +426,7 @@ const InGame = ({locale, changeLocale}) => {
<div className='menuGame'> <div className='menuGame'>
<div className='resetDiv'> <div className='resetDiv'>
<button className='button' <button className='button'
style={{ style={{
@ -423,6 +448,8 @@ const InGame = ({locale, changeLocale}) => {
</button> </button>
</div> </div>
@ -514,15 +541,67 @@ const InGame = ({locale, changeLocale}) => {
<Offcanvas show={showS} <Offcanvas show={showS}
onHide={handleCloseS} onHide={handleCloseS}
placement='top' placement='top'
style={{height: '30%', width: '30%', left: '70%' }}> style={{height: '60%', width: '30%', left: '70%' }}>
<Offcanvas.Header closeButton> <Offcanvas.Header closeButton>
<Offcanvas.Title><img src={Param} alt='param'/> <FormattedMessage id='param'/></Offcanvas.Title> <Offcanvas.Title><img src={Param} alt='param'/> <FormattedMessage id='param'/></Offcanvas.Title>
</Offcanvas.Header> </Offcanvas.Header>
<Offcanvas.Body> <Offcanvas.Body >
<label style={{ display:'flex'}}> <div style={{display: "flex", justifyContent: "center", flexDirection: "column", alignItems: "center"}}>
<Switch checked={soundPreference} onChange={handleSoundPreferenceChange}/> <label style={{ display:'flex'}}>
<p style={{ marginLeft:'20px'}}><FormattedMessage id='sfx'/></p> <Switch checked={soundPreference} onChange={handleSoundPreferenceChange}/>
</label> <p style={{ marginLeft:'20px'}}><FormattedMessage id='sfx'/></p>
</label>
{IsSolo &&
<div className='nbNodeDiv'>
<label htmlFor="numberInput">Sélectionner le nombre de noeuds (entre 20 et 50) :</label>
<div>
<button className='valuebutton' onClick={() => { if (enteredNumber>20) setEnteredNumber(enteredNumber-1)}}
style={{borderColor:theme.colors.secondary}}> - </button>
<input
// type="number"
style={{textAlign:'center'}}
id="numberInput"
disabled
value={enteredNumber}
onChange={handleNumberChange}
min={20}
max={60}/>
<button className='valuebutton' onClick={() => { if (enteredNumber<50) setEnteredNumber(enteredNumber+1)}}
style={{borderColor:theme.colors.secondary}}> + </button>
</div>
<button onClick={() => {setHistory([]); changeGraph(enteredNumber, enteredNumberIndices)}}
style={{
backgroundColor: theme.colors.tertiary,
borderColor: theme.colors.secondary,
}}>Valider</button>
</div>}
{IsSolo &&
<div className='nbNodeDiv'>
<label htmlFor="numberInput">Sélectionner le nombre d'indices (entre 3 et 6) :</label>
<div>
<button className='valuebutton' onClick={() => { if (enteredNumberIndices>3) setEnteredNumberIndices(enteredNumberIndices-1)}}
style={{borderColor:theme.colors.secondary}}> - </button>
<input
// type="number"
style={{textAlign:'center'}}
id="numberInput"
disabled
value={enteredNumberIndices}
onChange={handleNumberIndicesChange}
min={3}
max={6}/>
<button className='valuebutton' onClick={() => { if (enteredNumberIndices<6) setEnteredNumberIndices(enteredNumberIndices+1)}}
style={{borderColor:theme.colors.secondary}}> + </button>
</div>
<button onClick={() => {setHistory([]); changeGraph(enteredNumber, enteredNumberIndices)}}
style={{
backgroundColor: theme.colors.tertiary,
borderColor: theme.colors.secondary,
}}>Valider</button>
</div>}
</div>
</Offcanvas.Body> </Offcanvas.Body>
</Offcanvas> </Offcanvas>
</div> </div>

@ -58,7 +58,7 @@ function Lobby() {
const theme=useTheme(); const theme=useTheme();
const navigate = useNavigate(); const navigate = useNavigate();
const { indices, setIndicesData, indice, setIndiceData, person, setPersonData, personNetwork, setPersonNetworkData, players, setPlayersData, setActualPlayerIndexData, setTurnPlayerIndexData, setRoomData, setNodesData } = useGame(); const { indices, setIndicesData, setGameStartData, indice, setIndiceData, person, setPersonData, personNetwork, setPersonNetworkData, players, setPlayersData, setActualPlayerIndexData, setTurnPlayerIndexData, setRoomData, setNodesData } = useGame();
const {user, setUserData, manager, login} = useAuth() const {user, setUserData, manager, login} = useAuth()
let first = true let first = true
@ -139,6 +139,7 @@ function Lobby() {
setPersonData(choosenOne) setPersonData(choosenOne)
setPersonNetworkData(network) setPersonNetworkData(network)
setIndicesData(choosenIndices) setIndicesData(choosenIndices)
setGameStartData(true)
first = true first = true
gameStarted = true gameStarted = true
//socket.off("player left") //socket.off("player left")
@ -177,6 +178,7 @@ function Lobby() {
setPersonData(choosenOne) setPersonData(choosenOne)
setPersonNetworkData(networkPerson) setPersonNetworkData(networkPerson)
setIndicesData(choosenIndices) setIndicesData(choosenIndices)
setGameStartData(true)
first = true first = true
gameStarted = true gameStarted = true
navigate(`${basePath}/game?solo=false&daily=false`) navigate(`${basePath}/game?solo=false&daily=false`)
@ -187,7 +189,6 @@ function Lobby() {
for (const p of tab.tab){ for (const p of tab.tab){
tmpTab.push(JSONParser.JSONToPlayer(p)) tmpTab.push(JSONParser.JSONToPlayer(p))
} }
console.log(tmpTab);
setPlayersData(tmpTab); setPlayersData(tmpTab);
}); });
@ -209,7 +210,6 @@ function Lobby() {
for (const p of tab.tab){ for (const p of tab.tab){
tmpTab.push(JSONParser.JSONToPlayer(p)) tmpTab.push(JSONParser.JSONToPlayer(p))
} }
console.log(tmpTab)
setPlayersData(tmpTab) setPlayersData(tmpTab)
}) })

@ -43,7 +43,7 @@ function NewPlay() {
const theme=useTheme() const theme=useTheme()
const {isLoggedIn, login, user, setUserData, manager } = useAuth(); const {isLoggedIn, login, user, setUserData, manager } = useAuth();
const {setDailyEnigmeData, setIndicesData, setPersonData, setPersonNetworkData } = useGame() const {setDailyEnigmeData, setIndicesData, setPersonData, setPersonNetworkData, setGameStartData } = useGame()
const target = useRef(null); const target = useRef(null);
@ -51,6 +51,7 @@ function NewPlay() {
cptNavigation++ cptNavigation++
if (cptNavigation % 2 == 0){ if (cptNavigation % 2 == 0){
if (navigationType.toString() == "POP"){ if (navigationType.toString() == "POP"){
first=true
socket.emit("player quit") socket.emit("player quit")
} }
} }
@ -100,6 +101,7 @@ function NewPlay() {
setPersonNetworkData(networkPerson) setPersonNetworkData(networkPerson)
setIndicesData(choosenIndices) setIndicesData(choosenIndices)
setIndicesData(choosenIndices) setIndicesData(choosenIndices)
setGameStartData(true)
navigate(`${basePath}/game?solo=true&daily=false`); navigate(`${basePath}/game?solo=true&daily=false`);
} }
@ -162,8 +164,28 @@ function NewPlay() {
setPersonNetworkData(networkPerson) setPersonNetworkData(networkPerson)
setIndicesData(choosenIndices) setIndicesData(choosenIndices)
setIndicesData(choosenIndices) setIndicesData(choosenIndices)
setGameStartData(true)
navigate(`${basePath}/game?solo=true&daily=true&difficulty=easy`);
setShowOverlay(false);
};
const handleStartMediumGame = () => {
navigate(`${basePath}/game?solo=true&daily=true&easy=true`); //* Mode facile
//todo différencier les deux
const [networkPerson, choosenPerson, choosenIndices] = GameCreator.CreateGame(3, 30)
setPersonData(choosenPerson)
setPersonNetworkData(networkPerson)
setIndicesData(choosenIndices)
setGameStartData(true)
navigate(`${basePath}/game?solo=true&daily=true&difficulty=intermediate`);
if (first){
first = false
const map = EnigmeDuJourCreator.createEnigme(networkPerson, choosenIndices, choosenPerson, Stub.GenerateIndice())
setDailyEnigmeData(map)
}
setShowOverlay(false); setShowOverlay(false);
}; };
@ -175,13 +197,13 @@ function NewPlay() {
setPersonData(choosenPerson) setPersonData(choosenPerson)
setPersonNetworkData(networkPerson) setPersonNetworkData(networkPerson)
setIndicesData(choosenIndices) setIndicesData(choosenIndices)
setIndicesData(choosenIndices) setGameStartData(true)
if (first){ if (first){
first = false first = false
const map = EnigmeDuJourCreator.createEnigme(networkPerson, choosenIndices, choosenPerson, Stub.GenerateIndice()) const map = EnigmeDuJourCreator.createEnigme(networkPerson, choosenIndices, choosenPerson, Stub.GenerateIndice())
setDailyEnigmeData(map) setDailyEnigmeData(map)
} }
navigate(`${basePath}/game?solo=true&daily=true&easy=false`); navigate(`${basePath}/game?solo=true&daily=true&difficulty=hard`);
setShowOverlay(false); setShowOverlay(false);
}; };
@ -206,7 +228,7 @@ function NewPlay() {
<div className='NewbuttonGroupVertical'> <div className='NewbuttonGroupVertical'>
<button onClick={launchMastermind} className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> <FormattedMessage id="play.jouerseul"/> </button> <button onClick={launchMastermind} className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> <FormattedMessage id="play.jouerseul"/> </button>
<button ref={target} onClick={launchEngimeJour} className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> <FormattedMessage id="play.enigme"/> </button> <button ref={target} onClick={launchEngimeJour} className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> <FormattedMessage id="play.enigme"/> </button>
<Overlay show={showOverlay} target={target.current} placement="bottom" rootClose={true} rootCloseEvent='click'> <Overlay show={showOverlay} target={target.current} placement="bottom" rootClose={true} rootCloseEvent='click' onHide={() => setShowOverlay(false)}>
{({ placement, arrowProps, show: _show, popper, ...props }) => ( {({ placement, arrowProps, show: _show, popper, ...props }) => (
<div <div
{...props} {...props}
@ -219,7 +241,7 @@ function NewPlay() {
<ButtonGroup aria-label="difficulty"> <ButtonGroup aria-label="difficulty">
<Button onClick={handleStartEasyGame}><FormattedMessage id='play.enigme.easy'/></Button> <Button onClick={handleStartEasyGame}><FormattedMessage id='play.enigme.easy'/></Button>
<Button onClick={handleStartEasyGame}><FormattedMessage id='play.enigme.medium'/></Button> <Button onClick={handleStartMediumGame}><FormattedMessage id='play.enigme.medium'/></Button>
<Button onClick={handleStartHardGame}><FormattedMessage id='play.enigme.hard'/></Button> <Button onClick={handleStartHardGame}><FormattedMessage id='play.enigme.hard'/></Button>
</ButtonGroup> </ButtonGroup>
</div> </div>

@ -29,7 +29,7 @@ class EnigmeDuJourCreator{
possibleIndices.forEach((possibleIndice, index) =>{ possibleIndices.forEach((possibleIndice, index) =>{
const tester = IndiceTesterFactory.Create(possibleIndice) const tester = IndiceTesterFactory.Create(possibleIndice)
if (tester.Works(person)){ if (tester.Works(person)){
const t = veryTmpIndice.findIndex((tmpIndice) => tmpIndice.getId() == possibleIndice.getId()) const t = veryTmpIndice.findIndex((tmpIndice) => tmpIndice.getId() == possibleIndice.getId())
if (t != -1){ if (t != -1){
veryTmpIndice.splice(t, 1) veryTmpIndice.splice(t, 1)
} }
@ -58,10 +58,7 @@ class EnigmeDuJourCreator{
} }
possibleIndices = [...tmpPossibleIndices] possibleIndices = [...tmpPossibleIndices]
modifiedPersons.push(choosenPair) modifiedPersons.push(choosenPair)
console.log(possibleIndices)
} }
console.log("choosenIndice => " + choosenIndice.ToString("fr"))
console.log("possibleIndices => " + possibleIndices[0].ToString("fr"))
modifiedPersons.forEach((pair) =>{ modifiedPersons.forEach((pair) =>{
map.get(pair.first.getId())?.push(new Pair(choosenIndice, pair.second)) map.get(pair.first.getId())?.push(new Pair(choosenIndice, pair.second))
}) })

Loading…
Cancel
Save