Exemplo n.º 1
0
    public void Event(byte[] _baBuffer, GameData.EnumGameCatchStructType _eStructType)
    {
        switch (_eStructType)
        {
        case GameData.EnumGameCatchStructType.RECEIVE_POPUP_TIME_START_PACKET:
        {
            Debug.Log("Receive Popup Time Start Packet");

            //1// 서버에서 받은 패킷 deserializing - 모든 플레이어 준비 완료 시 "잠시 후 게임이 시작됩니다." -> 타이머 start
            GameData.ReceivePopupTimeStartPacket timeStart = new GameData.ReceivePopupTimeStartPacket();
            timeStart = Serializer.ByteToStructure <GameData.ReceivePopupTimeStartPacket>(_baBuffer);
            //1//

            StopAllPopupTime();
            m_goPopup.SetActive(true);

            StartTime();
        }
        break;

        case GameData.EnumGameCatchStructType.RECEIVE_POPUP_TIME_END_PACKET:
        {
            Debug.Log("Receive Popup Time End Packet");

            //1// 서버에서 받은 패킷 deserializing - "잠시 후 게임이 시작됩니다." -> 타이머 end
            GameData.ReceivePopupTimeEndPacket timeEnd = new GameData.ReceivePopupTimeEndPacket();
            timeEnd = Serializer.ByteToStructure <GameData.ReceivePopupTimeEndPacket>(_baBuffer);
            //1//

            // "잠시 후 게임이 시작됩니다." -> 팝업 내리고 게임 시작
            EndTime();
            ChoiceAnswer();
        }
        break;

        case GameData.EnumGameCatchStructType.RECEIVE_EXAMINER_ANSWERS_PACKET:
        {
            Debug.Log("Receive Examiner Answer Packet");

            //1// 서버에서 받은 패킷 deserializing - 출제자에게 5개의 정답 선택지 제공
            GameData.ReceiveExaminerAnswersPacket examinerAnswers = new GameData.ReceiveExaminerAnswersPacket();
            examinerAnswers = Serializer.ByteToStructure <GameData.ReceiveExaminerAnswersPacket>(_baBuffer);
            //1//

            //2// 문자열은 UTF8로 따로 인코딩
            m_textAnswer1.text = Serializer.EncodingByteArrayToString(_baBuffer, GameData.iStringStartIdx, GameData.iStringAnswerSize);
            m_textAnswer2.text = Serializer.EncodingByteArrayToString(_baBuffer, GameData.iStringStartIdx + GameData.iStringAnswerSize, GameData.iStringAnswerSize);
            m_textAnswer3.text = Serializer.EncodingByteArrayToString(_baBuffer, GameData.iStringStartIdx + (GameData.iStringAnswerSize * 2), GameData.iStringAnswerSize);
            m_textAnswer4.text = Serializer.EncodingByteArrayToString(_baBuffer, GameData.iStringStartIdx + (GameData.iStringAnswerSize * 3), GameData.iStringAnswerSize);
            m_textAnswer5.text = Serializer.EncodingByteArrayToString(_baBuffer, GameData.iStringStartIdx + (GameData.iStringAnswerSize * 4), GameData.iStringAnswerSize);
            //2//

            m_strAnswer = m_textAnswer1.text;
        }
        break;

        case GameData.EnumGameCatchStructType.RECEIVE_SELECT_END_PACKET:
        {
            Debug.Log("Receive Select End Packet");

            //1// 서버에서 받은 패킷 deserializing - 출제자 선택 완료 신호
            GameData.ReceiveSelectCompletePacket examinerAnswer = new GameData.ReceiveSelectCompletePacket();
            examinerAnswer = Serializer.ByteToStructure <GameData.ReceiveSelectCompletePacket>(_baBuffer);
            //1//

            RoundStart();
        }
        break;

        case GameData.EnumGameCatchStructType.RECEIVE_INGAME_TIME_PACKET:
        {
            Debug.Log("Receive Ingame Time Packet");

            //1// 서버에서 받은 패킷 deserializing - 인게임 타이머
            GameData.ReceiveIngameTimePacket ingameTime = new GameData.ReceiveIngameTimePacket();
            ingameTime = Serializer.ByteToStructure <GameData.ReceiveIngameTimePacket>(_baBuffer);
            //1//

            m_iIngameLimitTime = ingameTime.iIngameTime;

            if (_baBuffer.Length > GameData.iReceiveIngameTimePacketStructSize)
            {
                byte[] baNewArray = ResizeArray(_baBuffer, GameData.iReceiveIngameTimePacketStructSize);

                IngameManager.m_Instance.Event(baNewArray);
            }
        }
        break;

        case GameData.EnumGameCatchStructType.RECEIVE_POINT_PACKET:
        {
            Debug.Log("Receive Point Packet");

            //1// 서버에서 받은 패킷 deserializing - 출제자가 그린 점 정보
            GameData.ReceivePointPacket point = new GameData.ReceivePointPacket();
            point = Serializer.ByteToStructure <GameData.ReceivePointPacket>(_baBuffer);
            //1//

            Vector2 vPoint;
            vPoint.x = point.fX;
            vPoint.y = point.fY;

            DrawLine(point.iLineIdx, vPoint, point.iColor);

            ++m_iRecvPointCount;            // 임시

            if (_baBuffer.Length > GameData.iReceivePointPacketStructSize)
            {
                byte[] baNewArray = ResizeArray(_baBuffer, GameData.iReceivePointPacketStructSize);

                IngameManager.m_Instance.Event(baNewArray);
            }
        }
        break;

        case GameData.EnumGameCatchStructType.RECEIVE_CHAT_PACKET:
        {
            Debug.Log("Receive Chat Packet");

            //1// 서버에서 받은 패킷 deserializing - 채팅
            GameData.ReceiveChatPacket chat = new GameData.ReceiveChatPacket();
            chat = Serializer.ByteToStructure <GameData.ReceiveChatPacket>(_baBuffer);
            //1//

            Chat(chat.strChat, chat.iPlayerIdx, chat.iAnswer);
        }
        break;

        default:
            break;
        }
    }
Exemplo n.º 2
0
    public void Event(byte[] _baBuffer, GameData.EnumGameTwentyStructType _eStructType)
    {
        Debug.Log("MGT Event :: " + _baBuffer);
        switch (_eStructType)
        {
        case GameData.EnumGameTwentyStructType.RECEIVE_POPUP_TIME_START_PACKET:
        {
            //1// 서버에서 받은 패킷 deserializing - 모든 플레이어 준비 완료 시 "잠시 후 게임이 시작됩니다." -> 타이머 start
            GameData.ReceivePopupTimeStartPacket timeStart = new GameData.ReceivePopupTimeStartPacket();
            timeStart = Serializer.ByteToStructure <GameData.ReceivePopupTimeStartPacket>(_baBuffer);
            //1//

            StopAllPopupTime();
            m_goPlayerExitPopup.SetActive(false);
            m_goReserveExitOrCancel.SetActive(false);
            m_goAnswerPopup.SetActive(false);
            m_goPopup.SetActive(true);

            StartTime();
        }
        break;

        case GameData.EnumGameTwentyStructType.RECEIVE_POPUP_TIME_END_PACKET:
        {
            //1// 서버에서 받은 패킷 deserializing - "잠시 후 게임이 시작됩니다." -> 타이머 end
            GameData.ReceivePopupTimeEndPacket timeEnd = new GameData.ReceivePopupTimeEndPacket();
            timeEnd = Serializer.ByteToStructure <GameData.ReceivePopupTimeEndPacket>(_baBuffer);
            //1//

            // "잠시 후 게임이 시작됩니다." -> 팝업 내리고 게임 시작
            EndTime();
            ChoiceAnswer();
        }
        break;

        case GameData.EnumGameTwentyStructType.RECEIVE_EXAMINER_ANSWERS_PACKET:
        {
            //1// 서버에서 받은 패킷 deserializing - 출제자에게 5개의 정답 선택지 제공
            GameData.ReceiveExaminerAnswersPacket examinerAnswers = new GameData.ReceiveExaminerAnswersPacket();
            examinerAnswers = Serializer.ByteToStructure <GameData.ReceiveExaminerAnswersPacket>(_baBuffer);
            //1//

            //2// 문자열은 UTF8로 따로 인코딩
            m_textAnswer1.text = Serializer.EncodingByteArrayToString(_baBuffer, GameData.iStringStartIdx, GameData.iStringAnswerSize);
            m_textAnswer2.text = Serializer.EncodingByteArrayToString(_baBuffer, GameData.iStringStartIdx + GameData.iStringAnswerSize, GameData.iStringAnswerSize);
            m_textAnswer3.text = Serializer.EncodingByteArrayToString(_baBuffer, GameData.iStringStartIdx + (GameData.iStringAnswerSize * 2), GameData.iStringAnswerSize);
            m_textAnswer4.text = Serializer.EncodingByteArrayToString(_baBuffer, GameData.iStringStartIdx + (GameData.iStringAnswerSize * 3), GameData.iStringAnswerSize);
            m_textAnswer5.text = Serializer.EncodingByteArrayToString(_baBuffer, GameData.iStringStartIdx + (GameData.iStringAnswerSize * 4), GameData.iStringAnswerSize);
            //2//

            m_strAnswer = m_textAnswer1.text;
        }
        break;

        case GameData.EnumGameTwentyStructType.RECEIVE_SELECT_END_PACKET:
        {
            //1// 서버에서 받은 패킷 deserializing - 출제자 선택 완료 신호
            GameData.ReceiveSelectCompletePacket examinerAnswer = new GameData.ReceiveSelectCompletePacket();
            examinerAnswer = Serializer.ByteToStructure <GameData.ReceiveSelectCompletePacket>(_baBuffer);
            //1//

            RoundStart();
        }
        break;

        case GameData.EnumGameTwentyStructType.RECEIVE_INGAME_TIME_PACKET:
        {
            //1// 서버에서 받은 패킷 deserializing - 인게임 타이머
            GameData.ReceiveIngameTimePacket ingameTime = new GameData.ReceiveIngameTimePacket();
            ingameTime = Serializer.ByteToStructure <GameData.ReceiveIngameTimePacket>(_baBuffer);
            //1//

            m_iIngameLimitTime = ingameTime.iIngameTime;
        }
        break;

        case GameData.EnumGameTwentyStructType.RECEIVE_QUESTION_PACKET:
        {
            //1// 서버에서 받은 패킷 deserializing - 서버에서 받은 채팅 정보
            GameData.ReceiveQuestionPacket chat = new GameData.ReceiveQuestionPacket();
            chat = Serializer.ByteToStructure <GameData.ReceiveQuestionPacket>(_baBuffer);
            //1//

            //2// 문자열은 UTF8로 따로 인코딩
            string strNickname = Serializer.EncodingByteArrayToString(_baBuffer, GameData.iStringStartIdx, GameData.iStringNicknameSize);
            string strQuestion = Serializer.EncodingByteArrayToString(_baBuffer, GameData.iStringStartIdx + GameData.iStringNicknameSize, GameData.iStringChatSize);
            //2//

            bool bExitMsg = false;
            InputChatToMainScreen(strNickname + " : " + strQuestion, Color.black, bExitMsg);
            ChoiceYesOrNo();
        }
        break;

        case GameData.EnumGameTwentyStructType.RECEIVE_YES_OR_NO_PACKET:
        {
            //1// 서버에서 받은 패킷 deserializing - 서버에서 받은 정답 확인 정보
            GameData.ReceiveYesOrNoPacket yesOrNo = new GameData.ReceiveYesOrNoPacket();
            yesOrNo = Serializer.ByteToStructure <GameData.ReceiveYesOrNoPacket>(_baBuffer);
            //1//

            // 문자열은 UTF8로 따로 인코딩
            string strNickname = Serializer.EncodingByteArrayToString(_baBuffer, GameData.iStringStartIdx, GameData.iStringNicknameSize);

            if (yesOrNo.iYesOrNo == 1)
            {
                bool bExitMsg = false;

                // 출제자가 Yes 대답을 했을 경우
                InputChatToMainScreen(strNickname + " : Yes", Color.blue, bExitMsg);
            }
            else
            {
                bool bExitMsg = false;

                // 출제자가 No 대답을 했을 경우
                InputChatToMainScreen(strNickname + " : No", Color.red, bExitMsg);
            }
        }
        break;

        case GameData.EnumGameTwentyStructType.RECEIVE_CHECK_ANSWER_PACKET:
        {
            //1// 서버에서 받은 패킷 deserializing - 서버에서 받은 정답 확인 정보
            GameData.ReceiveCheckAnswerPacket receiveCheckAnswer = new GameData.ReceiveCheckAnswerPacket();
            receiveCheckAnswer = Serializer.ByteToStructure <GameData.ReceiveCheckAnswerPacket>(_baBuffer);
            //1//

            //2// 문자열은 UTF8로 따로 인코딩
            string strNickname = Serializer.EncodingByteArrayToString(_baBuffer, GameData.iStringStartIdx, GameData.iStringNicknameSize);
            string strAnswer   = Serializer.EncodingByteArrayToString(_baBuffer, GameData.iStringStartIdx + GameData.iStringNicknameSize, GameData.iStringAnswerSize);
            //2//

            bool bExitMsg = false;
            InputChatToMainScreen(strNickname + " : " + strAnswer + " <정답 도전>", Color.black, bExitMsg);
            CheckAnswer(receiveCheckAnswer.iResult, strNickname, strAnswer);
        }
        break;

        case GameData.EnumGameTwentyStructType.RECEIVE_NEXT_CHALLENGER_PACKET:
        {
            //1// 서버에서 받은 패킷 deserializing - 다음 질문자 정보
            GameData.ReceiveNextChallengerPacket nextChallenger = new GameData.ReceiveNextChallengerPacket();
            nextChallenger = Serializer.ByteToStructure <GameData.ReceiveNextChallengerPacket>(_baBuffer);
            //1//

            // 문자열은 UTF8로 따로 인코딩
            string strNickname = Serializer.EncodingByteArrayToString(_baBuffer, GameData.iStringStartIdx, GameData.iStringNicknameSize);

            // 다음 질문자로 넘어감
            ChangeChallenger(strNickname, nextChallenger.iChangeType);
        }
        break;

        case GameData.EnumGameTwentyStructType.RECEIVE_ROUND_END_PACKET:
        {
            GameData.ReceiveRoundEndPacket roundEnd = new GameData.ReceiveRoundEndPacket();
            roundEnd = Serializer.ByteToStructure <GameData.ReceiveRoundEndPacket>(_baBuffer);

            RoundEnd(roundEnd.strNextExaminer, roundEnd.strNextChallenger, roundEnd.iRound);
        }
        break;

        case GameData.EnumGameTwentyStructType.RECEIVE_SOCRE_PACKET:
        {
            GameData.ReceiveScorePacket score = new GameData.ReceiveScorePacket();
            score = Serializer.ByteToStructure <GameData.ReceiveScorePacket>(_baBuffer);

            // 문자열은 UTF8로 따로 인코딩
            string strNickname = Serializer.EncodingByteArrayToString(_baBuffer, GameData.iStringStartIdx, GameData.iStringNicknameSize);

            UpdateScore(strNickname, score.iScore);
        }
        break;

        case GameData.EnumGameTwentyStructType.RECEIVE_ANSWER_POPUP_TIME_START_PACKET:
        {
            GameData.ReceiveAnswerPopupTimePacket answerPopupTime = new GameData.ReceiveAnswerPopupTimePacket();
            answerPopupTime = Serializer.ByteToStructure <GameData.ReceiveAnswerPopupTimePacket>(_baBuffer);

            StopAllPopupTime();
            m_fLimitPopupTime       = 3;
            m_bStartAnswerPopupTime = true;
            m_goAnswerPopup.SetActive(true);
        }
        break;

        case GameData.EnumGameTwentyStructType.RECEIVE_ANSWER_POPUP_ANSWER_PACKET:
        {
            GameData.ReceiveAnswerPopupAnswerPacket answerPopupAnswer = new GameData.ReceiveAnswerPopupAnswerPacket();
            answerPopupAnswer = Serializer.ByteToStructure <GameData.ReceiveAnswerPopupAnswerPacket>(_baBuffer);

            m_textAnswerPopupNickname.text = "도전 실패";
            m_textAnswerPopupAnswer.text   = "정답 : " + answerPopupAnswer.strAnswer;
        }
        break;

        case GameData.EnumGameTwentyStructType.RECEIVE_GAME_END_PACKET:
        {
            GameData.ReceiveGameEndPacket gameEnd = new GameData.ReceiveGameEndPacket();
            gameEnd = Serializer.ByteToStructure <GameData.ReceiveGameEndPacket>(_baBuffer);

            //1// 서버가 준 1등 ~ 5등 이름, 점수를 출력
            m_textResultPopupNickname1.text = gameEnd.strNickname1;
            m_textResultPopupNickname2.text = gameEnd.strNickname2;
            m_textResultPopupNickname3.text = gameEnd.strNickname3;
            m_textResultPopupNickname4.text = gameEnd.strNickname4;
            m_textResultPopupNickname5.text = gameEnd.strNickname5;

            m_textScore1.text = "" + gameEnd.iScore1;

            if (m_textResultPopupNickname2.text.Equals(""))
            {
                m_textScore2.text = "";
            }
            else
            {
                m_textScore2.text = "" + gameEnd.iScore2;
            }

            if (m_textResultPopupNickname3.text.Equals(""))
            {
                m_textScore3.text = "";
            }
            else
            {
                m_textScore3.text = "" + gameEnd.iScore3;
            }

            if (m_textResultPopupNickname4.text.Equals(""))
            {
                m_textScore4.text = "";
            }
            else
            {
                m_textScore4.text = "" + gameEnd.iScore4;
            }

            if (m_textResultPopupNickname5.text.Equals(""))
            {
                m_textScore5.text = "";
            }
            else
            {
                m_textScore5.text = "" + gameEnd.iScore5;
            }
            //1//

            GameEnd();
        }
        break;

        case GameData.EnumGameTwentyStructType.RECEIVE_EXAMINER_EXIT_PACKET:
        {
            GameData.ReceiveExaminerExitPacket examinerExit = new GameData.ReceiveExaminerExitPacket();
            examinerExit = Serializer.ByteToStructure <GameData.ReceiveExaminerExitPacket>(_baBuffer);

            ExaminerExit(examinerExit.strNickname, examinerExit.iGameEnd);
        }
        break;

        case GameData.EnumGameTwentyStructType.RECEIVE_NON_EXAMINER_EXIT_PACKET:
        {
            GameData.ReceiveNonExaminerExitPacket nonExaminerExit = new GameData.ReceiveNonExaminerExitPacket();
            nonExaminerExit = Serializer.ByteToStructure <GameData.ReceiveNonExaminerExitPacket>(_baBuffer);

            NonExaminerExit(nonExaminerExit.strNickname, nonExaminerExit.iGameEnd, nonExaminerExit.iChallenger);
        }
        break;

        case GameData.EnumGameTwentyStructType.RECEIVE_EXIT_PACKET:
        {
            GameData.ReceiveExitPacket exit = new GameData.ReceiveExitPacket();
            exit = Serializer.ByteToStructure <GameData.ReceiveExitPacket>(_baBuffer);

            // 게임 종료 -> 게임 선택 메인 메뉴 활성
            ExitGame(GameData.EnumGameType.TWENTY);
        }
        break;

        case GameData.EnumGameTwentyStructType.RECEIVE_RESERVE_EXIT_OR_CANCEL_NICKNAME_PACEKT:
        {
            GameData.ReceiveReserveExitOrCancelNicknamePacket reserveExitOrCancelNickname = new GameData.ReceiveReserveExitOrCancelNicknamePacket();
            reserveExitOrCancelNickname = Serializer.ByteToStructure <GameData.ReceiveReserveExitOrCancelNicknamePacket>(_baBuffer);

            m_goReserveExitOrCancel.SetActive(true);

            string strNickname = reserveExitOrCancelNickname.strNickname;

            if (reserveExitOrCancelNickname.iReserve.Equals(1))
            {
                if (strNickname.Equals(m_textNickname1.text))
                {
                    m_goReserveExit1.SetActive(true);
                }
                else if (strNickname.Equals(m_textNickname2.text))
                {
                    m_goReserveExit2.SetActive(true);
                }
                else if (strNickname.Equals(m_textNickname3.text))
                {
                    m_goReserveExit3.SetActive(true);
                }
                else if (strNickname.Equals(m_textNickname4.text))
                {
                    m_goReserveExit4.SetActive(true);
                }
                else if (strNickname.Equals(m_textNickname5.text))
                {
                    m_goReserveExit5.SetActive(true);
                }
            }
            else
            {
                if (strNickname.Equals(m_textNickname1.text))
                {
                    m_goReserveExit1.SetActive(false);
                }
                else if (strNickname.Equals(m_textNickname2.text))
                {
                    m_goReserveExit2.SetActive(false);
                }
                else if (strNickname.Equals(m_textNickname3.text))
                {
                    m_goReserveExit3.SetActive(false);
                }
                else if (strNickname.Equals(m_textNickname4.text))
                {
                    m_goReserveExit4.SetActive(false);
                }
                else if (strNickname.Equals(m_textNickname5.text))
                {
                    m_goReserveExit5.SetActive(false);
                }
            }
        }
        break;

        case GameData.EnumGameTwentyStructType.RECEIVE_QUESTION_COUNT_PACKET:
        {
            GameData.ReceiveQuestionCountPacket questionCount = new GameData.ReceiveQuestionCountPacket();
            questionCount = Serializer.ByteToStructure <GameData.ReceiveQuestionCountPacket>(_baBuffer);

            m_iQuestionCount = questionCount.iQuestionCount;
        }
        break;

        default:
            break;
        }
    }