예제 #1
0
파일: CM_Ready.cs 프로젝트: qornwh/C_Shap
 private void btn_Start_Click(object sender, EventArgs e)
 {
     if (on_off == false)
     {
         Ready_Off ready_Off = new Ready_Off();
         byte[]    bytes     = new byte[1024 * 4];
         ready_Off.On   = true;
         ready_Off.type = (int)CM_All.레디;
         Stream stream = new NetworkStream(client.Client);
         bytes = CM_Library.Serialize(ready_Off);
         stream.Write(bytes, 0, bytes.Length);
         stream.Flush();
         on_off = true;
         //ReadyToGame();
         thread1 = new Thread(new ThreadStart(ReadyToGame));
         thread1.Start();
     }
 }
예제 #2
0
파일: CM_Server.cs 프로젝트: qornwh/C_Shap
        public void Request(int Type, byte[] bytes, TcpClient client) //Type에 따라 달라지는 직렬화
        {
            switch (Type)
            {
            case (int)CM_All.메시지:
            {
                Library.Message message = new Library.Message();
                message = (Library.Message)CM_Library.Deserialize(bytes);
                DisplayText(message.MMS);
                //Set_byte(bytes);
                //bytes = CM_Library.Serialize(message);
                //모든 클라이언트에 보내주는 메소드 만들어야함
                for (int i = 0; i < count; i++)
                {
                    Stream stream4 = new NetworkStream(tcpClients[i].Client);
                    stream4.Write(bytes, 0, bytes.Length);
                    stream4.Flush();
                }
                break;
            }

            case (int)CM_All.레디:
            {
                Ready_Off ready_Off = new Ready_Off();
                ready_Off = (Ready_Off)CM_Library.Deserialize(bytes);
                on.On[Number_D[client]] = true;
                on.type = (int)CM_All.자기번호;
                Set_byte(bytes);
                bytes = CM_Library.Serialize(on);
                for (int i = 0; i < count; i++)
                {
                    Stream stream3 = new NetworkStream(tcpClients[i].Client);
                    stream3.Write(bytes, 0, bytes.Length);
                    stream3.Flush();
                }
                break;
            }

            case (int)CM_All.닉네임:
            {
                Login login = new Login();
                login = (Login)CM_Library.Deserialize(bytes);

                //login_D.Add(dictionary, login);
                User_point.Add(login.id, 0);
                Nick.Add(login.id);
                Set_byte(bytes);

                Ready ready = new Ready();
                ready.type = (int)CM_All.클라이언트라벨;
                for (int i = 0; i < count; i++)
                {
                    ready.nickNameList[i] = Nick[i].ToString();
                }
                bytes = CM_Library.Serialize(ready);
                for (int i = 0; i < count; i++)
                {
                    Stream stream2 = new NetworkStream(tcpClients[i].Client);
                    stream2.Write(bytes, 0, bytes.Length);
                    stream2.Flush();
                }
                break;
            }

            case (int)CM_All.좌표:
            {
                //GPoint gPoint = new GPoint();
                //gPoint = (GPoint)CM_Library.Deserialize(bytes);
                for (int i = 0; i < count; i++)
                {
                    if (i != ti_time)
                    {
                        Stream stream1 = new NetworkStream(tcpClients[i].Client);
                        stream1.Write(bytes, 0, bytes.Length);
                        stream1.Flush();
                    }
                }
                break;
            }

            case (int)CM_All.턴:
            {
                ++ti_time;
                if (ti_time == 0)
                {
                    Library.Message mms = new Library.Message();
                    mms.type = (int)CM_All.메시지;
                    mms.MMS  = "게임시작";
                    byte[] buffer = new byte[1024 * 4];
                    buffer = CM_Library.Serialize(mms);
                    foreach (var cl in tcpClients)
                    {
                        Stream stream_2 = new NetworkStream(cl.Client);
                        stream_2.Write(buffer, 0, buffer.Length);
                        stream_2.Flush();
                    }
                }
                Set_byte(bytes);
                Problem problem = new Problem();
                problem.type    = (int)CM_All.문제;
                problem.problem = Allproblem[ti_time].ToString();
                bytes           = CM_Library.Serialize(problem);
                Stream stream0 = new NetworkStream(tcpClients[ti_time].Client);
                stream0.Write(bytes, 0, bytes.Length);
                stream0.Flush();
                break;
            }

            case (int)CM_All.정답:
            {
                /*클라이언트의 답과 제시한 문제의 답과 같을 경우 점수를 주고 마지막 폼4번에서 점수를 출력해준다. <- 만들어야한다*/
                Answer answer = new Answer();
                answer = (Answer)CM_Library.Deserialize(bytes);
                if (Allproblem[ti_time] == answer.txtAnswer)
                {
                    User_point[answer.Nicname] += 10;
                    DisplayText(answer.Nicname + " : " + User_point[answer.Nicname].ToString());
                }
                //모두에게 각자의 점수를 보내준다
                Upoint upoint = new Upoint();
                upoint.Nic   = answer.Nicname;
                upoint.point = User_point[answer.Nicname];
                upoint.type  = (int)CM_All.점수;
                Set_byte(bytes);
                bytes = CM_Library.Serialize(upoint);
                for (int i = 0; i < count; i++)
                {
                    Stream stream_1 = new NetworkStream(tcpClients[i].Client);
                    stream_1.Write(bytes, 0, bytes.Length);
                    stream_1.Flush();
                }
                break;
            }

            case (int)CM_All.처음좌표:
            {
                for (int i = 0; i < count; i++)
                {
                    if (i != ti_time)
                    {
                        Stream stream1 = new NetworkStream(tcpClients[i].Client);
                        stream1.Write(bytes, 0, bytes.Length);
                        stream1.Flush();
                    }
                }
                break;
            }

            case (int)CM_All.그림초기화:
            {
                for (int i = 0; i < count; i++)
                {
                    if (i != ti_time)
                    {
                        Stream stream_2 = new NetworkStream(tcpClients[i].Client);
                        stream_2.Write(bytes, 0, bytes.Length);
                        stream_2.Flush();
                    }
                }
                break;
            }
            }
        }