merge manuel de demo et master

pull/87/head
Pierre Ferreira 1 year ago
parent 7451857b0b
commit 3fb5a514b2

@ -25,6 +25,7 @@ interface MyGraphComponentProps {
addToHistory: (message : string) => void addToHistory: (message : string) => void
solo : boolean solo : boolean
isDaily : boolean isDaily : boolean
isEasy: boolean
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
@ -45,9 +46,9 @@ let lastNodes: NodePerson[] = []
let cptEndgame = 0 let cptEndgame = 0
let firstEnigme = true let firstEnigme = true
let endgame= false let endgame= false
let firstHistory = true
const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange, playerTouched, setPlayerTouched, changecptTour, solo, isDaily, isEasy, addToHistory, showLast, setNetwork, setNetworkEnigme}) => {
const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleShowTurnBar, handleTurnBarTextChange, playerTouched, setPlayerTouched, changecptTour, solo, isDaily, addToHistory, showLast, setNetwork, setNetworkEnigme}) => {
let cptTour: number = 0 let cptTour: number = 0
//* Gestion du temps : //* Gestion du temps :
@ -291,18 +292,28 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
setNetwork(network) setNetwork(network)
if (isDaily){ if (isDaily){
setNetworkEnigme(dailyEnigme) if(!isEasy){
// setNetworkEnigme(dailyEnigme)
dailyEnigme.forEach((pairs, index) => { dailyEnigme.forEach((pairs, index) => {
pairs.forEach((pair) => { pairs.forEach((pair) => {
const i = indices.findIndex((indice) => pair.first.getId() === indice.getId()) const i = indices.findIndex((indice) => pair.first.getId() === indice.getId())
const node = networkData.nodes.get().find((n) => index == n.id) const node = networkData.nodes.get().find((n) => index == n.id)
if (node != undefined){ if (node != undefined){
networkData.nodes.update({id: node.id, label: node.label + positionToEmoji(i, pair.second)}) networkData.nodes.update({id: node.id, label: node.label + positionToEmoji(i, pair.second)})
const test = networkData.nodes.get().find((n) => index == n.id) // const test = networkData.nodes.get().find((n) => index == n.id)
} }
}) })
}); });
} }
else{
if (firstHistory){
firstHistory=false
indices.forEach((indice, index) => {
addToHistory("Indice " + positionToEmoji(index, true) + " : " + indice.ToString("fr"))
})
}
}
}
socket.on("reset graph", () => { socket.on("reset graph", () => {
console.log("reset graph") console.log("reset graph")
@ -438,9 +449,11 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
else { else {
if (firstLap){ if (firstLap){
firstLap=false firstLap=false
if (!isDaily){
addToHistory("<----- [Tour " + 1 +"/"+networkData.nodes.length + "] ----->"); addToHistory("<----- [Tour " + 1 +"/"+networkData.nodes.length + "] ----->");
} }
} }
}
socket.on("put correct background", () =>{ socket.on("put correct background", () =>{
@ -510,6 +523,7 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
askedWrong=false askedWrong=false
askedWrongBot=false askedWrongBot=false
endgame = true endgame = true
firstHistory=true
try{ try{
if(isLoggedIn){ if(isLoggedIn){

@ -72,6 +72,12 @@ const InGame = ({locale, changeLocale}) => {
isDaily=false isDaily=false
} }
let isEasy: boolean = true
const isEasytmp = params.get('easy');
if (isEasytmp == "false"){
isEasy=false
}
//* Historique //* Historique
const [history, setHistory] = useState<string[]>([]); const [history, setHistory] = useState<string[]>([]);
const [showLast, setShowLast] = useState(false) const [showLast, setShowLast] = useState(false)
@ -258,6 +264,7 @@ const InGame = ({locale, changeLocale}) => {
addToHistory={addToHistory} addToHistory={addToHistory}
solo={IsSolo} solo={IsSolo}
isDaily={isDaily} isDaily={isDaily}
isEasy={isEasy}
setPlayerTouched={handleSetPlayerTouched} setPlayerTouched={handleSetPlayerTouched}
playerTouched={playerTouched} playerTouched={playerTouched}
setNetwork={setNetworkData} setNetwork={setNetworkData}
@ -275,7 +282,7 @@ const InGame = ({locale, changeLocale}) => {
</div> </div>
} }
{!isDaily && {(!isDaily || (isDaily && isEasy)) &&
<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>

@ -70,3 +70,28 @@
.lobbyR *{ .lobbyR *{
margin: 20px 10px; margin: 20px 10px;
} }
.valuebutton{
border-radius: 90px;
width: 50px;
height: 50px;
background-color: #fff;
}
.nbNodeDiv{
display: flex;
flex-direction: column;
justify-content: center;
border: solid 2px whitesmoke;
border-radius: 15px;
background-color: white;
width: 70%;
}
.nbNodeDiv div {
display: flex;
justify-content: center;
}

@ -273,18 +273,23 @@ function Lobby() {
)} )}
</Overlay> </Overlay>
<div className='nbNodeDiv'>
<label htmlFor="numberInput">Sélectionner le nombre de noeud (entre 20 et 60) :</label>
<div> <div>
<label htmlFor="numberInput">Séléctionner le nombre de noeud (entre 20 et 60) :</label> <button className='valuebutton' onClick={() => { if (enteredNumber>20) setEnteredNumber(enteredNumber-1)}}
style={{borderColor:theme.colors.secondary}}> - </button>
<input <input
type="number" // type="number"
id="numberInput" id="numberInput"
value={enteredNumber} disabled
value={ "Nombre de noeuds : " + enteredNumber}
onChange={handleNumberChange} onChange={handleNumberChange}
min={20} min={20}
max={60}/> max={60}/>
<p>La valeur saisie : {enteredNumber}</p> <button className='valuebutton' onClick={() => { if (enteredNumber<60) setEnteredNumber(enteredNumber+1)}}
style={{borderColor:theme.colors.secondary}}> + </button>
</div>
</div> </div>
<button className='button' onClick={StartGame} <button className='button' onClick={StartGame}

@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useRef, useState } from 'react';
/* Context */ /* Context */
import { useAuth } from '../Contexts/AuthContext'; import { useAuth } from '../Contexts/AuthContext';
@ -27,6 +27,10 @@ import Stub from '../model/Stub';
import SessionService from '../services/SessionService'; import SessionService from '../services/SessionService';
import { loadImageAsync } from '../ImageHelper'; import { loadImageAsync } from '../ImageHelper';
import { Overlay, ToggleButton, ToggleButtonGroup } from 'react-bootstrap';
import Button from 'react-bootstrap/Button';
import ButtonGroup from 'react-bootstrap/ButtonGroup';
function Play() { function Play() {
let first = true let first = true
@ -35,6 +39,8 @@ function Play() {
const {isLoggedIn, login, user, setUserData, manager } = useAuth(); const {isLoggedIn, login, user, setUserData, manager } = useAuth();
const {setDailyEnigmeData} = useGame() const {setDailyEnigmeData} = useGame()
const target = useRef(null);
useEffect(() => { useEffect(() => {
const fetchUserInformation = async () => { const fetchUserInformation = async () => {
try { try {
@ -124,17 +130,22 @@ function Play() {
function launchEngimeJour(){ function launchEngimeJour(){
const [networkPerson, choosenPerson, choosenIndices] = GameCreator.CreateGame(3, 30) //* overlay
setPersonData(choosenPerson)
setPersonNetworkData(networkPerson) if (!showOverlay)setShowOverlay(true)
setIndicesData(choosenIndices) else setShowOverlay(true)
setIndicesData(choosenIndices)
if (first){ // const [networkPerson, choosenPerson, choosenIndices] = GameCreator.CreateGame(3, 30)
first = false // setPersonData(choosenPerson)
const map = EnigmeDuJourCreator.createEnigme(networkPerson, choosenIndices, choosenPerson, Stub.GenerateIndice()) // setPersonNetworkData(networkPerson)
setDailyEnigmeData(map) // setIndicesData(choosenIndices)
} // setIndicesData(choosenIndices)
navigate('/game?solo=true&daily=true'); // if (first){
// first = false
// const map = EnigmeDuJourCreator.createEnigme(networkPerson, choosenIndices, choosenPerson, Stub.GenerateIndice())
// setDailyEnigmeData(map)
// }
// navigate('/game?solo=true&daily=true');
} }
@ -160,6 +171,47 @@ function Play() {
} }
}, [room, navigate]); }, [room, navigate]);
const [showOverlay, setShowOverlay] = useState(false);
const [selectedDifficulty, setSelectedDifficulty] = useState(null);
//@ts-ignore
const handleDifficultyChange = (value) => {
setSelectedDifficulty(value);
};
const handleStartEasyGame = () => {
//* Mode facile
const [networkPerson, choosenPerson, choosenIndices] = GameCreator.CreateGame(3, 30)
setPersonData(choosenPerson)
setPersonNetworkData(networkPerson)
setIndicesData(choosenIndices)
setIndicesData(choosenIndices)
navigate('/game?solo=true&daily=true&easy=true');
setShowOverlay(false);
};
const handleStartHardGame = () => {
//* Mode difficile
//todo différencier les deux
const [networkPerson, choosenPerson, choosenIndices] = GameCreator.CreateGame(3, 30)
setPersonData(choosenPerson)
setPersonNetworkData(networkPerson)
setIndicesData(choosenIndices)
setIndicesData(choosenIndices)
if (first){
first = false
const map = EnigmeDuJourCreator.createEnigme(networkPerson, choosenIndices, choosenPerson, Stub.GenerateIndice())
setDailyEnigmeData(map)
}
navigate('/game?solo=true&daily=true&easy=false');
setShowOverlay(false);
};
return ( return (
<div className="MainContainer"> <div className="MainContainer">
@ -182,7 +234,28 @@ function Play() {
</div> </div>
<div className='buttonGroupVertical'> <div className='buttonGroupVertical'>
<button onClick={launchMastermind} className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> Jouer seul </button> <button onClick={launchMastermind} className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> Jouer seul </button>
<button onClick={launchEngimeJour} className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> Résoudre une énigme</button> <button ref={target} onClick={launchEngimeJour} className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> Résoudre une énigme</button>
<Overlay show={showOverlay} target={target.current} placement="bottom" rootClose={true} rootCloseEvent='click'>
{({ placement, arrowProps, show: _show, popper, ...props }) => (
<div
{...props}
style={{
backgroundColor: theme.colors.secondary,
padding: '2px 10px',
borderRadius: 3,
...props.style,
}}>
<ButtonGroup aria-label="difficulty">
<Button onClick={handleStartEasyGame}>Facile</Button>
<Button onClick={handleStartHardGame}>Difficile</Button>
</ButtonGroup>
</div>
)}
</Overlay>
<button onClick={createLobby} className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> Créer une partie </button> <button onClick={createLobby} className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> Créer une partie </button>
<button className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> Rejoindre </button> <button className="ButtonNav" style={{backgroundColor: theme.colors.primary, borderColor: theme.colors.secondary}}> Rejoindre </button>

Loading…
Cancel
Save