serveur pour le jeu presque fini

pull/56/head
Thomas Chazot 1 year ago
parent 980784b270
commit e0d3c291da

@ -13,7 +13,6 @@ const ChoiceBar = () => {
function askPlayer(playerId: string){
if (nodeId !== null){
console.log("CLICK")
socket.emit("ask player", nodeId, playerId, players.find((p) => p.id === socket.id))
}
}
@ -23,29 +22,28 @@ const ChoiceBar = () => {
const person = personNetwork?.getPersons().find((p) => p.getId() == nodeId)
if (person != undefined){
const indiceTester = IndiceTesterFactory.Create(indices[actualPlayerIndex])
let nextPlayerIndex = actualPlayerIndex + 1
if (nextPlayerIndex == players.length){
nextPlayerIndex = 0
}
let playerIndex = actualPlayerIndex + 1
if (indiceTester.Works(person)){
socket.emit("node checked", nodeId, true, positionToColor(actualPlayerIndex), room, actualPlayerIndex + 1)
socket.emit("node checked", nodeId, true, positionToColor(actualPlayerIndex), room, nextPlayerIndex)
while(playerIndex != actualPlayerIndex){
const tester = IndiceTesterFactory.Create(indices[playerIndex])
const works = tester.Works(person)
socket.emit("node checked", nodeId, works, positionToColor(playerIndex), room, actualPlayerIndex + 1)
if (!works){
break
}
playerIndex ++
if (playerIndex == players.length){
playerIndex = 0
}
const tester = IndiceTesterFactory.Create(indices[playerIndex])
const works = tester.Works(person)
socket.emit("node checked", nodeId, works, positionToColor(playerIndex), room, nextPlayerIndex)
if(!works){
return
}
playerIndex ++
}
else{
console.log("Ne marche pas")
console.log(person)
}
}
console.log("CLICK")
//socket.emit("ask player", nodeId, playerId, players.find((p) => p.id === socket.id))
}
}

@ -33,9 +33,9 @@ let first = true
const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleShowTurnBar}) => {
const { indices, indice, person, personNetwork, setNodeIdData, players, askedPersons, setActualPlayerIndexData, room, actualPlayerIndex } = useGame();
const { indices, indice, person, personNetwork, setNodeIdData, players, askedPersons, setActualPlayerIndexData, room, actualPlayerIndex, turnPlayerIndex } = useGame();
let playerIndex: number = actualPlayerIndex
let playerIndex: number = turnPlayerIndex
let index = 0
for (let i=0; i<players.length; i++){
if(players[i].id == socket.id){
@ -44,14 +44,14 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
}
}
let thisPlayerIndex = index
if (playerIndex == thisPlayerIndex){
handleShowTurnBar(true)
}
if (first){
first = false
console.log(indice)
setActualPlayerIndexData(index)
if (playerIndex == thisPlayerIndex){
handleShowTurnBar(true)
}
indices.forEach(i => {
console.log(i.ToString("en"))
});
@ -104,11 +104,13 @@ const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick, handleS
onNodeClick(false)
playerIndex = newPlayerIndex
networkData.nodes.update({id: id, label: node.label + colorToEmoji(color, works)})
if (playerIndex == thisPlayerIndex){
console.log(playerIndex + " => " + thisPlayerIndex)
if (playerIndex === thisPlayerIndex){
handleShowTurnBar(true)
}
else{
handleShowTurnBar(false)
console.log("je passe bien ici ?????")
}
}
lastAskingPlayer = 0

@ -13,6 +13,7 @@ interface GameContextProps {
nodeId: number | null
askedPersons: Person[];
actualPlayerIndex: number;
turnPlayerIndex: number;
room: string;
setIndicesData: (newIndices: Indice[]) => void;
setIndiceData: (newIndice: Indice) => void;
@ -22,6 +23,7 @@ interface GameContextProps {
setNodeIdData: (newId: number) => void;
setAskedPersonsData: (newAskedPersons: Person[]) => void;
setActualPlayerIndexData: (newActualPlayerIndex: number) => void;
setTurnPlayerIndexData: (newTurnPlayerIndex: number) => void;
setRoomData: (newRoom: string) => void;
}
@ -40,6 +42,7 @@ export const GameProvider: React.FC<GameProviderProps> = ({ children }) => {
const [nodeId, setNodeId] = useState<number | null>(null);
const [askedPersons, setAskedPersons] = useState<Person[]>([])
const [actualPlayerIndex, setActualPlayerIndex] = useState<number>(-1)
const [turnPlayerIndex, setTurnPlayerIndex] = useState<number>(-1)
const [room, setRoom] = useState<string>("")
@ -76,12 +79,16 @@ export const GameProvider: React.FC<GameProviderProps> = ({ children }) => {
setActualPlayerIndex(newActualPlayerIndex)
}
const setTurnPlayerIndexData = (newTurnPlayerIndex: number) =>{
setTurnPlayerIndex(newTurnPlayerIndex)
}
const setRoomData = (newRoom: string) =>{
setRoom(newRoom)
}
return (
<GameContext.Provider value={{ indices, setIndicesData, indice, setIndiceData, person, setPersonData, personNetwork, setPersonNetworkData, players, setPlayersData, nodeId, setNodeIdData, askedPersons, setAskedPersonsData, actualPlayerIndex, setActualPlayerIndexData, room, setRoomData }}>
<GameContext.Provider value={{ indices, setIndicesData, indice, setIndiceData, person, setPersonData, personNetwork, setPersonNetworkData, players, setPlayersData, nodeId, setNodeIdData, askedPersons, setAskedPersonsData, actualPlayerIndex, setActualPlayerIndexData, turnPlayerIndex, setTurnPlayerIndexData, room, setRoomData }}>
{children}
</GameContext.Provider>
);

@ -50,8 +50,10 @@ const InGame = ({locale, changeLocale}) => {
const handleShowTurnBar = (shouldShowTurnBar: boolean) => {
console.log("je passe bien ici avec : " + shouldShowTurnBar)
setShowTurnBar(shouldShowTurnBar);
};
/* offcanvas */
//? faire une fonction pour close et show en fonction de l'etat du canva ?
//? comment faire pour eviter la recopie de tout le code a chaque canvas boostrap ?
@ -107,7 +109,7 @@ const InGame = ({locale, changeLocale}) => {
return (
<div id="mainDiv">
{showTurnBar && <TurnBar />}
{showTurnBar && <TurnBar/>}
<div id='graphDiv'>
<GraphContainer onNodeClick={handleNodeClick} handleShowTurnBar={handleShowTurnBar} />
</div>

@ -31,7 +31,7 @@ function Lobby() {
const navigate = useNavigate();
const { indices, setIndicesData, indice, setIndiceData, person, setPersonData, personNetwork, setPersonNetworkData, players, setPlayersData, setActualPlayerIndexData, setRoomData } = useGame();
const { indices, setIndicesData, indice, setIndiceData, person, setPersonData, personNetwork, setPersonNetworkData, players, setPlayersData, setActualPlayerIndexData, setTurnPlayerIndexData, setRoomData } = useGame();
let first = true
@ -65,7 +65,8 @@ function Lobby() {
if (room != null){
setRoomData(room)
}
setActualPlayerIndexData(playerIndex)
setTurnPlayerIndexData(playerIndex)
setActualPlayerIndexData(index)
setIndiceData(choosenIndices[index])
setPersonData(choosenOne)
setPersonNetworkData(network)

Loading…
Cancel
Save