Example #1
0
        private void timer1_Tick(object sender, EventArgs e)        // 남은 시간 표시
        {
            if (timeSec > 0)
            {
                timeSec--;
                int minute = timeSec / 60;
                int second = timeSec % 60;
                time.Text = string.Format("{0:0#} : {1:0#}", minute, second);
                return;
            }
            if (timeSec <= 0 && client_number == turnClientNum)          // 제한 시간 초과시 턴 변경 요청
            {
                TurnChange turnPacket = new TurnChange();
                turnPacket.Type = (int)PacketType.정답;

                turnPacket.turn      = turnClientNum;
                turnPacket.clientNum = client_number;
                turnPacket.Correct   = false;
                turnPacket.message   = "***   제한 시간이 초과되었습니다.   ***";
                turnPacket.score     = 0;
                turnPacket.turnCount = turnCount;
                Packet.Serialize(turnPacket).CopyTo(this.sendbuffer, 0);

                stream.Write(this.sendbuffer, 0, this.sendbuffer.Length);
                this.stream.Flush();
                resetBuffer(sendbuffer);
            }
        }
Example #2
0
        public void SendTurnAll(int turn, string message)
        {
            TurnChange turnPacket = new TurnChange();

            turnPacket.Type = (int)PacketType.턴;

            turnPacket.turn = turn;
            if (message != "")
            {
                turnPacket.message = message + "\r\n";
            }

            turnPacket.message += "*** " + nickNameList[turn] + "님의 차례입니다. ***";
            turnPacket.Word     = SetAnswer();

            for (int i = 0; i < counter; i++)
            {
                turnPacket.clientscore[i] = clientScore[i];
            }

            foreach (var pair in clientList)
            {
                TcpClient client = pair.Key as TcpClient;

                NetworkStream stream = client.GetStream();
                Packet.Serialize(turnPacket).CopyTo(this.sendbuffer, 0);

                stream.Write(this.sendbuffer, 0, this.sendbuffer.Length);
                this.stream.Flush();
                resetBuffer(sendbuffer);
            }
        }
Example #3
0
 public static void CallWriteTurnChangesEvent(TurnChange currentTurnChange)
 {
     if (WriteTurnChangesEvent != null)
     {
         WriteTurnChangesEvent(currentTurnChange);
     }
 }
Example #4
0
    private void AddTurnChangeToRewindSidebar(TurnChange currentTurnChange)
    {
        //rewindListItemContainer
        GameObject instance = GameObject.Instantiate(rewindListItemPrefab.gameObject) as GameObject;

        instance.transform.SetParent(rewindListItemContainer, false);
        InitializeItemView(instance, currentTurnChange);
    }
Example #5
0
    private void InitializeItemView(GameObject instance, TurnChange currentTurnChange)
    {
        RewindListItem Listitem = instance.GetComponent <RewindListItem>();

        Listitem
        .FluentResetValues(changeList.Count, currentTurnChange.FromCellWithId, currentTurnChange.ToCellWithId)
        .Init();

        return;
    }
Example #6
0
        private void txtBox_user_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter && txtBox_user.Text != "")
            {
                ClientMessage clientMessage = new ClientMessage();
                clientMessage.Type = (int)PacketType.메세지;

                clientMessage.Message = this.txtBox_user.Text;
                //MessageBox.Show(nickNameList.Count.ToString());
                clientMessage.nickName = nickNameList[client_number].ToString();
                Packet.Serialize(clientMessage).CopyTo(this.sendbuffer, 0);

                stream.Write(this.sendbuffer, 0, this.sendbuffer.Length);
                stream.Flush();
                resetBuffer(sendbuffer);

                if (txtBox_user.Text == answer && turnClientNum != client_number && gameStart)             // 만약 정답이면
                {
                    TurnChange turnPacket = new TurnChange();
                    turnPacket.Type = (int)PacketType.정답;

                    turnPacket.turn      = turnClientNum;
                    turnPacket.Correct   = true;
                    turnPacket.message   = "***   정답입니다.   ***";
                    turnPacket.score     = timeSec;
                    turnPacket.clientNum = client_number;
                    turnPacket.turnCount = turnCount;
                    Packet.Serialize(turnPacket).CopyTo(this.sendbuffer, 0);

                    stream.Write(this.sendbuffer, 0, this.sendbuffer.Length);
                    stream.Flush();
                    resetBuffer(sendbuffer);
                }

                this.txtBox_user.Text = "";
            }
        }
Example #7
0
        ////////////////////////////////////////////////////   서버와의 통신   ////////////////////////////////////////////////////
        private void GetRequest()       //서버로부터 받은 요청을 처리하는 쓰레드 메소드
        {
            while (true)
            {
                stream = clientSocket.GetStream();  //스트림 읽음
                int bytes = stream.Read(this.readbuffer, 0, this.readbuffer.Length);

                Packet packet = (Packet)Packet.Deserialize(this.readbuffer);

                switch ((int)packet.Type)
                {
                case (int)PacketType.메세지:
                {
                    ClientMessage clientMessage = new ClientMessage();
                    clientMessage = (ClientMessage)Packet.Deserialize(this.readbuffer);
                    DisplayText(clientMessage.Message, Color.Black);           //텍스트창에 띄움
                    break;
                }

                case (int)PacketType.그림정보:
                {
                    ClientDrawingInfo drawInfo = new ClientDrawingInfo();
                    drawInfo = (ClientDrawingInfo)Packet.Deserialize(this.readbuffer);
                    //로컬에서 테스트할때 이름 안 겹치게하려고..

                    fileStrm = new FileStream(filepath + "turnPic_" + client_number + ".jpg", FileMode.Create, FileAccess.Write);

                    break;
                }

                case (int)PacketType.그림:
                {
                    ClientDrawing draw = new ClientDrawing();
                    draw = (ClientDrawing)Packet.Deserialize(this.readbuffer);
                    string fileName = null;
                    //클라이언트로부터 받은 파일을 쓴다.
                    if (fileStrm != null)
                    {
                        fileStrm.Write(draw.buffer, 0, draw.buffer.Length);
                        countRead++;
                        if (countRead == draw.count)
                        {
                            fileName = fileStrm.Name;
                            fileStrm.Close();
                            fileStrm  = null;
                            countRead = 0;
                            //picture박스에 그림표시해야함.
                            FileStream fs = new FileStream(filepath + "turnPic_" + client_number + ".jpg", FileMode.Open, FileAccess.Read);
                            gamePicture.Image = System.Drawing.Image.FromStream(fs);
                            fs.Close();
                        }
                    }
                    break;
                }

                case (int)PacketType.프로필정보:
                {
                    ClientProfileInfo profileInfo = new ClientProfileInfo();
                    profileInfo = (ClientProfileInfo)Packet.Deserialize(this.readbuffer);
                    fileStrm    = new FileStream(filepath + client_number.ToString() + "-" + profileInfo.clientNum.ToString() + ".jpg", FileMode.Create, FileAccess.Write);
                    break;
                }

                case (int)PacketType.게임상태:
                {
                    GameState statePacket = new GameState();
                    statePacket = (GameState)Packet.Deserialize(this.readbuffer);
                    DisplayText(statePacket.message, Color.Red);
                    gameStart = statePacket.gameStart;
                    if (!gameStart)
                    {
                        settingTurnChange(-1);
                        System.Threading.Thread.Sleep(2000);
                        Next_Form();
                    }
                    break;
                }

                case (int)PacketType.턴:
                {
                    TurnChange turnPacket = new TurnChange();
                    turnPacket.turnCount = turnCount;
                    turnPacket           = (TurnChange)Packet.Deserialize(this.readbuffer);
                    turnReceived(turnPacket.turn, turnPacket.Word, turnPacket.message, turnPacket.clientscore);
                    break;
                }

                case (int)PacketType.프로필:
                {
                    ClientProfile profile = new ClientProfile();
                    profile = (ClientProfile)Packet.Deserialize(this.readbuffer);
                    string fileName = null;
                    //클라이언트로부터 받은 파일을 쓴다.
                    if (fileStrm != null)
                    {
                        fileStrm.Write(profile.buffer, 0, profile.buffer.Length);
                        countRead++;
                        if (countRead == profile.count)
                        {
                            fileName = fileStrm.Name;
                            fileStrm.Close();
                            fileStrm  = null;
                            countRead = 0;
                            if (profile.clientNum > client_number)
                            {
                                switch (profile.clientNum)
                                {
                                case 1: this.Invoke(new MethodInvoker(delegate() { nickNameList.Add(profile.nickName); })); break;

                                case 2: this.Invoke(new MethodInvoker(delegate() { nickNameList.Add(profile.nickName); })); break;

                                case 3: this.Invoke(new MethodInvoker(delegate() { nickNameList.Add(profile.nickName); })); break;
                                }
                            }
                            setProfile(profile.clientNum);
                        }
                    }
                    break;
                }

                case (int)PacketType.초기화:
                {
                    Init init = new Init();
                    init          = (Init)Packet.Deserialize(this.readbuffer);
                    client_number = init.clinetNumber;           //자신의 클라이언트 넘버 초기화
                    break;
                }

                case (int)PacketType.닉네임:       //6.13 초기화랑 닉네임 바꿈 -> initReceive함수 옮김
                {
                    NickName nick_name = new NickName();
                    nick_name = (NickName)Packet.Deserialize(this.readbuffer);
                    initReceived(nick_name.nickNameList, nick_name.client_sum);
                    break;
                }
                }
            }
        }
Example #8
0
 private void WriteTurnChangeInList(TurnChange currentTurnChange)
 {
     changeList.Add(currentTurnChange);
     AddTurnChangeToRewindSidebar(currentTurnChange);
 }
Example #9
0
        private void OnRequest(int requestType, byte[] readBuffer, int cli_num)
        {   //클라이언트의 리퀘스트 타입을 식별하여 타입에 알맞게 처리
            switch (requestType)
            {
            case (int)PacketType.메세지:
            {
                ClientMessage clientMessage = new ClientMessage();
                clientMessage = (ClientMessage)Packet.Deserialize(readBuffer);
                msgReceived(clientMessage.Message, clientMessage.nickName);
                break;
            }

            case (int)PacketType.프로필:
            {
                ClientProfile clientProfile = new ClientProfile();
                clientProfile = (ClientProfile)Packet.Deserialize(readBuffer);
                profileReceived(clientProfile.nickName, clientProfile.buffer, clientProfile.count, cli_num);
                break;
            }

            case (int)PacketType.게임상태:
            {
                GameState statePacket = new GameState();
                statePacket = (GameState)Packet.Deserialize(readBuffer);
                stateReceived(statePacket.gameStart);
                break;
            }

            case (int)PacketType.랭킹:
            {
                Ranking rank = new Ranking();
                rank = (Ranking)Packet.Deserialize(readBuffer);
                SendScoreAll();
                break;
            }

            case (int)PacketType.정답:
            {
                TurnChange turnPacket = new TurnChange();
                turnPacket = (TurnChange)Packet.Deserialize(readBuffer);
                DisplayText("Turn Change" + turnPacket.turn.ToString());
                answerReceived(turnPacket.turn, turnPacket.score, turnPacket.message, turnPacket.clientNum);

                break;
            }

            case (int)PacketType.그림정보:
            {
                ClientDrawingInfo drawinfo = new ClientDrawingInfo();
                drawinfo = (ClientDrawingInfo)Packet.Deserialize(readBuffer);
                DisplayText(drawinfo.clientNum + "의 그림 도착");
                fileStrm = new FileStream(Environment.CurrentDirectory + "\\Server\\bin\\Debug\\" + drawinfo.clientNum + "turn.jpg"
                                          , FileMode.Create, FileAccess.Write);
                break;
            }

            case (int)PacketType.그림:
            {
                ClientDrawing draw = new ClientDrawing();
                draw = (ClientDrawing)Packet.Deserialize(readBuffer);
                drawReceived(draw.buffer, draw.count, draw.clientNum);
                break;
            }
            }
        }
Example #10
0
    private void WriteTurnChanges(BoardCell fromBoardCell, BoardCell toBoardCell)
    {
        TurnChange currentTurnChange = new TurnChange(fromBoardCell.CellId, toBoardCell.CellId);

        EventHandler.CallWriteTurnChangesEvent(currentTurnChange);
    }