/// <summary> /// Mặc định /// </summary> public Mainform() { InitializeComponent(); server = new DauTruongServer(this, 5); treeView2.Size = treeView1.Size; treeView2.Location = treeView1.Location; treeView2.Visible = false; Controls.Add(treeView2); }
/// <summary> /// Cài đặt chuẩn bị cho việc send /// </summary> /// <param name="serv"></param> public void SetUpSend(DauTruongServer serv) { try { //sock.Send(DauTruongServer._ENCODE.GetBytes("READY")); AsyncCallback sendCallback = new AsyncCallback(serv.SendCallback); sb.Clear(); sb.AppendLine("QUES"); sb.AppendLine(serv.NowQuestion.strContent.ToString()); serv.buffer = DauTruongServer._ENCODE.GetBytes(sb.ToString()); sock.BeginSend(serv.buffer, 0, serv.buffer.Length, SocketFlags.None, sendCallback, this); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// cài đặt trước cho việc nhận /// </summary> /// <param name="serv"></param> public void SetupForRecv(DauTruongServer serv) { try { AsyncCallback receiveData = new AsyncCallback(serv.OnReceive); sock.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, receiveData, this); } catch (Exception ex) { MessageBox.Show("Recieve callback setup failed! {0}", ex.Message); } }
/// <summary> /// Hàm khởi tạo với tham số /// </summary> /// <param name="playerCount">số người chơi</param> /// <param name="timeOut">thời gian trả lời câu hỏi của người chơi thường</param> /// <param name="QuesCount">số câu hỏi </param> public Mainform(int playerCount, int timeOut, int QuesCount) { InitializeComponent(); server = new DauTruongServer(this, playerCount); treeView2.Size = treeView1.Size; treeView2.Location = treeView1.Location; treeView2.Visible = false; Controls.Add(treeView2); timeOutSecond = timeOut; sendThread = new Thread(SendQues); sendThread.IsBackground = true; easyQuestions = new List<Question>(QuesCount / 2); hardQuestions = new List<Question>(QuesCount - easyQuestions.Capacity); _ContainerList = new List<Question>(easyQuestions.Capacity + hardQuestions.Capacity); }