diff --git a/webapp/src/components/game/LobbyGame.tsx b/webapp/src/components/game/LobbyGame.tsx index e96d3c0..8e06c22 100644 --- a/webapp/src/components/game/LobbyGame.tsx +++ b/webapp/src/components/game/LobbyGame.tsx @@ -1,6 +1,7 @@ -import { FC } from 'react' +import { FC, useRef } from 'react' import { Player } from './GameSinglePlayer'; import './LobbyGame.scss'; +import { TableBody } from '@mui/material'; interface LobbyGameProps { setPlayers: (players:Player[]) => void; @@ -9,15 +10,32 @@ interface LobbyGameProps { isFetched: boolean; } -const LobbyGame: FC = ({setPlayers, players, setCurrentStage, isFetched}) => { + +const LobbyGame: FC = ({setPlayers, players, setCurrentStage, isFetched}) => { + function* botCounter(){ + let count=0; + while(true){ + count++; + yield count; + } + + }; + const botGen = useRef(botCounter()); // Assign the function to the variable const addBotPlayer = () => { if (players.length < 4) { - setPlayers([...players, { username: `Bot ${players.length + 1}`, points: 0, isBot: true }]); + setPlayers([...players, { username: `Bot ${botGen.current.next().value}`, + points: 0, isBot: true }]); // Call next() on the generator instance } }; + + + + + + const deletePlayer = (playerIndex: number) => { const newPlayers = [...players]; newPlayers.splice(playerIndex, 1); @@ -43,11 +61,9 @@ const LobbyGame: FC = ({setPlayers, players, setCurrentStage, is {player.username} Total points: {player.points} - {player.isBot ? ( - - ) : ( - - )} + {player.isBot && ( + + )} ))}