I am creating a small game (Android) to play me some more friends of mine. The game is called "Cops and Thieves". At least it is necessary to have 4 players in which one of them will be the POLICE, another will be the CRIMINAL, another will be the DAMA and the rest will be CIVIS (Normal People).
I'm currently using Socket.IO to connect players and communicate. But at the time of giving a profession to each player, I came across a problem. This is the part of the code he creates and sends to the player his profession:
var PoliceAlready,CriminalAlready,DamaAlready = false;
for(var SI in clients) {
var socket = clients[SI];
var profissaoT;
if(!PoliceAlready){
profissaoT="POLÍCIA";
PoliceAlready = true;
}else if(!CriminalAlready){
profissaoT="CRIMINOSO";
CriminalAlready = true;
}else if(!DamaAlready){
profissaoT="DAMA";
DamaAlready = true;
}else{
profissaoT="CIVÍL";
}
socket.emit('profissao', profissaoT);
}
But it will have to have a Police, Criminal and Lady and these can not be repeated. From the code above it will do this, but the for () function will execute the data of the array "clients" in order, which means that it always has the same profession and the objective is always to re-execute this function give the profession, always be random!
var clients = {'/#53h2bn324buh234', '/#h32h324h5234uh2', '/#3pm3b4ij234'};
I would like to thank you for taking the time to help me, or at least to try.