-
Notifications
You must be signed in to change notification settings - Fork 2
#16 Game Information Exchange
Loop Diagramm
If the lobby is full (4 Players), the Server send to the cleints the event io.in(room.id).emit('START_GAME', room.id, room.players)
. The second parameter (room) contains the room.players object.
"A5MfiQGFeJwNiY9SAAAF": {
"socket": "A5MfiQGFeJwNiY9SAAAF",
"playerIndex": 1,
"money": 1000000,
"position": 1,
"stocks": {
"HardSteel_PLC": 0,
"ShortCircuit_PLC": 0,
"DryOil_PLC": 0
},
"yourTurn": false,
"dice_1": 0,
"dice_2": 0,
"dice_Count": 0
},
"fGATPLFoFazxs7VNAAAH": {
"socket": "fGATPLFoFazxs7VNAAAH",
"playerIndex": 2,
"money": 1000000,
"position": 2,
"stocks": {
"HardSteel_PLC": 0,
"ShortCircuit_PLC": 0,
"DryOil_PLC": 0
},
"yourTurn": false,
"dice_1": 0,
"dice_2": 0,
"dice_Count": 0
},
"MZK8E_21DhjleWaPAAAD": {
"socket": "MZK8E_21DhjleWaPAAAD",
"playerIndex": 3,
"money": 1000000,
"position": 3,
"stocks": {
"HardSteel_PLC": 0,
"ShortCircuit_PLC": 0,
"DryOil_PLC": 0
},
"yourTurn": false,
"dice_1": 0,
"dice_2": 0,
"dice_Count": 0
},
"oQV9u7TyN6XH1wcIAAAE": {
"socket": "oQV9u7TyN6XH1wcIAAAE",
"playerIndex": 4,
"money": 1000000,
"position": 4,
"stocks": {
"HardSteel_PLC": 0,
"ShortCircuit_PLC": 0,
"DryOil_PLC": 0
},
"yourTurn": false,
"dice_1": 0,
"dice_2": 0,
"dice_Count": 0
}
}
The next step is to choose the two stocks. For that, the client will create a object ` const stock = { HardSteel_PLC: 2, ShortCircuit_PLC: 0, DryOil_PLC : 0 }
and send it to the server,
socket.emit("CHOSE_STOCKS", lobby, stock)
If all clients have selected their stocks the server send an event to the clients with the updated players object.
socket.on('ROLE_THE_HIGHEST_DICE', (room)
After this event the client will roll the highest dice and send the result bach to the server.
The result should be saved in an array.
diceCounts = [dice1, dice2]
io.in(room).emit('ROLE_THE_HIGHEST_DICE', rooms[room].players);
If all clients have send their reults to the server, the server will check if we have one winner.
-
Case One Winner The server will send an event
socket.on('START_ROUND', (data, winner)
data= players Object, winner = winner ID Round will start -
Case Two ore more Winners The server will send an event
socket.on('ROLE_THE_HIGHEST_DICE_AGAIN', (data, winner)
data = players object, winner = winner Array Loop the array and check if the socketID eqauls your id, if this is true roll the dice again and emit to the server.socket.emit('ROLE_THE_HIGHEST_DICE_AGAIN', lobby, diceCounts, winner.length)
This loop will last unit we have an winner.