Exemplo n.º 1
0
        public void puzzle_click(object sender, EventArgs e)
        {
            if (box1 == null)
            {
                box1             = (PtB)sender;
                box1.BorderStyle = BorderStyle.FixedSingle;
            }
            else if (box2 == null)
            {
                box2             = (PtB)sender;
                box1.BorderStyle = BorderStyle.Fixed3D;
                //box2.BorderStyle = BorderStyle.FixedSingle;
                switch_img(box1, box2);
                box1 = box2 = null;
            }
            if (check())
            {
                MessageBox.Show("Đã hoàn thành");
            }

            /*else
             * {
             *  box1 = box2;
             *  box1.BorderStyle = BorderStyle.Fixed3D;
             *  box2 = (PtB)sender;
             *  box2.BorderStyle = BorderStyle.FixedSingle;
             *  switch_img(box1, box2);
             * }*/
        }
Exemplo n.º 2
0
        private void switch_img(PtB _box1, PtB _box2)
        {
            int temp   = _box2.ImageID;
            PtB _box_t = new PtB();

            _box_t.Image  = _box2.Image;
            _box2.Image   = _box1.Image;
            _box2.ImageID = _box1.ImageID;
            _box1.Image   = _box_t.Image;
            _box1.ImageID = temp;

            /*if(check())
             * {
             *  MessageBox.Show("Đã hoàn thành");
             * }*/
        }
Exemplo n.º 3
0
        private void make_lv(int x)
        {
            if (box != null)
            {
                puzzle.Controls.Remove(box);
                box.Dispose();
                box = null;
            }
            if (box == null)
            {
                boxs   = new PictureBox[x * x];
                images = new Image[x * x];
            }
            int size = puzzle.Width / x;

            int[] id = new int[x * x];

            try
            {
                for (int i = 0; i < x * x; i++)
                {
                    id[i] = i;
                    if (boxs[i] == null)
                    {
                        boxs[i]             = new PtB();
                        boxs[i].BorderStyle = BorderStyle.Fixed3D;
                        boxs[i].Click      += new EventHandler(puzzle_click);
                    }
                    boxs[i].Width        = boxs[i].Height = size;
                    ((PtB)boxs[i]).Index = i;

                    cre_bitmap(image, images, i, x, size);

                    boxs[i].Location = new Point(size * (i % x), size * (i / x));
                    if (!puzzle.Controls.Contains(boxs[i]))
                    {
                        puzzle.Controls.Add(boxs[i]);
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Chưa chọn ảnh");
                return;
            }

            clue  = new int[x * x, x *x];
            suufe = new int[x, x];
            suffle(ref id);
            for (int i = 0; i < x * x; i++)
            {
                //boxs[i].Image = images[id[i]];
                images[i].Tag = id[i];
                //((PtB)boxs[i]).ImageID = id[i];
            }
            int count = 0;

            for (int i = 0; i < x; i++)
            {
                for (int j = 0; j < x; j++)
                {
                    suufe[i, j] = id[count];
                    count++;
                }
            }

            suffle(ref id);
            for (int i = 0; i < x * x; i++)
            {
                for (int j = 0; j < x * x; j++)
                {
                    if (Int32.Parse(images[j].Tag.ToString()) == id[i])
                    {
                        boxs[i].Image          = images[j];
                        ((PtB)boxs[i]).ImageID = id[i];
                        break;
                    }
                }
            }


            /*for(int i =0;i<x;i++)
             * {
             *  for(int j=0;j<x;j++)
             *  {
             *      suufe[i, j] = Int32.Parse(images[count].Tag.ToString());
             *      count++;
             *  }
             * }*/


            for (int i = 0; i < x * x; i++)
            {
                for (int j = 0; j < x * x; j++)
                {
                    clue[i, j] = 0;
                }
            }
        }