Esempio n. 1
0
        /**
         * @brief 접속 종료
         * @param nickName 이름
         * @param pos 생성 위치
         * @param isPlayer 나 인가 아닌가
         */
        public void CreateUser(string nickName, Vector3 pos, MOVE_CONTROL moveC, MOVE_CONTROL seeDir, bool isPlayer)
        {
            GameObject obj    = Instantiate(playerPrefs, pos, Quaternion.identity) as GameObject;
            User       player = obj.GetComponent <User>();

            player.nickName.text = nickName;
            player.isPlayer      = isPlayer;
            player.myMove        = moveC;
            player.setDirection(seeDir);

            v_user.Add(player);
        }
Esempio n. 2
0
        /**
         * @brief 접속 종료
         * @param nickName 이름
         * @param pos 생성 위치
         * @param isPlayer 나 인가 아닌가
         */
        public void CreateUser(int idx, string nickName, Vector3 pos, MOVE_CONTROL moveC, bool isPlayer)
        {
            GameObject  obj    = Instantiate(playerPrefs, pos, Quaternion.identity) as GameObject;
            SPlayerMove player = obj.GetComponent <SPlayerMove>();

            player.myIdx    = idx;
            player.nickName = nickName;
            player.isPlayer = isPlayer;
            player.myMove   = moveC;

            v_user.Add(player);
        }
Esempio n. 3
0
    void Update()
    {
        if (isPlayer)
        {
            if (Input.GetKey(KeyCode.UpArrow))
            {
                myMove = MOVE_CONTROL.UP;
            }
            else if (Input.GetKey(KeyCode.LeftArrow))
            {
                myMove = MOVE_CONTROL.LEFT;
            }
            else if (Input.GetKey(KeyCode.RightArrow))
            {
                myMove = MOVE_CONTROL.RIGHT;
            }
            else if (Input.GetKey(KeyCode.DownArrow))
            {
                myMove = MOVE_CONTROL.DOWN;
            }
            else
            {
                myMove = MOVE_CONTROL.STOP;
            }

            if (myMove != beforeMove)
            {
                GM.NetworkManager.getInstance.SendMsg(string.Format("MOVE:{0}:{1}:{2}", transform.position.x, transform.position.y, (int)myMove));
                beforeMove = myMove;
            }
        }

        if (myMove == MOVE_CONTROL.UP)
        {
            //anim.Play("UP");
            transform.Translate(Vector3.up * 4f * Time.deltaTime);
        }
        else if (myMove == MOVE_CONTROL.DOWN)
        {
            //anim.Play("DOWN");
            transform.Translate(Vector3.down * 4f * Time.deltaTime);
        }
        else if (myMove == MOVE_CONTROL.LEFT)
        {
            //anim.Play("LEFT");
            transform.Translate(Vector3.left * 4f * Time.deltaTime);
        }
        else if (myMove == MOVE_CONTROL.RIGHT)
        {
            //anim.Play("RIGHT");
            transform.Translate(Vector3.right * 4f * Time.deltaTime);
        }
    }
Esempio n. 4
0
    void Update()
    {
        if (isPlayer && isLive)
        {
            if (proper == PROPER.POLICE)
            {
                SGameMng.I.uiScrp.GetSkill(nhp.ToString());
            }
            Blind();
            if (!bStartup)
            {
                KeyDown();
            }
            else
            {
                KeyDown();
            }

            if (myMove != beforeMove && !bStartup)
            {
                GM.NetworkManager.getInstance.SendMsg(string.Format("MOVE:{0}:{1}:{2}:{3}", myIdx, transform.position.x, transform.position.y, (int)myMove));
                beforeMove = myMove;
            }
            if (Input.GetKeyDown(KeyCode.Space) && proper.Equals(PROPER.POLICE) && !isSkill && !bStartup)
            {
                if (nhp <= 1)
                {
                    GM.NetworkManager.getInstance.SendMsg(string.Format("DIE:{0}:{1}", myIdx, myIdx));
                    Debug.Log("죽은놈" + myIdx); Debug.Log("죽인놈" + myIdx);
                    isLive = false;
                }
                else
                {
                    GM.NetworkManager.getInstance.SendMsg(string.Format("ATTACK:{0}", myIdx));
                }
                //Attack();
                Debug.Log("attack down");
            }

            WatchScrp.Move(this.transform);
        }

        if (gameObject.tag.Equals("Police") && bStartup)
        {
            myMove = 0;
        }
        else
        {
            Move();
        }
    }
Esempio n. 5
0
        /**
         * @brief 이동
         */
        void Move()
        {
            //int idx = Server.v_user.IndexOf(this);
            //int idx = 0;
            //for (int i = 0; i < Server.v_user.Count; i++)
            //{
            //    if (Server.v_user[i] != this && myRoomIdx.Equals(Server.v_user[i].myRoomIdx))
            //    {
            //        idx++;
            //    }
            //}

            int idx = 0;

            for (int i = 0; i < Server.v_user.Count; i++)
            {
                if (myRoomIdx.Equals(Server.v_user[i].myRoomIdx))
                {
                    if (Server.v_user[i] == this)
                    {
                        break;
                    }
                    idx++;
                }
            }

            for (int i = 0; i < Server.v_user.Count; i++)
            {
                if (Server.v_user[i] != this && myRoomIdx.Equals(Server.v_user[i].myRoomIdx))
                {
                    Server.v_user[i].SendMsg(string.Format("MOVE:{0}:{1}:{2}:{3}", i, posX, posY, (int)myMove)); // 내 인덱스 번호와 현재 위치 이동할 방향을 보낸다.
                }
            }
            if (myMove > MOVE_CONTROL.STOP)
            {
                seeDirection = myMove;                             // STOP이 아닌 경우 마지막 바라보던 방향을 저장해둔다.
            }
        }
Esempio n. 6
0
 void KeyDown()
 {
     if (Input.GetKey(KeyCode.UpArrow))
     {
         myMove = MOVE_CONTROL.UP;
     }
     else if (Input.GetKey(KeyCode.LeftArrow))
     {
         myMove = MOVE_CONTROL.LEFT;
     }
     else if (Input.GetKey(KeyCode.RightArrow))
     {
         myMove = MOVE_CONTROL.RIGHT;
     }
     else if (Input.GetKey(KeyCode.DownArrow))
     {
         myMove = MOVE_CONTROL.DOWN;
     }
     else
     {
         myMove = MOVE_CONTROL.STOP;
     }
 }
Esempio n. 7
0
        /**
         * brief 패킷 분석
         * param len 길이
         */
        private void ParsePacket(int len)
        {
            string msg = Encoding.UTF8.GetString(userData.buf, 2, len - 2);

            string[] txt = msg.Split(':');      // 암호를 ':' 로 분리해서 읽음

            //Console.WriteLine(msg);

            /************* 기능이 추가되면 덧붙일 것 ***************/
            if (txt[0].Equals("MOVE"))
            {
                int idx = int.Parse(txt[1]);
                posX   = float.Parse(txt[2]);
                posY   = float.Parse(txt[3]);
                myMove = (MOVE_CONTROL)int.Parse(txt[4]);

                Move(idx);

                if (proper.Equals(PROPER.THIEF))
                {
                    thiefActiveMass++;
                }
            }
            else if (txt[0].Equals("CHAT"))
            {
                Console.WriteLine("MSG");
                Chat(txt[1], txt[2]);
            }
            else if (txt[0].Equals("KINEMATIC"))
            {
                for (int i = 0; i < Server.v_user.Count; i++)
                {
                    Server.v_user[i].SendMsg(msg);
                }
            }
            else if (txt[0].Equals("ATTACK"))
            {
                Console.WriteLine("ATTACK");
                Attack(int.Parse(txt[1]));
                policeActiveMass--;             // 아직 모호함
            }
            else if (txt[0].Equals("DIE"))
            {
                Die(int.Parse(txt[1]), int.Parse(txt[2]));
            }
            else if (txt[0].Equals("START"))
            {
                StartGame();
            }
            else if (txt[0].Equals("LOGIN"))
            {
                nickName = txt[1];
                Login(txt[2]);
                Console.WriteLine(txt[1] + " is Login.");
            }
            else if (txt[0].Equals("DISCONNECT"))
            {
                if (nickName.Length > 0)
                {
                    Console.WriteLine(nickName + " is Logout.");
                    Logout();
                }
                userData.workSocket.Shutdown(SocketShutdown.Both);
                userData.workSocket.Close();

                Server.RemoveUser(myIdx);

                if (Server.v_user.Count.Equals(0))
                {
                    timeCount = maxPlayTime;
                    tmr.Stop();
                    for (int j = 0; j < Server.v_user.Count; j++)
                    {
                        Server.v_user[j].SendMsg(string.Format("DIE:{0}:{1}", myIdx, myIdx));
                    }
                }
                else
                {
                    for (int j = 0; j < Server.v_user.Count; j++)
                    {
                        Server.v_user[j].SendMsg(string.Format("DIE:{0}:{1}", myIdx, myIdx));
                    }
                }
            }
            else
            {
                //!< 이 부분에 들어오는 일이 있으면 안됨 (패킷 실수)
                Console.WriteLine("Un Correct Message ");
            }
        }
Esempio n. 8
0
        /**
         * brief 패킷 분석
         * param len 길이
         */
        private void ParsePacket(int len)
        {
            string msg = Encoding.UTF8.GetString(userData.buf, 2, len - 2);

            string[] txt = msg.Split(':');      // 암호를 ':' 로 분리해서 읽음

            /************* 기능이 추가되면 덧붙일 것 ***************/
            if (txt[0].Equals("LOGIN"))
            {
                myIdxInRoom = 0;
                nickName    = txt[1];
                Login();
                Console.WriteLine(txt[1] + " is Login." + myIdxInRoom);
            }
            else if (txt[0].Equals("DISCONNECT"))
            {
                if (nickName.Length > 0)
                {
                    Console.WriteLine(nickName + " is Logout.");
                    Logout();
                }
                userData.workSocket.Shutdown(SocketShutdown.Both);
                userData.workSocket.Close();
            }
            else if (txt[0].Equals("MOVE"))
            {
                posX   = float.Parse(txt[1]);
                posY   = float.Parse(txt[2]);
                myMove = (MOVE_CONTROL)int.Parse(txt[3]);
                Move();
            }
            else if (txt[0].Equals("CHAT"))
            {
                Chat(txt[1]);
            }
            else if (txt[0].Equals("FOUND_ROOM"))
            {
                for (int j = 0; j < Server.v_rooms.Count; j++)
                {
                    SendMsg(string.Format("FOUND_ROOM:{0}:{1}:{2}:{3}:{4}",
                                          Server.v_rooms[j].roomIdx, Server.v_rooms[j].roomName, Server.v_rooms[j].roomPW, Server.v_rooms[j].nowUser, Server.v_rooms[j].limitUser));
                }
            }
            else if (txt[0].Equals("INTO_ROOM"))
            {
                IntoRoom(txt[1]);
            }
            else if (txt[0].Equals("CREATE_ROOM"))
            {
                Logout();
                CreateRoom(txt[1], txt[2], txt[3]);
                SendMsg(string.Format("CHANGE_ROOM:{0}", myRoomIdx));
            }
            else if (txt[0].Equals("CHANGE_ROOM"))
            {
                Logout();
                myRoomIdx = int.Parse(txt[1]);
            }
            else if (txt[0].Equals("OUT_ROOM"))
            {
                for (int i = 0; i < Server.v_rooms.Count; i++)
                {
                    if (Server.v_rooms[i].roomIdx.Equals(int.Parse(txt[1])))
                    {
                        Server.v_rooms[i].nowUser--;
                        if (Server.v_rooms[i].nowUser <= 0)
                        {
                            Server.v_rooms.RemoveAt(i);
                        }
                        break;
                    }
                }
            }
            else
            {
                //!< 이 부분에 들어오는 일이 있으면 안됨 (패킷 실수)
                Console.WriteLine("Un Correct Message ");
            }
        }
Esempio n. 9
0
 /**
  * @brief 바라볼 방향 설정
  * @param direction 방향
  */
 public void setDirection(MOVE_CONTROL direction)
 {
     //
 }