示例#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);
        }