Пример #1
0
        public IInputHandler GetNetworkPlayer()
        {
            SocketHandler socketHandler = clients[counter];

            counter++;
            return(socketHandler);
        }
Пример #2
0
 public SocketHandler ConnectPlayer()
 {
     TcpClient client = tcpListener.AcceptTcpClient();
     SocketHandler player = new SocketHandler(client);
     clients.Add(player);
     return player;
 }
Пример #3
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            while (socketManager.CountClients < maxClients)
            {
                if (worker.CancellationPending)
                {
                    socketManager.Stop();
                    e.Cancel = true;
                    break;
                }

                if (socketManager.HasIncoming)
                {
                    SocketHandler player     = socketManager.ConnectPlayer();
                    string        playerName = player.WaitForName();
                    Debug.WriteLine(playerName);
                }

                string state = string.Format("Waiting for {0} players..",
                                             maxClients -
                                             socketManager.CountClients);
                worker.ReportProgress(socketManager.CountClients * 100 / maxClients,
                                      state);
                Thread.Sleep(10);
            }
        }
Пример #4
0
        public SocketHandler ConnectPlayer()
        {
            TcpClient     client = tcpListener.AcceptTcpClient();
            SocketHandler player = new SocketHandler(client);

            clients.Add(player);
            return(player);
        }