Exemplo n.º 1
0
 void Update()
 {
     if (matchedClientFlag && matchedHostFlag)
     {
         count++;
         gameSignalingHost.SendData(new ClientReceiveSignalData(
                                        new CommandData(1, CommandKind.Move, count, new object[] { Direction.Down, 5 }),
                                        MatchType.Client
                                        )
                                    );
         gameSignalingClient.SendData(new HostReceiveSignalData(
                                          new CommandData(1, CommandKind.Move, count, new object[] { Direction.Up, 1 }))
                                      );
         gameSignalingClient.SendData(new HostReceiveSignalData(
                                          new CommandData(1, CommandKind.Move, count, new object[] { Direction.Up, 1 }))
                                      );
         gameSignalingHost.SendData(new ClientReceiveSignalData(
                                        new CommandData(1, CommandKind.Move, count, new object[] { Direction.Down, 5 }),
                                        MatchType.Client
                                        )
                                    );
         gameSignalingClient.Update();
         gameSignalingHost.Update();
     }
     else
     {
         matchingServer1.Update();
         matchingServer2.Update();
     }
 }
        Task SendCommandData(CommandKind commandKind, object[] parameters)
        {
            var id        = Interlocked.Increment(ref currentId);
            var semaphore = new SemaphoreSlim(0, 1);

            semaphores.TryAdd(id, semaphore);
            gameSignalingClient.SendData(new HostReceiveSignalData(
                                             new CommandData(id, commandKind, 0, parameters)
                                             ));
            return(semaphore.WaitAsync());
        }