Exemple #1
0
        /* public void ChapNhanKetNoi()
         * {
         *   //chap nhan ket noi
         *   ROOM room = new ROOM();
         *  // PLAYER Player1=new PLAYER(),Player2 = new PLAYER();
         *   int status = -1;
         *   String str = "";
         *   int NumberofPlayer = 0;
         *   while (NumberofPlayer < 2)
         *   {
         *       Socket s = tcp.SetUpANewConnection(ref status);
         *       SocketModel   socket = new SocketModel(s);
         *       str = str + socket.GetRemoteEndpoint() + "\n";
         *       textBox3.AppendText(str);
         *       textBox3.Update();
         *       if(FindRoom()==null)
         *           if (soClientHienTai % 2 == 0)
         *           {
         *               room.Add_Player_M(new PLAYER(0, socket));
         *               room.player_M.SendMaster();
         *               Thread.Sleep(15);
         *
         *           }
         *           else
         *           {
         *               room.Add_Player_S(new PLAYER(0, socket));
         *               Thread.Sleep(15);
         *
         *             //  Thread.Sleep(15);
         *           }
         *       else
         *       {
         *           room.Add_Player_S(new PLAYER(0, socket));
         *           Thread.Sleep(15);
         *       }
         *       soClientHienTai++;
         *       NumberofPlayer++;
         *   }
         *   //cap nhat giao dien
         * //  string a = "9";
         *   room.Set_Room(soRoomHienTai);
         *   room.player_M.SendRoom();
         *   Thread.Sleep(15);
         *   // while (room.player_M.sk.ReceiveData() != a) ;
         *   room.player_S.SendRoom();
         *   Thread.Sleep(15);
         *   // while (room.player_S.sk.ReceiveData() != a) ;
         *   room.CreatMap();
         *   room.player_M.SendMap(room.lstGold);
         *   Thread.Sleep(15);
         *   //   Thread.Sleep(15);
         *   room.player_S.SendMap(room.lstGold);
         *   Thread.Sleep(15);
         *   // Thread.Sleep(15);
         *
         *   lstROOM.Add(room);
         *   soRoomHienTai++;
         *
         * }*/
        public void AcceptConnect()
        {
            ROOM        room;
            int         status = -1;
            Socket      s      = tcp.SetUpANewConnection(ref status);
            SocketModel socket = new SocketModel(s);
            String      str    = "";

            str = str + socket.GetRemoteEndpoint() + "\n";
            textBox3.AppendText(str);
            textBox3.Update();
            room = FindRoom();
            if (room == null)
            {
                room = new ROOM();
                room.Add_Player_M(new PLAYER(0, socket));
                room.player_M.SendMaster();
                Thread.Sleep(15);

                Thread.Sleep(15);
                lstROOM.Add(room);
                room.Set_Room_Player_M(lstROOM.Count);
                room.player_M.SendRoom();
            }
            else
            {
                if (room.player_M == null)
                {
                    room.Add_Player_M(new PLAYER(0, socket));
                    room.player_M.SendMaster();
                    Thread.Sleep(15);
                    room.Set_Room_Player_M(room.room);
                    Thread.Sleep(15);
                    room.player_M.SendRoom();
                    return;
                }
                room.Add_Player_S(new PLAYER(0, socket));
                Thread.Sleep(15);
                room.Set_Room_Player_S(room.player_M.Room);
                // while (room.player_M.sk.ReceiveData() != a) ;
                room.player_S.SendRoom();
                Thread.Sleep(15);
                // while (room.player_S.sk.ReceiveData() != a) ;
                room.Clear_LstGold();
                room.CreatMap();
                room.player_M.SendMap(room.lstGold);
                Thread.Sleep(15);
                //   Thread.Sleep(15);
                room.player_S.SendMap(room.lstGold);
                Thread.Sleep(15);
                // Thread.Sleep(15);
                Thread t = new Thread(PhucVuYeuCauRoom);
                t.Start(room);
            }
        }
Exemple #2
0
        public void Accept()
        {
            int    status = -1;
            Socket s      = tcp.SetUpANewConnection(ref status);

            socketList[currentClient] = new SocketModel(s);
            string str  = socketList[currentClient].GetRemoteEndpoint();
            string str1 = "New connection from: " + str + "\n";

            textBox3.AppendText(str1);
        }
Exemple #3
0
 //public PLAYER() { };
 public PLAYER(int mark, SocketModel s)
 {
     this.Mark          = mark;
     this.sk            = s;
     this.StatusConnect = false;
 }