Ejemplo n.º 1
0
        public void ChoiGame()
        {
            if (buttonclicked <= 5)
            {
                while (KiemTra.ThemLuotDi(banchoi, banchoi.MangOChua, nguoichoi, huongdi))
                {
                    ohientai = banchoi.TraViTriOHienTai();
                    if (huongdi == true && nguoichoi == false || huongdi == false && nguoichoi == true)
                    {
                        ohientai--;
                        if (ohientai == -1)
                        {
                            ohientai = 11;
                        }
                    }
                    if (huongdi == false && nguoichoi == false || huongdi == true && nguoichoi == true)
                    {
                        ohientai++;
                        if (ohientai == 12)
                        {
                            ohientai = 0;
                        }
                    }
                    txt_Display.Text    = ("Lượt tiếp tục");
                    txt_Display.Visible = true;
                    txt_Display.Refresh();

                    banchoi.RaiQuan(banchoi.GetHoleArray[(ohientai)], nguoichoi, huongdi, MangBanTay, this, btn_Da);
                    //Thread.Sleep(300);
                    txt_Display.Visible = false;
                }
                while ((KiemTra.ThemLuotDi(banchoi, banchoi.MangOChua, nguoichoi, huongdi)) == false)
                {
                    if (huongdi) // huong di ben phai cua nguoi choi 1
                    {
                        #region KhaiBaoBien
                        ohientai = banchoi.TraViTriOHienTai();
                        if (ohientai == 10)
                        {
                            o1 = 11;
                            o2 = 0;
                        }
                        else if (ohientai == 11)
                        {
                            o1 = 0;
                            o2 = 1;
                        }
                        else
                        {
                            o1 = ohientai + 1;
                            o2 = ohientai + 2;
                        }
                        #endregion
                        int kho_a = 12;
                        /*code dang sai*/
                        if (hamcon(kho_a) == -1)
                        {
                            break;
                        }


                        if (ohientai == 11)
                        {
                            ohientai = 1;
                        }
                        else if (ohientai == 10)
                        {
                            ohientai = 0;
                        }
                        else
                        {
                            ohientai += 2;
                        }
                        banchoi.OHienTai = ohientai;
                    }
                    else if (huongdi == false) // huong di qua ben trai cua nguoi 1
                    {
                        #region KhaiBaoBien
                        ohientai = banchoi.TraViTriOHienTai();
                        if (ohientai == 0)
                        {
                            o1 = 11;
                            o2 = 10;
                        }
                        else if (ohientai == 1)
                        {
                            o1 = 0;
                            o2 = 11;
                        }
                        else
                        {
                            o1 = ohientai - 1;
                            o2 = ohientai - 2;
                        }
                        #endregion

                        int kho_a = 12;
                        if (hamcon(kho_a) == -1)
                        {
                            break;
                        }

                        if (ohientai == 0)
                        {
                            ohientai = 10;
                        }
                        else if (ohientai == 1)
                        {
                            ohientai = 11;
                        }
                        else
                        {
                            ohientai -= 2;
                        }
                        banchoi.OHienTai = ohientai;
                    }
                }
                nguoichoi = false;
            }
            else if (nguoichoi == false)
            {
                while (KiemTra.ThemLuotDi(banchoi, banchoi.MangOChua, nguoichoi, huongdi))
                {
                    ohientai = banchoi.TraViTriOHienTai();
                    if (huongdi == true && nguoichoi == false || huongdi == false && nguoichoi == true)
                    {
                        ohientai--;
                    }
                    if (huongdi == false && nguoichoi == false || huongdi == true && nguoichoi == true)
                    {
                        ohientai++;
                        if (ohientai == 12)
                        {
                            ohientai = 0;
                        }
                    }
                    txt_Display.Text    = ("Lượt tiếp tục");
                    txt_Display.Visible = true;
                    txt_Display.Refresh();

                    banchoi.RaiQuan(banchoi.GetHoleArray[(ohientai)], nguoichoi, huongdi, MangBanTay, this, btn_Da);
                    //Thread.Sleep(300);
                    txt_Display.Visible = false;
                }
                while ((KiemTra.ThemLuotDi(banchoi, banchoi.MangOChua, nguoichoi, huongdi)) == false)
                {
                    if (huongdi) // huong di ben phai cua nguoi choi 2
                    {
                        #region KhaiBaoBien
                        ohientai = banchoi.TraViTriOHienTai();
                        if (ohientai == 0)
                        {
                            o1 = 11;
                            o2 = 10;
                        }
                        else if (ohientai == 1)
                        {
                            o1 = 0;
                            o2 = 11;
                        }
                        else
                        {
                            o1 = ohientai - 1;
                            o2 = ohientai - 2;
                        }
                        #endregion
                        int kho_b = 13;
                        if (hamcon(kho_b) == -1)
                        {
                            break;
                        }


                        if (ohientai == 0)
                        {
                            ohientai = 10;
                        }
                        else if (ohientai == 1)
                        {
                            ohientai = 11;
                        }
                        else
                        {
                            ohientai -= 2;
                        }
                        banchoi.OHienTai = ohientai;
                    }
                    else if (huongdi == false) // huong di qua ben trai cua nguoi 2
                    {
                        #region KhaiBaoBien
                        ohientai = banchoi.TraViTriOHienTai();
                        if (ohientai == 10)
                        {
                            o1 = 11;
                            o2 = 0;
                        }
                        else if (ohientai == 11)
                        {
                            o1 = 0;
                            o2 = 1;
                        }
                        else
                        {
                            o1 = ohientai + 1;
                            o2 = ohientai + 2;
                        }
                        #endregion

                        int kho_b = 13;
                        if (hamcon(kho_b) == -1)
                        {
                            break;
                        }

                        if (ohientai == 11)
                        {
                            ohientai = 1;
                        }
                        else if (ohientai == 10)
                        {
                            ohientai = 0;
                        }
                        else
                        {
                            ohientai += 2;
                        }
                        banchoi.OHienTai = ohientai;
                    }
                }
                nguoichoi = true;
            }


            if (nguoichoi == false)
            {
                ptb_player2.Visible = true;
                ptb_player1.Visible = false;
            }
            else
            {
                ptb_player1.Visible = true;
                ptb_player2.Visible = false;
            }
        }