Beispiel #1
0
        /*	void CreatMap()
         * {
         *  for (int i = 0; i < Cons.Number_Gold_Crearted; i++)
         *  {
         *      lstGolg.Add(new GOLD());
         *  }
         * }*/
        void PhucVuPlayer(Object obj)
        {
            string str1       = "";
            PLAYER player     = (PLAYER)obj;
            ROOM   roomofplay = lstROOM.Find(x => x.room == player.Room);

            while (true)
            {
                //nhan yeu cau va cap nhat giao dien
                //  while (flagservice) ;
                //    lock (player.sk)
                {
                    str1 = player.sk.ReceiveData();
                    lock (lockth)
                    {
                        if (str1.StartsWith("Socket is closed with") == true)
                        {
                            player.sk.CloseSocket();
                            if (roomofplay.player_M == player && roomofplay.player_S == null)
                            {
                                roomofplay.player_M = null;
                                return;
                            }
                            if (roomofplay.player_M == player)
                            {
                                roomofplay.player_M = roomofplay.player_S;
                                roomofplay.player_M.sk.SendData(Cons.Send_Master + "");
                                roomofplay.player_S = null;
                                roomofplay.player_M.StatusConnect = true;
                                roomofplay.player_M.SendDisconnect();
                            }

                            else
                            {
                                try
                                {
                                    roomofplay.player_S = null;
                                    roomofplay.player_M.SendDisconnect();
                                }
                                catch { }
                            }
                            return;
                        }
                        HandleClient(player, str1);
                    }
                    textBox4.AppendText(str1 + "\n");
                }
            }
        }
Beispiel #2
0
        void HandleClient(PLAYER play, String str)
        {
            ROOM roomofplay = lstROOM.Find(x => x.room == play.Room);

            if (str[0] == Cons.Receive_End)
            {
                play.End = true;
                if (roomofplay.player_M.End == true && roomofplay.player_S.End == true)
                {
                    if (roomofplay.player_S.Mark > roomofplay.player_M.Mark)
                    {
                        roomofplay.player_S.SendResult(1);
                        roomofplay.player_M.SendResult(-1);
                    }
                    if (roomofplay.player_S.Mark < roomofplay.player_M.Mark)
                    {
                        roomofplay.player_S.SendResult(-1);
                        roomofplay.player_M.SendResult(1);
                    }
                    if (roomofplay.player_S.Mark == roomofplay.player_M.Mark)
                    {
                        roomofplay.player_S.SendResult(0);
                        roomofplay.player_M.SendResult(0);
                    }
                    roomofplay.lstGold.Clear();
                    roomofplay.player_S.SendEnd();
                    roomofplay.player_M.SendEnd();
                    roomofplay.player_M.End = false;
                    roomofplay.player_S.End = false;
                    roomofplay.CreatMap();
                }
                return;
            }
            if (str[0] == Cons.Receive_Ready)
            {
                roomofplay.player_M.SendReady();
                Thread.Sleep(15);
                roomofplay.player_M.SendMap(roomofplay.lstGold);
                Thread.Sleep(15);
                //   Thread.Sleep(15);
                roomofplay.player_S.SendMap(roomofplay.lstGold);
                Thread.Sleep(15);
                return;
            }
            if (str[0] == Cons.Receive_Start)
            {
                roomofplay.player_M.SendStart();
                roomofplay.player_S.SendStart();
                return;
            }
            if (str[0] == Cons.Receive_CanCau)
            {
                str = str.Substring(1);
                string[] arrListStr = str.Split(',');
                Point    pt         = new Point(Int32.Parse(arrListStr[0]), Int32.Parse(arrListStr[1]));
                GOLD     remove     = new GOLD();

                //  lock (lstGolg)
                {
                    remove = Collision(pt, roomofplay);

                    if (remove != null)
                    {
                        if (play == roomofplay.player_M)
                        {
                            roomofplay.player_S.SendGold(remove.pos);
                        }
                        else
                        {
                            roomofplay.player_M.SendGold(remove.pos);
                        }

                        roomofplay.Remove_Gold(remove);
                    }
                }
                return;
            }
            if (str[0] == Cons.Receive_MyMark)
            {
                str = str.Substring(1);
                if (play == roomofplay.player_M)
                {
                    roomofplay.player_S.SendMark(str);
                }
                else
                {
                    roomofplay.player_M.SendMark(str);
                }
                play.Mark = Int32.Parse(str);
                return;
            }
        }
Beispiel #3
0
 public void Add_Player_M(PLAYER player)
 {
     player_M = player;
 }
Beispiel #4
0
 public void Add_Player_S(PLAYER player)
 {
     player_S = player;
 }
Beispiel #5
0
 public void Add_Player_M(PLAYER player)
 {
     player_M = null;
     player_S = null;
     player_M = player;
 }