Esempio n. 1
0
 protected internal void  BroadCast(ClientTank client)
 {
     byte[] data = client.player.Serialize();
     foreach (var item in clients)
     {
         //if(item.id != client.id)  //Самого себя не передаст
         item.networkStream.Write(data, 0, data.Length);
     }
 }
Esempio n. 2
0
 protected internal async void GetOpponent(ClientTank client)
 {
     foreach (ClientTank item in clients)
     {
         byte[] data = item.player.Serialize();
         //if(item.id != client.id)
         await client.networkStream.WriteAsync(data, 0, data.Length);
     }
 }
Esempio n. 3
0
 protected internal bool Collision(ClientTank client)
 {
     foreach (ClientTank item in clients)
     {
         if (item.id != client.player.Id)
         {
             double res = Math.Sqrt(Math.Pow((client.player.X) - item.player.X, 2) + Math.Pow(client.player.Y - item.player.Y, 2));
             if (res < 45)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     return(false);
 }
Esempio n. 4
0
 protected internal void ListenTcp()
 {
     try
     {
         this.tcpListener = new TcpListener(IPAddress.Any, 8000);
         tcpListener.Start();
         while (true)
         {
             TcpClient  tcpClient = tcpListener.AcceptTcpClient();
             ClientTank client    = new ClientTank(this, tcpClient);
             Thread     thread    = new Thread(new ThreadStart(client.Process));
             thread.Start();
         }
     }
     catch (Exception ex)
     {
         Disconnect();
         Console.WriteLine(ex.Message);
     }
 }
Esempio n. 5
0
 protected internal void Disconnect(ClientTank client)
 {
     clients.Remove(client);
 }
Esempio n. 6
0
 protected internal void AddConnection(ClientTank item)
 {
     clients.Add(item);
 }