5
I am creating a small game (Android) to play I 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 LADY and the rest will be CIVIL (Normal People).
I am currently using Socket.IO to make the connection between players and communication. But when it came to giving each player a profession, I ran into a problem. This is the part of the code in which 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 you must have a police officer, a criminal and a lady, and they must never happen again. Apart from the above code it will do just that, but the function for() will execute the data of the array "clients" in order, which makes it always have the same profession and the goal is to always return to perform this function of giving the profession, always be randomly!
var clients = {'/#53h2bn324buh234', '/#h32h324h5234uh2', '/#3pm3b4ij234'};
I would like to thank those who are willing to help me, or at least try.
Lucas, I may have misunderstood the question and the game, but I think I also played this game :P . But so to someone who gets to know the teachers of all, right? Shouldn’t each one just know his own? Anyway +1
– Miguel
In real life yes @Miguel! You say this because you feel that the professions should be allocated on the server?
– BrTkCa
Yes, at least I thought I did. So that there will be no conflicts and each one only know his... Very soon we see
– Miguel
You’re right. It actually displays in HTML only to make the distribution of the papers visible. And I did in javascript to show the logic :) in case just pass to Node, or PHP to be more suitable.
– BrTkCa
It worked Lucas, I did the respective tests and it’s exactly as I wanted!
– Bruno Miguel
http://image.prntscr.com/image/74c41261bcb64f92bf2e1aa2862ddcec.png
– Bruno Miguel
Nice guy! I’m happy to help :)
– BrTkCa
Miguel, the chosen profession will be sent only to that same player with a Socket Emit. The game I am creating is based on Sockets (Socket.IO,Nodejs,...) with an Android application (Java)!
– Bruno Miguel