public void Receive() { string msg = null; // 내가 받을 메세지 or 쓸 메세지 int w, x, y, z; //받을 그림의 좌표 int draw; //drawmode int rgb; Color color; Pen newpen; try { //상대방과 연결되었다면 do { msg = reader.ReadLine(); //라인 단위로 문자열 읽어오기 string[] temp = msg.Split(':'); if (temp[0] == "nickname") { // wnd.label1.Text = temp[1]; CSafeSetText(wnd.label1, temp[1]); //wnd.changeLabel(wnd.label1, temp[1]); } else if (temp[0] == "chat") { wnd.Add_MSG("[" + wnd.label1.Text + "]" + temp[1]); if (temp[1] == wnd.label6.Text) { msg = "정답입니다."; wnd.Add_MSG(msg); Send("answer:" + msg); wnd.saveData.Clear(); // wnd.label6.Text = ""; CSafeSetText(wnd.label6, ""); ControlToPanel(wnd.panel1); wnd.mycount = 60; wnd.turn = !wnd.turn; } } else if (temp[0] == "paint") // 무브 { //wnd.Add_MSG(temp[1] + ", "+temp[2]); //좌표받기 w = Int32.Parse(temp[1]); //받은 그림 x좌표(start) x = Int32.Parse(temp[2]); //받은 그림 y좌표(start) y = Int32.Parse(temp[3]); //받은 그림 x좌표(end) z = Int32.Parse(temp[4]); //받은 그림 y좌표(end) draw = Int32.Parse(temp[5]); rgb = Int32.Parse(temp[6]); color = Color.FromArgb(rgb); newpen = new Pen(color, 2); Point start = new Point(w, x); //마우스 클릭시 시작 포인트 Point end = new Point(y, z); // 마우스 무브시 엔드포인트 DrawData drawdata = new DrawData(start, end, newpen, draw); drawdata.drawData(wnd.panel1.CreateGraphics()); } else if (temp[0] == "clear") { wnd.saveData.Clear(); ControlToPanel(wnd.panel1); } else if (temp[0] == "answer") //"정답입니다"를 받으면 { wnd.Add_MSG(temp[1]); //내 메세지창에도 정답입니다를 씀 wnd.saveData.Clear(); //그림판 청소 //wnd.panel1.Invalidate();//얘도 //wnd.panel1.Update();//청소햇으니 업데이트 ControlToPanel(wnd.panel1); wnd.mycount = 60; //카운트 초기화 wnd.turn = !wnd.turn; //차례를 바꿈 if (wnd.turn == true) //내 차례이면 { index = wnd.random.Next(0, wnd.answer.Length - 1); //인덱스를 랜덤으로 돌리고 // wnd.label6.Text = wnd.answer[index]; CSafeSetText(wnd.label6, wnd.answer[index]); //그 인덱스에 있는 answer을 문제로 냄 } } } while (msg != null); } catch (Exception ex) { wnd.Add_MSG(ex.Message); } }
public void Receive() //서버 클라 공용 { string msg = null; // 내가 받을 메세지 or 쓸 메세지 int w, x, y, z; //받을 그림의 좌표 int draw; //drawmode의 mode번호 int rgb; //색깔 받아오는 변수 Color color; Pen newpen; try { //상대방과 연결되었다면 string m = wnd.label1.Text; //label1의 텍스트를 가져옴 Send("nickname:" + m); //nickname=temp[0]. m=temp[1] do { msg = reader.ReadLine(); //라인 단위로 문자열 읽어오기 string[] temp = msg.Split(':'); if (temp[0] == "nickname") { //wnd.label2.Text = temp[1]; //닉네임을 받음 CSafeSetText(wnd.label2, temp[1]); //wnd.label2Change(temp[1]); } else if (temp[0] == "chat") { wnd.Add_MSG("[" + wnd.label2.Text + "]" + temp[1]); //이름+대화내용을 보냄 if (temp[1] == wnd.label5.Text) //대화내용 == 답 { msg = "정답입니다."; wnd.Add_MSG(msg); Send("answer:" + msg); wnd.saveData.Clear(); //그림판 청소 CSafeSetText(wnd.label5, ""); CSafeSetText(wnd.panel1, "panel"); ControlToPanel(wnd.panel1); wnd.mycount = 60; //타이머 다시 60초로 바꿈(초기화) wnd.turn = !wnd.turn; //차례를 바꿈 } } //아예 판을 바꿈. 상대팀에서 "정답입니다"를 받았을때 else if (temp[0] == "answer") //"정답입니다"를 받으면 { wnd.Add_MSG(temp[1]); //내 메세지창에도 정답입니다를 씀 wnd.saveData.Clear(); //그림판 청소 CSafeSetText(wnd.panel1, "panel"); wnd.mycount = 60; //카운트 초기화 wnd.turn = !wnd.turn; //차례를 바꿈 if (wnd.turn == true) //다음 차례로 바꿈 { index = wnd.random.Next(0, wnd.answer.Length - 1); //인덱스를 랜덤으로 돌리고 //wnd.label5.Text = wnd.answer[index]; CSafeSetText(wnd.label5, wnd.answer[index]); //그 인덱스에 있는 answer을 문제로 냄 } } else if (temp[0] == "paint") { // wnd.Add_MSG(temp[1] + ", " + temp[2]); //좌표받기 w = Int32.Parse(temp[1]); //받은 그림 x좌표(start) x = Int32.Parse(temp[2]); //받은 그림 y좌표(start) y = Int32.Parse(temp[3]); //받은 그림 x좌표(end) z = Int32.Parse(temp[4]); //받은 그림 y좌표(end) draw = Int32.Parse(temp[5]); //drawMode값, DrawData에서 불러오려고 rgb = Int32.Parse(temp[6]); //RGB를 받아줌 color = Color.FromArgb(rgb); //RGB를 받은 색 newpen = new Pen(color, 2); //위에(RGB로 받은 색) 색으로 만든 펜 Point start = new Point(w, x); //마우스 클릭시 시작 포인트 Point end = new Point(y, z); // 마우스 무브시 엔드포인트 DrawData drawdata = new DrawData(start, end, newpen, draw); //DrawData의 함수 drawData로 받아줌 drawdata.drawData(wnd.panel1.CreateGraphics()); } } while (msg != null); } catch (Exception ex) { wnd.Add_MSG(ex.Message); } }