/// <summary> /// Send a message containing the current DateTime to the chanel "PING" to test the viability of the socket /// </summary> public void Ping() { SimpleObjectFormater objectToSend = new SimpleObjectFormater(); objectToSend.AddString("time", DateTime.Now.TimeOfDay.ToString()); Emit("PING", objectToSend.JSONFormat()); }
/// <summary> /// Starts players detection and connect the game to the backend /// </summary> public void StartCapture() { socketIO.Connect(); socketIO.On("kinectStartRun", StartRun); socketIO.On("gameFinished", FinishRun); socketIO.On("kinectRestart", StartNewGame); if (logMode) { log.Info(Step.ToString() + " : Open socket - Start Capture"); } SimpleObjectFormater objectToSend = new SimpleObjectFormater(); objectToSend.AddString("state", kinectMotor.Status); socketIO.Emit("kinectConnected", objectToSend.JSONFormat()); }
/// <summary> /// Send all players who jumped to the backend /// </summary> /// <param name="jumpers">List containing jumpers id</param> /// <remarks> /// Gameplay method : You shouldn't call it manually. /// </remarks> public void SendJumpers(List <int> jumpers) { foreach (int jumperId in jumpers) { SimpleObjectFormater objectToSend = new SimpleObjectFormater(); objectToSend.AddInt("playerId", jumperId); socketIO.Emit("kinectPlayerJump", objectToSend.JSONFormat()); if (logMode) { log.Info(Step.ToString() + " : Player " + jumperId + " has jumped"); } players[jumperId - 1].ValidateJump(DateTime.Now); } }
/// <summary> /// Send the current players to the backend /// </summary> /// <remarks> /// Gameplay method : You shouldn't call it manually. /// </remarks> public void SendPlayers() { SimpleObjectFormater objectToSend = new SimpleObjectFormater(); SimpleArray playersArray = new SimpleArray(); foreach (Player player in players) { if (player.IsDefined()) { SimpleObjectFormater playerObjectToSend = new SimpleObjectFormater(); playerObjectToSend.AddInt("id", player.PlayerId); playerObjectToSend.AddInt("state", (int)player.State); playersArray.AddMember(playerObjectToSend); } } objectToSend.AddArray("players", playersArray); if (logMode) { log.Info(Step.ToString() + " : Send available players = " + objectToSend.JSONFormat()); } socketIO.Emit("players", objectToSend.JSONFormat()); }
/// <summary> /// Send all players speed to the backend /// </summary> /// <remarks> /// Gameplay method : You shouldn't call it manually. /// </remarks> public void SendSpeed() { SimpleObjectFormater objectToSend = new SimpleObjectFormater(); SimpleArray playersArray = new SimpleArray(); foreach (Player player in players) { if (player.IsDefined()) { SimpleObjectFormater playerObjectToSend = new SimpleObjectFormater(); playerObjectToSend.AddInt("id", player.PlayerId); playerObjectToSend.AddFloat("speed", player.Speed.value); playersArray.AddMember(playerObjectToSend); } } objectToSend.AddArray("players", playersArray); if (logMode) { log.Info(Step.ToString() + " : Send players speed = " + objectToSend.JSONFormat()); } socketIO.Emit("kinectPlayerSpeed", objectToSend.JSONFormat()); }