Ejemplo n.º 1
0
        private void btnReady_Click(object sender, EventArgs e)
        {
            tcpForPlayer.SendData("chiabai");
            string result = tcpForPlayer.ReadData();

            //Nếu người chơi nhận được lượt đánh thì enable btbDanh
            int players = Convert.ToInt32(result[result.Length - 2].ToString());

            op = new int[players - 1];
            int Myturn = Convert.ToInt16(result.Last().ToString());

            op[0] = (Myturn + 1) % players;
            for (int i = 1; i < players - 1; i++)
            {
                op[i] = (op[i - 1] + 1) % players;
            }


            if (result.Contains("turn"))
            {
                result          = result.Remove(result.Length - 6);//Xóa 6 kí tự cuối chuối(là string "turni")
                btnDanh.Enabled = true;
            }
            else
            {
                result = result.Remove(result.Length - 2);
            }
            ConvertToListDouble(BaiHienTai, result);//Convert từ string sang List<double>
            //Kiểm tra xem bài của người cho có tới trắng hay không
            if (XuLyBai.KiemTraToiTrang(BaiHienTai) == true)
            {
                tcpForPlayer.SendData(ConvertToString(BaiHienTai) + "wintrang");
            }

            txbBai.Text = ConvertToString(BaiHienTai);//gọi hàm load hình LoadHinh(BaiHienTai)
            for (int i = 0; i < BaiHienTai.Count(); i++)
            {
                pictureBoxList1[i].Visible     = true;
                pictureBoxList1[i].Image       = Image.FromFile(path + BaiHienTai[i].ToString() + ".png");
                pictureBoxList1[i].BackColor   = Color.White;
                pictureBoxList1[i].BorderStyle = BorderStyle.FixedSingle;
                pictureBoxList1[i].Tag         = BaiHienTai[i];
            }
            btnReady.Enabled = false;
        }
Ejemplo n.º 2
0
        void Danhbai()
        {
            List <double> Buffer = new List <double>();
            //Viết xử lý ở đây:
            //Khi bấm vào 1 quân bài thì sẽ có 1 double được add về buffer
            string input = txtDanh.Text;

            input = input.Trim();
            string[] Input = input.Split(' ');
            foreach (var i in Input)
            {
                Buffer.Add(Convert.ToDouble(i));
            }
            string flag = "";

            if (XuLyBai.KiemTraHopLe(Buffer, BaiCuaDoiThu) == true)//Nếu những quân bài đánh ra hợp lệ thì làm 3 viêc: 1. Xóa những quân bài đã đánh ra khỏi List BaiHienTai; 2.Nếu số quân bài còn lại ==0 thì gán thêm flag win cho server; 3. Trả về kết quả đánh
            {
                string temp;
                temp = ConvertToString(Buffer);
                ResetPictureBoxList2(13);
                HienThiBai(temp);
                //for (int i = 0; i < Buffer.Count(); i++)
                //{
                //    pictureBoxList2[i].BringToFront();
                //    pictureBoxList2[i].Image = Image.FromFile(path + Buffer[i].ToString() + ".png");
                //    pictureBoxList2[i].BackColor = Color.White;
                //    pictureBoxList2[i].BorderStyle = BorderStyle.FixedSingle;
                //}

                foreach (var i in Buffer)
                {
                    BaiHienTai.Remove(i);
                }
                BaiHienTai.Sort();

                for (int i = 0; i < 13; i++)
                {
                    pictureBoxList1[i].Image       = null;
                    pictureBoxList1[i].BackColor   = this.BackColor;
                    pictureBoxList1[i].BorderStyle = BorderStyle.None;
                    pictureBoxList1[i].Location    = new Point(pictureBoxList1[i].Location.X, Y);
                    pictureBoxList1[i].Tag         = null;
                    txtDanh.Clear();
                }

                for (int i = BaiHienTai.Count(); i < 13; i++)
                {
                    pictureBoxList1[i].Visible = false;
                }

                for (int i = 0; i < BaiHienTai.Count(); i++)
                {
                    pictureBoxList1[i].Image       = Image.FromFile(path + BaiHienTai[i].ToString() + ".png");
                    pictureBoxList1[i].BackColor   = Color.White;
                    pictureBoxList1[i].BorderStyle = BorderStyle.FixedSingle;
                    pictureBoxList1[i].Tag         = BaiHienTai[i];
                }
                //Gọi hàm load hình LoadHinh(Buffer)

                txbBai.Text = ConvertToString(BaiHienTai);// gọi hàm load hinh; LoadHinh(BaiHienTai)
                if (BaiHienTai.Count == 0)
                {
                    flag = "win";
                    BaiCuaDoiThu.Clear();
                    btnReady.Enabled = true;
                }
                tcpForPlayer.SendData(ConvertToString(Buffer) + flag);
                Buffer.Clear();
                btnDanh.Enabled   = false;
                btnBoLuot.Enabled = false;
            }
        }