Esempio n. 1
0
        /****************************************************/


        public User(Socket socket)
        {
            if (tmr.Interval != 1000)
            {
                tmr.Interval  = 1000;
                tmr.Elapsed  += timeCheck;
                tmr.AutoReset = true;
            }

            myIdx  = Server.userIdx;
            proper = PROPER.GENERAL;
            color  = COLOR.WHITE;
            userData.workSocket = socket;

            userData.workSocket.BeginReceive(userData.buf, userData.recvLen, UserData.BUFFER_SIZE, 0, new AsyncCallback(ReadCallBack), userData);
            SendMsg("CONNECT");
        }
Esempio n. 2
0
        /**
         * @brief 게임 시작 (직업 나눠줌)
         */
        static void StartGame()
        {
            mapNum = Server.rand.Next(0, 6);
            Console.WriteLine(string.Format("START !!! : {0}", mapNum));


            for (int j = 0; j < Server.v_user.Count; j++)
            {
                if (Server.v_user[j] != null)
                {
                    Server.v_user[j].SendMsg(string.Format("START:{0}", mapNum));
                    Server.v_user[j].isLive           = true;
                    Server.v_user[j].policeActiveMass = 0;
                    Server.v_user[j].thiefActiveMass  = 0;
                }
            }

            int memCount = 0;

            for (int i = 0; i < Server.v_user.Count; i++)
            {
                if (Server.v_user[i] != null)
                {
                    memCount++;
                }
            }

            PROPER[] proArr = new PROPER[memCount];

            for (int i = 0; i < memCount / 3; i++)
            {
                proArr[i] = PROPER.POLICE;
            }
            for (int i = 0; i < memCount - (memCount / 3); i++)
            {
                proArr[(memCount / 3) + i] = PROPER.THIEF;
            }

            int mIdx = 0;

            for (int i = 0; i < Server.v_user.Count; i++)
            {
                if (Server.v_user[i] != null)
                {
                    int colorT = Server.rand.Next(0, 9);
                    int pIdx   = Server.rand.Next(0, memCount - (mIdx++));
                    Server.v_user[i].proper = proArr[pIdx];
                    for (int j = 0; j < Server.v_user.Count; j++)
                    {
                        if (Server.v_user[j] != null)
                        {
                            Server.v_user[j].SendMsg(string.Format("PROPER:{0}:{1}:{2}", Server.v_user[i].myIdx, (int)proArr[pIdx], (int)colorT));
                        }
                    }

                    PROPER tp = proArr[memCount - mIdx];
                    proArr[memCount - mIdx] = proArr[pIdx];
                    proArr[pIdx]            = tp;
                }
            }

            //int police = memCount / 3;
            //int thief = memCount - police;

            //for (int i = 0; i < Server.v_user.Count; i++)
            //{
            //    int colorT = Server.rand.Next(0, 9);

            //    if (Server.v_user[i] != null)
            //    {
            //        if (thief.Equals(0))
            //        {
            //            police--;
            //            Server.v_user[i].proper = PROPER.POLICE;

            //            for (int j = 0; j < Server.v_user.Count; j++)
            //                if (Server.v_user[j] != null)
            //                    Server.v_user[j].SendMsg(string.Format("PROPER:{0}:{1}:{2}", Server.v_user[i].myIdx, (int)PROPER.POLICE, (int)colorT));
            //        }
            //        else if (police > 0)
            //        {
            //            if (Server.rand.Next(0, 2) == 0)
            //            {
            //                police--;
            //                Server.v_user[i].proper = PROPER.POLICE;

            //                for (int j = 0; j < Server.v_user.Count; j++)
            //                    if (Server.v_user[j] != null)
            //                        Server.v_user[j].SendMsg(string.Format("PROPER:{0}:{1}:{2}", Server.v_user[i].myIdx, (int)PROPER.POLICE, (int)colorT));
            //            }
            //            else
            //            {
            //                thief--;
            //                Server.v_user[i].proper = PROPER.THIEF;

            //                for (int j = 0; j < Server.v_user.Count; j++)
            //                    if (Server.v_user[j] != null)
            //                        Server.v_user[j].SendMsg(string.Format("PROPER:{0}:{1}:{2}", Server.v_user[i].myIdx, (int)PROPER.THIEF, (int)colorT));
            //            }
            //        }
            //        else
            //        {
            //            thief--;
            //            Server.v_user[i].proper = PROPER.THIEF;

            //            for (int j = 0; j < Server.v_user.Count; j++)
            //                if (Server.v_user[j] != null)
            //                    Server.v_user[j].SendMsg(string.Format("PROPER:{0}:{1}:{2}", Server.v_user[i].myIdx, (int)PROPER.THIEF, (int)colorT));
            //        }
            //    }
            //}

            tmr.Start();
        }
Esempio n. 3
0
    public void OpenResult(PROPER whoWin, int mvpIdx)
    {
        if (whoWin.Equals(PROPER.POLICE))
        {
            winnerThiefTxt.SetActive(false);
            winnerPoliceTxt.SetActive(true);
        }
        else
        {
            winnerThiefTxt.SetActive(true);
            winnerPoliceTxt.SetActive(false);
        }

        List <string> v_nickList = new List <string>();
        int           lIdx       = 0;

        for (int i = 0; i < GM.NetworkManager.getInstance.v_user.Count; i++)
        {
            if (GM.NetworkManager.getInstance.v_user[i] != null)
            {
                if (GM.NetworkManager.getInstance.v_user[i].proper.Equals(whoWin))
                {
                    v_nickList.Add(GM.NetworkManager.getInstance.v_user[i].nickName);
                }

                if (GM.NetworkManager.getInstance.v_user[i].myIdx.Equals(mvpIdx))
                {
                    lIdx = v_nickList.Count - 1;
                }
            }
        }


        p_1.gameObject.SetActive(false);
        for (int i = 0; i < 2; i++)
        {
            p_2[i].gameObject.SetActive(false);
        }
        for (int i = 0; i < 3; i++)
        {
            p_3[i].gameObject.SetActive(false);
        }
        for (int i = 0; i < 4; i++)
        {
            p_4[i].gameObject.SetActive(false);
        }
        for (int i = 0; i < 5; i++)
        {
            p_5[i].gameObject.SetActive(false);
        }
        for (int i = 0; i < 6; i++)
        {
            p_6[i].gameObject.SetActive(false);
        }

        if (v_nickList.Count.Equals(1))
        {
            p_1.gameObject.SetActive(true);
            p_1.gameObject.GetComponentInChildren <UnityEngine.UI.Text>().text = v_nickList[0];
            mvpObj.transform.position = p_1.gameObject.transform.position;
            StartCoroutine("mvpOpen", 1.6f);
        }
        else if (v_nickList.Count.Equals(2))
        {
            for (int i = 0; i < 2; i++)
            {
                p_2[i].gameObject.SetActive(true);
                p_2[i].gameObject.GetComponentInChildren <UnityEngine.UI.Text>().text = v_nickList[i];
            }
            mvpObj.transform.position = p_2[lIdx].gameObject.transform.position;
            StartCoroutine("mvpOpen", 1.75f);
        }
        else if (v_nickList.Count.Equals(3))
        {
            for (int i = 0; i < 3; i++)
            {
                p_3[i].gameObject.SetActive(true);
                p_3[i].gameObject.GetComponentInChildren <UnityEngine.UI.Text>().text = v_nickList[i];
            }
            mvpObj.transform.position = p_3[lIdx].gameObject.transform.position;
            StartCoroutine("mvpOpen", 1.9f);
        }
        else if (v_nickList.Count.Equals(4))
        {
            for (int i = 0; i < 4; i++)
            {
                p_4[i].gameObject.SetActive(true);
                p_4[i].gameObject.GetComponentInChildren <UnityEngine.UI.Text>().text = v_nickList[i];
            }
            mvpObj.transform.position = p_4[lIdx].gameObject.transform.position;
            StartCoroutine("mvpOpen", 2.05f);
        }
        else if (v_nickList.Count.Equals(5))
        {
            for (int i = 0; i < 5; i++)
            {
                p_5[i].gameObject.SetActive(true);
                p_5[i].gameObject.GetComponentInChildren <UnityEngine.UI.Text>().text = v_nickList[i];
            }
            mvpObj.transform.position = p_5[lIdx].gameObject.transform.position;
            StartCoroutine("mvpOpen", 2.2f);
        }
        else if (v_nickList.Count.Equals(6))
        {
            for (int i = 0; i < 6; i++)
            {
                p_6[i].gameObject.SetActive(true);
                p_6[i].gameObject.GetComponentInChildren <UnityEngine.UI.Text>().text = v_nickList[i];
            }
            mvpObj.transform.position = p_6[lIdx].gameObject.transform.position;
            StartCoroutine("mvpOpen", 2.35f);
        }
        resultAnim.SetTrigger("RESULT");
    }