Exemplo n.º 1
0
 public MoKimCuong()
 {
     for (int i = 0; i < 8; i++)
     {
         for (int j = 0; j < 8; j++)
         {
             kimcuong[i, j] = new KimCuong();
             kimcuong[i, j].BackColor = Color.Black;
             kimcuong[i, j].Location = new Point(10 + 85 * j, 10 + 85 * i);
             kimcuong[i, j].Doc = i;
             kimcuong[i, j].Ngang = j;
             kimcuong[i, j].SoMau = 0;
             kimcuong[i, j].SoTT = i * 8 + j;
         }
     }
 }
Exemplo n.º 2
0
        //timer doi cho
        private void tg_kt_Tick(object sender, EventArgs e)
        {
            tg_cd.Stop();
            KimCuong temp = new KimCuong();
            if (lan == 1)//doi cho lan thu nhat
            {
                point[2] = point[0];
                point[3] = point[1];
                if (mokimcuong.kimcuong[point[1].X, point[1].Y].XuLy == 3)//neu nhu point 1 la o dac biet
                {
                    foreach (KimCuong kc1 in mokimcuong.kimcuong)
                    {
                        if (kc1.SoMau == mokimcuong.kimcuong[point[0].X, point[0].Y].SoMau)
                        {
                            kc1.XuLy = 1;
                        }
                    }
                    Hinhnen[mokimcuong.kimcuong[point[0].X, point[0].Y].SoMau].bm = clip(hinh_an[mokimcuong.kimcuong[point[0].X, point[0].Y].SoMau], 4, 1);
                    Hinhnen[mokimcuong.kimcuong[point[1].X, point[1].Y].SoMau].bm = clip(hinh_an[mokimcuong.kimcuong[point[1].X, point[1].Y].SoMau], 4, 1);
                    mokimcuong.kimcuong[point[1].X, point[1].Y].XuLy = 1;
                    tg_anhinh.Start();
                    tg_kt.Stop();
                    return;
                }
                if (mokimcuong.kimcuong[point[0].X, point[0].Y].XuLy == 3)//neu nhu point 0 la o dac biet
                {
                    foreach (KimCuong kc1 in mokimcuong.kimcuong)
                    {
                        if (kc1.SoMau == mokimcuong.kimcuong[point[1].X, point[1].Y].SoMau)
                        {
                            kc1.XuLy = 1;
                        }
                    }
                    Hinhnen[mokimcuong.kimcuong[point[0].X, point[0].Y].SoMau].bm = clip(hinh_an[mokimcuong.kimcuong[point[0].X, point[0].Y].SoMau], 4, 1);
                    Hinhnen[mokimcuong.kimcuong[point[1].X, point[1].Y].SoMau].bm = clip(hinh_an[mokimcuong.kimcuong[point[1].X, point[1].Y].SoMau], 4, 1);
                    mokimcuong.kimcuong[point[0].X, point[0].Y].XuLy = 1;
                    tg_anhinh.Start();
                    tg_kt.Stop();
                    return;
                }
                if (point[0].X == point[1].X)//neu la hang ngang
                {
                    if (point[0].Y > point[1].Y)
                    {
                        mokimcuong.kimcuong[point[0].X, point[0].Y].Left = mokimcuong.kimcuong[point[0].X, point[0].Y].Left - 17;
                        mokimcuong.kimcuong[point[1].X, point[1].Y].Left = mokimcuong.kimcuong[point[1].X, point[1].Y].Left + 17;
                    }
                    if (point[1].Y > point[0].Y)
                    {
                        mokimcuong.kimcuong[point[0].X, point[0].Y].Left = mokimcuong.kimcuong[point[0].X, point[0].Y].Left + 17;
                        mokimcuong.kimcuong[point[1].X, point[1].Y].Left = mokimcuong.kimcuong[point[1].X, point[1].Y].Left - 17;
                    }

                }
                if (point[0].Y == point[1].Y)
                {
                    if (point[0].X < point[1].X)
                    {
                        mokimcuong.kimcuong[point[0].X, point[0].Y].Top = mokimcuong.kimcuong[point[0].X, point[0].Y].Top + 17;
                        mokimcuong.kimcuong[point[1].X, point[1].Y].Top = mokimcuong.kimcuong[point[1].X, point[1].Y].Top - 17;
                    }
                    if (point[1].X < point[0].X)
                    {
                        mokimcuong.kimcuong[point[0].X, point[0].Y].Top = mokimcuong.kimcuong[point[0].X, point[0].Y].Top - 17;
                        mokimcuong.kimcuong[point[1].X, point[1].Y].Top = mokimcuong.kimcuong[point[1].X, point[1].Y].Top + 17;
                    }
                }
                i++;
                if (i == 5)
                {
                    i = 0;
                    temp = mokimcuong.kimcuong[point[0].X, point[0].Y];
                    mokimcuong.kimcuong[point[0].X, point[0].Y] = mokimcuong.kimcuong[point[1].X, point[1].Y];
                    mokimcuong.kimcuong[point[1].X, point[1].Y] = temp;
                    tg_kt.Stop();
                    KiemTra(ref mokimcuong);

                    if (kiemtratrung(ref mokimcuong) == false)
                    {
                        Point a = new Point();
                        a = point[0];
                        point[0] = point[1];
                        point[1] = a;
                        kt = 1;
                        tg_kt.Start();
                        lan = 2;

                    }

                }
            }
            if (lan == 2)//xu ly nguoc lai neu ko an dc
            {
                point[0] = point[2]; point[1] = point[3];
                if (point[0].X == point[1].X)//neu la hang ngang
                {
                    if (point[0].Y > point[1].Y)
                    {
                        mokimcuong.kimcuong[point[0].X, point[0].Y].Left = mokimcuong.kimcuong[point[0].X, point[0].Y].Left - 17;
                        mokimcuong.kimcuong[point[1].X, point[1].Y].Left = mokimcuong.kimcuong[point[1].X, point[1].Y].Left + 17;
                    }
                    if (point[1].Y > point[0].Y)
                    {
                        mokimcuong.kimcuong[point[0].X, point[0].Y].Left = mokimcuong.kimcuong[point[0].X, point[0].Y].Left + 17;
                        mokimcuong.kimcuong[point[1].X, point[1].Y].Left = mokimcuong.kimcuong[point[1].X, point[1].Y].Left - 17;
                    }

                }
                if (point[0].Y == point[1].Y)
                {
                    if (point[0].X < point[1].X)
                    {
                        mokimcuong.kimcuong[point[0].X, point[0].Y].Top = mokimcuong.kimcuong[point[0].X, point[0].Y].Top + 17;
                        mokimcuong.kimcuong[point[1].X, point[1].Y].Top = mokimcuong.kimcuong[point[1].X, point[1].Y].Top - 17;
                    }
                    if (point[1].X < point[0].X)
                    {
                        mokimcuong.kimcuong[point[0].X, point[0].Y].Top = mokimcuong.kimcuong[point[0].X, point[0].Y].Top - 17;
                        mokimcuong.kimcuong[point[1].X, point[1].Y].Top = mokimcuong.kimcuong[point[1].X, point[1].Y].Top + 17;
                    }
                }
                i++;
                if (i == 5)
                {
                    i = 0;
                    temp = mokimcuong.kimcuong[point[0].X, point[0].Y];
                    mokimcuong.kimcuong[point[0].X, point[0].Y] = mokimcuong.kimcuong[point[1].X, point[1].Y];
                    mokimcuong.kimcuong[point[1].X, point[1].Y] = temp;
                    kt = 0;

                    //AM THANH KO DI CHUYEN
                    Thread a_cntmove = new Thread(new ThreadStart(A_cantmove));
                    a_cntmove.Start();

                    tg_kt.Stop();
                    lan = 1;
                }

            }
        }
Exemplo n.º 3
0
        private void XuLySuKien(object sender, EventArgs e)
        {
            if (cout==3)//chan su kien click khi game over
            {
                return;
            }
            if (kt==1)
            {
                return;
            }
            tg_progress.Start();
            point[0].X = 0; point[0].Y = 0;
            point[1].X = 0; point[1].Y = 0;
            KimCuong kc = new KimCuong();
            kc = (KimCuong)sender;
            kc.TrangThai = true;//trang thai dang kich hoat
            if (kc.SoMau == 0)//neu chua bam new game
            {
                kc.TrangThai = false;
                return;
            }
            if (cout == 0)//click lan dau tien
            {

                tg_kt.Stop();
                bitmap = clip(hinh_cd[kc.SoMau], 20, 1);
                tg_cd.Start();
            }
            if (cout == 1)//click lan thu 2
            {
                int dem = 0;
                for (int i = 0; i < 8; i++)//doi cho 2 o gan nhau
                    for (int j = 0; j < 8; j++)
                    {
                        if (mokimcuong.kimcuong[i, j].TrangThai == true)
                        {
                            if (dem == 0)
                            {
                                point[0].X = i;//luu 2 phan tu dang xu ly
                                point[0].Y = j;
                            }
                            if (dem == 1)
                            {
                                point[1].X = i;
                                point[1].Y = j;
                            }
                            dem++;
                        }
                    }

                if (dem == 2)
                {
                    dem = 0;
                    if (point[0].X == point[1].X && (point[0].Y == point[1].Y + 1 || point[0].Y == point[1].Y - 1))
                    {
                        lan = 1;
                        tg_kt.Start();
                    }
                    if (point[0].Y == point[1].Y && (point[0].X == point[1].X + 1 || point[0].X == point[1].X - 1))
                    {
                        lan = 1;
                        tg_kt.Start();
                    }
                }
                foreach (KimCuong kc2 in mokimcuong.kimcuong)
                {
                    kc2.TrangThai = false;
                    XuatHinh();
                }
            }

            cout++;
            if (cout == 2)
            {
                cout = 0;
            }
        }