ajout du lien d'invitation et selecteur de nombre de noeud dans lobby

pull/87/head
Pierre Ferreira 1 year ago
parent 8f7188a2a5
commit 7451857b0b

@ -60,3 +60,13 @@
display: flex; display: flex;
justify-content: center; justify-content: center;
} }
.lobbyR{
display: flex;
flex-direction: column;
align-items: center;
}
.lobbyR *{
margin: 20px 10px;
}

@ -42,6 +42,10 @@ import { socket } from "../SocketConfig";
import { random } from 'lodash'; import { random } from 'lodash';
import SessionService from '../services/SessionService'; import SessionService from '../services/SessionService';
import { useRef } from 'react';
import Button from 'react-bootstrap/Button';
import Overlay from 'react-bootstrap/Overlay';
let gameStarted = false let gameStarted = false
@ -62,7 +66,14 @@ function Lobby() {
socket.emit("lobby joined", room, new EasyBot("botId" + Math.floor(Math.random() * 1000), "Bot" + Math.floor(Math.random() * 100), "").toJson()) socket.emit("lobby joined", room, new EasyBot("botId" + Math.floor(Math.random() * 1000), "Bot" + Math.floor(Math.random() * 100), "").toJson())
} }
//* nb Node
const [enteredNumber, setEnteredNumber] = useState(20);
//@ts-ignore
const handleNumberChange = (event) => {
const newNumber = Math.max(20, Math.min(60, parseInt(event.target.value, 10)));
setEnteredNumber(newNumber);
};
useEffect(() => { useEffect(() => {
if (first){ if (first){
@ -146,7 +157,7 @@ function Lobby() {
function StartGame(){ function StartGame(){
const [networkPerson, choosenPerson, choosenIndices] = GameCreator.CreateGame(players.length, 30) const [networkPerson, choosenPerson, choosenIndices] = GameCreator.CreateGame(players.length, enteredNumber)
setPersonData(choosenPerson) setPersonData(choosenPerson)
setPersonNetworkData(networkPerson) setPersonNetworkData(networkPerson)
setIndicesData(choosenIndices) setIndicesData(choosenIndices)
@ -159,6 +170,21 @@ function Lobby() {
socket.emit('network created', JSON.stringify(networkPerson, null, 2), JSON.stringify(choosenPerson), JSON.stringify(choosenIndices), room, start); socket.emit('network created', JSON.stringify(networkPerson, null, 2), JSON.stringify(choosenPerson), JSON.stringify(choosenIndices), room, start);
} }
const copyGameLink = () => {
setShow(!show)
const gameLink = "http://localhost:3000/lobby?room="+ room;
navigator.clipboard.writeText(gameLink)
.then(() => {
console.log('Lien copié avec succès !');
})
.catch((err) => {
console.error('Erreur lors de la copie du lien :', err);
});
};
const [show, setShow] = useState(false);
const target = useRef(null);
return ( return (
<div className='lobby-container'> <div className='lobby-container'>
<div className='left-part'> <div className='left-part'>
@ -191,7 +217,7 @@ function Lobby() {
<div className="lobby-vertical-divider" style={{backgroundColor: theme.colors.secondary}}></div> <div className="lobby-vertical-divider" style={{backgroundColor: theme.colors.secondary}}></div>
<div className='right-part'> <div className='right-part'>
<div className='title-param-div'> {/* <div className='title-param-div'>
<img src={param} alt="param"/> <img src={param} alt="param"/>
<h2>Paramètre de la partie</h2> <h2>Paramètre de la partie</h2>
</div> </div>
@ -200,21 +226,78 @@ function Lobby() {
<li><h4>paramètre super important pour la partie</h4></li> <li><h4>paramètre super important pour la partie</h4></li>
<li><h4>paramètre super important pour la partie</h4></li> <li><h4>paramètre super important pour la partie</h4></li>
<li><h4>paramètre super important pour la partie</h4></li> <li><h4>paramètre super important pour la partie</h4></li>
<li><h4>Niveau des bots : Facile </h4></li> {/* mettre un dropdown ou un swiper */} <li><h4>Niveau des bots : Facile </h4></li>
<li><h4>Thèmes : basique </h4></li> {/* mettre un dropdown*/} <li><h4>Thèmes : basique </h4></li> */}
{ {
//? mettre un timer pour chaques personne ? //? mettre un timer pour chaques personne ?
//? indice avancé ? ==> négation, voisin du 2e degré etc. //? indice avancé ? ==> négation, voisin du 2e degré etc.
} }
</ul> {/* </ul> */}
{/* <center > {/* <center >
<button className='buttonNabImg' onClick={StartGame}> <button className='buttonNabImg' onClick={StartGame}>
<img src={cible} alt="Button Image" height="50" width="50" /> <img src={cible} alt="Button Image" height="50" width="50" />
<p>{"la chasse !"}</p> <p>{"la chasse !"}</p>
</button> </button>
</center> */} </center> */}
<div className='lobbyR'
style={{flexDirection:'column',
alignItems:'space-around'}}>
<h3>Bienvenue dans votre lobby !</h3>
<p>Attendez que tous vos amis rejoignent avant de lancer la partie.</p>
{/* Bouton pour copier le lien */}
<Button variant="primary" ref={target} onClick={copyGameLink}>
Inviter des amis
</Button>
<Overlay target={target.current} show={show} placement="top">
{({
placement: _placement,
arrowProps: _arrowProps,
show: _show,
popper: _popper,
hasDoneInitialMeasure: _hasDoneInitialMeasure,
...props
}) => (
<div
{...props}
style={{
position: 'absolute',
backgroundColor: theme.colors.secondary,
padding: '2px 10px',
color: 'white',
borderRadius: 3,
...props.style,
}}
>
Lien copié
</div>
)}
</Overlay>
<div>
<label htmlFor="numberInput">Séléctionner le nombre de noeud (entre 20 et 60) :</label>
<input
type="number"
id="numberInput"
value={enteredNumber}
onChange={handleNumberChange}
min={20}
max={60}/>
<p>La valeur saisie : {enteredNumber}</p>
</div>
<div className='centerDivH'> <button className='button' onClick={StartGame}
style={{
backgroundColor: theme.colors.tertiary,
borderColor: theme.colors.secondary,
width: 'auto',
height: 'auto'
}}>
Démarrer la partie !
</button>
</div>
{/* <div className='centerDivH'>
<button className='button' onClick={StartGame} <button className='button' onClick={StartGame}
style={{ style={{
backgroundColor: theme.colors.tertiary, backgroundColor: theme.colors.tertiary,
@ -222,7 +305,7 @@ function Lobby() {
}}> }}>
<img src={cible} alt="cible" height="40"/> <img src={cible} alt="cible" height="40"/>
</button> </button>
</div> </div> */}
</div> </div>
</div> </div>
); );

Loading…
Cancel
Save