Пример #1
0
        private void PlayLevel()
        {
            if (picBoxWhole != null)
            {
                groupBoxPuzzle.Controls.Remove(picBoxWhole);
                picBoxWhole.Dispose();
                picBoxWhole = null;
            }

            if (picBoxes == null)
            {
                images   = new Image[currentLevel];
                picBoxes = new PictureBox[currentLevel];
            }

            int numRow = (int)Math.Sqrt(currentLevel);
            int numCol = numRow;
            int unitX  = groupBoxPuzzle.Width / numRow;
            int unitY  = groupBoxPuzzle.Height / numCol;

            int[] indice = new int[currentLevel];

            for (int i = 0; i < currentLevel; i++)
            {
                indice[i] = i;
                if (picBoxes[i] == null)
                {
                    picBoxes[i]             = new MyPictureBox();
                    picBoxes[i].Click      += new EventHandler(OnPuzzleClick);
                    picBoxes[i].BorderStyle = BorderStyle.Fixed3D;
                }
                picBoxes[i].Width  = unitX;
                picBoxes[i].Height = unitY;
                ((MyPictureBox)picBoxes[i]).Index = i;

                CreateBitmapImage(image, images, i, numRow, numCol, unitX, unitY);

                picBoxes[i].Location = new Point(unitX * (i % numCol), unitY * (i / numCol));

                if (!groupBoxPuzzle.Controls.Contains(picBoxes[i]))
                {
                    groupBoxPuzzle.Controls.Add(picBoxes[i]);
                }
            }

            shuffle(ref indice);
            for (int i = 0; i < currentLevel; i++)
            {
                picBoxes[i].Image = images[indice[i]];
                ((MyPictureBox)picBoxes[i]).ImageIndex = indice[i];
            }
        }
Пример #2
0
        private void SwitchImages(MyPictureBox box1, MyPictureBox box2)
        {
            int tmp = box2.ImageIndex;

            box2.Image      = images[box1.ImageIndex];
            box2.ImageIndex = box1.ImageIndex;
            box1.Image      = images[tmp];
            box1.ImageIndex = tmp;

            if (isSuccessful())
            {
                labelStatus.Text = "TEBRİKLER";
            }
        }
Пример #3
0
 public void OnPuzzleClick(object sender, EventArgs e)
 {
     if (firstBox == null)
     {
         firstBox = (MyPictureBox)sender;
         ((MyPictureBox)sender).BorderStyle = BorderStyle.FixedSingle;
     }
     else if (secondBox == null)
     {
         secondBox             = (MyPictureBox)sender;
         firstBox.BorderStyle  = BorderStyle.Fixed3D;
         secondBox.BorderStyle = BorderStyle.FixedSingle;
         SwitchImages(firstBox, secondBox);
         firstBox  = null;
         secondBox = null;
     }
 }